Struct HardwareInfo

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

Reports non-changing information about the system hardware.

To inspect information that may change over time, use HardwareTracker.

Functions exposed by this type represent the system hardware and are not limited by the current system or process configuration. That is, this type will still count processors and memory regions that are currently inactive (e.g. some processors are physically disconnected) or are not available to this process (e.g. because of cgroups policy).

§Example

use many_cpus::HardwareInfo;

let max_processor_id = HardwareInfo::max_processor_id();
println!("The maximum processor ID is: {max_processor_id}");

Implementations§

Source§

impl HardwareInfo

Source

pub fn max_processor_id() -> ProcessorId

Gets the maximum (inclusive) processor ID of any processor that could possibly be present on the system at any point in time.

This includes processors that are not currently active and processors that are active but not available to the current process.

Source

pub fn max_memory_region_id() -> MemoryRegionId

Gets the maximum (inclusive) memory region ID of any memory region that could possibly be present on the system at any point in time.

This includes memory regions that are not currently active and memory regions that are active but not available to the current process.

§Example
use many_cpus::HardwareInfo;

let max_memory_region_id = HardwareInfo::max_memory_region_id();
let max_memory_region_count = HardwareInfo::max_memory_region_count();

println!("Memory region IDs range from 0 to {max_memory_region_id}");
println!("System can have up to {max_memory_region_count} memory regions");

// Useful for creating arrays indexed by memory region ID
let mut data_per_region = vec![0; max_memory_region_count];
println!(
    "Created array with {} slots for memory region data",
    data_per_region.len()
);
Source

pub fn max_processor_count() -> usize

Gets the maximum number of processors that could possibly be present on the system at any point in time.

This includes processors that are not currently active and processors that are active but not available to the current process.

Source

pub fn max_memory_region_count() -> usize

Gets the maximum number of memory regions that could possibly be present on the system at any point in time.

This includes memory regions that are not currently active and memory regions that are active but not available to the current process.

§Example
use many_cpus::HardwareInfo;

let max_regions = HardwareInfo::max_memory_region_count();
let max_processors = HardwareInfo::max_processor_count();

println!("System architecture supports:");
println!("  Up to {max_processors} processors");
println!("  Up to {max_regions} memory regions");

let avg_processors_per_region = max_processors as f64 / max_regions as f64;
println!(
    "  Average of {:.1} processors per memory region",
    avg_processors_per_region
);

Trait Implementations§

Source§

impl Debug for HardwareInfo

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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

Source§

fn vzip(self) -> V