Skip to content

Commit e558ead

Browse files
committed
x86/tsc: Remove CPUID "frequency" leaf magic numbers.
All the code that reads the CPUID frequency information leaf hard-codes a magic number. Give it a symbolic name and use it. Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Zhao Liu <[email protected]> Link: https://lore.kernel.org/all/20241213205036.4397658F%40davehans-spike.ostc.intel.com
1 parent 030c15b commit e558ead

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

arch/x86/include/asm/cpuid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum cpuid_regs_idx {
2424
#define CPUID_MWAIT_LEAF 0x5
2525
#define CPUID_DCA_LEAF 0x9
2626
#define CPUID_TSC_LEAF 0x15
27+
#define CPUID_FREQ_LEAF 0x16
2728

2829
#ifdef CONFIG_X86_32
2930
bool have_cpuid_p(void);

arch/x86/kernel/tsc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ unsigned long native_calibrate_tsc(void)
681681

682682
/*
683683
* Denverton SoCs don't report crystal clock, and also don't support
684-
* CPUID.0x16 for the calculation below, so hardcode the 25MHz crystal
685-
* clock.
684+
* CPUID_FREQ_LEAF for the calculation below, so hardcode the 25MHz
685+
* crystal clock.
686686
*/
687687
if (crystal_khz == 0 &&
688688
boot_cpu_data.x86_vfm == INTEL_ATOM_GOLDMONT_D)
@@ -701,10 +701,10 @@ unsigned long native_calibrate_tsc(void)
701701
* clock, but we can easily calculate it to a high degree of accuracy
702702
* by considering the crystal ratio and the CPU speed.
703703
*/
704-
if (crystal_khz == 0 && boot_cpu_data.cpuid_level >= 0x16) {
704+
if (crystal_khz == 0 && boot_cpu_data.cpuid_level >= CPUID_FREQ_LEAF) {
705705
unsigned int eax_base_mhz, ebx, ecx, edx;
706706

707-
cpuid(0x16, &eax_base_mhz, &ebx, &ecx, &edx);
707+
cpuid(CPUID_FREQ_LEAF, &eax_base_mhz, &ebx, &ecx, &edx);
708708
crystal_khz = eax_base_mhz * 1000 *
709709
eax_denominator / ebx_numerator;
710710
}
@@ -739,12 +739,12 @@ static unsigned long cpu_khz_from_cpuid(void)
739739
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
740740
return 0;
741741

742-
if (boot_cpu_data.cpuid_level < 0x16)
742+
if (boot_cpu_data.cpuid_level < CPUID_FREQ_LEAF)
743743
return 0;
744744

745745
eax_base_mhz = ebx_max_mhz = ecx_bus_mhz = edx = 0;
746746

747-
cpuid(0x16, &eax_base_mhz, &ebx_max_mhz, &ecx_bus_mhz, &edx);
747+
cpuid(CPUID_FREQ_LEAF, &eax_base_mhz, &ebx_max_mhz, &ecx_bus_mhz, &edx);
748748

749749
return eax_base_mhz * 1000;
750750
}

0 commit comments

Comments
 (0)