pub struct WorkerCtx<'a> { /* private fields */ }Expand description
Execution context handed to a WorkType::Custom worker function.
Exposes the worker’s stop flag plus the parts of its runtime
environment a scheduler probe most often needs — its effective
cpuset, its cgroup-sibling pids, its own cgroup-v2 directory, and a
fork-safe CustomCfg payload — plus open_sibling_cgroup_procs() to
open a sibling cgroup’s cgroup.procs, so a custom worker does not
re-roll sched_getaffinity, cgroup.procs, or /proc/self/cgroup
parsing. The captured fields are read once, at worker entry, before
the work loop runs.
Borrowed, not owned: the framework constructs a WorkerCtx
pointing at stack-local data in worker_main and passes it by
reference for the duration of the call. A worker that needs the
sibling set, cpuset, or cgroup dir to outlive a single read should
copy what it needs out of the returned slices / path.
Implementations§
Source§impl<'a> WorkerCtx<'a>
impl<'a> WorkerCtx<'a>
Sourcepub fn stop(&self) -> &AtomicBool
pub fn stop(&self) -> &AtomicBool
The worker’s stop flag. The work loop must poll this and return
a WorkerReport once it reads true (flipped by the SIGUSR1
handler in CloneMode::Fork, or a per-worker AtomicBool in
CloneMode::Thread).
Sourcepub fn cpus(&self) -> &[usize]
pub fn cpus(&self) -> &[usize]
The worker’s effective cpuset — the CPUs it may run on, read
from sched_getaffinity at entry. Empty if the query failed.
Sourcepub fn sibling_pids(&self) -> &[pid_t] ⓘ
pub fn sibling_pids(&self) -> &[pid_t] ⓘ
The worker’s cgroup-sibling pids — every task in the worker’s
own cgroup.procs except itself, read at entry. Empty if the
worker has no siblings or the cgroup could not be read. See
WorkType::CrossAffinityChurn for the discovery contract
(a worker sees only the siblings present when it starts, so
declaration order matters).
Sourcepub fn cgroup_dir(&self) -> Option<&Path>
pub fn cgroup_dir(&self) -> Option<&Path>
The worker’s own cgroup-v2 directory (/sys/fs/cgroup<rel>),
captured at entry from /proc/self/cgroup — or None when the
worker runs in the root cgroup or cgroup v2 is unavailable. A
Custom worker that needs to address a sibling cgroup (write its
cgroup.procs, read a peer’s members) resolves the target from
here instead of re-parsing /proc/self/cgroup itself. None,
never a bogus /sys/fs/cgroup, so the root is never mistaken for
a dedicated cgroup.
Sourcepub fn cfg(&self) -> CustomCfg
pub fn cfg(&self) -> CustomCfg
The CustomCfg payload declared on this worker’s
WorkType::Custom (or CustomCfg::default — all-zero — when
the worker was built with WorkType::custom rather than
WorkType::custom_with). Copy POD, inherited byte-faithfully
across fork, so a Custom closure reads its per-worker config from
here instead of a static/global.
Sourcepub fn open_sibling_cgroup_procs(&self, name: &str) -> Result<File>
pub fn open_sibling_cgroup_procs(&self, name: &str) -> Result<File>
Open the cgroup.procs of a cgroup under this worker’s cgroup parent
for writing — the ready-to-use migration target a Custom worker needs
without re-parsing /proc/self/cgroup or hand-rolling a writability
precheck. Resolves to cgroup_dir().parent()/<name>/cgroup.procs: a
single-component name is a sibling of this worker’s cgroup, a
multi-component name a nested descendant of that parent.
The write-mode open IS the precheck: a successful return means the
sibling’s cgroup.procs exists and was openable for write. The
kernel checks cgroup.procs WRITE permission at write time (against
the open-time credentials), so a returned File can still fail on
the actual write — the caller must handle write errors too.
§Errors
InvalidInputifnameis empty, absolute, contains a NUL, or has a./../leading-dot/empty path component (rejected before any fs access, so a hostile name cannot escape the parent via join).NotFoundif the worker has no resolvable cgroup-v2 dir (root / non-v2 — run it in a dedicated cgroup) or its cgroup has no parent.- the underlying open error (
NotFoundfor a missing sibling,PermissionDeniedfor an unwritable one, …) withErrorKindpreserved and the resolved path in the message.
Trait Implementations§
impl<'a> Copy for WorkerCtx<'a>
Auto Trait Implementations§
impl<'a> Freeze for WorkerCtx<'a>
impl<'a> RefUnwindSafe for WorkerCtx<'a>
impl<'a> Send for WorkerCtx<'a>
impl<'a> Sync for WorkerCtx<'a>
impl<'a> Unpin for WorkerCtx<'a>
impl<'a> UnwindSafe for WorkerCtx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more