Expand description
Β§SCX Arena library setup utilities
Crate for setting up the BPF arena library for sched-ext schedulers.
Re-exportsΒ§
pub(crate) use libbpf_rs::AsRawLibbpf as _;πpub(crate) use libbpf_rs::MapCore as _;πpub(crate) use std::fs::File;πpub(crate) use std::io::BufRead;πpub(crate) use std::io::BufReader;πpub(crate) use std::io::ErrorKind;πpub(crate) use std::os::fd::AsFd;πpub(crate) use std::os::fd::AsRawFd;πpub(crate) use std::os::fd::BorrowedFd;πpub(crate) use std::os::fd::FromRawFd;πpub(crate) use std::os::fd::OwnedFd;πpub(crate) use std::time::Duration;πpub(crate) use std::time::Instant;πpub(crate) use anyhow::Context;πpub(crate) use anyhow::Result;πpub(crate) use anyhow::bail;πpub(crate) use libbpf_rs::libbpf_sys;π
ModulesΒ§
- arenalib π
- bpf_
skel π - scx_
libarena π
StructsΒ§
- Arena
Lib - Live BPF arena library state. Returned by setup() and must be kept alive for as long as the scheduler instance uses the arena: dropping it stops and joins the libraryβs background threads.
- Daemon π
- One background thread and the eventfd that stops it. Dropping writes the eventfd and joins the thread.
- ScxLib
Arena - Live BPF arena library state. Returned by setup() and must be kept alive for as long as the scheduler instance uses the arena: dropping it stops and joins the libraryβs background threads.
- Stream
Fd π - A stream opened as a descriptor.
readersplits the lines andpendingcarries the partial line a read ends in over to the next read. - Urcu
Grace πPeriod - membarrier(MEMBARRIER_CMD_GLOBAL) is synchronize_rcu() except in two cases: it fails with EINVAL when nohz_full is active and it returns without waiting when only one CPU is online. Both fall back to updating a private map-in-map slot, which the kernel documents as waiting for the running non-sleepable programs. That wait is an expedited grace period and IPIs every CPU in the kernel, so the daemon spaces those rounds out.
ConstantsΒ§
- BPF_
STDERR π - BPF_
STDOUT π - BPF_
STREAMS π - CACHELINE_
SIZE - MEMBARRIER_
CMD_ πGLOBAL - STREAM_
POLL_ πINTERVAL - URCU_
DOORBELL π - URCU_
FALLBACK_ πINTERVAL - URCU_
MEMBARRIER_ πRETRIES - URCU_
MIN_ πINTERVAL
FunctionsΒ§
- hotplug_
seq π - membarrier_
global π - online_
cpus π - prog_
fd_ πclone - Duplicate @progβs fd, None for programs that were not loaded and thus have no fd, prog.as_fd() on those would construct a BorrowedFd from an invalid fd. Errors only when a loaded programβs fd cannot be duplicated.
- stop_
eventfd π - Create the eventfd a Daemon is stopped through.
- stream_
extract_ πlines - Split the complete lines out of @carry, keeping a trailing partial for the next read. Stream elements are concatenated without separators and reads split lines arbitrarily, so prefixes may only be matched on complete lines. @new_data says whether this poll read anything: a partial with no continuation after a full poll interval is flushed as a line of its own.
- stream_
forward π - Forward a batch of complete lines from one stream to the matching standard stream of the scheduler, and abort when the kernel reports an error on a stderr stream. Lines prefixed βIGN: β are dropped instead of forwarded, for prints with side effects that nobody needs to see, the arena association print in scx_arena_subprog_init() for example.
- stream_
is_ πfatal - The kernel prefixes the errors it reports on a programβs BPF stderr stream with βERROR: β.
- stream_
read π - stream_
watch_ πfds - poll(2) the stream descriptors and the stop eventfd. A stream is dropped at EOF and a stop request gets one last read of every stream.
- stream_
watch_ πperiodic - Read every stream once per STREAM_POLL_INTERVAL through the read command and assemble the lines here, for kernels without stream descriptors.
- stream_
watcher_ πspawn - Forward the BPF stdout/stderr streams of every program in the object to the schedulerβs stdout and stderr. Nothing reads these streams otherwise, so messages would be silently dropped. On a kernel with stream descriptors the watcher poll(2)s them and forwards each line as it is written. Elsewhere it reads the streams periodically. Called from ArenaLib::setup(), the watcher is owned by the returned ArenaLib.
- urcu_
daemon π - urcu_
run_ πprog - Userspace half of the scx_urcu machinery, see the BPF side in lib/sdt_alloc.bpf.c. ArenaLib::setup() spawns the daemon when the object carries the scx_urcu doorbell. The returned ArenaLib owns it and stops and joins it on drop, so nothing else is visible to the scheduler: its whole runtime surface is calling the scx_*_free_rcu() variants from its free path hooks.
- urcu_
spawn π - Spawn the urcu reclaim daemon if @obj carries the scx_urcu doorbell and driver programs. Called from ArenaLib::setup(), the daemon is owned by the returned ArenaLib.