Topology

Struct Topology 

Source
pub struct Topology {
    pub llcs: u32,
    pub cores_per_llc: u32,
    pub threads_per_core: u32,
    pub numa_nodes: u32,
    pub nodes: Option<&'static [NumaNode]>,
    pub distances: Option<&'static NumaDistance>,
}
Expand description

Re-exports of topology types for use in KtstrTestEntry statics generated by the #[ktstr_test] macro. CPU topology specification with NUMA memory topology.

Models the hierarchy: NUMA nodes → LLCs → cores → threads.

Each NUMA node owns a contiguous range of LLCs and a memory region. When nodes is None (the default), memory and LLCs are distributed uniformly across numa_nodes synthetic nodes with 10/20 distances.

Use new for the simple uniform case, or with_nodes for explicit per-node configuration.

Fields§

§llcs: u32

Total number of last-level caches across the whole VM; must be a multiple of numa_nodes when nodes is None.

§cores_per_llc: u32

Physical cores grouped into each LLC.

§threads_per_core: u32

Hardware threads exposed per core (1 = no SMT, 2 = SMT-2).

§numa_nodes: u32

Number of NUMA nodes.

§nodes: Option<&'static [NumaNode]>

Per-node configuration. When None, LLCs and memory are distributed uniformly. When Some, the slice length must equal numa_nodes and the sum of all NumaNode::llcs must equal self.llcs.

§distances: Option<&'static NumaDistance>

Inter-node distance matrix. When None, distances default to 10 (local) / 20 (remote). When Some, the matrix dimension must equal numa_nodes.

Implementations§

Source§

impl Topology

Source

pub const DEFAULT_FOR_PAYLOAD: Topology

Fallback topology used by Payload::topology for binary-kind payloads that have no scheduler-side topology opinion. Matches the inline default in KtstrTestEntry::DEFAULT: 1 NUMA node / 1 LLC / 2 cores / 1 thread (2 CPUs total), the smallest VM shape that runs the harness meaningfully.

Source

pub const fn new( numa_nodes: u32, llcs: u32, cores_per_llc: u32, threads_per_core: u32, ) -> Self

Validated const constructor for uniform topologies.

Produces a topology where LLCs and memory are distributed evenly across NUMA nodes, with default 10/20 distances.

See validate for a non-panicking alternative.

§Panics

Panics if any invariant is violated:

  • any of llcs, cores_per_llc, threads_per_core, numa_nodes is zero
  • llcs is not divisible by numa_nodes
  • total CPU count (llcs * cores_per_llc * threads_per_core) overflows u32
Source

