Skip to contentSkip to conversation

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

PATCH RESEND Superseded Lei Chen 2 participants 3 messages Apr 8, 2024 – Apr 10, 2024 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lei Chen

author
#0 lore raw

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

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.

---
 arch/x86/kernel/tsc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/x86/kernel/tsc.c +8 -1
index 15f97c0abc9d..a68b16e72df1 100644
@@ -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",
Signature · 1 line
2.44.0
#1 lore raw
Quoted 15 lines · Lei Chen

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.

---
 arch/x86/kernel/tsc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/x86/kernel/tsc.c +0 -0
index 15f97c0abc9d..a68b16e72df1 100644

arch/x86/kernel/tsc.c static void tsc_refine_calibration_work(struct work_struct *work) · line 1439

Quoted 6 lines
arch/x86/kernel/tsc.c +2 -1
@@ -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",

Yeah, so it wouldn't cost us anything to more precisely define 'too much':

s/deviates too much from
/deviates by more than 1% from

Right?

arch/x86/kernel/tsc.c static void tsc_refine_calibration_work(struct work_struct *work) · line 1446

Quoted 7 lines
arch/x86/kernel/tsc.c +6 -0
+			hpet ? "HPET" : "PM_TIMER",
+			(unsigned long)freq / 1000,
+			(unsigned long)freq % 1000,
+			(unsigned long)tsc_khz / 1000,
+			(unsigned long)tsc_khz % 1000);
 		goto out;
+	}

The warning makes sense I suppose, if it's one per system and once per bootup [right?], but I think pr_info() would be plenty enough priority for this condition - especially as we didn't have the warning before and don't know how frequent it is?

Thanks,

Ingo

author
#2 lore raw
Quoted 28 lines · Ingo Molnar
Quoted 15 lines · Lei Chen

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.

---
 arch/x86/kernel/tsc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/x86/kernel/tsc.c +0 -0
index 15f97c0abc9d..a68b16e72df1 100644

arch/x86/kernel/tsc.c static void tsc_refine_calibration_work(struct work_struct *work) · line 1439

Quoted 6 lines
arch/x86/kernel/tsc.c +2 -1
@@ -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",

Yeah, so it wouldn't cost us anything to more precisely define 'too much':

Quoted 4 lines

s/deviates too much from
/deviates by more than 1% from

Right?

Thanks for your suggestion, I'll change it.

Quoted 9 lines

arch/x86/kernel/tsc.c static void tsc_refine_calibration_work(struct work_struct *work) · line 1446

Quoted 8 lines
arch/x86/kernel/tsc.c +6 -0
+                     hpet ? "HPET" : "PM_TIMER",
+                     (unsigned long)freq / 1000,
+                     (unsigned long)freq % 1000,
+                     (unsigned long)tsc_khz / 1000,
+                     (unsigned long)tsc_khz % 1000);
              goto out;
+     }
Quoted 5 lines

The warning makes sense I suppose, if it's one per system and once per bootup [right?], but I think pr_info() would be plenty enough priority for this condition - especially as we didn't have the warning before and don't know how frequent it is?

I'm afraid tsc frequency deviates from HPET more than 1% is a system risk. It means either HPET or tsc might be not stable. Users should be cautious of the risk and turn to ntp for help. In our production nodes, it indeed causes more
time skew. So maybe warning is a better way to expose the risk ?