x86/tsc: print some log if calibrated tsc freq deviates from original too much

Message ID 20240301033610.1719052-1-lei.chen@smartx.com
State New
Headers
Series x86/tsc: print some log if calibrated tsc freq deviates from original too much |

Commit Message

Lei Chen March 1, 2024, 3:36 a.m. UTC
  In most cases, tsc_khz is refined by hpet on boot. But in a few
production-level nodes, the refinement fails because calibrated
freq diviates from origin tsc freq more than 1%. Printing some
logs will help get this info.

Signed-off-by: Lei Chen <lei.chen@smartx.com>
---
 arch/x86/kernel/tsc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
  

Patch

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 15f97c0abc9d..a68b16e72df1 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -1435,8 +1435,15 @@  static void tsc_refine_calibration_work(struct work_struct *work)
 	}
 
 	/* Make sure we're within 1% */
-	if (abs(tsc_khz - freq) > tsc_khz/100)
+	if (abs(tsc_khz - freq) > tsc_khz/100) {
+		pr_warn("Warning: TSC freq calibrated by [%s]: %lu.%03lu MHz deviates too much from original freq: %lu.%03lu MHz\n",
+			hpet ? "HPET" : "PM_TIMER",
+			(unsigned long)freq / 1000,
+			(unsigned long)freq % 1000,
+			(unsigned long)tsc_khz / 1000,
+			(unsigned long)tsc_khz % 1000);
 		goto out;
+	}
 
 	tsc_khz = freq;
 	pr_info("Refined TSC clocksource calibration: %lu.%03lu MHz\n",