2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-06-27 10:55:12 +02:00
|
|
|
#ifndef IOPRIO_H
|
|
|
|
|
#define IOPRIO_H
|
|
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
2017-10-04 17:49:01 +02:00
|
|
|
#include <linux/sched/rt.h>
|
2008-01-24 08:52:45 +01:00
|
|
|
#include <linux/iocontext.h>
|
2005-06-27 10:55:12 +02:00
|
|
|
|
2021-07-14 21:56:55 +02:00
|
|
|
#include <uapi/linux/ioprio.h>
|
2012-03-19 15:10:58 -07:00
|
|
|
|
2021-08-11 12:37:02 +09:00
|
|
|
/*
|
|
|
|
|
* Default IO priority.
|
|
|
|
|
*/
|
|
|
|
|
#define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_BE_NORM)
|
|
|
|
|
|
2021-08-11 12:36:59 +09:00
|
|
|
/*
|
|
|
|
|
* Check that a priority value has a valid class.
|
|
|
|
|
*/
|
|
|
|
|
static inline bool ioprio_valid(unsigned short ioprio)
|
|
|
|
|
{
|
|
|
|
|
unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
|
|
|
|
|
|
|
|
|
|
return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-27 10:55:12 +02:00
|
|
|
/*
|
|
|
|
|
* if process has set io priority explicitly, use that. if not, convert
|
|
|
|
|
* the cpu scheduler nice value to an io priority
|
|
|
|
|
*/
|
|
|
|
|
static inline int task_nice_ioprio(struct task_struct *task)
|
|
|
|
|
{
|
|
|
|
|
return (task_nice(task) + 20) / 5;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-07 09:51:23 +02:00
|
|
|
/*
|
|
|
|
|
* This is for the case where the task hasn't asked for a specific IO class.
|
|
|
|
|
* Check for idle and rt task process, and return appropriate IO class.
|
|
|
|
|
*/
|
|
|
|
|
static inline int task_nice_ioclass(struct task_struct *task)
|
|
|
|
|
{
|
|
|
|
|
if (task->policy == SCHED_IDLE)
|
|
|
|
|
return IOPRIO_CLASS_IDLE;
|
2017-10-04 17:49:01 +02:00
|
|
|
else if (task_is_realtime(task))
|
2008-05-07 09:51:23 +02:00
|
|
|
return IOPRIO_CLASS_RT;
|
|
|
|
|
else
|
|
|
|
|
return IOPRIO_CLASS_BE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 10:52:35 +09:00
|
|
|
/*
|
|
|
|
|
* If the calling process has set an I/O priority, use that. Otherwise, return
|
|
|
|
|
* the default I/O priority.
|
|
|
|
|
*/
|
|
|
|
|
static inline int get_current_ioprio(void)
|
|
|
|
|
{
|
|
|
|
|
struct io_context *ioc = current->io_context;
|
|
|
|
|
|
|
|
|
|
if (ioc)
|
|
|
|
|
return ioc->ioprio;
|
2021-08-11 12:37:02 +09:00
|
|
|
return IOPRIO_DEFAULT;
|
2018-11-20 10:52:35 +09:00
|
|
|
}
|
|
|
|
|
|
2005-06-27 10:55:12 +02:00
|
|
|
/*
|
|
|
|
|
* For inheritance, return the highest of the two given priorities
|
|
|
|
|
*/
|
2006-08-21 10:02:50 +02:00
|
|
|
extern int ioprio_best(unsigned short aprio, unsigned short bprio);
|
2005-06-27 10:55:12 +02:00
|
|
|
|
2009-01-05 22:46:26 -05:00
|
|
|
extern int set_task_ioprio(struct task_struct *task, int ioprio);
|
|
|
|
|
|
2018-06-04 10:59:56 -07:00
|
|
|
#ifdef CONFIG_BLOCK
|
2018-05-22 10:52:17 -07:00
|
|
|
extern int ioprio_check_cap(int ioprio);
|
2018-06-04 10:59:56 -07:00
|
|
|
#else
|
|
|
|
|
static inline int ioprio_check_cap(int ioprio)
|
|
|
|
|
{
|
|
|
|
|
return -ENOTBLK;
|
|
|
|
|
}
|
|
|
|
|
#endif /* CONFIG_BLOCK */
|
2018-05-22 10:52:17 -07:00
|
|
|
|
2005-06-27 10:55:12 +02:00
|
|
|
#endif
|