CpusetSpec

Enum CpusetSpec 

Source
#[non_exhaustive]
pub enum CpusetSpec { Llc(usize), Numa(usize), Range { start_frac: f64, end_frac: f64, }, Disjoint { index: usize, of: usize, }, Overlap { index: usize, of: usize, frac: f64, }, Exact(BTreeSet<usize>), }
Expand description

How to compute a cpuset from topology.

§#[non_exhaustive]

CpusetSpec is #[non_exhaustive] — see [crate::non_exhaustive] for the cross-crate pattern-match and construction rules shared by every such type.

Variant-specific guidance for CpusetSpec: prefer the associated constructor functions — Self::llc, Self::numa, Self::range, Self::disjoint, Self::overlap, and Self::exact — over naming variant literals like CpusetSpec::Llc(0) or CpusetSpec::Range { start_frac, end_frac }. Two reasons:

  1. Stability across variant reshaping. A future commit that adds a field to Range (e.g. a stride parameter) breaks every caller that spelled out CpusetSpec::Range { start_frac, end_frac }; the Self::range(..) constructor absorbs the new field behind a defaulted parameter. The #[non_exhaustive] attribute is what reserves that freedom for the enum; the constructor convention is how callers opt into benefiting from it.
  2. Semantic consistency with Self::exact. The exact constructor accepts any IntoIterator<Item = usize> (arrays, ranges, Vec, BTreeSet) and converts to BTreeSet<usize> internally; callers that bypass it and write CpusetSpec::Exact(set) directly must hand-build the BTreeSet — duplicate bookkeeping a future-proofed constructor erases.

Test code that needs to inspect a variant via pattern match necessarily references the variant literal (the name is load- bearing for the match), so the construction-side rule is a convention for production call sites, not a hard constraint. Inside this crate, matchers obey the pattern-side rule above; constructors obey this rule.

Clone + Debug + PartialEq. Eq / Hash are impossible because Range and Overlap carry f64 fractions; Default has no honest value (Llc(0) vs. Range(0..1) vs. Exact(empty) are all different “no-op” semantics).

Note: f64::NAN != f64::NAN per IEEE 754, so a CpusetSpec containing NaN fractions will not equal a clone of itself; validate() rejects NaN inputs.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Llc(usize)

All CPUs in a given LLC index.

§

Numa(usize)

All CPUs in a given NUMA node index.

§

Range

Fractional range of usable CPUs [start_frac..end_frac).

Fields

§start_frac: f64
§end_frac: f64
§

Disjoint

Partition usable CPUs into of equal disjoint sets; take the index-th.

Fields

§index: usize
§

Overlap

Like Disjoint but each set overlaps neighbors by frac of its size.

Fields

§index: usize
§frac: f64
§

Exact(BTreeSet<usize>)

Exact CPU set (no topology resolution).

Implementations§

Source§

impl CpusetSpec

Source

pub fn exact(cpus: impl IntoIterator<Item = usize>) -> Self

Construct an Exact cpuset from any iterator of CPU indices.

Accepts arrays, ranges, Vec, BTreeSet, or any IntoIterator<Item = usize>.

Source

pub const fn disjoint(index: usize, of: usize) -> Self

Partition usable CPUs into of equal disjoint sets; take the index-th.

Source

pub const fn overlap(index: usize, of: usize, frac: f64) -> Self

Like disjoint but each set overlaps neighbors by frac of its size.

Source

pub const fn range(start_frac: f64, end_frac: f64) -> Self

Fractional range of usable CPUs [start_frac..end_frac).

Source

pub const fn llc(index: usize) -> Self

All CPUs in a given LLC index.

Source

pub const fn numa(index: usize) -> Self

All CPUs in a given NUMA node index.

Source§

impl CpusetSpec

Source

pub fn validate(&self, ctx: &Ctx<'_>) -> Result<(), String>

Check whether this spec can produce a non-empty cpuset for the given topology. Returns Err with a human-readable reason on failure.

Source

pub fn resolve(&self, ctx: &Ctx<'_>) -> BTreeSet<usize>

Resolve to a concrete CPU set given the topology.

Callers SHOULD run Self::validate first and propagate its error. apply_setup and apply_ops::SetCpuset do so via anyhow::bail!, then call Self::resolve_quiet which skips the warns this method emits on degenerate inputs.

Defense-in-depth: every malformed input that validate rejects (out-of-range Llc/Numa, partition of == 0, index >= of, inverted or non-finite Range.start_frac / end_frac, out-of-bounds Overlap.frac) also has a panic-free fallback here — out-of-range indices clamp to the last valid index with a tracing::warn!, of == 0 returns an empty set with a warn, and inverted/non-finite fracs clamp to [0, len] so the resulting slice never inverts. Skipping validate therefore degrades into a usable (possibly empty) cpuset rather than crashing the caller, but the warns surface the silent-degradation case — a caller who computed a CPU count via crate::scenario::Ctx::cpuset_cpus (which doesn’t validate) sees the warn instead of silently planning against the wrong denominator.

Source

pub fn resolve_quiet(&self, ctx: &Ctx<'_>) -> BTreeSet<usize>

Like Self::resolve but suppresses the degenerate-input tracing::warn!s. Use this from call sites that pair the resolution with a Self::validate call (either before or after this one) and bail on its error — validate is the canonical error channel for malformed specs, and a warn here would be redundant noise on a path already known- broken via the validate gate. apply_setup resolves first (to keep the workers_pct empty-cpuset diagnostic ahead of validate’s generic empty-Exact rejection) and validates after; Op::SetCpuset validates first and resolves after. Both patterns satisfy the contract.

Trait Implementations§

Source§

impl Clone for CpusetSpec

Source§

fn clone(&self) -> CpusetSpec

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 Debug for CpusetSpec

Source§

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

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

impl PartialEq for CpusetSpec

Source§

fn eq(&self, other: &CpusetSpec) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CpusetSpec

Auto Trait Implementations§

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,