Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1 | #ifndef IOPRIO_H |
| 2 | #define IOPRIO_H |
Venkat Gopalakrishnan | 76c9b14 | 2013-02-12 16:14:32 -0800 | [diff] [blame] | 3 | #ifdef __KERNEL__ |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4 | #include <linux/sched.h> |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 5 | #include <linux/iocontext.h> |
Venkat Gopalakrishnan | 76c9b14 | 2013-02-12 16:14:32 -0800 | [diff] [blame] | 6 | #endif /* __KERNEL__ */ |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 7 | |
| 8 | /* |
| 9 | * Gives us 8 prio classes with 13-bits of data for each class |
| 10 | */ |
| 11 | #define IOPRIO_BITS (16) |
| 12 | #define IOPRIO_CLASS_SHIFT (13) |
Venkat Gopalakrishnan | 76c9b14 | 2013-02-12 16:14:32 -0800 | [diff] [blame] | 13 | #ifdef __KERNEL__ |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 14 | #define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1) |
| 15 | |
| 16 | #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT) |
| 17 | #define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK) |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 18 | #define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 19 | |
| 20 | #define ioprio_valid(mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE) |
Venkat Gopalakrishnan | 76c9b14 | 2013-02-12 16:14:32 -0800 | [diff] [blame] | 21 | #endif /* __KERNEL__ */ |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * These are the io priority groups as implemented by CFQ. RT is the realtime |
| 25 | * class, it always gets premium service. BE is the best-effort scheduling |
| 26 | * class, the default for any process. IDLE is the idle scheduling class, it |
| 27 | * is only served when no one else is using the disk. |
| 28 | */ |
| 29 | enum { |
| 30 | IOPRIO_CLASS_NONE, |
| 31 | IOPRIO_CLASS_RT, |
| 32 | IOPRIO_CLASS_BE, |
| 33 | IOPRIO_CLASS_IDLE, |
| 34 | }; |
| 35 | |
| 36 | /* |
| 37 | * 8 best effort priority levels are supported |
| 38 | */ |
| 39 | #define IOPRIO_BE_NR (8) |
| 40 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 41 | enum { |
| 42 | IOPRIO_WHO_PROCESS = 1, |
| 43 | IOPRIO_WHO_PGRP, |
| 44 | IOPRIO_WHO_USER, |
| 45 | }; |
| 46 | |
Venkat Gopalakrishnan | 76c9b14 | 2013-02-12 16:14:32 -0800 | [diff] [blame] | 47 | #ifdef __KERNEL__ |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 48 | /* |
| 49 | * if process has set io priority explicitly, use that. if not, convert |
| 50 | * the cpu scheduler nice value to an io priority |
| 51 | */ |
| 52 | #define IOPRIO_NORM (4) |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 53 | static inline int task_ioprio(struct io_context *ioc) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 54 | { |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 55 | if (ioprio_valid(ioc->ioprio)) |
| 56 | return IOPRIO_PRIO_DATA(ioc->ioprio); |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 57 | |
| 58 | return IOPRIO_NORM; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 61 | static inline int task_ioprio_class(struct io_context *ioc) |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 62 | { |
Jens Axboe | fd0928d | 2008-01-24 08:52:45 +0100 | [diff] [blame] | 63 | if (ioprio_valid(ioc->ioprio)) |
| 64 | return IOPRIO_PRIO_CLASS(ioc->ioprio); |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 65 | |
| 66 | return IOPRIO_CLASS_BE; |
| 67 | } |
| 68 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 69 | static inline int task_nice_ioprio(struct task_struct *task) |
| 70 | { |
| 71 | return (task_nice(task) + 20) / 5; |
| 72 | } |
| 73 | |
| 74 | /* |
Jens Axboe | 6d63c27 | 2008-05-07 09:51:23 +0200 | [diff] [blame] | 75 | * This is for the case where the task hasn't asked for a specific IO class. |
| 76 | * Check for idle and rt task process, and return appropriate IO class. |
| 77 | */ |
| 78 | static inline int task_nice_ioclass(struct task_struct *task) |
| 79 | { |
| 80 | if (task->policy == SCHED_IDLE) |
| 81 | return IOPRIO_CLASS_IDLE; |
| 82 | else if (task->policy == SCHED_FIFO || task->policy == SCHED_RR) |
| 83 | return IOPRIO_CLASS_RT; |
| 84 | else |
| 85 | return IOPRIO_CLASS_BE; |
| 86 | } |
| 87 | |
| 88 | /* |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 89 | * For inheritance, return the highest of the two given priorities |
| 90 | */ |
Oleg Nesterov | e014ff8 | 2006-08-21 10:02:50 +0200 | [diff] [blame] | 91 | extern int ioprio_best(unsigned short aprio, unsigned short bprio); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 92 | |
Theodore Ts'o | b3881f7 | 2009-01-05 22:46:26 -0500 | [diff] [blame] | 93 | extern int set_task_ioprio(struct task_struct *task, int ioprio); |
| 94 | |
Venkat Gopalakrishnan | 76c9b14 | 2013-02-12 16:14:32 -0800 | [diff] [blame] | 95 | #endif /* __KERNEL__ */ |
| 96 | #endif /* IOPRIO_H */ |