perf_cpu_map__nr(9)
πΈ perf_cpu_map__nr πΈ
okay so bestie, welcome to perf_cpu_map__nr β the libperf function that tells you how many CPUs are in your map, but with one iconic little plot twist π
β¨ SYNOPSIS β¨
LIBPERF_API unsigned int perf_cpu_map__nr (const struct perf_cpu_map
*cpus );
π¦ DESCRIPTION π¦
Alright so here's the tea, and you're gonna want to sit down for this one π«
If the map is empty, this thing returns 1. Not 0. 1. And why?? Because perf_cpu_map__cpu returns a cpu of -1 for an invalid index β so an empty map literally ends up looking like it contains the "any CPU"/dummy value. It's giving "empty but make it look like it has one thing in it" π no cap, that's the whole vibe.
Otherwise, the result is the number of CPUs in the map, plus one if the "any CPU"/dummy value is present. So like, count your CPUs, then check if the dummy value is crashing the party β if it is, add one π
π ARGUMENTS π
cpusβ literally says-- undescribed --in the source docs, so that's all we got, bestie π (it's aconst struct perf_cpu_map *, iykyk)
π SEE ALSO π
Go check out the kernel file ./tools/lib/perf/include/perf/cpumap.h, plus these absolute main characters:
struct perf_cpu(9)perf_cpu_map__new_any_cpu(9)perf_cpu_map__new_online_cpus(9)perf_cpu_map__new(9)perf_cpu_map__cpu(9)perf_cpu_map__has_any_cpu_or_is_empty(9)perf_cpu_map__is_any_cpu_or_is_empty(9)perf_cpu_map__is_empty(9)perf_cpu_map__min(9)perf_cpu_map__max(9)
and that's the whole page, periodt β¨ this lil masterpiece lives over at ./tools/lib/perf/include/perf, stamped October 2026, and it's officially perf_cpu_map__nr(9) β slay, bye bestie ππ¦πΈ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms