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