Skip to content

Commit 568894e

Browse files
committed
sched_ext: Add scx_cgroup_enabled to gate cgroup operations and fix scx_tg_online()
If the BPF scheduler does not implement ops.cgroup_init(), scx_tg_online() didn't set SCX_TG_INITED which meant that ops.cgroup_exit(), even if implemented, won't be called from scx_tg_offline(). This is because SCX_HAS_OP(cgroupt_init) is used to test both whether SCX cgroup operations are enabled and ops.cgroup_init() exists. Fix it by introducing a separate bool scx_cgroup_enabled to gate cgroup operations and use SCX_HAS_OP(cgroup_init) only to test whether ops.cgroup_init() exists. Make all cgroup operations consistently use scx_cgroup_enabled to test whether cgroup operations are enabled. scx_cgroup_enabled is added instead of using scx_enabled() to ease planned locking updates. Signed-off-by: Tejun Heo <[email protected]>
1 parent 4269c60 commit 568894e

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

kernel/sched/ext.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,6 +3706,7 @@ bool scx_can_stop_tick(struct rq *rq)
37063706
#ifdef CONFIG_EXT_GROUP_SCHED
37073707

37083708
DEFINE_STATIC_PERCPU_RWSEM(scx_cgroup_rwsem);
3709+
static bool scx_cgroup_enabled;
37093710
static bool cgroup_warned_missing_weight;
37103711
static bool cgroup_warned_missing_idle;
37113712

@@ -3725,8 +3726,7 @@ static void scx_cgroup_warn_missing_weight(struct task_group *tg)
37253726

37263727
static void scx_cgroup_warn_missing_idle(struct task_group *tg)
37273728
{
3728-
if (scx_ops_enable_state() == SCX_OPS_DISABLED ||
3729-
cgroup_warned_missing_idle)
3729+
if (!scx_cgroup_enabled || cgroup_warned_missing_idle)
37303730
return;
37313731

37323732
if (!tg->idle)
@@ -3747,15 +3747,18 @@ int scx_tg_online(struct task_group *tg)
37473747

37483748
scx_cgroup_warn_missing_weight(tg);
37493749

3750-
if (SCX_HAS_OP(cgroup_init)) {
3751-
struct scx_cgroup_init_args args = { .weight = tg->scx_weight };
3750+
if (scx_cgroup_enabled) {
3751+
if (SCX_HAS_OP(cgroup_init)) {
3752+
struct scx_cgroup_init_args args =
3753+
{ .weight = tg->scx_weight };
37523754

3753-
ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, cgroup_init,
3754-
tg->css.cgroup, &args);
3755-
if (!ret)
3755+
ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, cgroup_init,
3756+
tg->css.cgroup, &args);
3757+
if (ret)
3758+
ret = ops_sanitize_err("cgroup_init", ret);
3759+
}
3760+
if (ret == 0)
37563761
tg->scx_flags |= SCX_TG_ONLINE | SCX_TG_INITED;
3757-
else
3758-
ret = ops_sanitize_err("cgroup_init", ret);
37593762
} else {
37603763
tg->scx_flags |= SCX_TG_ONLINE;
37613764
}
@@ -3786,7 +3789,7 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset)
37863789
/* released in scx_finish/cancel_attach() */
37873790
percpu_down_read(&scx_cgroup_rwsem);
37883791

3789-
if (!scx_enabled())
3792+
if (!scx_cgroup_enabled)
37903793
return 0;
37913794

37923795
cgroup_taskset_for_each(p, css, tset) {
@@ -3829,7 +3832,7 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset)
38293832

38303833
void scx_move_task(struct task_struct *p)
38313834
{
3832-
if (!scx_enabled())
3835+
if (!scx_cgroup_enabled)
38333836
return;
38343837

38353838
/*
@@ -3865,7 +3868,7 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset)
38653868
struct cgroup_subsys_state *css;
38663869
struct task_struct *p;
38673870

3868-
if (!scx_enabled())
3871+
if (!scx_cgroup_enabled)
38693872
goto out_unlock;
38703873

38713874
cgroup_taskset_for_each(p, css, tset) {
@@ -3882,7 +3885,7 @@ void scx_group_set_weight(struct task_group *tg, unsigned long weight)
38823885
{
38833886
percpu_down_read(&scx_cgroup_rwsem);
38843887

3885-
if (tg->scx_weight != weight) {
3888+
if (scx_cgroup_enabled && tg->scx_weight != weight) {
38863889
if (SCX_HAS_OP(cgroup_set_weight))
38873890
SCX_CALL_OP(SCX_KF_UNLOCKED, cgroup_set_weight,
38883891
tg_cgrp(tg), weight);
@@ -4054,6 +4057,9 @@ static void scx_cgroup_exit(void)
40544057

40554058
percpu_rwsem_assert_held(&scx_cgroup_rwsem);
40564059

4060+
WARN_ON_ONCE(!scx_cgroup_enabled);
4061+
scx_cgroup_enabled = false;
4062+
40574063
/*
40584064
* scx_tg_on/offline() are excluded through scx_cgroup_rwsem. If we walk
40594065
* cgroups and exit all the inited ones, all online cgroups are exited.
@@ -4129,6 +4135,9 @@ static int scx_cgroup_init(void)
41294135
}
41304136
rcu_read_unlock();
41314137

4138+
WARN_ON_ONCE(scx_cgroup_enabled);
4139+
scx_cgroup_enabled = true;
4140+
41324141
return 0;
41334142
}
41344143

0 commit comments

Comments
 (0)