pub struct CpuTopology { /* private fields */ }Expand description
The SMT layout of the logical CPUs this process may run on: for each allowed CPU, in ascending id order, the set of CPUs sharing its physical core.
An empty sibling list means “sysfs did not answer for this CPU”.
Such a CPU is treated as a physical core of its own and is never
merged with another unknown one — guessing that two unreadable CPUs
are siblings would silently halve the pool on any host that simply
has no topology/ directory (a container with a masked /sys, some
hypervisors, anything non-Linux), and that regression arrives with no
error attached to it.
Implementations§
Source§impl CpuTopology
impl CpuTopology
Sourcepub fn from_sibling_lists<I>(entries: I) -> Self
pub fn from_sibling_lists<I>(entries: I) -> Self
Build a topology from explicit sibling lists — the injection point that makes every rule in this module testable on a host with no SMT, no root, and no particular CPU count.
Entries are sorted by CPU id and deduplicated, because the rules pick the first allowed CPU of each physical core as that core’s representative and that choice must not depend on the order the caller happened to enumerate in.
Sourcepub fn read_from(root: &Path, allowed: &[usize]) -> Self
pub fn read_from(root: &Path, allowed: &[usize]) -> Self
Read {root}/cpu{n}/topology/thread_siblings_list for each CPU in
allowed. A CPU whose file is missing or unreadable gets an empty
sibling list (see the type docs: it becomes its own core), so a
host without sysfs topology degrades to one worker per allowed CPU
instead of erroring out mid-boot.
Sourcepub fn detect() -> Self
pub fn detect() -> Self
This host’s topology: SYSFS_CPU_ROOT restricted to
process_affinity_cpus.
Sourcepub fn allowed_cpus(&self) -> Vec<usize>
pub fn allowed_cpus(&self) -> Vec<usize>
The allowed logical CPUs, ascending.
Trait Implementations§
Source§impl Clone for CpuTopology
impl Clone for CpuTopology
Source§fn clone(&self) -> CpuTopology
fn clone(&self) -> CpuTopology
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CpuTopology
impl Debug for CpuTopology
Source§impl Default for CpuTopology
impl Default for CpuTopology
Source§fn default() -> CpuTopology
fn default() -> CpuTopology
impl Eq for CpuTopology
Source§impl PartialEq for CpuTopology
impl PartialEq for CpuTopology
impl StructuralPartialEq for CpuTopology
Auto Trait Implementations§
impl Freeze for CpuTopology
impl RefUnwindSafe for CpuTopology
impl Send for CpuTopology
impl Sync for CpuTopology
impl Unpin for CpuTopology
impl UnsafeUnpin for CpuTopology
impl UnwindSafe for CpuTopology
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,
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