xref: /openbmc/linux/include/linux/ioprio.h (revision fc25545e)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
222e2c507SJens Axboe #ifndef IOPRIO_H
322e2c507SJens Axboe #define IOPRIO_H
422e2c507SJens Axboe 
522e2c507SJens Axboe #include <linux/sched.h>
636436440SSebastian Andrzej Siewior #include <linux/sched/rt.h>
7fd0928dfSJens Axboe #include <linux/iocontext.h>
822e2c507SJens Axboe 
906447ae5SOliver Hartkopp #include <uapi/linux/ioprio.h>
10598971bfSTejun Heo 
11598971bfSTejun Heo /*
12e70344c0SDamien Le Moal  * Default IO priority.
13e70344c0SDamien Le Moal  */
14e589f464SJan Kara #define IOPRIO_DEFAULT	IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0)
15e70344c0SDamien Le Moal 
16e70344c0SDamien Le Moal /*
17a553a835SDamien Le Moal  * Check that a priority value has a valid class.
18a553a835SDamien Le Moal  */
ioprio_valid(unsigned short ioprio)19a553a835SDamien Le Moal static inline bool ioprio_valid(unsigned short ioprio)
20a553a835SDamien Le Moal {
21a553a835SDamien Le Moal 	unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
22a553a835SDamien Le Moal 
23a553a835SDamien Le Moal 	return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
24a553a835SDamien Le Moal }
25a553a835SDamien Le Moal 
26a553a835SDamien Le Moal /*
2722e2c507SJens Axboe  * if process has set io priority explicitly, use that. if not, convert
2822e2c507SJens Axboe  * the cpu scheduler nice value to an io priority
2922e2c507SJens Axboe  */
task_nice_ioprio(struct task_struct * task)3022e2c507SJens Axboe static inline int task_nice_ioprio(struct task_struct *task)
3122e2c507SJens Axboe {
3222e2c507SJens Axboe 	return (task_nice(task) + 20) / 5;
3322e2c507SJens Axboe }
3422e2c507SJens Axboe 
3522e2c507SJens Axboe /*
366d63c275SJens Axboe  * This is for the case where the task hasn't asked for a specific IO class.
376d63c275SJens Axboe  * Check for idle and rt task process, and return appropriate IO class.
386d63c275SJens Axboe  */
task_nice_ioclass(struct task_struct * task)396d63c275SJens Axboe static inline int task_nice_ioclass(struct task_struct *task)
406d63c275SJens Axboe {
416d63c275SJens Axboe 	if (task->policy == SCHED_IDLE)
426d63c275SJens Axboe 		return IOPRIO_CLASS_IDLE;
4336436440SSebastian Andrzej Siewior 	else if (task_is_realtime(task))
446d63c275SJens Axboe 		return IOPRIO_CLASS_RT;
456d63c275SJens Axboe 	else
466d63c275SJens Axboe 		return IOPRIO_CLASS_BE;
476d63c275SJens Axboe }
486d63c275SJens Axboe 
49*893e5d32SJan Kara #ifdef CONFIG_BLOCK
50*893e5d32SJan Kara int __get_task_ioprio(struct task_struct *p);
51*893e5d32SJan Kara #else
__get_task_ioprio(struct task_struct * p)52*893e5d32SJan Kara static inline int __get_task_ioprio(struct task_struct *p)
53*893e5d32SJan Kara {
54*893e5d32SJan Kara 	return IOPRIO_DEFAULT;
55*893e5d32SJan Kara }
56*893e5d32SJan Kara #endif /* CONFIG_BLOCK */
57*893e5d32SJan Kara 
get_current_ioprio(void)5864845a1dSDamien Le Moal static inline int get_current_ioprio(void)
5964845a1dSDamien Le Moal {
60*893e5d32SJan Kara 	return __get_task_ioprio(current);
6164845a1dSDamien Le Moal }
6264845a1dSDamien Le Moal 
63b3881f74STheodore Ts'o extern int set_task_ioprio(struct task_struct *task, int ioprio);
64b3881f74STheodore Ts'o 
65b0966e7bSAdam Manzanares #ifdef CONFIG_BLOCK
66aa434577SAdam Manzanares extern int ioprio_check_cap(int ioprio);
67b0966e7bSAdam Manzanares #else
ioprio_check_cap(int ioprio)68b0966e7bSAdam Manzanares static inline int ioprio_check_cap(int ioprio)
69b0966e7bSAdam Manzanares {
70b0966e7bSAdam Manzanares 	return -ENOTBLK;
71b0966e7bSAdam Manzanares }
72b0966e7bSAdam Manzanares #endif /* CONFIG_BLOCK */
73aa434577SAdam Manzanares 
7422e2c507SJens Axboe #endif
75