num_online_cpus(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… num_online_cpus β€” the Kernel API Manual, bestie edition

okay so real talk, this one is from the Kernel API Manual (section 9, kernel dev girlies know πŸ‘‘) and it's a tiny little function that answers one very important question: how many CPUs are online right now?


✨ NAME ✨

num_online_cpus β€” literally just reads the number of online CPUs πŸ–₯οΈπŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

unsigned int num_online_cpus (void );

bestie it takes nothing. no arguments, no drama, no surprises. she just shows up and returns an unsigned int. periodt. πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • void β€” no arguments. none. zero. the void is voiding. πŸ«₯✨

🌸 DESCRIPTION 🌸

okay so here's the tea β˜• β€” internally this thing is built on __num_online_cpus, which is of type atomic_t. and you'd think "atomic, so it's safe, right?" and that's the trap, bestie. 😭

this interface gives you only a momentary snapshot. it is not protected against concurrent CPU hotplug operations β€” unless you invoke it from a region where cpuhp_lock is held. that's the caveat, and it's a real one, so don't come for me if your count shifts mid-thought while CPUs are hotplugging around you. πŸ”₯πŸ‘€

no cap: atomic type β‰  your answer is frozen in time. it's a snapshot, not a promise. πŸ’€

⭐ RETURN ⭐

a momentary snapshot of the number of online CPUs πŸŽ€βœ¨ (snapshot. momentary. i said what i said.)


πŸ’œ SEE ALSO πŸ’œ

all my girls in Kernel file ./include/linux/cpumask.h β€” say hi to the whole cpumask friend group, they're iconic and there are so many of them:


and that's the whole page, bestie πŸ«ΆπŸ’– sign-off time: this lil beauty lives in ./include/linux, dated October 2026, and yes it's still called num_online_cpus(9) β€” same name, same energy, forever iconic 🌈⭐🧚

πŸ“¦ where this page comes from