blob: 66f4a7625564796831e270535d8da185ec0d1ba9 [file] [log] [blame]
From ad2fc68b109f84d98b0c0f43cb4cffc8da82982b Mon Sep 17 00:00:00 2001
From: Daniel Drake <>
Date: Thu, 9 May 2019 13:54:17 +0800
Subject: [PATCH] x86/tsc: Set LAPIC timer period to crystal clock frequency
commit 2420a0b1798d7a78d1f9b395f09f3c80d92cc588 upstream.
The APIC timer calibration (calibrate_APIC_timer()) can be skipped
in cases where we know the APIC timer frequency. On Intel SoCs,
we believe that the APIC is fed by the crystal clock; this would make
sense, and the crystal clock frequency has been verified against the
APIC timer calibration result on ApolloLake, GeminiLake, Kabylake,
CoffeeLake, WhiskeyLake and AmberLake.
Set lapic_timer_period based on the crystal clock frequency
APIC timer calibration would normally be skipped on modern CPUs
by nature of the TSC deadline timer being used instead,
however this change is still potentially useful, e.g. if the
TSC deadline timer has been disabled with a kernel parameter.
calibrate_APIC_timer() uses the legacy timer, but we are seeing
new platforms that omit such legacy functionality, so avoiding
such codepaths is becoming more important.
Suggested-by: Thomas Gleixner <>
Signed-off-by: Daniel Drake <>
Reviewed-by: Thomas Gleixner <>
Cc: Andy Lutomirski <>
Cc: Borislav Petkov <>
Cc: H. Peter Anvin <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Signed-off-by: Ingo Molnar <>
Signed-off-by: Paul Gortmaker <>
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index c42baeaf8100..f30730621c8a 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -665,6 +665,16 @@ unsigned long native_calibrate_tsc(void)
if (boot_cpu_data.x86_model == INTEL_FAM6_ATOM_GOLDMONT)
+ /*
+ * The local APIC appears to be fed by the core crystal clock
+ * (which sounds entirely sensible). We can set the global
+ * lapic_timer_period here to avoid having to calibrate the APIC
+ * timer later.
+ */
+ lapic_timer_period = crystal_khz * 1000 / HZ;
return crystal_khz * ebx_numerator / eax_denominator;