Re: [RFC PATCH 1/2] sched_ext: Reenqueue IMMED tasks when a higher class wins the pick

From: Kuba Piecuch

Date: Mon Nov 30 2026 - 11:26:19 EST


Hi Tejun,

On Mon, 30 Nov 2026 15:11, Tejun Heo wrote:
> This is just from reading the code and I could be wrong, but AFAICS there
> are three cases where wakeup_preempt_scx() finds an IMMED task on the
> local DSQ which doesn't already have a reenqueue scheduled:
>
> 1. The CPU is idle and hasn't picked the task which was just inserted.
>
> 2. The CPU is in dispatch.
>
> 3. The task was inserted with SCX_ENQ_PREEMPT or SCX_ENQ_PREEMPT_LAZY and
> curr hasn't scheduled out yet.
>
> In the first two, the CPU looks to be already on its way to the pick, so
> I don't think there's much difference. In the last one, triggering from
> wakeup_preempt_scx() may be a bit sooner, but that doesn't seem that
> significant to me, especially given that the task was already waiting for
> curr to schedule out, which is the latency the preempt path already
> accepts. Am I missing something?

I think you're right. Put as an invariant: an IMMED task on a local DSQ
either has a reenqueue scheduled, or its CPU is in the pick or has a
resched pending. rq_is_open() only keeps a lone IMMED task in your three
cases, and rq_owned_post_enq() provides the resched for them: through
wakeup_preempt() when next_class is below ext, and through the slice
reset and resched_curr() for PREEMPT. So when a higher class task wakes
up, the CPU is going through __schedule() anyway, and scx_settle_pick()
catches the IMMED tasks there if the pick lands above ext. If the pick
lands on ext (the ext dl_server still has budget, or the woken task got
pushed away), the IMMED task can run right after the pick.

There are two exceptions I know of:

- A forced idle pick consumes the resched and leaves the IMMED task
queued with next_class at idle. That's intended (AFAIK), and a higher
class wakeup goes through wakeup_preempt_idle() there anyway, so we
don't lose anything by removing the reenqueue from
wakeup_preempt_scx().

- Under core scheduling, the core-wide pick can dispatch on a sibling
that has an RT task current. It gets to do_pick_task_scx() on the
sibling through the ext dl_server, which lowers the sibling's
next_class to ext and runs dispatch with SCX_RQ_IN_DISPATCH set, so
rq_owned_post_enq() skips the resched. If the core pick then hands the
sibling its current task, nothing reschedules it, and the IMMED task
stays behind the RT task with next_class stuck at ext. That's the case
Sashiko reported, and I'll fix it in v2.

Dropping the reenqueue from wakeup_preempt_scx() doesn't make this case
worse. That reenqueue only runs when a task of a class above ext wakes
up on the sibling: because of the stale next_class, wakeup_preempt()
calls wakeup_preempt_scx(), and then resched_curr(). The sibling then
goes through __schedule(), which resets next_class from its pick, and
scx_settle_pick() reenqueues the IMMED task if that pick lands above
ext. All that's lost is the time until the sibling reschedules.

So I'll drop the reenqueue from wakeup_preempt_scx() in v2, so that
scx_settle_pick() is the only place.

Thanks,
Kuba