~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/ioprio.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 /*
 51  * If the task has set an I/O priority, use that. Otherwise, return
 52  * the default I/O priority.
 53  *
 54  * Expected to be called for current task or with task_lock() held to keep
 55  * io_context stable.
 56  */
 57 static inline int __get_task_ioprio(struct task_struct *p)
 58 {
 59         struct io_context *ioc = p->io_context;
 60         int prio;
 61 
 62         if (!ioc)
 63                 return IOPRIO_DEFAULT;
 64 
 65         if (p != current)
 66                 lockdep_assert_held(&p->alloc_lock);
 67 
 68         prio = ioc->ioprio;
 69         if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
 70                 prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
 71                                          task_nice_ioprio(p));
 72         return prio;
 73 }
 74 #else
 75 static inline int __get_task_ioprio(struct task_struct *p)
 76 {
 77         return IOPRIO_DEFAULT;
 78 }
 79 #endif /* CONFIG_BLOCK */
 80 
 81 static inline int get_current_ioprio(void)
 82 {
 83         return __get_task_ioprio(current);
 84 }
 85 
 86 extern int set_task_ioprio(struct task_struct *task, int ioprio);
 87 
 88 #ifdef CONFIG_BLOCK
 89 extern int ioprio_check_cap(int ioprio);
 90 #else
 91 static inline int ioprio_check_cap(int ioprio)
 92 {
 93         return -ENOTBLK;
 94 }
 95 #endif /* CONFIG_BLOCK */
 96 
 97 #endif
 98 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php