Skip to contentSkip to conversation

Mark rdtsc as sync only for netburst, not for core2

PATCH In review Arjan van de Ven 4 participants 7 messages Nov 28, 2006 – Nov 29, 2006 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mark rdtsc as sync only for netburst, not for core2

Hi,

On the Core2 cpus, the rdtsc instruction is not serializing (as defined in the architecture reference since rdtsc exists) and due to the deep speculation of these cores, it's possible that you can observe time go backwards between cores due to this speculation. Since the kernel already deals with this with the SYNC_RDTSC flag, the solution is simple, only assume that the instruction is serializing on family 15...

The price one pays for this is a slightly slower gettimeofday (by a dozen or two cycles), but that increase is quite small to pay for a really-going-forward tsc counter.

arch/x86_64/kernel/setup.c renamed from arch/x86_64/kernel/setup.c.org +4 -1
@@ -854,7 +854,10 @@ static void __cpuinit init_intel(struct 
 		set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
 	if (c->x86 == 6)
 		set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
-	set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
+	if (c->x86 == 15)
+		set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
+	else
+		clear_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
  	c->x86_max_cores = intel_num_cpu_cores(c);
 
 	srat_detect_node();
#1 lore raw
Quoted 9 lines · Arjan van de Ven

Hi,

On the Core2 cpus, the rdtsc instruction is not serializing (as defined in the architecture reference since rdtsc exists) and due to the deep speculation of these cores, it's possible that you can observe time go backwards between cores due to this speculation. Since the kernel already deals with this with the SYNC_RDTSC flag, the solution is simple, only assume that the instruction is serializing on family 15...

Quoted 3 lines

The price one pays for this is a slightly slower gettimeofday (by a dozen or two cycles), but that increase is quite small to pay for a really-going-forward tsc counter.

Added thanks

-Andi

A message that is not in the archive (sent off-list or not yet received): 1164774239.15257.5.camel@ymzhang

#3 lore raw
Quoted 2 lines · Yanmin

If it's a single processor, the go backwards issue doesn't exist. Below is my patch based on Arjan's. It's against 2.6.19-rc5-mm2.

Hi,

this patch is incorrect

arch/x86_64/kernel/setup.c static void __cpuinit init_intel(struct · line 865

Quoted 9 lines
arch/x86_64/kernel/setup.c +1 -1
@@ -861,7 +861,7 @@ static void __cpuinit init_intel(struct 
 		set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
 	if (c->x86 == 6)
 		set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
-	if (c->x86 == 15)
+	if (c->x86 == 15 && num_possible_cpus() != 1)
 		set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);

first of all, you probably meant "|| num_possible_cpus() == 1"

but second of all, the core2 cpus are dual core so.. .what does it bring you at all?

#4 lore raw
Quoted 24 lines · Arjan van de Ven
Quoted 2 lines · Yanmin

If it's a single processor, the go backwards issue doesn't exist. Below is my patch based on Arjan's. It's against 2.6.19-rc5-mm2.

Hi,

this patch is incorrect

arch/x86_64/kernel/setup.c static void __cpuinit init_intel(struct · line 865

Quoted 11 lines

--- linux-2.6.19-rc5-mm2_arjan/arch/x86_64/kernel/setup.c

2006-11-29 10:41:21.000000000 +0800
+++ linux-2.6.19-rc5-mm2_arjan_fix/arch/x86_64/kernel/setup.c    
2006-11-29 10:42:28.000000000 +0800
arch/x86_64/kernel/setup.c renamed from arch/x86_64/kernel/setup.c.org +1 -1
@@ -861,7 +861,7 @@ static void __cpuinit init_intel(struct          
 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
     if (c->x86 == 6)
         set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
-    if (c->x86 == 15)
+    if (c->x86 == 15 && num_possible_cpus() != 1)
         set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);

first of all, you probably meant "|| num_possible_cpus() == 1"

Quoted 1 line

but second of all, the core2 cpus are dual core so.. .what does it bring you at all?

I guess you could boot with a UP kernel or maxcpus=1?

Signature · 2 lines
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 
#5 lore raw
Quoted 26 lines · Nick Piggin
Quoted 25 lines · Arjan van de Ven
Quoted 3 lines · Yanmin

If it's a single processor, the go backwards issue doesn't exist. Below is
my patch based on Arjan's. It's against 2.6.19-rc5-mm2.

Hi,

this patch is incorrect

arch/x86_64/kernel/setup.c static void __cpuinit init_intel(struct · line 865

Quoted 11 lines

--- linux-2.6.19-rc5-mm2_arjan/arch/x86_64/kernel/setup.c

2006-11-29 10:41:21.000000000 +0800
+++ linux-2.6.19-rc5-mm2_arjan_fix/arch/x86_64/kernel/setup.c    
2006-11-29 10:42:28.000000000 +0800
arch/x86_64/kernel/setup.c renamed from arch/x86_64/kernel/setup.c.org +1 -1
@@ -861,7 +861,7 @@ static void __cpuinit init_intel(struct          
 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
     if (c->x86 == 6)
         set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
-    if (c->x86 == 15)
+    if (c->x86 == 15 && num_possible_cpus() != 1)
         set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);

first of all, you probably meant "|| num_possible_cpus() == 1"

Quoted 4 lines
Quoted 2 lines

but second of all, the core2 cpus are dual core so.. .what does it bring you at all?

I guess you could boot with a UP kernel or maxcpus=1?

Yes, with the new patch. My reply email to Arjan was lost in LKML because my email client was crazy to set the email as HTML format.

Quoted 1 line

A message that is not in the archive (sent off-list or not yet received): 1164787104.2899.7.camel@ymzhang

#7 lore raw
Quoted 3 lines · Yanmin
Quoted 1 line

but second of all, the core2 cpus are dual core so.. .what does it bring you at all?

When there is only one cpu (or UP), the go backwards issue doesn't exist,

it does exist for single-socket dual core already. And core2 is dual core...

Quoted 3 lines

so
don't use cpuid here for UP. Another function init_amd already does so.

not anymore.. that got fixed very recently...
(but you are right; on AMD the speculation is even bigger so there even on single core you need cpuid)

#8 lore raw
Quoted 6 lines · Arjan van de Ven
Quoted 4 lines · Yanmin
Quoted 2 lines

but second of all, the core2 cpus are dual core so.. .what does it bring you at all?

When there is only one cpu (or UP), the go backwards issue doesn't exist,

Quoted 7 lines

it does exist for single-socket dual core already. And core2 is dual core...

Quoted 3 lines

so
don't use cpuid here for UP. Another function init_amd already does so.

not anymore.. that got fixed very recently...

Thanks.

Quoted 2 lines

(but you are right; on AMD the speculation is even bigger so there even on single core you need cpuid)