perf_cpu_map__nr(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 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 a const 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:


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