cpuid_subleaf(9)
β¨ 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-time0xNformat. like0x7or0xf. no cap, the0xmatters β¨_subleafβ the CPUID subleaf, but this one's in compile-time decimal format. so like0,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
_cpuinfohas not yet been populated. (it's giving "not ready yet" π) - The CPUID table inside
_cpuinfowas populated, but the CPU doesn't implement the CPUID_leaf/_subleafcombination you're asking for. - The CPUID table inside
_cpuinfowas populated, but the kernel's CPUID parser has predetermined that the requested CPUID_leaf/_subleafhardware 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
- 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