Skip to contentSkip to conversation

Allow Intel platforms to declare unsynchronized TSC to kernel

PATCH In review Andi Kleen 2 participants 4 messages Mar 24, 2010 – Mar 29, 2010 x86

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Allow Intel platforms to declare unsynchronized TSC to kernel

Allow Intel platforms to declare unsynchronized TSC to kernel

[This came out of a private discussion with Linus last week]

Nehalem class processors support the CONSTANT_TSC bit in the 8000_0007 CPUID leaf to declare CONSTANT_TSC. One of the ideas behind this bit was to allow the platform to clear it when it cannot guarantee a constant TSC.

Unfortunately this doesn't work right now because the Intel CPU initialization also checks the model number and assumes that all CPUs newer than Yonah have CONSTANT_TSC too.

Terminate the model number check before Nehalem and rely on the 8000_0007 bit only on newer CPUs. This way the platform can actually turn it off.

Atom CPUs might also have newer model numbers and do not necessarily have that bit, but they are all single socket and expected to always have synchronous TSCs.

Open: the two checks still differ in setting sched_clock_stable.

---
 arch/x86/kernel/cpu/intel.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/intel.c +9 -1
Index: linux-2.6.34-rc1-ak/arch/x86/kernel/cpu/intel.c
===================================================================
@@ -43,8 +43,16 @@
 		}
 	}
 
+	/*
+	 * On Nehalem+ class we trust the CONSTANT_TSC bit in 8000_0007 edx,
+	 * so that a platform that doesn't have synchronized TSCs can clear it.
+ 	 * Older CPUs didn't set that bit, so we keep hard coding the model
+	 * numbers for those.
+ 	 * Note this matches Atom class too, but there the TSCs are always
+	 * synchronized anyways.
+ 	 */
 	if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
-		(c->x86 == 0x6 && c->x86_model >= 0x0e))
+		(c->x86 == 0x6 && c->x86_model >= 0x0e && c->x86_model < 0x1a))
 		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
 
 #ifdef CONFIG_X86_64
author
#1 lore raw
Quoted 3 lines · Andi Kleen

Allow Intel platforms to declare unsynchronized TSC to kernel

[This came out of a private discussion with Linus last week]

Ping? Please review this patch.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#2 lore raw
Quoted 9 lines · Andi Kleen
Quoted 3 lines · Andi Kleen

Allow Intel platforms to declare unsynchronized TSC to kernel

[This came out of a private discussion with Linus last week]

Ping? Please review this patch.

-Andi

Does "constant" implicitly means "synchronized"?
IMHO the answer is no.

Following commit tells us that there could be
"constant-but-unsynchronized TSC":
6c56ccecf05fafe100ab4ea94f6fccbf5ff00db7

Quoted 1 line

So, reenable TSC sync test even on constant and non-stop TSC systems.

Quote from the patch description of commit:
40fb17152c50a69dc304dd632131c2f41281ce44

Quoted 9 lines

Add support for CPUID_0x80000007_Bit8 on Intel CPUs as well. This bit means that the TSC is invariant with C/P/T states and always runs at constant frequency.

With Intel CPUs, we have 3 classes
* CPUs where TSC runs at constant rate and does not stop n C-states
* CPUs where TSC runs at constant rate, but will stop in deep C-states
* CPUs where TSC rate will vary based on P/T-states and TSC will stop in deep C-states.

It looks like that "invariant" also means "constant."

I suppose your change is intended to allow newer platform to declare "not invariant", instead of "not invariant but constant." Humm, but how things change...? Still newer platform cannot declare one of 3 classes. Which class is "never on newer platform"? Or we need to have 4th new class?

At least I think your patch description needs some update, to get more comments without confusing reviewers.

Thanks,
H.Seto

author
#3 lore raw
Quoted 5 lines · Hidetoshi Seto
Quoted 4 lines · Andi Kleen
Quoted 2 lines · Andi Kleen

Allow Intel platforms to declare unsynchronized TSC to kernel

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[This came out of a private discussion with Linus last week]

Ping? Please review this patch.

-Andi

Does "constant" implicitly means "synchronized"?

Yes it does for the CPUID bit.

Quoted 4 lines

Following commit tells us that there could be
"constant-but-unsynchronized TSC":
6c56ccecf05fafe100ab4ea94f6fccbf5ff00db7

Quoted 1 line

So, reenable TSC sync test even on constant and non-stop TSC systems.

First the platform is supposed to clear in this case and when it doesn't the later check catches it anyways.

BTW all the things you're mentioning are not actually changed by my patch. In this regard it behaves the same as before. I don't think the patch description has to describe things it does not change or be a general tutorial on TSCs.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.