Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef IOPRIO_H
0003 #define IOPRIO_H
0004 
0005 #include <linux/sched.h>
0006 #include <linux/sched/rt.h>
0007 #include <linux/iocontext.h>
0008 
0009 #include <uapi/linux/ioprio.h>
0010 
0011 /*
0012  * Default IO priority.
0013  */
0014 #define IOPRIO_DEFAULT  IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0)
0015 
0016 /*
0017  * Check that a priority value has a valid class.
0018  */
0019 static inline bool ioprio_valid(unsigned short ioprio)
0020 {
0021     unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
0022 
0023     return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
0024 }
0025 
0026 /*
0027  * if process has set io priority explicitly, use that. if not, convert
0028  * the cpu scheduler nice value to an io priority
0029  */
0030 static inline int task_nice_ioprio(struct task_struct *task)
0031 {
0032     return (task_nice(task) + 20) / 5;
0033 }
0034 
0035 /*
0036  * This is for the case where the task hasn't asked for a specific IO class.
0037  * Check for idle and rt task process, and return appropriate IO class.
0038  */
0039 static inline int task_nice_ioclass(struct task_struct *task)
0040 {
0041     if (task->policy == SCHED_IDLE)
0042         return IOPRIO_CLASS_IDLE;
0043     else if (task_is_realtime(task))
0044         return IOPRIO_CLASS_RT;
0045     else
0046         return IOPRIO_CLASS_BE;
0047 }
0048 
0049 #ifdef CONFIG_BLOCK
0050 int __get_task_ioprio(struct task_struct *p);
0051 #else
0052 static inline int __get_task_ioprio(struct task_struct *p)
0053 {
0054     return IOPRIO_DEFAULT;
0055 }
0056 #endif /* CONFIG_BLOCK */
0057 
0058 static inline int get_current_ioprio(void)
0059 {
0060     return __get_task_ioprio(current);
0061 }
0062 
0063 extern int set_task_ioprio(struct task_struct *task, int ioprio);
0064 
0065 #ifdef CONFIG_BLOCK
0066 extern int ioprio_check_cap(int ioprio);
0067 #else
0068 static inline int ioprio_check_cap(int ioprio)
0069 {
0070     return -ENOTBLK;
0071 }
0072 #endif /* CONFIG_BLOCK */
0073 
0074 #endif