mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCHSET v6 sched_ext/for-7.4] sched_ext: Add lazy preemption support
@ 2026-09-17  7:02 Andrea Righi
  2026-09-17  7:02 ` [PATCH 1/2] " Andrea Righi
  2026-09-17  7:02 ` [PATCH 2/2] selftests/sched_ext: Add lazy preemption tests Andrea Righi
  0 siblings, 2 replies; 3+ messages in thread
From: Andrea Righi @ 2026-09-17  7:02 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min
  Cc: Emil Tsalapatis, Cheng-Yang Chou, sched-ext, linux-kernel

The fair scheduling class can defer a scheduling boundary through lazy
rescheduling, but sched_ext currently exposes only immediate preemption to BPF
schedulers.

This series adds lazy variants of the enqueue and kick preemption flags. They
expire the running sched_ext task's slice while allowing the scheduling boundary
to be deferred until a return to user space or the next scheduler tick.

SCX_OPS_LAZY_SLICE_EXPIRY selects lazy slice expiry by default. Schedulers can
override that default in either direction for individual tasks through
scx_bpf_task_set_slice_expiry(). The helper preserves sub-scheduler task
ownership boundaries. Bypass continues to force immediate rescheduling.

Lazy enqueue and kick requests also restore the scheduler tick when targeting an
infinite-slice task on a NO_HZ_FULL CPU. The reschedule request is set first so
that the dependency update's IPI can serve it on return to user space, while the
restored tick guarantees eventual promotion otherwise.

The selftests cover immediate and lazy preemption, coalescing and precedence
between kick modes, enqueue preemption, per-task slice-expiry overrides, invalid
flags, and lazy preemption of infinite-slice tasks on NO_HZ_FULL CPUs.  The
NO_HZ_FULL cases verify that the tick has stopped before issuing the lazy
request.

Tested in separate virtme-ng runs, covering preempt=lazy and nohz_full:

 $ vng -a "preempt=lazy" -- \
     tools/testing/selftests/sched_ext/runner -t kick

  kick:
    PASSED:  6
    SKIPPED: 0
    FAILED:  0

 $ vng --cpus 4 -a "nohz_full=1-3" -- \
     tools/testing/selftests/sched_ext/runner -t nohz_tick

  nohz_tick:
    CPU 1 received 6 finite-slice ticks
    PASSED:  1
    SKIPPED: 0
    FAILED:  0

The mode-sensitive kick_lazy and kick_tick cases also passed after switching
/sys/kernel/debug/sched/preempt between lazy and full.

Changes in v6:
 - Pack slice_expires_lazy next to scx.disallow instead of growing task_struct
   by eight bytes (Tejun Heo).
 - Correct the SCX_OPS_LAZY_SLICE_EXPIRY documentation for PREEMPT_DYNAMIC and
   bypass (Tejun Heo).
 - Set the lazy reschedule request before restoring the tick dependency, so the
   dependency update's IPI can serve it on return to user space (Tejun Heo).
 - Explain the pinned rq locking and the newly rejected unknown kick flags in
   the patch description (Tejun Heo).
 - Regenerate the enum headers in definition order (Tejun Heo).
 - kselftest: use SCX_OPS_ENQ_LAST to drive kick-test victims through
   ops.stopping() (Tejun Heo).
 - kselftest: poll for the SCX_KICK_WAIT callback after ops.stopping()
   (Tejun Heo).
 - kselftest: skip trace-based tests when their BTF targets are unavailable
   (Tejun Heo).
 - kselftest: verify that the NO_HZ_FULL tick has stopped before testing lazy
   enqueue and kick requests (Tejun Heo).
 - Link to v5: https://lore.kernel.org/r/20260915194611.2674127-1-arighi@nvidia.com

Changes in v5:
 - kselftest: detect static lazy preemption when CONFIG_PREEMPT_DYNAMIC is
   disabled and the sched/preempt debugfs file is unavailable (Cheng-Yang Chou).
 - Link to v4: https://lore.kernel.org/r/20260915090127.2321020-1-arighi@nvidia.com

