Skip to contentSkip to conversation

x86: Fix sched_clock_cpu for systems with unsynchronized TSC

PATCH In review Dimitri Sivanich 2 participants 3 messages Mar 1, 2010 – Mar 2, 2010 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: Fix sched_clock_cpu for systems with unsynchronized TSC

On UV systems, the TSC is not synchronized across blades. The sched_clock_cpu() function is returning values that can go backwards (I've seen as much as 8 seconds) when switching between cpus.

As each cpu comes up, early_init_intel() will currently set the sched_clock_stable flag true. When mark_tsc_unstable() runs, it clears the flag, but this only occurs once (the first time a cpu comes up whose TSC is not synchronized with cpu 0). After this, early_init_intel() will set the flag again as the next cpu comes up.

Only set sched_clock_stable if tsc has not been marked unstable.

---

Only affects x86 arch.

 arch/x86/kernel/cpu/intel.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/intel.c +2 -1
Index: linux/arch/x86/kernel/cpu/intel.c
===================================================================
@@ -70,7 +70,8 @@ static void __cpuinit early_init_intel(s
 	if (c->x86_power & (1 << 8)) {
 		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
 		set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
-		sched_clock_stable = 1;
+		if (!check_tsc_unstable())
+			sched_clock_stable = 1;
 	}
 
 	/*
Acked-by on v2 1/1
#1 lore raw
Quoted 35 lines · Dimitri Sivanich

On UV systems, the TSC is not synchronized across blades. The sched_clock_cpu() function is returning values that can go backwards (I've seen as much as 8 seconds) when switching between cpus.

As each cpu comes up, early_init_intel() will currently set the sched_clock_stable flag true. When mark_tsc_unstable() runs, it clears the flag, but this only occurs once (the first time a cpu comes up whose TSC is not synchronized with cpu 0). After this, early_init_intel() will set the flag again as the next cpu comes up.

Only set sched_clock_stable if tsc has not been marked unstable.

---

Only affects x86 arch.

 arch/x86/kernel/cpu/intel.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/kernel/cpu/intel.c
===================================================================

arch/x86/kernel/cpu/intel.c +2 -1
@@ -70,7 +70,8 @@ static void __cpuinit early_init_intel(s
 	if (c->x86_power & (1 << 8)) {
 		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
 		set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
-		sched_clock_stable = 1;
+		if (!check_tsc_unstable())
+			sched_clock_stable = 1;
 	}
 
 	/*
#2 lore raw
In reply to Dimitri Sivanich
Commit-ID:  14be1f7454ea96ee614467a49cf018a1a383b189
Gitweb:     http://git.kernel.org/tip/14be1f7454ea96ee614467a49cf018a1a383b189
Author:     Dimitri Sivanich <[email protected]>
AuthorDate: Mon, 1 Mar 2010 11:48:15 -0600
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 2 Mar 2010 13:36:11 +0100

x86: Fix sched_clock_cpu for systems with unsynchronized TSC

On UV systems, the TSC is not synchronized across blades. The sched_clock_cpu() function is returning values that can go backwards (I've seen as much as 8 seconds) when switching between cpus.

As each cpu comes up, early_init_intel() will currently set the sched_clock_stable flag true. When mark_tsc_unstable() runs, it clears the flag, but this only occurs once (the first time a cpu comes up whose TSC is not synchronized with cpu 0). After this, early_init_intel() will set the flag again as the next cpu comes up.

Only set sched_clock_stable if tsc has not been marked unstable.

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/cpu/intel.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/intel.c +2 -1
index 879666f..7e1cca1 100644
@@ -70,7 +70,8 @@ static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
 	if (c->x86_power & (1 << 8)) {
 		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
 		set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
-		sched_clock_stable = 1;
+		if (!check_tsc_unstable())
+			sched_clock_stable = 1;
 	}
 
 	/*