[PATCH 3/8] sched_ext: Relocate scx_cgroup_enabled
Tejun Heo <[email protected]> Fri, 17 Jul 2026 22:17:22 -1000
| Newsgroups | dev.linux.lists.sched-ext,org.kernel.vger.cgroups,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
scx_cgroup_enabled is in the CONFIG_EXT_GROUP_SCHED block. The upcoming cgroup migration re-homing needs the gate outside the block. Move the definition and flag flips outside CONFIG_EXT_GROUP_SCHED. No functional changes. Signed-off-by: Tejun Heo <[email protected]> --- kernel/sched/ext/ext.c | 18 ++++++++++++------ kernel/sched/ext/internal.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index 145bda57b6fe..cd99947b4229 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -80,6 +80,14 @@ static bool scx_switching_all; DEFINE_STATIC_KEY_FALSE(__scx_switched_all); static DEFINE_STATIC_KEY_FALSE(__scx_tid_to_task_enabled); +/* + * Gates cgroup ops delivery. Set at the end of the cgroup init phase of root + * enable and cleared before root disable starts tearing down tasks, both under + * scx_cgroup_lock(). Holding cgroup_lock() and seeing %true guarantees no race + * against root tearing down tasks. + */ +bool scx_cgroup_enabled; + /* * True once SCX_OPS_TID_TO_TASK has been negotiated with the root scheduler * and the tid->task table is live. Wraps the static key so callers don't @@ -4309,7 +4317,6 @@ bool scx_can_stop_tick(struct rq *rq) #ifdef CONFIG_EXT_GROUP_SCHED DEFINE_STATIC_PERCPU_RWSEM(scx_cgroup_ops_rwsem); -static bool scx_cgroup_enabled; void scx_tg_init(struct task_group *tg) { @@ -4689,8 +4696,6 @@ static void scx_cgroup_exit(struct scx_sched *sch) { struct cgroup_subsys_state *css; - scx_cgroup_enabled = false; - /* * scx_tg_on/offline() are excluded through cgroup_lock(). If we walk * cgroups and exit all the inited ones, all online cgroups are exited. @@ -4745,9 +4750,6 @@ static int scx_cgroup_init(struct scx_sched *sch) tg->scx.flags |= SCX_TG_INITED; } - WARN_ON_ONCE(scx_cgroup_enabled); - scx_cgroup_enabled = true; - return 0; } @@ -5971,6 +5973,7 @@ static void scx_root_disable(struct scx_sched *sch) * doesn't race against scx_disable_and_exit_task(). */ scx_cgroup_lock(); + scx_cgroup_enabled = false; scx_cgroup_exit(sch); scx_cgroup_unlock(); @@ -7234,6 +7237,9 @@ static void scx_root_enable_workfn(struct kthread_work *work) if (ret) goto err_disable_unlock_all; + WARN_ON_ONCE(scx_cgroup_enabled); + scx_cgroup_enabled = true; + scx_task_iter_start(&sti, NULL); while ((p = scx_task_iter_next_locked(&sti))) { /* diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h index 4f4130f0d121..d76ac22019af 100644 --- a/kernel/sched/ext/internal.h +++ b/kernel/sched/ext/internal.h @@ -1949,6 +1949,7 @@ __printf(3, 0) s32 scx_bstr_format(struct scx_sched *sch, struct scx_bstr_buf *b extern raw_spinlock_t scx_sched_lock; extern struct mutex scx_enable_mutex; extern struct percpu_rw_semaphore scx_fork_rwsem; +extern bool scx_cgroup_enabled; extern raw_spinlock_t scx_exit_bstr_buf_lock; extern struct scx_bstr_buf scx_exit_bstr_buf; #ifdef CONFIG_EXT_SUB_SCHED -- 2.55.0