* [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Avoid unnecessary IMMED reenqueues on idle CPUs
@ 2026-10-29 7:35 Andrea Righi
2026-10-29 17:27 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Righi @ 2026-10-29 7:35 UTC (permalink / raw)
To: Tejun Heo, David Vernet, Changwoo Min; +Cc: sched-ext, linux-kernel
When two IMMED tasks wake on an idle CPU, the kernel can unnecessarily
send both back to BPF instead of keeping the first task ready to run.
The first wakeup inserts a task into the local DSQ and raises
rq->next_class to ext before the CPU leaves idle. The second insertion
queues a reenqueue scan. rq_is_open() sees next_class == ext and reports
the CPU unavailable, although it is still idle. The scan then reenqueues
the head along with the task behind it, losing a placement that could
have been honored on the next pick.
Report the rq as open while the CPU is idle, even if a local insertion
has already raised next_class to ext. This keeps the local DSQ head
through the reenqueue scan while IMMED tasks behind it are returned to
BPF.
A local reproducer runs in a four-vCPU virtme-ng guest: two futex
waiters pinned to CPU 0 are woken together from CPU 2, and the BPF
scheduler inserts their wakeups into the local DSQ with SCX_ENQ_IMMED.
Across 10000 pairs, kernel instrumentation counts 9776 unnecessary head
reenqueues while the CPU is idle and next_class is ext. Keeping the idle
CPU open eliminates these head reenqueues.
Fixes: 98d709cba319 ("sched_ext: Implement SCX_ENQ_IMMED")
Reported-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/1548cc9309a6e0894e358262e0b3d4ee@kernel.org
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
Changes in v2:
- Remove the core-scheduling cookie check (Tejun Heo).
- Remove the independent skipped-head bookkeeping fix (Tejun Heo).
- Link to v1:
https://lore.kernel.org/r/20261028165258.3723153-1-arighi@nvidia.com
kernel/sched/ext/ext.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 1b098728676f3..8862e81b63157 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -461,6 +461,14 @@ static bool rq_is_open(struct rq *rq, u64 enq_flags)
* @rq is either picking, in transition to, or running an SCX task.
*/
+ /*
+ * A local insertion can raise next_class to ext while the donor is
+ * still idle. Keep the rq open so that the local DSQ head is not
+ * unnecessarily reenqueued before the CPU can pick it.
+ */
+ if (rq->donor == rq->idle)
+ return true;
+
/*
* If we're in the dispatch path holding rq lock, $donor may or may not
* be ready depending on whether the on-going dispatch decides to extend
--
2.56.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Avoid unnecessary IMMED reenqueues on idle CPUs
2026-10-29 7:35 [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Avoid unnecessary IMMED reenqueues on idle CPUs Andrea Righi
@ 2026-10-29 17:27 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-10-29 17:27 UTC (permalink / raw)
To: Andrea Righi; +Cc: David Vernet, Changwoo Min, sched-ext, linux-kernel
Applied to sched_ext/for-7.4-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-29 17:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 7:35 [PATCH v2 sched_ext/for-7.4-fixes] sched_ext: Avoid unnecessary IMMED reenqueues on idle CPUs Andrea Righi
2026-10-29 17:27 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®