cpuid_subleaf(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ cpuid_subleaf(9) ✨

okay bestie, this one's from the Linux kernel API manual β€” it's cpuid_subleaf(9) and it's literally your shortcut to all the CPUID tea without touching the raw hardware yourself πŸ’…


🌸 NAME 🌸

cpuid_subleaf β€” access parsed CPUID πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

cpuid_subleaf (_cpuinfo , _leaf , _subleaf );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • _cpuinfo β€” a reference to the CPU capability structure, aka 'struct cpuinfo_x86'. this is where all the parsed goodies live 🫢
  • _leaf β€” the CPUID leaf, and it has to be in compile-time 0xN format. like 0x7 or 0xf. no cap, the 0x matters ✨
  • _subleaf β€” the CPUID subleaf, but this one's in compile-time decimal format. so like 0, 1, 3. decimal only, bestie, don't come at it with hex πŸ™ˆ

πŸ”₯ DESCRIPTION πŸ”₯

So what does it actually do? It hands you back a pointer to the parsed CPUID output β€” pulled straight from the CPUID table sitting inside _cpuinfo β€” typed as a <cpuid/leaf_types.h> data type. the type is 'struct leaf_0xM_N', where 0xM is the token you passed as _leaf and N is the token you passed as _subleaf. so if you asked for leaf 0x7 and subleaf 0, you get struct leaf_0x7_0. iconic, honestly πŸ’–

And it returns NULL if the CPUID _leaf/_subleaf query output you asked for isn't present in the parsed CPUID table inside _cpuinfo. that can happen in a few situations:

  • The CPUID table inside _cpuinfo has not yet been populated. (it's giving "not ready yet" 😭)
  • The CPUID table inside _cpuinfo was populated, but the CPU doesn't implement the CPUID _leaf/_subleaf combination you're asking for.
  • The CPUID table inside _cpuinfo was populated, but the kernel's CPUID parser has predetermined that the requested CPUID _leaf/_subleaf hardware output is invalid or unsupported. the parser already did a vibe check and said no πŸ’€

Example usage β€” look at it, learn it, love it:

const struct leaf_0x7_0 *l7_0 = cpuid_subleaf(c, 0x7, 0);
if (!l7_0) {
        // Handle error
}

const struct leaf_0x7_1 *l7_1 = cpuid_subleaf(c, 0x7, 1);
if (!l7_1) {
        // Handle error
}
always check for NULL, bestie. fr fr. the if (!l7_0) block is not decorative 🫢

🌈 SEE ALSO 🌈

Kernel file ./arch/x86/include/asm/cpuid/api.h β€” and while you're there, go say hi to cpuid_leaf_0x2(9), for_each_cpuid_0x2_desc(9), cpuid_leaf(9), cpuid_leaf_raw(9), cpuid_subleaf_n(9), cpuid_subleaf_n_raw(9), and cpuid_subleaf_count(9). the whole squad is there 🧚


⭐ this lil page lives at ./arch/x86/include/asm/cpuid, dated October 2026 β€” that's the whole manual, diva, go read some CPUID tables and slay πŸ’œπŸŒΈ

πŸ“¦ where this page comes from