Skip to content

Commit 0e2f4ab

Browse files
j-piecuchhtejun
authored andcommitted
sched_ext: Skip ops.set_weight() for disabled tasks
When switching a task's sched_class away from sched_ext, we get the following sequence of events in __sched_setscheduler(): sched_change_begin() switched_from_scx() scx_disable_task(p) ops.disable(p) __setscheduler_params() set_load_weight() reweight_task_scx(p) ops.set_weight(p) p->sched_class = next_class; sched_change_end() ... Notably, ops.set_weight() is called _after_ ops.disable(). This violates the expected semantics of the callbacks, the expectation being that ops.disable() can only be followed by ops.exit_task() or ops.enable(). Skipping the weight adjustment for disabled tasks should be harmless since the weight will be recalculated in scx_enable_task() if the task ever rejoins SCX. Fixes: 637b068 ("sched: Fold sched_class::switch{ing,ed}_{to,from}() into the change pattern") Cc: stable@vger.kernel.org # v6.19+ Signed-off-by: Kuba Piecuch <jpiecuch@google.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent e6979d0 commit 0e2f4ab

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

kernel/sched/ext/ext.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,6 +3967,17 @@ static void reweight_task_scx(struct rq *rq, struct task_struct *p,
39673967
if (task_dead_and_done(p))
39683968
return;
39693969

3970+
/*
3971+
* When switching sched_class away from SCX, reweight_task_scx()
3972+
* is called _after_ scx_disable_task(). Skip calling ops.set_weight()
3973+
* since the BPF scheduler may have already forgotten the task in
3974+
* ops.disable().
3975+
* p->scx.weight will be recalculated in scx_enable_task() if the task
3976+
* ever returns to SCX class.
3977+
*/
3978+
if (scx_get_task_state(p) != SCX_TASK_ENABLED)
3979+
return;
3980+
39703981
p->scx.weight = sched_weight_to_cgroup(scale_load_down(lw->weight));
39713982
if (SCX_HAS_OP(sch, set_weight))
39723983
SCX_CALL_OP_TASK(sch, set_weight, rq, p, p->scx.weight);

0 commit comments

Comments
 (0)