ioprio.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef IOPRIO_H
  3. #define IOPRIO_H
  4. #include <linux/sched.h>
  5. #include <linux/sched/rt.h>
  6. #include <linux/iocontext.h>
  7. #include <uapi/linux/ioprio.h>
  8. /*
  9. * Default IO priority.
  10. */
  11. #define IOPRIO_DEFAULT IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0)
  12. /*
  13. * Check that a priority value has a valid class.
  14. */
  15. static inline bool ioprio_valid(unsigned short ioprio)
  16. {
  17. unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
  18. return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
  19. }
  20. /*
  21. * if process has set io priority explicitly, use that. if not, convert
  22. * the cpu scheduler nice value to an io priority
  23. */
  24. static inline int task_nice_ioprio(struct task_struct *task)
  25. {
  26. return (task_nice(task) + 20) / 5;
  27. }
  28. /*
  29. * This is for the case where the task hasn't asked for a specific IO class.
  30. * Check for idle and rt task process, and return appropriate IO class.
  31. */
  32. static inline int task_nice_ioclass(struct task_struct *task)
  33. {
  34. if (task->policy == SCHED_IDLE)
  35. return IOPRIO_CLASS_IDLE;
  36. else if (task_is_realtime(task))
  37. return IOPRIO_CLASS_RT;
  38. else
  39. return IOPRIO_CLASS_BE;
  40. }
  41. #ifdef CONFIG_BLOCK
  42. int __get_task_ioprio(struct task_struct *p);
  43. #else
  44. static inline int __get_task_ioprio(struct task_struct *p)
  45. {
  46. return IOPRIO_DEFAULT;
  47. }
  48. #endif /* CONFIG_BLOCK */
  49. static inline int get_current_ioprio(void)
  50. {
  51. return __get_task_ioprio(current);
  52. }
  53. extern int set_task_ioprio(struct task_struct *task, int ioprio);
  54. #ifdef CONFIG_BLOCK
  55. extern int ioprio_check_cap(int ioprio);
  56. #else
  57. static inline int ioprio_check_cap(int ioprio)
  58. {
  59. return -ENOTBLK;
  60. }
  61. #endif /* CONFIG_BLOCK */
  62. #endif