topology_unit_count(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… topology_unit_count(9) โ€” like, the whole Kernel API Manual vibe โœจ

okay bestie, so this one lives in section 9 of the kernel API manual and it's called topology_unit_count โ€” say that three times fast, i dare you ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

topology_unit_count โ€” retrieves the count of specified units at a given topology domain level. that's it, that's the whole job, and she does it slayfully ๐Ÿ’–


โœจ SYNOPSIS โœจ

unsigned int topology_unit_count (u32 apicid , enum x86_topology_domains which_units , enum x86_topology_domains at_level );

look at that signature. three args, one unsigned int coming back at ya. iconic behavior honestly ๐Ÿ‘‘


๐ŸŽ€ ARGUMENTS ๐ŸŽ€

  • apicid โ€” the APIC ID, aka the little guy that specifies the search range ๐Ÿ”
  • which_units โ€” the domain level that specifies which units we're counting, like, what are we even tallying here
  • at_level โ€” the domain level at which which_units have to be counted. soโ€ฆ where the counting happens ๐Ÿงฎ

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so what does she actually do? she returns the number of possible units according to the enumerated information. no cap, that's the whole thing ๐Ÿ’…

like, for example โ€” and this is the moment, bestie โ€” topology_count_units(apicid, TOPO_CORE_DOMAIN, TOPO_PKG_DOMAIN) counts the number of possible cores in the package that apicid belongs to. cute right? cores in a package, counted, done ๐ŸŒธ

now the important part, pay attention:

at_level must obviously be greater than which_level to produce useful results. like, obviously. this is not a drill, this is the useful-results prerequisite ๐Ÿ”ฅ
  • if at_level is equal to which_units, the result is โ€” unsurprisingly โ€” 1. yeah. one. that's it. one unit. don't act shocked ๐Ÿ’€
  • if at_level is less than which_units, the result is, by definition, undefined, and the function returns 0. undefined behavior bestie, we do NOT stan, be careful out there ๐Ÿ™ˆ

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

the kernel file ./arch/x86/kernel/cpu/topology.c and its whole friend group:

go read them, they're all main character energy in their own way, iykyk โญ


okay that's the whole page, mwah ๐Ÿ’œ this gem is brought to you straight from ./arch/x86/kernel/cpu, dated October 2026, and yes she's still serving topology_unit_count(9) realness. periodt. ๐ŸŽ€๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from