[PATCH v7 073/120] perf/x86/intel: Use parsed CPUID(0x15)

"Ahmed S. Darwish" <[email protected]> Thu, 28 May 2026 17:38:35 +0200
Newsgroups dev.linux.lists.x86-cpuid,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Use parsed CPUID(0x15) instead of a direct CPUID query and raw register
access.

Remove the maximum CPUID level check as it is implied by the CPUID API not
returning NULL.

Remove the excessive details regarding CPUID(0x15).EBX being zero since it
is not relevant to the actual code beneath it.  The code only caches the
TSC to core crystal clock ration numerator and denominator.

Signed-off-by: Ahmed S. Darwish <[email protected]>
---
 arch/x86/events/intel/pt.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index b5726b50e77d..b938acac9cee 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -189,6 +189,7 @@ static const struct attribute_group *pt_attr_groups[] = {
 
 static int __init pt_pmu_hw_init(void)
 {
+	const struct leaf_0x15_0 *l15;
 	struct dev_ext_attribute *de_attrs;
 	struct attribute **attrs;
 	size_t size;
@@ -199,18 +200,11 @@ static int __init pt_pmu_hw_init(void)
 	rdmsrq(MSR_PLATFORM_INFO, reg);
 	pt_pmu.max_nonturbo_ratio = (reg & 0xff00) >> 8;
 
-	/*
-	 * if available, read in TSC to core crystal clock ratio,
-	 * otherwise, zero for numerator stands for "not enumerated"
-	 * as per SDM
-	 */
-	if (boot_cpu_data.cpuid_level >= CPUID_LEAF_TSC) {
-		u32 eax, ebx, ecx, edx;
-
-		cpuid(CPUID_LEAF_TSC, &eax, &ebx, &ecx, &edx);
-
-		pt_pmu.tsc_art_num = ebx;
-		pt_pmu.tsc_art_den = eax;
+	/* Save the TSC to core crystal clock ratio, if available */
+	l15 = cpuid_leaf(&boot_cpu_data, 0x15);
+	if (l15) {
+		pt_pmu.tsc_art_num = l15->tsc_numerator;
+		pt_pmu.tsc_art_den = l15->tsc_denominator;
 	}
 
 	/* model-specific quirks */
-- 
2.54.0