Expand description
Loading and running a Rust BPF sched_ext scheduler: the object, the struct_ops map the kernel can take, the configuration table’s kernel entries resolved from BTF, the map sizes set before the load, the attach, the exit record, the arena statistics, the per-callback profiler, the sampler of the per-CID queues, and the CPU capacity and packing tiers the runtime ranks CIDs by. Nothing here is particular to a scheduling policy.
Re-exports§
pub use tiers::Tiers;pub(crate) use collections::BTreeMap;🔒pub(crate) use CString;🔒pub(crate) use OsStr;🔒pub(crate) use AsFd;🔒pub(crate) use AsRawFd;🔒pub(crate) use FromRawFd;🔒pub(crate) use OwnedFd;🔒pub(crate) use ptr::NonNull;🔒pub(crate) use Arc;🔒pub(crate) use AtomicBool;🔒pub(crate) use Ordering;🔒pub(crate) use Duration;🔒pub(crate) use Instant;🔒pub(crate) use Context;🔒pub(crate) use bail;🔒pub(crate) use ensure;🔒pub(crate) use Btf;🔒pub(crate) use Link;🔒pub(crate) use MapCore;🔒pub(crate) use MapFlags;🔒pub(crate) use ObjectBuilder;🔒pub(crate) use OpenObject;🔒pub(crate) use ProgramType;🔒pub(crate) use BtfType;🔒pub(crate) use HasSize;🔒pub(crate) use ReferencesType;🔒pub(crate) use Composite;🔒pub(crate) use Enum;🔒pub(crate) use Enum64;🔒pub(crate) use Func;🔒pub(crate) use FuncProto;🔒pub(crate) use Int;🔒pub(crate) use IntEncoding;🔒pub(crate) use MemberAttr;🔒pub(crate) use Ptr;🔒pub(crate) use Struct;🔒pub(crate) use info;🔒pub(crate) use warn;🔒pub use scx_rustsched_abi as config;pub(crate) use UserExitInfo;🔒pub(crate) use libbpf_clap_opts::LibbpfOpts;🔒
Modules§
- compat
- The kernel’s sched_ext flags, 0 where it lacks one, for a scheduler’s
user space to choose the ops flags it loads with, see
Params::add_flags(). - edq
- The eligible deadline queue, from the source the BPF program is built from: the loader reads the queues in the arena through the same code. Eligible Deadline Queue: an intrusive red-black tree, a port of scx_eevdf’s lib/edq.bpf.c.
- kfunc_
protos 🔒 - Match the return types of the object’s kfunc prototypes to the running kernel’s.
- queues 🔒
- The per-CID queues, observed from the loader. The arena the BPF program
keeps them in is mapped into this process too, at the addresses the
program itself uses, so the loader reads a queue through the same
edqcode the program runs, over a memory that can only load. - tiers
- CPU capacities and asymmetric packing priorities, the loader’s half of scx_rustsched’s tiers.rs and topology.rs. The capacities and the scheduling-domain spans come from scx_utils’ Topology. The ITMT priority and SD_ASYM_PACKING come from the kernel through the rust_cpu_priority() syscall program, since neither has a user-space ABI. The result goes to the BPF program per CPU, which translates it to CIDs at init.
Macros§
- main
- The
main()of a scheduler: the objects its build script left in OUT_DIR, loaded and run by cli(). The scheduler’s options are aclap::Argsstructure, each field named as the tunable it sets, a time in microseconds as the tunable in nanoseconds, and what else the scheduler adds to the loader is itsSchedulerimplementation: - param_
values 🔒
Structs§
- Arena
View - The arena, read through the mapping libbpf made when it created the map. The addresses the BPF program stores are user addresses in that mapping, so they are read as they are. An address outside of it reads as 0. The view keeps the object, and with it the mapping, alive.
- Attached
- The run of an attached scheduler, see
Scheduler::attached(): one method for each thing the loader knows about it. - Capacity
- How the CPUs’ capacities and packing ranks are read for the scheduler, see tiers.rs.
- CidTable
Reader - A per-CID table of the scheduler’s, read from the loader: the one whose
header is in the
.datasectionsection, see scx_rustsched’scid_slot!, withwords64-bit words per CID. For counters each CPU keeps for itself, which cost the scheduling paths no shared write. - Cli 🔒
- The options every scheduler takes, beside its own.
- Loaded
- The attached scheduler’s object, shared. What reads the arena keeps a clone, and with it the arena’s mapping, which goes with the object.
- NoOpts
- The options of a scheduler with no tunables.
- Object
- Represents a loaded BPF object file.
- OpStats
- One struct_ops program’s run count, run time and recursion misses, as the kernel accounts them while the profiler is enabled.
- OpsProfiler
- Each callback is its own BPF program and the kernel keeps a run count and a run time per program once the accounting is switched on. That costs two clock reads around every callback, so it is on only while a stats client is polling and goes away by itself once nobody has asked for a while.
- Params
- The tunables of an object that is open and not loaded yet, the ones it
declares with
scx_rustsched::params!, to set before the load, and the ops flags it is loaded with. It records which tunables were set: run() refuses to start a scheduler that has one nobody set. - Queue
Sampler - Samples the depth of every CID’s queue while a stats client is polling, and parks once nobody has asked for a while, as the callback profiler drops its accounting.
- Queue
Stats - What the sampler saw of one CID’s queue, cumulative.
- RunOptions
- How run() loads and runs a scheduler.
- Stats
- A scheduler’s statistics: what it serves to scx_stats clients, and how
--statsand--monitorprint it. A scheduler has none unless itsScheduler::statsreturns this, built from its two callbacks. - Topology 🔒
- What
Attachedreads off scx_utils’ Topology, once asked.
Constants§
- ARENA_
PAGES 🔒 - The arena’s size in pages, as scheds/include/lib/arena_map.h declares it: address space only, backed by the pages actually allocated. An arena spans at most 4 GiB, which 2^16 pages keep to with 64 KiB pages on arm64.
- EXIT_
DUMP_ DEFAULT - SCX_EXIT_DUMP_DFL_LEN, the dump length the kernel uses for 0.
- EXIT_
UNREG_ 🔒KERN - SCX_EXIT_UNREG_KERN, the last of the graceful exit kinds.
- PARAM_
PREFIX 🔒 - The section of a tunable:
scx_rustsched::params!puts each in a read-only section of its own, named PREFIX NAME “.” TYPE. - POOL_
PAGES - Pages the pool of task slots starts with. It grows as tasks need more.
- UEI_
BYTES 🔒 - Size of struct user_exit_info: kind, exit_cpu, exit_code, a 128-byte reason and a 1024-byte message.
- WATCHDOG_
MAX_ TIMEOUT_ MS - The longest watchdog timeout the kernel takes, SCX_WATCHDOG_MAX_TIMEOUT, which is also what it applies when the timeout is 0.
Traits§
- Param
Value - A value a tunable can hold: an integer or a bool, alone or as the element of an array.
- Scheduler
- What a scheduler adds to the loader, on its options. Every method has a
default, so
impl Scheduler for Opts {}is a scheduler with nothing but the tunables its options name.
Functions§
- arena_
stats - The arena statistics the BPF side keeps, see pool.rs: slots taken and released, validation errors, failed and successful page allocations, and idle-mask updates that ran out of retries.
- arena_
usage - What the arena holds, from the map’s memlock accounting, which kernels from 7.3 keep for the allocated pages, and the size of the map.
- attach
- Attach the scheduler through its struct_ops map
ops. - cgroup_
ops - The struct_ops map of the BPF object whose cgroup callbacks have the names the running kernel gives them: cpuctl_, or cgroup_ on a kernel from before the cid form renamed them. None for a kernel built without group scheduling, which has neither.
- check_
arena_ stats - What the statistics must say after a clean run.
- cli
- The whole loader of a scheduler: parse the command line, then run()
until Ctrl-C.
main!calls this with the scheduler’s name, version and objects, and with its options asS. - configuration
- The configuration table’s kernel entries: the offsets and enumerators
resolved from the running kernel’s BTF, the pool size, the dump length,
the tick period and the runtime’s options, a mask of
config::runtime’s bits. - declared_
dump_ len - The length of the debug dump the scheduler’s struct_ops map asks for,
dump_lenof#[scheduler]. - enumerator
- The value of the enumerator
namein kernel BTF, if the kernel has it. - exit_
report - The exit record ops.exit() keeps, reported as scx_utils reports it: the debug dump and the exit reason, as an error for an error exit.
- exit_
summary 🔒 - A graceful unregister as one line, “reason” or “reason (msg)”, read off the exit record. None when the scheduler has not exited, or was kicked out by an error, which keeps the standard report and its debug dump.
- init_
logger 🔒 - Log at info level to stderr, each line with the local time and its level, as the C-form schedulers do.
- member
- missing_
callbacks - The byte ranges, in the BPF object’s struct_ops type
ops, of the cgroup callbacks the running kernel’s sched_ext_ops_cid lacks, read off both BTFs: all of them on a kernel built without group scheduling, the newer ones on an older kernel. libbpf skips a member the kernel lacks only when it is zero. - named 🔒
- The options of
Awith their values as given or defaulted, by name. - open
- Open the object
objectasname, with libbpf’s open options that ObjectBuilder does not take, such as a BPF token path, as the C schedulers pass them. - ops_
flags - The ops flags the struct_ops map
opsasks the kernel for, as#[scheduler]declares them. - ops_
member - The byte range of the member
nameof the BPF object’s struct_ops typeops, read off its BTF. - ops_
type 🔒 - The BPF object’s struct_ops type of the map
ops. - param_
element 🔒 - The element type of an array tunable, whose type is its element’s in brackets.
- param_
name 🔒 - A tunable’s name as the command line takes it.
- param_
of 🔒 - The name, in lower case, and the type of the tunable the map
sectionholds, if it holds one. - param_
parse 🔒 - The value
textgives a tunable of typetyandsizebytes: true or false for a bool, and otherwise an integer, decimal or 0x hexadecimal, in the range of the type. None if it is not one. - publish_
tiers 🔒 - Read the CPUs’ capacities and packing priorities and hand them to the loaded object, see tiers.rs.
- run
- Load, attach and run the scheduler
nameuntilshutdownis set, the duration is over or the kernel ejects it.legacyandsizedare the two objects scx_rustsched_build leaves in OUT_DIR, of which the running kernel takes one.matchesis the command line the optionsschedulerwere parsed from: its options set the tunables they name, and the scheduler’s own settings the rest. - select_
ops - Pick the struct_ops map of the object
namethe kernel can take: the one whose cgroup callbacks it knows,cgroup_ops, orrust_opswithout the callbacks it lacks, which are zeroed in the map’s initial value. The exit dump buffer is sized todump_lenand the map told so. Returns the map’s name. - set_
config - Fill the frozen configuration table with
config. - set_
ops_ flags - Load the struct_ops map
opswith the opsflags. - set_
ops_ timeout - Load the struct_ops map
opswith the watchdog timeouttimeout_ms, in place oftimeout_msof#[scheduler]. - size_
maps - Size the arena and, when the object has them, the hrtick timers, one per CID. CIDs are dense and never exceed nr_cpu_ids.
- sized_
topology - Does the running kernel’s scx_bpf_cid_topo() take the structure’s size? Such a kernel copies only the fields it has and leaves the rest at -1, so its structure may still be the legacy one, without the cluster fields.
- spawn_
monitor 🔒 - The stats client, in its own thread: beside the scheduler with
--stats, started once its server is up. - tick_ns 🔒
- TICK_NSEC. The coarse clocks advance only from the timer interrupt, so their resolution is the tick period.
- time_
unit 🔒 - The tunable in nanoseconds that an option in microseconds or
milliseconds sets, and the factor:
slice_ussetsslice_ns, 1000.
Type Aliases§
- Idle 🔒
- What a scheduler does while no stats client asks, see
Stats::idle. - Result
Result<T, Error>
Derive Macros§
- Opts
- The derive that lets a field of the loader’s options carry
#[opts(no_bpf)]: an option that only the loader uses, for whichopts!()declares no tunable on the BPF side.