Changes in v4:
 - Preserve SCX_KICK_WAIT synchronization when it is combined with
   SCX_KICK_PREEMPT_LAZY (Sashiko).
 - Restore the scheduler tick dependency when ops.tick() lazily expires an
   infinite slice, ensuring the request is promoted by a later tick (Sashiko).
 - kselftest: verify that the deferred SCX_KICK_WAIT callback runs (Sashiko).
 - kselftest: keep the kick test controller off the victim CPU and skip cleanly
   when a second allowed CPU is unavailable (Sashiko).
 - kselftest: select the nohz_tick controller from allowed housekeeping CPUs
   outside the NOHZ_FULL mask and skip when the required topology is
   unavailable.
 - Link to v3: https://lore.kernel.org/r/20260914144620.2032614-1-arighi@nvidia.com

Changes in v3:
 - Avoid redundant rq clock updates when restoring the tick dependency and use
   the pinned rq lock helpers for lazy kick delivery (Sashiko).
 - Set PR_SET_PDEATHSIG for the indefinitely spinning kick test workers so they
   don't survive unexpected test-runner exit (Sashiko).
 - Wait for a delta in nr_lazy_victim_running instead of an absolute count that
   may include reschedules from the previous phase (Sashiko).
 - Increase the nohz_tick scheduler watchdog and phase timeouts to tolerate
   scheduling delays in oversubscribed test VMs.
 - Link to v2: https://lore.kernel.org/r/20260914084955.1798562-1-arighi@nvidia.com

Changes in v2:
 - Make lazy slice expiry a per-task property (Tejun Heo).
 - Add scx_bpf_task_set_slice_expiry() for per-task overrides from any sched_ext
   callback (preserving sub-scheduler task ownership).
 - Restore the scheduler tick dependency for lazy enqueue and kick preemption of
   infinite-slice tasks on NO_HZ_FULL CPUs (Tejun Heo).
 - Accumulate immediate and lazy kick requests independently and resolve their
   precedence in kick_one_cpu() (Tejun Heo).
 - Allow PREEMPT|PREEMPT_LAZY and WAIT|PREEMPT_LAZY, immediate preemption, WAIT
   and plain kicks take precedence over lazy preemption (Tejun Heo).
 - Clear both preemption masks together when processing or skipping a preemption
   request (Tejun Heo).
 - Extend the kselftests with combined and ordered kick requests, per-task
   expiry overrides and NO_HZ_FULL coverage.
 - Link to v1: https://lore.kernel.org/r/20260911195800.974364-1-arighi@nvidia.com

Andrea Righi (2):
  sched_ext: Add lazy preemption support
  selftests/sched_ext: Add lazy preemption tests

 include/linux/sched/ext.h                         |   8 +
 kernel/sched/ext/ext.c                            | 152 ++++-
 kernel/sched/ext/internal.h                       |  40 +-
 kernel/sched/ext/sub.c                            |  15 +-
 tools/sched_ext/include/scx/compat.bpf.h          |  17 +
 tools/sched_ext/include/scx/enum_defs.autogen.h   |   3 +
 tools/sched_ext/include/scx/enums.autogen.bpf.h   |   6 +
 tools/sched_ext/include/scx/enums.autogen.h       |   2 +
 tools/sched_ext/include/scx/enums_abi.autogen.h   |   5 +-
 tools/testing/selftests/sched_ext/Makefile        |   1 +
 tools/testing/selftests/sched_ext/kick.bpf.c      | 191 +++++++
 tools/testing/selftests/sched_ext/kick.c          | 655 ++++++++++++++++++++++
 tools/testing/selftests/sched_ext/nohz_tick.bpf.c |  62 +-
 tools/testing/selftests/sched_ext/nohz_tick.c     | 280 ++++++++-
 14 files changed, 1372 insertions(+), 65 deletions(-)

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

end of thread, other threads:[~2026-09-17  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17  7:02 [PATCHSET v6 sched_ext/for-7.4] sched_ext: Add lazy preemption support Andrea Righi
2026-09-17  7:02 ` [PATCH 1/2] " Andrea Righi
2026-09-17  7:02 ` [PATCH 2/2] selftests/sched_ext: Add lazy preemption tests Andrea Righi

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®