Re: SCX_ENQ_IMMED potentially leaving dispatched tasks lingering on local DSQs
From: Kuba Piecuch
Date: Thu Apr 23 2026 - 06:03:22 EST
Hi Tejun,
On Wed Apr 22, 2026 at 4:50 PM UTC, Tejun Heo wrote:
> Hello, Kuba.
>
> On Wed, Apr 22, 2026 at 01:21:27PM +0000, Kuba Piecuch wrote:
>> diff --git i/kernel/sched/ext.c w/kernel/sched/ext.c
>> index d66fea57ee69..480627fdc203 100644
>> --- i/kernel/sched/ext.c
>> +++ w/kernel/sched/ext.c
>> @@ -3079,8 +3079,11 @@ do_pick_task_scx(struct rq *rq, struct rq_flags *rf, bool force_scx)
>> * If @force_scx is true, always try to pick a SCHED_EXT task,
>> * regardless of any higher-priority sched classes activity.
>> */
>> - if (!force_scx && rq_modified_above(rq, &ext_sched_class))
>> + if (!force_scx && rq_modified_above(rq, &ext_sched_class)) {
>> + if (rq->scx.nr_immed)
>> + schedule_reenq_local(rq, 0);
>> return RETRY_TASK;
>> + }
>>
>> keep_prev = rq->scx.flags & SCX_RQ_BAL_KEEP;
>> if (unlikely(keep_prev &&
>
> Ah, good catch.
>
>> ...but I think this only fixes the case where the RT task wakes up on the CPU
>> that is doing the dispatch. The other case is one where the RT task wakes up
>> on the remote CPU (the one the second task was dispatched to) after insertion
>> of the second task, assuming the remote CPU is initially idle.
>>
>> To fix both cases, one potential solution that comes to mind is bumping
>> rq->next_class to &ext_sched_class when inserting a task into rq->scx.local_dsq.
>> Perhaps we should call wakeup_preempt() in dispatch_to_local_dsq()?
>
> I think what's missing is wakeup_preempt() call in
> move_remote_task_to_local_dsq(). This is SCX's version of move_queued_task()
> and we're missing wakeup_preempt() call after activate_task().
I'm not sure if we should limit ourselves to just remote tasks.
If we call wakeup_preempt(rq, p, flags) when adding @p to @rq's local DSQ
regardless of whether @p/@rq is remote, then I think that should cover all
cases and the patch above wouldn't be needed.
Perhaps local_dsq_post_enq() would be a good place to invoke wakeup_preempt()?
Thanks,
Kuba