Expand description
CPU count and thread affinity.
Functions§
- allowed_
cpus - The CPUs this process may run on, as indices (the affinity mask on Linux and Windows).
Falls back to
0..cpu_count()(or one CPU) where the mask can’t be read. - cpu_
count - The number of CPUs this process may use (at least 1): the affinity mask, capped on Linux by
a cgroup v2 CPU quota (
cpu.max, as containers set it), likestd::thread::available_parallelismbut without its cgroup v1 code. - keep_
current_ thread_ off_ net_ rx - Takes the receive-interrupt CPU recorded by
net_rx_concentratedout of the calling thread’s affinity mask (Linux; elsewhere, or when none was recorded, it does nothing). Nothing changes when the thread may not run there anyway or it is the only CPU left. - net_
rx_ concentrated - Whether the network’s receive processing concentrates on one CPU (K12): a NIC with a single
receive queue and no RPS runs every packet’s softirq on the CPU that takes its interrupt, as on
DigitalOcean’s 4-vCPU droplets (about 65% of that CPU at 165k packets/s). Read from the
softirq time per CPU in
/proc/stat: true when one CPU spent at least half of all the softirq time since boot, and there was some (2 s). Network receive dominates softirq time on a busy server; timers and the rest are spread over the CPUs. Linux only; false elsewhere or when the file can’t be read. - pin_
current_ thread - Pins the calling thread to one CPU. Returns
Unsupportedon macOS, which has no hard affinity.