pub const fn with_nodes( cores_per_llc: u32, threads_per_core: u32, nodes: &'static [NumaNode], ) -> Self

Const constructor with explicit per-node configuration.

Total LLC count is computed from the sum of NumaNode::llcs across all nodes. Memory-only nodes (llcs=0) are permitted.

§Panics

Panics if:

  • nodes is empty
  • cores_per_llc == 0
  • threads_per_core == 0
  • node LLC sum overflows u32
  • a CPU-bearing node (llcs > 0) has memory_mib == 0
  • total CPU count overflows u32
  • no node has LLCs (at least one must have llcs > 0)
Source

pub const fn distances(self, distances: &'static NumaDistance) -> Self

Attach a distance matrix.

§Panics

Panics if distances.n != self.numa_nodes — the matrix dimension must equal the topology’s NUMA node count.

Source

pub fn validate(&self) -> Result<(), String>

Non-panicking validation.

Returns Ok(()) if all invariants hold, or Err with a description of the first violated invariant.

Source

pub fn total_cpus(&self) -> u32

Total vCPU count = llcs * cores_per_llc * threads_per_core.

Source

pub fn num_llcs(&self) -> u32

Number of LLC domains in the topology.

Source

pub fn num_numa_nodes(&self) -> u32

Number of NUMA nodes in the topology.

Source

pub fn llcs_in_node(&self, node_id: u32) -> u32

LLCs owned by NUMA node node_id.

With explicit nodes, returns nodes[node_id].llcs. With uniform distribution, returns llcs / numa_nodes.

Source

pub fn llcs_per_numa_node(&self) -> u32

LLCs per NUMA node (uniform distribution only).

§Panics

Panics if the topology uses explicit nodes (use llcs_in_node instead), if numa_nodes == 0, or if llcs is not divisible by numa_nodes.

Source

pub fn numa_node_of(&self, llc_id: u32) -> u32

NUMA node that owns the given LLC index.

With explicit nodes, walks the node list to find the owning node. With uniform distribution, computes llc_id / llcs_per_node.

Out-of-bounds llc_id (>= total LLCs): with explicit nodes, saturates to the last node index; with uniform distribution, no bounds check — returns llc_id / llcs_per_node, which may exceed numa_nodes - 1.

Source

pub fn first_llc_in_node(&self, node_id: u32) -> u32

First LLC index owned by NUMA node node_id.

Uniform topologies do not bounds-check and return node_id * llcs_per_node for any input.

§Panics

Panics if node_id > numa_nodes for explicit-node topologies (the walk would index past the end of the node slice).

Source

pub fn node_memory_mib(&self, node_id: u32) -> Option<u32>

Memory in MiB for NUMA node node_id.

With explicit nodes, returns nodes[node_id].memory_mib. With uniform distribution, returns None (caller must divide total memory evenly).

Source

pub fn total_node_memory_mib(&self) -> Option<u32>

Total memory across all explicit nodes, or None for uniform.

Source

pub fn distance(&self, i: u32, j: u32) -> u8

Distance from node i to node j.

Returns the explicit distance if a matrix is attached, otherwise 10 for local and 20 for remote.

Source

pub fn has_memory_only_nodes(&self) -> bool

Whether any node is memory-only (CXL).

Source

pub fn cpu_bearing_nodes(&self) -> u32

Number of nodes that have CPUs (non-memory-only).

Source

pub fn decompose(&self, cpu_id: u32) -> (u32, u32, u32)

Decompose a logical CPU ID into (llc, core, thread).

Trait Implementations§

Source§

impl Clone for Topology

Source§

fn clone(&self) -> Topology

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 Topology

Source§

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

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

impl Display for Topology

Formats as {numa}n{llcs}l{cores}c{threads}t — e.g. 1n2l4c2t = 1 NUMA node, 2 LLCs, 4 cores/LLC, 2 threads/core.

Source§

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

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

impl From<Topology> for TopologyJson

Project a Topology into its wire-format mirror. Drops the nodes and distances fields (uniform-distribution shape only); callers that need to preserve explicit per-node config or distance matrices must not use this conversion. Takes Topology by value (it derives Copy) to match the by-value shape of [From<TopologyConstraintsJson> for TopologyConstraints].

Source§

fn from(t: Topology) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Topology

Parse the Display format back into a uniform Topology with nodes = None and distances = None.

§Lossy round-trip

Only topologies built via Topology::new (uniform layout, no per-node configuration, default 10/20 distances) round-trip cleanly through DisplayFromStr. A Topology built via Topology::with_nodes or chained with Topology::distances loses its per-node config + custom distance matrix through Display (which serializes only the 4 primitives); FromStr cannot reconstruct that information and produces a uniform Topology instead. Use the Topology value directly when full fidelity is required.

Source§

type Err = TopologyParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Topology

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Topology

Source§

fn eq(&self, other: &Topology) -> 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 TryFrom<TopologyJson> for Topology

Result-based validation for wire-format topology values. Lets the verifier dispatch surface a per-cell “topology rejected” diagnostic instead of taking the Topology::new panic surface in the builder. Mirrors Topology::validate — any field == 0, overflow in total CPU count, or llcs not divisible by numa_nodes returns Err. The result is a uniform-distribution Topology (nodes = None, distances = None); explicit per-node config and distance matrices require constructing Topology directly.

Source§

type Error = String

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

fn try_from(value: TopologyJson) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Topology

Source§

impl Eq for Topology

Source§

impl StructuralPartialEq for Topology

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
§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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,