Skip to content

Commit 33796b9

Browse files
committed
sched_ext, sched/core: Don't call scx_group_set_weight() prematurely from sched_create_group()
During task_group creation, sched_create_group() calls scx_group_set_weight() with CGROUP_WEIGHT_DFL to initialize the sched_ext portion. This is premature and ends up calling ops.cgroup_set_weight() with an incorrect @CGRP before ops.cgroup_init() is called. sched_create_group() should just initialize SCX related fields in the new task_group. Fix it by factoring out scx_tg_init() from sched_init() and making sched_create_group() call that function instead of scx_group_set_weight(). v2: Retain CONFIG_EXT_GROUP_SCHED ifdef in sched_init() as removing it leads to build failures on !CONFIG_GROUP_SCHED configs. Signed-off-by: Tejun Heo <[email protected]> Fixes: 8195136 ("sched_ext: Add cgroup support") Cc: [email protected] # v6.12+
1 parent c50784e commit 33796b9

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

kernel/sched/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8545,7 +8545,7 @@ void __init sched_init(void)
85458545
init_cfs_bandwidth(&root_task_group.cfs_bandwidth, NULL);
85468546
#endif /* CONFIG_FAIR_GROUP_SCHED */
85478547
#ifdef CONFIG_EXT_GROUP_SCHED
8548-
root_task_group.scx_weight = CGROUP_WEIGHT_DFL;
8548+
scx_tg_init(&root_task_group);
85498549
#endif /* CONFIG_EXT_GROUP_SCHED */
85508550
#ifdef CONFIG_RT_GROUP_SCHED
85518551
root_task_group.rt_se = (struct sched_rt_entity **)ptr;
@@ -8985,7 +8985,7 @@ struct task_group *sched_create_group(struct task_group *parent)
89858985
if (!alloc_rt_sched_group(tg, parent))
89868986
goto err;
89878987

8988-
scx_group_set_weight(tg, CGROUP_WEIGHT_DFL);
8988+
scx_tg_init(tg);
89898989
alloc_uclamp_sched_group(tg, parent);
89908990

89918991
return tg;

kernel/sched/ext.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,6 +4092,11 @@ bool scx_can_stop_tick(struct rq *rq)
40924092
DEFINE_STATIC_PERCPU_RWSEM(scx_cgroup_rwsem);
40934093
static bool scx_cgroup_enabled;
40944094

4095+
void scx_tg_init(struct task_group *tg)
4096+
{
4097+
tg->scx_weight = CGROUP_WEIGHT_DFL;
4098+
}
4099+
40954100
int scx_tg_online(struct task_group *tg)
40964101
{
40974102
struct scx_sched *sch = scx_root;

kernel/sched/ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static inline void scx_update_idle(struct rq *rq, bool idle, bool do_notify) {}
7979

8080
#ifdef CONFIG_CGROUP_SCHED
8181
#ifdef CONFIG_EXT_GROUP_SCHED
82+
void scx_tg_init(struct task_group *tg);
8283
int scx_tg_online(struct task_group *tg);
8384
void scx_tg_offline(struct task_group *tg);
8485
int scx_cgroup_can_attach(struct cgroup_taskset *tset);
@@ -88,6 +89,7 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset);
8889
void scx_group_set_weight(struct task_group *tg, unsigned long cgrp_weight);
8990
void scx_group_set_idle(struct task_group *tg, bool idle);
9091
#else /* CONFIG_EXT_GROUP_SCHED */
92+
static inline void scx_tg_init(struct task_group *tg) {}
9193
static inline int scx_tg_online(struct task_group *tg) { return 0; }
9294
static inline void scx_tg_offline(struct task_group *tg) {}
9395
static inline int scx_cgroup_can_attach(struct cgroup_taskset *tset) { return 0; }

0 commit comments

Comments
 (0)