aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ioprio.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/ioprio.h')
-rw-r--r--include/linux/ioprio.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
new file mode 100644
index 000000000000..7811300d88ee
--- /dev/null
+++ b/include/linux/ioprio.h
@@ -0,0 +1,87 @@
1#ifndef IOPRIO_H
2#define IOPRIO_H
3
4#include <linux/sched.h>
5
6/*
7 * Gives us 8 prio classes with 13-bits of data for each class
8 */
9#define IOPRIO_BITS (16)
10#define IOPRIO_CLASS_SHIFT (13)
11#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
12
13#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
14#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
15
16#define ioprio_valid(mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
17
18/*
19 * These are the io priority groups as implemented by CFQ. RT is the realtime
20 * class, it always gets premium service. BE is the best-effort scheduling
21 * class, the default for any process. IDLE is the idle scheduling class, it
22 * is only served when no one else is using the disk.
23 */
24enum {
25 IOPRIO_CLASS_NONE,
26 IOPRIO_CLASS_RT,
27 IOPRIO_CLASS_BE,
28 IOPRIO_CLASS_IDLE,
29};
30
31/*
32 * 8 best effort priority levels are supported
33 */
34#define IOPRIO_BE_NR (8)
35
36asmlinkage int sys_ioprio_set(int, int, int);
37asmlinkage int sys_ioprio_get(int, int);
38
39enum {
40 IOPRIO_WHO_PROCESS = 1,
41 IOPRIO_WHO_PGRP,
42 IOPRIO_WHO_USER,
43};
44
45/*
46 * if process has set io priority explicitly, use that. if not, convert
47 * the cpu scheduler nice value to an io priority
48 */
49#define IOPRIO_NORM (4)
50static inline int task_ioprio(struct task_struct *task)
51{
52 WARN_ON(!ioprio_valid(task->ioprio));
53 return IOPRIO_PRIO_DATA(task->ioprio);
54}
55
56static inline int task_nice_ioprio(struct task_struct *task)
57{
58 return (task_nice(task) + 20) / 5;
59}
60
61/*
62 * For inheritance, return the highest of the two given priorities
63 */
64static inline int ioprio_best(unsigned short aprio, unsigned short bprio)
65{
66 unsigned short aclass = IOPRIO_PRIO_CLASS(aprio);
67 unsigned short bclass = IOPRIO_PRIO_CLASS(bprio);
68
69 if (!ioprio_valid(aprio))
70 return bprio;
71 if (!ioprio_valid(bprio))
72 return aprio;
73
74 if (aclass == IOPRIO_CLASS_NONE)
75 aclass = IOPRIO_CLASS_BE;
76 if (bclass == IOPRIO_CLASS_NONE)
77 bclass = IOPRIO_CLASS_BE;
78
79 if (aclass == bclass)
80 return min(aprio, bprio);
81 if (aclass > bclass)
82 return bprio;
83 else
84 return aprio;
85}
86
87#endif