[PATCHSET v3 sched_ext/for-7.4] sched_ext: Add lazy preemption support

From: Andrea Righi

Date: Mon Sep 14 2026 - 11:14:06 EST


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, ensuring forward progress even when the
target's tick has stopped.

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.

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 -a "preempt=lazy nohz_full=8-15" -- tools/testing/selftests/sched_ext/runner -t nohz_tick

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

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@xxxxxxxxxx

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@xxxxxxxxxx

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 | 153 +++++--
kernel/sched/ext/internal.h | 39 +-
kernel/sched/ext/sub.c | 15 +-
tools/sched_ext/include/scx/compat.bpf.h | 13 +
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 | 166 +++++++
tools/testing/selftests/sched_ext/kick.c | 530 ++++++++++++++++++++++
tools/testing/selftests/sched_ext/nohz_tick.bpf.c | 56 ++-
tools/testing/selftests/sched_ext/nohz_tick.c | 195 +++++++-
14 files changed, 1143 insertions(+), 49 deletions(-)
create mode 100644 tools/testing/selftests/sched_ext/kick.bpf.c
create mode 100644 tools/testing/selftests/sched_ext/kick.c