blob: da6e8c5efc0d2bf0c764a994ef3ab33240fb8aa0 [file] [log] [blame]
Jens Axboe22e2c502005-06-27 10:55:12 +02001#ifndef IOPRIO_H
2#define IOPRIO_H
Venkat Gopalakrishnan76c9b142013-02-12 16:14:32 -08003#ifdef __KERNEL__
Jens Axboe22e2c502005-06-27 10:55:12 +02004#include <linux/sched.h>
Jens Axboefd0928d2008-01-24 08:52:45 +01005#include <linux/iocontext.h>
Venkat Gopalakrishnan76c9b142013-02-12 16:14:32 -08006#endif /* __KERNEL__ */
Jens Axboe22e2c502005-06-27 10:55:12 +02007
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 Gopalakrishnan76c9b142013-02-12 16:14:32 -080013#ifdef __KERNEL__
Jens Axboe22e2c502005-06-27 10:55:12 +020014#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 Axboe3b181522005-06-27 10:56:24 +020018#define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
Jens Axboe22e2c502005-06-27 10:55:12 +020019
20#define ioprio_valid(mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
Venkat Gopalakrishnan76c9b142013-02-12 16:14:32 -080021#endif /* __KERNEL__ */
Jens Axboe22e2c502005-06-27 10:55:12 +020022
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 */
29enum {
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 Axboe22e2c502005-06-27 10:55:12 +020041enum {
42 IOPRIO_WHO_PROCESS = 1,
43 IOPRIO_WHO_PGRP,
44 IOPRIO_WHO_USER,
45};
46
Venkat Gopalakrishnan76c9b142013-02-12 16:14:32 -080047#ifdef __KERNEL__
Jens Axboe22e2c502005-06-27 10:55:12 +020048/*
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 Axboefd0928d2008-01-24 08:52:45 +010053static inline int task_ioprio(struct io_context *ioc)
Jens Axboe22e2c502005-06-27 10:55:12 +020054{
Jens Axboefd0928d2008-01-24 08:52:45 +010055 if (ioprio_valid(ioc->ioprio))
56 return IOPRIO_PRIO_DATA(ioc->ioprio);
Jens Axboe15c31be2007-07-10 13:43:25 +020057
58 return IOPRIO_NORM;
Jens Axboe22e2c502005-06-27 10:55:12 +020059}
60
Jens Axboefd0928d2008-01-24 08:52:45 +010061static inline int task_ioprio_class(struct io_context *ioc)
Vasily Tarasovc2dea2d2007-07-20 10:06:38 +020062{
Jens Axboefd0928d2008-01-24 08:52:45 +010063 if (ioprio_valid(ioc->ioprio))
64 return IOPRIO_PRIO_CLASS(ioc->ioprio);
Vasily Tarasovc2dea2d2007-07-20 10:06:38 +020065
66 return IOPRIO_CLASS_BE;
67}
68
Jens Axboe22e2c502005-06-27 10:55:12 +020069static inline int task_nice_ioprio(struct task_struct *task)
70{
71 return (task_nice(task) + 20) / 5;
72}
73
74/*
Jens Axboe6d63c272008-05-07 09:51:23 +020075 * 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 */
78static 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 Axboe22e2c502005-06-27 10:55:12 +020089 * For inheritance, return the highest of the two given priorities
90 */
Oleg Nesterove014ff82006-08-21 10:02:50 +020091extern int ioprio_best(unsigned short aprio, unsigned short bprio);
Jens Axboe22e2c502005-06-27 10:55:12 +020092
Theodore Ts'ob3881f72009-01-05 22:46:26 -050093extern int set_task_ioprio(struct task_struct *task, int ioprio);
94
Venkat Gopalakrishnan76c9b142013-02-12 16:14:32 -080095#endif /* __KERNEL__ */
96#endif /* IOPRIO_H */