Linus Torvalds has expressed his readiness to integrate into the Linux kernel 6.11, expected to be released at the end of September, patches implementing the "sched_ext" (SCX) mechanism. This mechanism allows using eBPF to create CPU schedulers that cover almost all aspects of task execution scheduling and CPU resource allocation. Such schedulers can be dynamically loaded and run within the Linux kernel in an eBPF virtual machine where, thanks to JIT compilation, bytecode is translated into machine instructions and executed with the performance of compiled code.
The proposed patches implement a new scheduling class SCHED_EXT, for which the kernel's call priority is set between the classes SCHED_IDLE and SCHED_NORMAL. This prevents BPF handlers tied to SCHED_EXT from affecting tasks already attached to the default task scheduler (SCHED_NORMAL), but allows individual tasks to be attached to SCHED_EXT or to move all processes with priority lower than that of real-time execution for processing using it. If no BPF handlers are tied to SCHED_EXT, all processes moved to the SCHED_EXT class will be handled using the SCHED_NORMAL scheduler. The work of BPF handlers is limited to parsing the queues of tasks waiting to be executed on the CPU (one global queue and one for each CPU core) and selecting the task that should be given CPU resources when a CPU core is freed.
The sched_ext mechanism simplifies the creation of schedulers tailored to specific tasks, allows experimentation with various techniques and scheduling strategies, and enables quick development of working prototypes and the replacement of schedulers on the fly in production infrastructures. For example, using sched_ext, one can create a scheduler that takes into account the specifics of a particular application and dynamically alters its execution scheduling strategy based on system state and other factors.
Currently, about a dozen schedulers based on sched_ext are being developed, with the logic for task scheduling defined in user space and loaded into the kernel in the form of BPF programs:
- scx_layered — a hybrid task scheduler that divides tasks into layers, each with its own scheduling strategy. For example, scx_layered allows certain tasks to be isolated in a separate layer, ensuring specific guaranteed CPU resources or elevating the priority of certain applications. The scheduler is developed by Meta. The user-space BPF generation logic is implemented in Rust.
- scx_rustland — a scheduler optimized for prioritizing interactive tasks against CPU-intensive tasks. For instance, in a test running the game application Terraria simultaneously with kernel compilation, the scx_rustland scheduler achieved a higher FPS in the game compared to the default EEVDF scheduler. The project is developed by an employee of Canonical. The user-space BPF generation logic is implemented in Rust.
- scx_lavd — an implementation of the LAVD (Latency-criticality Aware Virtual Deadline) scheduling algorithm, which takes into account the importance of minimizing latency for specific tasks and uses information about process execution to make CPU resource allocation decisions. The scheduler is developed by Igalia and Valve to reduce latency in computer games and interactive tasks. The user-space BPF generation logic is implemented in Rust.
- scx_rusty, scx_rlfifo, scx_mitosis — examples of schedulers with user-space components in Rust that implement balancing between groups of tasks based on load, a simple FIFO scheduler, and a scheduler for binding task groups to CPU cores.
- scx_central, scx_flatcg, scx_nest, scx_pair, scx_qmap, scx_simple, scx_userland — examples of schedulers with user-space components in C, illustrating various capabilities of sched-ext.
The sched_ext mechanism was initially proposed for consideration by kernel developers in 2022, after which six patch revisions were published. Despite the lack of support in the main kernel, it is possible to install sched_ext through additional packages for distributions like Ubuntu, Arch Linux, Fedora, and NixOS. Canonical is considering including sched_ext components in Ubuntu 24.10, while Valve is working on integrating sched_ext into the Steam Deck. At Meta, a scheduler based on sched_ext is already utilized in their operational infrastructure.
Google is experimenting with its own framework, ghOSt, which allows influencing task scheduler decisions through BPF programs. Currently, efforts are underway to port ghOSt to sched_ext. Google is also advancing the sched_ext port for ChromeOS with the intent to leverage a hybrid scheduler, scx_layered, to reduce latency without using extensions for real-time operation. Oculus is developing the sched_ext port for Android.
Source: opennet.ru
