ext.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * BPF extensible scheduler class: Documentation/scheduler/sched-ext.rst
  4. *
  5. * Copyright (c) 2022 Meta Platforms, Inc. and affiliates.
  6. * Copyright (c) 2022 Tejun Heo <tj@kernel.org>
  7. * Copyright (c) 2022 David Vernet <dvernet@meta.com>
  8. */
  9. #ifdef CONFIG_SCHED_CLASS_EXT
  10. void scx_tick(struct rq *rq);
  11. void init_scx_entity(struct sched_ext_entity *scx);
  12. void scx_pre_fork(struct task_struct *p);
  13. int scx_fork(struct task_struct *p);
  14. void scx_post_fork(struct task_struct *p);
  15. void scx_cancel_fork(struct task_struct *p);
  16. bool scx_can_stop_tick(struct rq *rq);
  17. void scx_rq_activate(struct rq *rq);
  18. void scx_rq_deactivate(struct rq *rq);
  19. int scx_check_setscheduler(struct task_struct *p, int policy);
  20. bool task_should_scx(int policy);
  21. void init_sched_ext_class(void);
  22. static inline u32 scx_cpuperf_target(s32 cpu)
  23. {
  24. if (scx_enabled())
  25. return cpu_rq(cpu)->scx.cpuperf_target;
  26. else
  27. return 0;
  28. }
  29. static inline bool task_on_scx(const struct task_struct *p)
  30. {
  31. return scx_enabled() && p->sched_class == &ext_sched_class;
  32. }
  33. #ifdef CONFIG_SCHED_CORE
  34. bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
  35. bool in_fi);
  36. #endif
  37. #else /* CONFIG_SCHED_CLASS_EXT */
  38. static inline void scx_tick(struct rq *rq) {}
  39. static inline void scx_pre_fork(struct task_struct *p) {}
  40. static inline int scx_fork(struct task_struct *p) { return 0; }
  41. static inline void scx_post_fork(struct task_struct *p) {}
  42. static inline void scx_cancel_fork(struct task_struct *p) {}
  43. static inline u32 scx_cpuperf_target(s32 cpu) { return 0; }
  44. static inline bool scx_can_stop_tick(struct rq *rq) { return true; }
  45. static inline void scx_rq_activate(struct rq *rq) {}
  46. static inline void scx_rq_deactivate(struct rq *rq) {}
  47. static inline int scx_check_setscheduler(struct task_struct *p, int policy) { return 0; }
  48. static inline bool task_on_scx(const struct task_struct *p) { return false; }
  49. static inline void init_sched_ext_class(void) {}
  50. #endif /* CONFIG_SCHED_CLASS_EXT */
  51. #if defined(CONFIG_SCHED_CLASS_EXT) && defined(CONFIG_SMP)
  52. void __scx_update_idle(struct rq *rq, bool idle, bool do_notify);
  53. static inline void scx_update_idle(struct rq *rq, bool idle, bool do_notify)
  54. {
  55. if (scx_enabled())
  56. __scx_update_idle(rq, idle, do_notify);
  57. }
  58. #else
  59. static inline void scx_update_idle(struct rq *rq, bool idle, bool do_notify) {}
  60. #endif
  61. #ifdef CONFIG_CGROUP_SCHED
  62. #ifdef CONFIG_EXT_GROUP_SCHED
  63. void scx_tg_init(struct task_group *tg);
  64. int scx_tg_online(struct task_group *tg);
  65. void scx_tg_offline(struct task_group *tg);
  66. int scx_cgroup_can_attach(struct cgroup_taskset *tset);
  67. void scx_cgroup_move_task(struct task_struct *p);
  68. void scx_cgroup_finish_attach(void);
  69. void scx_cgroup_cancel_attach(struct cgroup_taskset *tset);
  70. void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight);
  71. void scx_group_set_idle(struct task_group *tg, bool idle);
  72. #else /* CONFIG_EXT_GROUP_SCHED */
  73. static inline void scx_tg_init(struct task_group *tg) {}
  74. static inline int scx_tg_online(struct task_group *tg) { return 0; }
  75. static inline void scx_tg_offline(struct task_group *tg) {}
  76. static inline int scx_cgroup_can_attach(struct cgroup_taskset *tset) { return 0; }
  77. static inline void scx_cgroup_move_task(struct task_struct *p) {}
  78. static inline void scx_cgroup_finish_attach(void) {}
  79. static inline void scx_cgroup_cancel_attach(struct cgroup_taskset *tset) {}
  80. static inline void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight) {}
  81. static inline void scx_group_set_idle(struct task_group *tg, bool idle) {}
  82. #endif /* CONFIG_EXT_GROUP_SCHED */
  83. #endif /* CONFIG_CGROUP_SCHED */