Re: [PATCH v2] sched_ext: Don't warn on core-sched forced idle in put_prev_task_scx()

From: Andrea Righi

Date: Mon Jun 29 2026 - 16:07:01 EST


Hi Tejun,

On Mon, Jun 29, 2026 at 09:43:55AM -1000, Tejun Heo wrote:
> put_prev_task_scx() warns when a runnable task drops to a lower
> sched_class without SCX_OPS_ENQ_LAST, assuming balance_one() would
> otherwise keep it running.
>
> Under core scheduling that assumption is wrong: a forced-idle SMT sibling
> reschedules through the core_pick fast path in pick_next_task(), which skips
> pick_task_scx() for the CPU, so balance_one() never runs and a runnable task
> can drop to idle with ENQ_LAST unset. Skip the warning when core scheduling
> is enabled.
>
> v2: Reworded the description per Kuba Piecuch's review. No code change.
>
> Fixes: 7c65ae81ea86 ("sched_ext: Don't call put_prev_task_scx() before picking the next task")
> Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
> ---
> kernel/sched/ext/ext.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 9c9cb9d08bca..503c4d2105ee 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -3092,7 +3092,9 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
> * which should trigger an explicit follow-up scheduling event.
> */
> if (next && sched_class_above(&ext_sched_class, next->sched_class)) {
> - WARN_ON_ONCE(!(sch->ops.flags & SCX_OPS_ENQ_LAST));
> + /* core-sched can force cpu idle while @p is runnable */
> + if (!sched_core_enabled(rq))
> + WARN_ON_ONCE(!(sch->ops.flags & SCX_OPS_ENQ_LAST));

I was wondering if this could be a better check:

WARN_ON_ONCE(sched_cpu_cookie_match(rq, p) &&
!(sch->ops.flags & SCX_OPS_ENQ_LAST));

With this:
- the surrounding branch establishes that runnable p is being replaced by
idle (class below sched_ext),
- the core picker has already stored the selected cookie,
- if p does not match that cookie, this CPU is being forced idle by core
scheduling,
- when core scheduling is disabled, sched_cpu_cookie_match() returns true, so
we preserve the warning
- when core scheduling is enabled and the cookies match the warning is also
preserved.

In theory it should work, unless I'm missing some other edge cases.

Thanks,
-Andrea

> do_enqueue_task(rq, p, SCX_ENQ_LAST, -1);
> } else {
> do_enqueue_task(rq, p, 0, -1);