xref: /openbmc/linux/include/linux/ioprio.h (revision b9544fb5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef IOPRIO_H
3 #define IOPRIO_H
4 
5 #include <linux/sched.h>
6 #include <linux/sched/rt.h>
7 #include <linux/iocontext.h>
8 
9 #include <uapi/linux/ioprio.h>
10 
11 /*
12  * Default IO priority.
13  */
14 #define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0)
15 
16 /*
17  * Check that a priority value has a valid class.
18  */
19 static inline bool ioprio_valid(unsigned short ioprio)
20 {
21 	unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
22 
23 	return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
24 }
25 
26 /*
27  * if process has set io priority explicitly, use that. if not, convert
28  * the cpu scheduler nice value to an io priority
29  */
30 static inline int task_nice_ioprio(struct task_struct *task)
31 {
32 	return (task_nice(task) + 20) / 5;
33 }
34 
35 /*
36  * This is for the case where the task hasn't asked for a specific IO class.
37  * Check for idle and rt task process, and return appropriate IO class.
38  */
39 static inline int task_nice_ioclass(struct task_struct *task)
40 {
41 	if (task->policy == SCHED_IDLE)
42 		return IOPRIO_CLASS_IDLE;
43 	else if (task_is_realtime(task))
44 		return IOPRIO_CLASS_RT;
45 	else
46 		return IOPRIO_CLASS_BE;
47 }
48 
49 #ifdef CONFIG_BLOCK
50 int __get_task_ioprio(struct task_struct *p);
51 #else
52 static inline int __get_task_ioprio(struct task_struct *p)
53 {
54 	return IOPRIO_DEFAULT;
55 }
56 #endif /* CONFIG_BLOCK */
57 
58 static inline int get_current_ioprio(void)
59 {
60 	return __get_task_ioprio(current);
61 }
62 
63 extern int set_task_ioprio(struct task_struct *task, int ioprio);
64 
65 #ifdef CONFIG_BLOCK
66 extern int ioprio_check_cap(int ioprio);
67 #else
68 static inline int ioprio_check_cap(int ioprio)
69 {
70 	return -ENOTBLK;
71 }
72 #endif /* CONFIG_BLOCK */
73 
74 #endif
75