CpuCap

Struct CpuCap 

Source
pub struct CpuCap { /* private fields */ }
Expand description

Re-export of the internal vmm::host_topology::CpuCap type so the ktstr and cargo-ktstr CLI binaries (which import this module through the pub mod cli surface) can resolve --cpu-cap N without depending on the pub(crate) vmm module. Keeping the canonical definition in vmm::host_topology (so the acquire_llc_plan internal call site consumes its own type without needing cli) and re-exporting here — versus inverting the dependency — avoids pulling the CLI module into the VMM internals. Parsed --cpu-cap N value. N is a CPU count: the planner reserves exactly N host CPUs by walking whole LLCs in contention- / NUMA-aware order (filtered to the calling process’s allowed cpuset) and partial-taking the last LLC so plan.cpus.len() == N. The flock set is still per-LLC (the last LLC is flocked whole even when only a prefix of its CPUs enters plan.cpus). Bounded to 1..=usize::MAX at the constructor — a cap of 0 is nonsensical (reserving zero CPUs is just “don’t run”) and rejected upstream by the CLI layer, but we enforce the bound in the type system via NonZeroUsize so callers can CpuCap::new(...)? without a follow-up bounds check.

The runtime upper bound — “don’t exceed the process’s allowed CPU count” — is enforced at acquire time via CpuCap::effective_count because the allowed set is not known until host_allowed_cpus reads sched_getaffinity.

Implementations§

Source§

impl CpuCap

Source

pub fn new(n: usize) -> Result<Self>

Construct from a raw usize CPU count. Returns Err on 0; usize::MAX is accepted here and clamped later by effective_count.

Source

pub fn resolve(cli_flag: Option<usize>) -> Result<Option<CpuCap>>

Three-tier resolution: explicit CLI flag wins over env var, which wins over “not set”. Returns None when neither is present, meaning “use the caller’s auto-sized default”: the kernel-build/planner path expands None to default_cpu_budget (30% of the allowed set); the no-perf VM-builder path expands it to no_perf_cpu_budget (max(30%, min(vcpus, allowed)), usually the vCPU count).

Env var is KTSTR_CPU_CAP (integer ≥ 1, CPU count). An empty or unset env var is treated as absent; a non-numeric value OR the numeric value 0 is an error — KTSTR_CPU_CAP=0 flows through CpuCap::new(0) which rejects with “–cpu-cap must be ≥ 1 CPU (got 0)”. Zero is not a silent fallback to “no cap”; it surfaces as a parse-time error so typos and scripting mistakes don’t accidentally disable the resource contract.

Source

pub fn effective_count(&self, allowed_cpus: usize) -> Result<usize>

Runtime-bounded cap: returns the inner count unless it exceeds allowed_cpus (the calling process’s sched_getaffinity cpuset count), in which case a CpuBudgetUnsatisfiable hard error (an explicit cap the host cannot satisfy is a FAIL, not a transient skip) steers the caller toward an actionable message. This check lives at acquire time — not at construction — because the allowed set is not known until host_allowed_cpus reads the syscall.

Trait Implementations§

Source§

impl Clone for CpuCap

Source§

fn clone(&self) -> CpuCap

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 CpuCap

Source§

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

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

impl PartialEq for CpuCap

Source§

fn eq(&self, other: &CpuCap) -> 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 Copy for CpuCap

Source§

impl Eq for CpuCap

Source§

impl StructuralPartialEq for CpuCap

Auto Trait Implementations§

§

impl Freeze for CpuCap

§

impl RefUnwindSafe for CpuCap

§

impl Send for CpuCap

§

impl Sync for CpuCap

§

impl Unpin for CpuCap

§

impl UnwindSafe for CpuCap

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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,