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