From: Kuba Piecuch <jpiecuch@google.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>
Cc: Kuba Piecuch <jpiecuch@google.com>,
Peter Zijlstra <peterz@infradead.org>,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [RFC PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reenqueue IMMED tasks when a higher class wins the pick
Date: Wed, 25 Nov 2026 11:50:51 +0000 [thread overview]
Message-ID: <20261125114932.3198836-1-jpiecuch@google.com> (raw)
This is the SCX_ENQ_IMMED fix extracted from the ops.cpu_acquire/release()
RFC, as requested by Tejun:
https://lore.kernel.org/all/657547efeaea54276c50a0c106399366@kernel.org/
SCX_ENQ_IMMED (commit 98d709cba319 ("sched_ext: Implement SCX_ENQ_IMMED"))
relies on rq->next_class to detect when a higher scheduling class is about
to take the CPU: rq_is_open() rejects IMMED insertions while next_class is
above ext, and wakeup_preempt_scx() schedules a reenqueue when a wakeup
raises next_class.
Several paths make a higher-class task runnable or let it win the pick
without passing through wakeup_preempt_scx(), leaving IMMED tasks stranded
on the local DSQ until that task yields:
1) sched_setscheduler() or a PI boost promoting a queued task to RT or DL:
sched_change_end() does not call wakeup_preempt() for non-running
tasks, switched_to_rt() only calls resched_curr(), and switched_to_dl()
calls wakeup_preempt_dl() directly.
2) DL replenishment, CFS bandwidth unthrottling (in partial mode), and RT
group unthrottling enqueue tasks without going through wakeup_preempt().
3) When the ext dl_server picks an SCX task, rq->next_class becomes ext
even though RT tasks are queued; once the server exhausts its budget,
RT takes over without a wakeup.
4) Under core scheduling, a forced-idle pick resets rq->next_class to idle
while tasks remain on the local DSQ. A later RT wakeup on that CPU goes
through wakeup_preempt_idle() instead of wakeup_preempt_scx().
With proxy execution enabled, scx_proxy_reenqueue_retry() already covers
all of these: __schedule() sets rq->next_class from the picked task right
before calling it, so it reenqueues IMMED tasks whenever a higher class
wins the pick, whether or not that task went through wakeup_preempt().
Without proxy execution (CONFIG_SCHED_PROXY_EXEC=n, or sched_proxy_exec=0),
nothing does.
Patch 1 adds scx_settle_pick() to __schedule(), after proxy resolution,
on the path which every pick reaches, independent of proxy execution.
When SCX is enabled, nr_immed is non-zero and rq->next_class (the donor's
class under proxy execution) is above ext, it schedules a deferred local
DSQ reenqueue. rq_is_open() is false when the reenqueue runs after the
context switch, so IMMED tasks are returned to the BPF scheduler.
Core-sched siblings apply remote picks in their own __schedule(), so they
are covered too. The IMMED check in scx_proxy_reenqueue_retry() becomes
redundant and is removed.
A forced idle CPU still doesn't reenqueue IMMED tasks. This matches
rq_is_open(), which returns true while the CPU is forced idle, as
rq->next_class is idle. The IMMED task at the head of the local DSQ waits
for the next core pick.
Patch 2 adds the immed_strand selftest covering the core-scheduling forced
idle case 4). It enables CONFIG_SCHED_CORE in the selftest config because
forced idle is the only case above that strands an IMMED task
deterministically without other non-default options. The promotion in 1),
DL replenishment and the dl_server case 3) reschedule the CPU right away
and only strand a task when racing with an insertion. CFS and RT group
unthrottling need CONFIG_CFS_BANDWIDTH or CONFIG_RT_GROUP_SCHED. The test
is skipped without SMT siblings or core scheduling. Without patch 1 and
with proxy execution disabled (sched_proxy_exec=0), immed_strand fails
with:
immed_strand: CPU 3: inserts=1 reenqs=0 hazards=1 strands=1 max=200419us
Expected bss->nr_strands == 0 (1 == 0)
The patches were written with the help of an AI coding assistant.
Kuba Piecuch (2):
sched_ext: Reenqueue IMMED tasks when a higher class wins the pick
selftests/sched_ext: Add immed_strand test
kernel/sched/core.c | 1 +
kernel/sched/ext/ext.c | 53 ++-
kernel/sched/ext/ext.h | 13 +
tools/testing/selftests/sched_ext/Makefile | 1 +
tools/testing/selftests/sched_ext/config | 1 +
.../selftests/sched_ext/immed_strand.bpf.c | 174 ++++++++
.../selftests/sched_ext/immed_strand.c | 383 ++++++++++++++++++
7 files changed, 617 insertions(+), 9 deletions(-)
create mode 100644 tools/testing/selftests/sched_ext/immed_strand.bpf.c
create mode 100644 tools/testing/selftests/sched_ext/immed_strand.c
base-commit: 97e1c7d467d07734f8f5c8c64730e1f7c415bd46
--
2.56.1.839.g22a8290db9-goog
next reply other threads:[~2026-11-25 11:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 11:50 Kuba Piecuch [this message]
2026-11-25 11:50 ` [RFC PATCH 1/2] " Kuba Piecuch
2026-11-25 11:50 ` [RFC PATCH 2/2] selftests/sched_ext: Add immed_strand test Kuba Piecuch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125114932.3198836-1-jpiecuch@google.com \
--to=jpiecuch@google.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®