Skip to contentSkip to conversation

use debug-key to check/test reliable tsc

PATCH New Dan Magenheimer 1 participant 1 message Oct 6, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use debug-key to check/test reliable tsc

Previous attempt was rejected as too intrusive, but further app rdtsc optimization work is very dependent on Xen being able to determine if TSC is reliable or not.

This patch starts to introduce the concept of X86_FEATURE_TSC_RELIABLE as it is defined and used by Linux, but uses it and tests it only in a debug-key for now, so that a wide variety of hardware can be measured by the broader Xen community to confirm/deny TSC assumptions. The eventual goal is for the evaluation of TSC reliability to be exported to userland so that apps can use rdtsc natively if and when it is safe to do so.

(See http://lists.xensource.com/archives/html/xen-devel/2009-10/msg00056.html)

Note that the original Linux code for tsc_sync.c uses a raw spinlock to ensure the "fastest, inlined, non-debug version of a critical section". Xen doesn't provide a _raw_spin_lock() so I used regular spinlocks, but I would prefer the code to use something more strict as Linux does.

(Also includes a minor nit: "NOSTOP" was used in an early version of a Linux patch, but mainline now uses "NONSTOP"... correct this for consistency.)

xen/arch/x86/Makefile +1 -0
diff -r 1e33261a814f xen/arch/x86/Makefile
@@ -45,6 +45,7 @@ obj-y += string.o
 obj-y += string.o
 obj-y += sysctl.o
 obj-y += time.o
+obj-y += tsc_sync.o
 obj-y += trace.o
 obj-y += traps.o
 obj-y += usercopy.o
xen/arch/x86/cpu/amd.c +1 -1
diff -r 1e33261a814f xen/arch/x86/cpu/amd.c
@@ -463,7 +463,7 @@ static void __devinit init_amd(struct cp
 		c->x86_power = cpuid_edx(0x80000007);
 		if (c->x86_power & (1<<8)) {
 			set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
-			set_bit(X86_FEATURE_NOSTOP_TSC, c->x86_capability);
+			set_bit(X86_FEATURE_NONSTOP_TSC, c->x86_capability);
 		}
 	}
 
xen/arch/x86/cpu/intel.c +2 -1
diff -r 1e33261a814f xen/arch/x86/cpu/intel.c
@@ -226,7 +226,8 @@ static void __devinit init_intel(struct 
 		set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
 	if (cpuid_edx(0x80000007) & (1u<<8)) {
 		set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
-		set_bit(X86_FEATURE_NOSTOP_TSC, c->x86_capability);
+		set_bit(X86_FEATURE_NONSTOP_TSC, c->x86_capability);
+		set_bit(X86_FEATURE_TSC_RELIABLE, c->x86_capability);
 	}
 	if ((c->cpuid_level >= 0x00000006) &&
 	    (cpuid_eax(0x00000006) & (1u<<2)))
xen/arch/x86/time.c +49 -1

68 lines not on this page · raw message

xen/arch/x86/tsc_sync.c new file +88 -0

88 lines not on this page · raw message

xen/include/asm-x86/cpufeature.h +2 -1
diff -r 1e33261a814f xen/include/asm-x86/cpufeature.h
@@ -74,9 +74,10 @@
 #define X86_FEATURE_P3		(3*32+ 6) /* P3 */
 #define X86_FEATURE_P4		(3*32+ 7) /* P4 */
 #define X86_FEATURE_CONSTANT_TSC (3*32+ 8) /* TSC ticks at a constant rate */
-#define X86_FEATURE_NOSTOP_TSC	(3*32+ 9) /* TSC does not stop in C states */
+#define X86_FEATURE_NONSTOP_TSC	(3*32+ 9) /* TSC does not stop in C states */
 #define X86_FEATURE_ARAT	(3*32+ 10) /* Always running APIC timer */
 #define X86_FEATURE_ARCH_PERFMON (3*32+11) /* Intel Architectural PerfMon */
+#define X86_FEATURE_TSC_RELIABLE (3*32+12) /* TSC is known to be reliable */
 
 /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
 #define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
xen/include/asm-x86/time.h +2 -0
diff -r 1e33261a814f xen/include/asm-x86/time.h
@@ -43,4 +43,6 @@ uint64_t ns_to_acpi_pm_tick(uint64_t ns)
 
 void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs);
 
+void check_tsc_warp(unsigned long tsc_khz, unsigned long *max_warp);
+
 #endif /* __X86_TIME_H__ */
xen/arch/x86/Makefile +1 -0
diff -r 1e33261a814f xen/arch/x86/Makefile
@@ -45,6 +45,7 @@ obj-y += string.o
 obj-y += string.o
 obj-y += sysctl.o
 obj-y += time.o
+obj-y += tsc_sync.o
 obj-y += trace.o
 obj-y += traps.o
 obj-y += usercopy.o
xen/arch/x86/cpu/amd.c +1 -1
diff -r 1e33261a814f xen/arch/x86/cpu/amd.c
@@ -463,7 +463,7 @@ static void __devinit init_amd(struct cp
 		c->x86_power = cpuid_edx(0x80000007);
 		if (c->x86_power & (1<<8)) {
 			set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
-			set_bit(X86_FEATURE_NOSTOP_TSC, c->x86_capability);
+			set_bit(X86_FEATURE_NONSTOP_TSC, c->x86_capability);
 		}
 	}
 
xen/arch/x86/cpu/intel.c +2 -1
diff -r 1e33261a814f xen/arch/x86/cpu/intel.c
@@ -226,7 +226,8 @@ static void __devinit init_intel(struct 
 		set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
 	if (cpuid_edx(0x80000007) & (1u<<8)) {
 		set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
-		set_bit(X86_FEATURE_NOSTOP_TSC, c->x86_capability);
+		set_bit(X86_FEATURE_NONSTOP_TSC, c->x86_capability);
+		set_bit(X86_FEATURE_TSC_RELIABLE, c->x86_capability);
 	}
 	if ((c->cpuid_level >= 0x00000006) &&
 	    (cpuid_eax(0x00000006) & (1u<<2)))
xen/arch/x86/time.c +49 -1

68 lines not on this page · raw message

xen/arch/x86/tsc_sync.c new file +88 -0

88 lines not on this page · raw message

xen/include/asm-x86/cpufeature.h +2 -1
diff -r 1e33261a814f xen/include/asm-x86/cpufeature.h
@@ -74,9 +74,10 @@
 #define X86_FEATURE_P3		(3*32+ 6) /* P3 */
 #define X86_FEATURE_P4		(3*32+ 7) /* P4 */
 #define X86_FEATURE_CONSTANT_TSC (3*32+ 8) /* TSC ticks at a constant rate */
-#define X86_FEATURE_NOSTOP_TSC	(3*32+ 9) /* TSC does not stop in C states */
+#define X86_FEATURE_NONSTOP_TSC	(3*32+ 9) /* TSC does not stop in C states */
 #define X86_FEATURE_ARAT	(3*32+ 10) /* Always running APIC timer */
 #define X86_FEATURE_ARCH_PERFMON (3*32+11) /* Intel Architectural PerfMon */
+#define X86_FEATURE_TSC_RELIABLE (3*32+12) /* TSC is known to be reliable */
 
 /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
 #define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
xen/include/asm-x86/time.h +2 -0
diff -r 1e33261a814f xen/include/asm-x86/time.h
@@ -43,4 +43,6 @@ uint64_t ns_to_acpi_pm_tick(uint64_t ns)
 
 void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs);
 
+void check_tsc_warp(unsigned long tsc_khz, unsigned long *max_warp);
+
 #endif /* __X86_TIME_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel