Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 detect a bad msr tsc and don't use it.



details:   https://anonhg.NetBSD.org/src/rev/1198950d6df3
branches:  trunk
changeset: 787625:1198950d6df3
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 27 00:37:34 2013 +0000

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

diffstat:

 sys/arch/x86/x86/tsc.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (48 lines):

diff -r fb23ca5b1a7d -r 1198950d6df3 sys/arch/x86/x86/tsc.c
--- a/sys/arch/x86/x86/tsc.c    Wed Jun 26 21:38:10 2013 +0000
+++ b/sys/arch/x86/x86/tsc.c    Thu Jun 27 00:37:34 2013 +0000
@@ -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 @@
 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 @@
        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 @@
        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();



Home | Main Index | Thread Index | Old Index