Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86 Some CPU have cpu counter (CPUID_TSC is there) ...



details:   https://anonhg.NetBSD.org/src/rev/e133975adc07
branches:  trunk
changeset: 761609:e133975adc07
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Feb 02 12:26:42 2011 +0000

description:
Some CPU have cpu counter (CPUID_TSC is there) but don't handle the
rdmsr instruction (CPUID_MSR is not there).
Introduce a cpu_counter_serializing() function to remplace rdmsr(MSR_TSC)
calls, which does a rdmsr(MSR_TSC) if available and cpu_counter() otherwise.
This makes the cpu counter useable on vortex86 CPUs.
OK ad@

diffstat:

 sys/arch/x86/include/cpu_counter.h |   3 ++-
 sys/arch/x86/x86/cpu.c             |   9 +++++----
 sys/arch/x86/x86/tsc.c             |  21 +++++++++++++++------
 3 files changed, 22 insertions(+), 11 deletions(-)

diffs (109 lines):

diff -r 19e40b74bcde -r e133975adc07 sys/arch/x86/include/cpu_counter.h
--- a/sys/arch/x86/include/cpu_counter.h        Wed Feb 02 09:07:32 2011 +0000
+++ b/sys/arch/x86/include/cpu_counter.h        Wed Feb 02 12:26:42 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_counter.h,v 1.4 2008/05/10 16:12:32 ad Exp $       */
+/*     $NetBSD: cpu_counter.h,v 1.5 2011/02/02 12:26:42 bouyer Exp $   */
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -35,6 +35,7 @@
 #ifdef _KERNEL
 
 uint64_t       cpu_counter(void);
+uint64_t       cpu_counter_serializing(void);
 uint32_t       cpu_counter32(void);
 uint64_t       cpu_frequency(struct cpu_info *);
 int            cpu_hascounter(void);
diff -r 19e40b74bcde -r e133975adc07 sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c    Wed Feb 02 09:07:32 2011 +0000
+++ b/sys/arch/x86/x86/cpu.c    Wed Feb 02 12:26:42 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.79 2011/01/11 18:25:25 jruoho Exp $  */
+/*     $NetBSD: cpu.c,v 1.80 2011/02/02 12:26:42 bouyer Exp $  */
 
 /*-
  * Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.79 2011/01/11 18:25:25 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.80 2011/02/02 12:26:42 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"                /* for MPDEBUG */
@@ -1080,9 +1080,10 @@
        uint64_t last_tsc;
 
        if (cpu_hascounter()) {
-               last_tsc = rdmsr(MSR_TSC);
+               last_tsc = cpu_counter_serializing();
                i8254_delay(100000);
-               ci->ci_data.cpu_cc_freq = (rdmsr(MSR_TSC) - last_tsc) * 10;
+               ci->ci_data.cpu_cc_freq =
+                   (cpu_counter_serializing() - last_tsc) * 10;
        }
 }
 
diff -r 19e40b74bcde -r e133975adc07 sys/arch/x86/x86/tsc.c
--- a/sys/arch/x86/x86/tsc.c    Wed Feb 02 09:07:32 2011 +0000
+++ b/sys/arch/x86/x86/tsc.c    Wed Feb 02 12:26:42 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tsc.c,v 1.27 2010/08/21 01:57:34 jruoho Exp $  */
+/*     $NetBSD: tsc.c,v 1.28 2011/02/02 12:26:42 bouyer Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.27 2010/08/21 01:57:34 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.28 2011/02/02 12:26:42 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -177,13 +177,13 @@
 
        /* Flag it and read our TSC. */
        atomic_or_uint(&ci->ci_flags, CPUF_SYNCTSC);
-       bptsc = rdmsr(MSR_TSC) >> 1;
+       bptsc = cpu_counter_serializing() >> 1;
 
        /* Wait for remote to complete, and read ours again. */
        while ((ci->ci_flags & CPUF_SYNCTSC) != 0) {
                __insn_barrier();
        }
-       bptsc += (rdmsr(MSR_TSC) >> 1);
+       bptsc += (cpu_counter_serializing() >> 1);
 
        /* Wait for the results to come in. */
        while (tsc_sync_cpu == ci) {
@@ -222,11 +222,11 @@
        while ((ci->ci_flags & CPUF_SYNCTSC) == 0) {
                __insn_barrier();
        }
-       tsc = (rdmsr(MSR_TSC) >> 1);
+       tsc = (cpu_counter_serializing() >> 1);
 
        /* Instruct primary to read its counter. */
        atomic_and_uint(&ci->ci_flags, ~CPUF_SYNCTSC);
-       tsc += (rdmsr(MSR_TSC) >> 1);
+       tsc += (cpu_counter_serializing() >> 1);
 
        /* Post result.  Ensure the whole value goes out atomically. */
        (void)atomic_swap_64(&tsc_sync_val, tsc);
@@ -257,3 +257,12 @@
 
        return cpu_feature[0] & CPUID_TSC;
 }
+
+uint64_t
+cpu_counter_serializing(void)
+{
+       if (cpu_feature[0] & CPUID_MSR)
+               return rdmsr(MSR_TSC);
+       else
+               return cpu_counter();
+}



Home | Main Index | Thread Index | Old Index