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

From: Andrea Righi

Date: Mon Sep 14 2026 - 05:10:33 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 kselftests 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
$ vng -a "preempt=lazy nohz_full=8-15" -- tools/testing/selftests/sched_ext/runner -t nohz_tick

kick:
PASSED: 6
SKIPPED: 0
FAILED: 0

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

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 | 146 +++++-
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 | 526 ++++++++++++++++++++++
tools/testing/selftests/sched_ext/nohz_tick.bpf.c | 54 ++-
tools/testing/selftests/sched_ext/nohz_tick.c | 189 +++++++-
14 files changed, 1129 insertions(+), 44 deletions(-)