Skip to contentSkip to conversation

X86_64: hpet tsc calibration fix broken smi detection logic

PATCH In review Thomas Gleixner 3 participants 3 messages Jul 14, 2007 – Jul 19, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 X86_64: hpet tsc calibration fix broken smi detection logic

The current SMI detection logic in read_hpet_tsc() makes sure, that when a SMI happens between the read of the HPET counter and the read of the TSC, this wrong value is used for TSC calibration.

This is not the intention of the function. The comparison must ensure, that we do _NOT_ use such a value.

Fix the check to use calibration values where delta of the two TSC reads is smaller than a reasonable threshold.

arch/x86_64/kernel/hpet.c +2 -2
@@ -190,7 +190,7 @@ int hpet_reenable(void)
  */
 
 #define TICK_COUNT 100000000
-#define TICK_MIN   5000
+#define SMI_THRESHOLD 50000
 #define MAX_TRIES  5
 
 /*
@@ -205,7 +205,7 @@ static void __init read_hpet_tsc(int *hpet, int *tsc)
 		tsc1 = get_cycles_sync();
 		hpet1 = hpet_readl(HPET_COUNTER);
 		tsc2 = get_cycles_sync();
-		if (tsc2 - tsc1 > TICK_MIN)
+		if ((tsc2 - tsc1) < SMI_TRESHOLD)
 			break;
 	}
 	*hpet = hpet1;
#1 lore raw
Quoted 25 lines · On Sat, 14 Jul 2007 10:41:39 +0200 Thomas Gleixner <[email protected]> wrote:

The current SMI detection logic in read_hpet_tsc() makes sure, that when a SMI happens between the read of the HPET counter and the read of the TSC, this wrong value is used for TSC calibration.

This is not the intention of the function. The comparison must ensure, that we do _NOT_ use such a value.

Fix the check to use calibration values where delta of the two TSC reads is smaller than a reasonable threshold.

arch/x86_64/kernel/hpet.c +1 -1
@@ -190,7 +190,7 @@ int hpet_reenable(void)
  */
 
 #define TICK_COUNT 100000000
-#define TICK_MIN   5000
+#define SMI_THRESHOLD 50000
 #define MAX_TRIES  5
 
 /*

arch/x86_64/kernel/hpet.c static void __init read_hpet_tsc(int *hpet, int *tsc) · line 211

Quoted 8 lines
arch/x86_64/kernel/hpet.c +1 -1
@@ -205,7 +205,7 @@ static void __init read_hpet_tsc(int *hpet, int *tsc)
 		tsc1 = get_cycles_sync();
 		hpet1 = hpet_readl(HPET_COUNTER);
 		tsc2 = get_cycles_sync();
-		if (tsc2 - tsc1 > TICK_MIN)
+		if ((tsc2 - tsc1) < SMI_TRESHOLD)
 			break;
 	}
 	*hpet = hpet1;

So I queued this, and then another patch to revert it so that the x86_64-clockevents conversion would apply. But I was unable to locate the corresponding bug in the post-x86_64-clockevents tree. Did it get fixed by other means in there?

#2 lore raw
Quoted 5 lines · Andrew Morton

So I queued this, and then another patch to revert it so that the x86_64-clockevents conversion would apply. But I was unable to locate the corresponding bug in the post-x86_64-clockevents tree. Did it get fixed by other means in there?

Yes, the code gets merged with i386 there

-Andi