Expand description
The processor: architecture and bitness, name and vendor, and the three counts (cores, hardware threads, and what this process may use).
use sys_lib as sys;
println!("{} ({:?}, {})", sys::cpu::name(), sys::cpu::vendor(), sys::cpu::arch().name());
println!("{} cores, {} threads, {} usable here", sys::cpu::physical(), sys::cpu::logical(), sys::cpu::available());
// Size a worker pool by what the container allows, not by the host.
let workers = sys::cpu::available();Enums§
Functions§
- arch
- The architecture this program was compiled for.
- available
- The CPUs this process may use right now: the affinity mask, intersected
with the cgroup cpuset, then limited by the cgroup CPU quota (Linux), or the
group affinity and the job object’s CPU rate (Windows). Size worker pools by
this. A live reading: affinity, hot-plug, and quotas change. Always between
1 and
logical(). - is_
32bit - Whether the processor is 32-bit only.
- is_
64bit - Whether the processor is 64-bit. A 32-bit program on a 64-bit machine
still sees
true(D-024); the program’s own bitness iscpu::arch().is_64bit(). - logical
- Configured hardware threads: the right size for per-CPU arrays. A static
fact (E-15: present CPUs, not the
possiblecount VMs inflate). Windows counts every processor group (FR-12). At least 1. - name
- The cleaned product name: “AMD Ryzen 9 7950X”, “Apple M2 Pro”, “Cortex-A76 + Cortex-A55”. Never empty: falls back to the vendor and architecture (“ARM aarch64”), then “unknown”.
- physical
- Physical cores;
logicalwhen the topology is hidden (E-18). Always between 1 andlogical(). - raw_
name - The name exactly as the OS reports it, for support output;
Nonewhere the OS reports no brand string (most ARM Linux systems). - vendor
- The vendor.