All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reenqueue IMMED tasks when a higher class wins the pick
@ 2026-11-25 11:50 Kuba Piecuch
  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
  0 siblings, 2 replies; 9+ messages in thread
From: Kuba Piecuch @ 2026-11-25 11:50 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
  Cc: Kuba Piecuch, Peter Zijlstra, sched-ext, linux-kernel

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-30 16:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:50 [RFC PATCHSET sched_ext/for-7.4-fixes] sched_ext: Reenqueue IMMED tasks when a higher class wins the pick Kuba Piecuch
2026-11-25 11:50 ` [RFC PATCH 1/2] " Kuba Piecuch
2026-11-25 12:16   ` sashiko-bot
2026-11-30 11:19     ` Kuba Piecuch
2026-11-27 15:10   ` Tejun Heo
2026-11-30 11:19     ` Kuba Piecuch
2026-11-30 15:11       ` Tejun Heo
2026-11-30 16:26         ` Kuba Piecuch
2026-11-25 11:50 ` [RFC PATCH 2/2] selftests/sched_ext: Add immed_strand test Kuba Piecuch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.