Skip to main content

Module cpu

Module cpu 

Source
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), like std::thread::available_parallelism but without its cgroup v1 code.
keep_current_thread_off_net_rx
Takes the receive-interrupt CPU recorded by net_rx_concentrated out 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 Unsupported on macOS, which has no hard affinity.