Skip to main content

Module compute

Module compute 

Source
Expand description

CPU topology, affinity, and parallelism utilities.

The helpers inspect logical-core availability and derive sibling sets for simultaneous multithreading and hardware nodes. Platform-specific implementations provide available parallelism and current-CPU data.

Re-exportsΒ§

use std::cell::Cell; πŸ”’
use std::fmt::Debug; πŸ”’
use std::fmt::Debug; πŸ”’
use std::path::PathBuf; πŸ”’
use std::sync::LazyLock; πŸ”’
use std::thread; πŸ”’
use core_affinity::get_core_ids; πŸ”’
use core_affinity::CoreId; πŸ”’
use core_affinity::set_each_for_current; πŸ”’
use core_affinity::set_for_current; πŸ”’
use crate::Result; πŸ”’
use crate::is_equal_to; πŸ”’

ConstantsΒ§

CORES_MAX
Maximum number of cores we support; for now limited to bits of our mask integral.
CORE_AFFINITY πŸ”’
Tracks the affinity for this thread. This is updated when affinities are set via our set_affinity() interface.
CORE_IDS_FROM_OS
Whether cores_available lists the operating system’s CPU IDs.
MASK_BITS πŸ”’

StaticsΒ§

CORES_AVAILABLE πŸ”’
The mask of logical cores available to the process (at startup).
NODE_TOPOLOGY πŸ”’
Stores the mask of logical-core associations on a node/socket. Bits are set for all logical cores within all physical cores of the node.
SMT_TOPOLOGY πŸ”’
Stores the mask of logical-cores with thread/HT/SMT association. Each group here makes up a physical-core.

FunctionsΒ§

_sys_path πŸ”’
available_parallelism
Get the number of threads which could execute in parallel based on hardware constraints of this system.
cores_available
Get the list of cores available. The values were recorded at program start.
from_mask πŸ”’
get_affinity
Get the core affinity for this thread.
getcpu
Returns the logical CPU currently executing the calling thread.
init_node_topology πŸ”’
init_smt_topology πŸ”’
into_mask πŸ”’
is_core_available
Determine if core (by id) is available to the process.
node_affinity
Get the cores sharing Node resources relative to id.
node_siblings
List the cores sharing Node-tier resources relative to this threads current affinity.
nth_core_available
Gets the ID of the nth core available. This bijects our sequence of cores to actual ID’s which may have gaps for cores which are not available.
pin πŸ”’
query_cores_available πŸ”’
set_affinity
Sets the core affinity for this thread.
smt_affinity
Get the cores sharing SMT resources relative to id.
smt_siblings
List the cores sharing SMT-tier resources

Type AliasesΒ§

Id πŸ”’
Mask πŸ”’
Masks πŸ”’