num_online_cpus(9)
π 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:
cpumask_pr_args(9)cpumask_first(9)cpumask_first_zero(9)cpumask_first_and(9)cpumask_first_andnot(9)cpumask_first_and_and(9)cpumask_last(9)cpumask_next(9)cpumask_next_zero(9)cpumask_next_and(9)cpumask_next_andnot(9)cpumask_next_and_wrap(9)cpumask_next_wrap(9)cpumask_random(9)for_each_cpu(9)for_each_cpu_wrap(9)for_each_cpu_and(9)for_each_cpu_andnot(9)for_each_cpu_or(9)for_each_cpu_from(9)cpumask_any_but(9)cpumask_any_and_but(9)cpumask_any_andnot_but(9)cpumask_nth(9)cpumask_nth_and(9)cpumask_nth_and_andnot(9)cpumask_set_cpu(9)cpumask_clear_cpus(9)cpumask_clear_cpu(9)cpumask_test_cpu(9)cpumask_test_and_set_cpu(9)cpumask_test_and_clear_cpu(9)cpumask_setall(9)cpumask_clear(9)cpumask_and(9)cpumask_or(9)cpumask_weighted_or(9)cpumask_xor(9)cpumask_andnot(9)cpumask_equal(9)cpumask_or_equal(9)cpumask_intersects(9)cpumask_subset(9)cpumask_empty(9)cpumask_full(9)cpumask_weight(9)cpumask_weight_and(9)cpumask_weight_andnot(9)cpumask_shift_right(9)cpumask_shift_left(9)cpumask_copy(9)cpumask_any(9)cpumask_any_and(9)cpumask_of(9)cpumask_parse_user(9)cpumask_parselist_user(9)cpumask_parse(9)cpulist_parse(9)cpumask_size(9)alloc_cpumask_var(9)to_cpumask(9)cpumap_print_bitmask_to_buf(9)cpumap_print_list_to_buf(9)
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
- 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