WorkerCtx

Struct WorkerCtx 

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

Source

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).

Source

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.

Source

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).

Source

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.

Source

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.

Source

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
  • InvalidInput if name is 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).
  • NotFound if 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 (NotFound for a missing sibling, PermissionDenied for an unwritable one, …) with ErrorKind preserved and the resolved path in the message.

Trait Implementations§

Source§

impl<'a> Clone for WorkerCtx<'a>

Source§

fn clone(&self) -> WorkerCtx<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for WorkerCtx<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,