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 11 void scx_tick(struct rq *rq); 12 void init_scx_entity(struct sched_ext_entity *scx); 13 void scx_pre_fork(struct task_struct *p); 14 int scx_fork(struct task_struct *p, struct kernel_clone_args *kargs); 15 void scx_post_fork(struct task_struct *p); 16 void scx_cancel_fork(struct task_struct *p); 17 bool scx_can_stop_tick(struct rq *rq); 18 void scx_rq_activate(struct rq *rq); 19 void scx_rq_deactivate(struct rq *rq); 20 int scx_check_setscheduler(struct task_struct *p, int policy); 21 bool task_should_scx(int policy); 22 bool scx_allow_ttwu_queue(const struct task_struct *p); 23 bool scx_allow_proxy_exec(const struct task_struct *p); 24 void scx_proxy_donor_start(struct rq *rq); 25 void scx_proxy_reenqueue_retry(struct rq *rq, struct task_struct *next); 26 void init_sched_ext_class(void); 27 28 static inline u32 scx_cpuperf_target(s32 cpu) 29 { 30 if (scx_enabled()) 31 return cpu_rq(cpu)->scx.cpuperf_target; 32 else 33 return 0; 34 } 35 36 static inline bool task_on_scx(const struct task_struct *p) 37 { 38 return scx_enabled() && p->sched_class == &ext_sched_class; 39 } 40 41 #ifdef CONFIG_SCHED_CORE 42 bool scx_prio_less(const struct task_struct *a, const struct task_struct *b, 43 bool in_fi); 44 #endif 45 46 #else /* CONFIG_SCHED_CLASS_EXT */ 47 48 static inline void scx_tick(struct rq *rq) {} 49 static inline void scx_pre_fork(struct task_struct *p) {} 50 static inline int scx_fork(struct task_struct *p, struct kernel_clone_args *kargs) { return 0; } 51 static inline void scx_post_fork(struct task_struct *p) {} 52 static inline void scx_cancel_fork(struct task_struct *p) {} 53 static inline u32 scx_cpuperf_target(s32 cpu) { return 0; } 54 static inline bool scx_can_stop_tick(struct rq *rq) { return true; } 55 static inline void scx_rq_activate(struct rq *rq) {} 56 static inline void scx_rq_deactivate(struct rq *rq) {} 57 static inline int scx_check_setscheduler(struct task_struct *p, int policy) { return 0; } 58 static inline bool task_on_scx(const struct task_struct *p) { return false; } 59 static inline bool scx_allow_ttwu_queue(const struct task_struct *p) { return true; } 60 static inline bool scx_allow_proxy_exec(const struct task_struct *p) { return true; } 61 static inline void scx_proxy_donor_start(struct rq *rq) {} 62 static inline void scx_proxy_reenqueue_retry(struct rq *rq, 63 struct task_struct *next) {} 64 static inline void init_sched_ext_class(void) {} 65 66 #endif /* CONFIG_SCHED_CLASS_EXT */ 67 68 #ifdef CONFIG_SCHED_CLASS_EXT 69 void __scx_update_idle(struct rq *rq, bool idle, bool do_notify); 70 71 static inline void scx_update_idle(struct rq *rq, bool idle, bool do_notify) 72 { 73 if (scx_enabled()) 74 __scx_update_idle(rq, idle, do_notify); 75 } 76 #else 77 static inline void scx_update_idle(struct rq *rq, bool idle, bool do_notify) {} 78 #endif 79 80 #ifdef CONFIG_CGROUP_SCHED 81 #ifdef CONFIG_EXT_GROUP_SCHED 82 void scx_tg_init(struct task_group *tg); 83 int scx_tg_online(struct task_group *tg); 84 void scx_tg_offline(struct task_group *tg); 85 int scx_cgroup_can_attach(struct cgroup_taskset *tset); 86 void scx_cgroup_move_task(struct task_struct *p); 87 void scx_cgroup_cancel_attach(struct cgroup_taskset *tset); 88 void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight); 89 void scx_group_set_idle(struct task_group *tg, bool idle); 90 void scx_group_set_bandwidth(struct task_group *tg, u64 period_us, u64 quota_us, u64 burst_us); 91 #else /* CONFIG_EXT_GROUP_SCHED */ 92 static inline void scx_tg_init(struct task_group *tg) {} 93 static inline int scx_tg_online(struct task_group *tg) { return 0; } 94 static inline void scx_tg_offline(struct task_group *tg) {} 95 static inline int scx_cgroup_can_attach(struct cgroup_taskset *tset) { return 0; } 96 static inline void scx_cgroup_move_task(struct task_struct *p) {} 97 static inline void scx_cgroup_cancel_attach(struct cgroup_taskset *tset) {} 98 static inline void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight) {} 99 static inline void scx_group_set_idle(struct task_group *tg, bool idle) {} 100 static inline void scx_group_set_bandwidth(struct task_group *tg, u64 period_us, u64 quota_us, u64 burst_us) {} 101 #endif /* CONFIG_EXT_GROUP_SCHED */ 102 #endif /* CONFIG_CGROUP_SCHED */ 103