* [PATCH sched_ext/for-7.3] sched_ext: skip ops.set_weight() for disabled tasks
@ 2026-07-10 14:43 Kuba Piecuch
2026-07-10 16:48 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Kuba Piecuch @ 2026-07-10 14:43 UTC (permalink / raw)
To: Tejun Heo, Andrea Righi, Changwoo Min, David Vernet
Cc: linux-kernel, sched-ext, Kuba Piecuch
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.
Signed-off-by: Kuba Piecuch <jpiecuch@google.com>
---
kernel/sched/ext/ext.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 5241b55a58ec..b75d8d71ef4d 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -3673,6 +3673,17 @@ static void reweight_task_scx(struct rq *rq, struct task_struct *p,
if (task_dead_and_done(p))
return;
+ /*
+ * When switching sched_class away from SCX, reweight_task_scx()
+ * is called _after_ scx_disable_task(). Skip calling ops.set_weight()
+ * since the BPF scheduler may have already forgotten the task in
+ * ops.disable().
+ * p->scx.weight will be recalculated in scx_enable_task() if the task
+ * ever returns to SCX class.
+ */
+ if (scx_get_task_state(p) != SCX_TASK_ENABLED)
+ return;
+
p->scx.weight = sched_weight_to_cgroup(scale_load_down(lw->weight));
if (SCX_HAS_OP(sch, set_weight))
SCX_CALL_OP_TASK(sch, set_weight, rq, p, p->scx.weight);
--
2.55.0.795.g602f6c329a-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH sched_ext/for-7.3] sched_ext: skip ops.set_weight() for disabled tasks
2026-07-10 14:43 [PATCH sched_ext/for-7.3] sched_ext: skip ops.set_weight() for disabled tasks Kuba Piecuch
@ 2026-07-10 16:48 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-07-10 16:48 UTC (permalink / raw)
To: Kuba Piecuch
Cc: Andrea Righi, Changwoo Min, David Vernet, Emil Tsalapatis,
linux-kernel, sched-ext
Hello,
Applied to sched_ext/for-7.2-fixes, thanks.
Added a Fixes: tag and stable Cc. The reversed set_weight()/disable()
ordering is a regression from the commit that moved ops.disable() ahead
of reweight_task_scx(), so it goes back to v6.19:
Fixes: 637b0682821b ("sched: Fold sched_class::switch{ing,ed}_{to,from}() into the change pattern")
Cc: stable@vger.kernel.org # v6.19+
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-10 16:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 14:43 [PATCH sched_ext/for-7.3] sched_ext: skip ops.set_weight() for disabled tasks Kuba Piecuch
2026-07-10 16:48 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox