Re: [PATCH v7 019/120] x86/tsc: Use parsed CPUID(0x16)

From: Borislav Petkov

Date: Wed Jun 24 2026 - 17:08:44 EST


On Thu, May 28, 2026 at 05:37:41PM +0200, Ahmed S. Darwish wrote:
> @@ -738,19 +734,9 @@ unsigned long native_calibrate_tsc(void)
>
> static unsigned long cpu_khz_from_cpuid(void)
> {
> - unsigned int eax_base_mhz, ebx_max_mhz, ecx_bus_mhz, edx;
> -
> - if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
> - return 0;
> -
> - if (boot_cpu_data.cpuid_level < CPUID_LEAF_FREQ)
> - return 0;
> -
> - eax_base_mhz = ebx_max_mhz = ecx_bus_mhz = edx = 0;
> -
> - cpuid(CPUID_LEAF_FREQ, &eax_base_mhz, &ebx_max_mhz, &ecx_bus_mhz, &edx);
> + const struct leaf_0x16_0 *l16 = cpuid_leaf(&boot_cpu_data, 0x16);
>
> - return eax_base_mhz * 1000;
> + return l16 ? (l16->cpu_base_mhz * 1000) : 0;

Ok, this looks like a vendor check which you're replacing with the *l16 leaf
pointer check.

So, instead of doing those vendor-specific thing and then having to update the
parser everytime a vendor implements a leaf, what you can do is check whether
the leaf is supported. If so, you can return NULL in cpuid_leaf() and thus
denote that the current vendor the kernel is running on, doesn't implement the
leaf.

And you can detect which leafs the vendor implements by looking at max
supported leaf.

And then you don't need any special vendor handling.

Btw, pls merge this patch with the previous one.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette