Module Name:    src
Committed By:   christos
Date:           Thu Jun 27 00:37:35 UTC 2013

Modified Files:
        src/sys/arch/x86/x86: tsc.c

Log Message:
detect a bad msr tsc and don't use it.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/tsc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.30 src/sys/arch/x86/x86/tsc.c:1.31
--- src/sys/arch/x86/x86/tsc.c:1.30	Mon Aug  8 13:00:23 2011
+++ src/sys/arch/x86/x86/tsc.c	Wed Jun 26 20:37:34 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.30 2011/08/08 17:00:23 jmcneill Exp $	*/
+/*	$NetBSD: tsc.c,v 1.31 2013/06/27 00:37:34 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.30 2011/08/08 17:00:23 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.31 2013/06/27 00:37:34 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,6 +51,7 @@ u_int	tsc_get_timecount(struct timecount
 uint64_t	tsc_freq; /* exported for sysctl */
 static int64_t	tsc_drift_max = 250;	/* max cycles */
 static int64_t	tsc_drift_observed;
+static bool	tsc_good;
 
 static volatile int64_t	tsc_sync_val;
 static volatile struct cpu_info	*tsc_sync_cpu;
@@ -76,6 +77,7 @@ tsc_tc_init(void)
 	ci = curcpu();
 	safe = false;
 	tsc_freq = ci->ci_data.cpu_cc_freq;
+	tsc_good = (cpu_feature[0] & CPUID_MSR) != 0 && rdmsr(MSR_TSC) != 0;
 
 	if (cpu_vendor == CPUVENDOR_INTEL) {
 		/*
@@ -258,10 +260,12 @@ cpu_hascounter(void)
 	return cpu_feature[0] & CPUID_TSC;
 }
 
+extern int cpu_msr_tsc;
+
 uint64_t
 cpu_counter_serializing(void)
 {
-	if (cpu_feature[0] & CPUID_MSR)
+	if (tsc_good)
 		return rdmsr(MSR_TSC);
 	else
 		return cpu_counter();

Reply via email to