1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/sched.h>
6 #include <linux/sched/rt.h>
7 #include <linux/iocontext.h>
9 #include <uapi/linux/ioprio.h>
12 * Default IO priority.
14 #define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
17 * Check that a priority value has a valid class.
19 static inline bool ioprio_valid(unsigned short ioprio)
21 unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
23 return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
27 * if process has set io priority explicitly, use that. if not, convert
28 * the cpu scheduler nice value to an io priority
30 static inline int task_nice_ioprio(struct task_struct *task)
32 return (task_nice(task) + 20) / 5;
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.
39 static inline int task_nice_ioclass(struct task_struct *task)
41 if (task->policy == SCHED_IDLE)
42 return IOPRIO_CLASS_IDLE;
43 else if (task_is_realtime(task))
44 return IOPRIO_CLASS_RT;
46 return IOPRIO_CLASS_BE;
50 * If the calling process has set an I/O priority, use that. Otherwise, return
51 * the default I/O priority.
53 static inline int get_current_ioprio(void)
55 struct io_context *ioc = current->io_context;
59 return IOPRIO_DEFAULT;
63 * For inheritance, return the highest of the two given priorities
65 extern int ioprio_best(unsigned short aprio, unsigned short bprio);
67 extern int set_task_ioprio(struct task_struct *task, int ioprio);
70 extern int ioprio_check_cap(int ioprio);
72 static inline int ioprio_check_cap(int ioprio)
76 #endif /* CONFIG_BLOCK */