Skip to main content

Crate scx_arena

Crate scx_arena 

Source
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Β§

ArenaLib
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.
ScxLibArena
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.
StreamFd πŸ”’
A stream opened as a descriptor. reader splits the lines and pending carries the partial line a read ends in over to the next read.
UrcuGracePeriod πŸ”’
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.