# sched_ext in Linux Kernel 6.12: Dynamic Schedulers with BPF
The Linux kernel 6.12 release introduces the sched_ext scheduler class, allowing dynamic replacement of task scheduling logic via BPF programs. This eliminates the need for patches and kernel rebuilds when experimenting with algorithms. Policies are loaded from user space, with the kernel ensuring safety through a fallback mechanism to SCHED_NORMAL on failures.
The sched_ext class splits responsibilities: the kernel handles dispatch queues (DSQ), task migration, and state management, while the BPF policy decides on classification, rank, and time slice. On task wakeup, the enqueue() hook is invoked; on kernel dispatch, dispatch() is called.
Task Lifecycle in sched_ext
A task wakes up via try_to_wake_up(), and the policy analyzes its characteristics: wakeup patterns, CPU/IO usage, cgroup, and presence of RT policies (SCHED_FIFO, SCHED_RR). The policy places the task into a global or local queue, using virtual time for prioritization.
In dispatch(), the task is dequeued and handed to the kernel via scx_bpf_dispatch() along with a time slice in nanoseconds. Migration is triggered by scx_bpf_kick_cpu() for load balancing or cache locality.
DSQ queues operate in FIFO or priority mode depending on the insertion method:
- scx_bpf_dispatch() — FIFO semantics.
- scx_bpf_dispatch_vtime() — ordering by vtime.
The policy's internal rank (score) does not affect kernel priorities (nice, prio).
Example: scx_horoscope as a Demonstration of Capabilities
The scx_horoscope project uses astrological data to tweak time slices, showcasing the sched_ext pattern. Every 60 seconds, it calculates planet positions, retrogrades, and moon phases to generate coefficients.
Task classification by:
- RT policies.
- Wakeup patterns.
- CPU/IO usage.
- cgroup.
The base time slice is adjusted by multipliers: zodiac signs boost or reduce slices for task types, retrogrades impose a 50% penalty, and full moons give bonuses to interactive tasks. Slices are bounded by min_slice_ns and max_slice_ns.
This is an educational example: real computations with stable operation, but no scientific basis for production use.
Practical Schedulers on sched_ext
The scx ecosystem includes production-oriented policies:
- scx_lavd (Latency-Aware Virtual Deadline): virtual deadlines based on wakeup patterns, reducing 99th percentile latencies by 15–30% vs CFS on desktops.
- scx_rusty: NUMA optimization, minimized migrations, and thermal limit awareness for servers.
- scx_flash: ML predictions from user space via shared memory.
Development cycles have shrunk to hours: build, load, metrics, iterate—no reboots needed.
Tools for Benchmarking
Evaluation via:
/sys/kernel/sched_ext/— dispatch and migration metrics.- bpftrace — event tracing.
- perf sched — context-switch latencies.
- cyclictest — tail latencies.
Focus on percentiles, not averages: tails are critical for responsiveness.
Use cases:
- Game servers: guaranteed slices for game logic, isolation from background tasks.
- Embedded systems: task grouping to reduce switch frequency.
- Cloud: bandwidth guarantees beyond cgroup.
- Audio/video: core reservation, jitter minimization.
Limitations and Development
Dispatch call overhead grows with high switch rates. Logical errors degrade performance without triggering panics. The API is evolving, and the feature remains experimental.
Key points:
- sched_ext in 6.12 with CONFIG_SCHED_CLASS_EXT.
- BPF policies for rapid prototyping.
- Fallback to SCHED_NORMAL on failures.
- Focus on percentiles in benchmarks.
- Applications in latency-critical and NUMA scenarios.
— Editorial Team
No comments yet.