Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86 Make new function named tsc_is_invariant() to a...



details:   https://anonhg.NetBSD.org/src/rev/1acc9a688869
branches:  trunk
changeset: 791932:1acc9a688869
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Wed Dec 11 02:14:08 2013 +0000

description:
Make new function named tsc_is_invariant() to avoid code duplication.
The behavior of acpicpu_md_flags() will change on some CPUs because
the detecting code of invariant TSC is replaced with newer code.

diffstat:

 sys/arch/x86/acpi/acpi_cpu_md.c |  42 +++++++++++++++-------------------------
 sys/arch/x86/x86/tsc.c          |  34 +++++++++++++++++++++++---------
 sys/arch/x86/x86/tsc.h          |   3 +-
 3 files changed, 42 insertions(+), 37 deletions(-)

diffs (173 lines):

diff -r 57f290c2edbe -r 1acc9a688869 sys/arch/x86/acpi/acpi_cpu_md.c
--- a/sys/arch/x86/acpi/acpi_cpu_md.c   Wed Dec 11 01:29:29 2013 +0000
+++ b/sys/arch/x86/acpi/acpi_cpu_md.c   Wed Dec 11 02:14:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_md.c,v 1.74 2013/11/20 13:52:30 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_md.c,v 1.75 2013/12/11 02:14:08 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.74 2013/11/20 13:52:30 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.75 2013/12/11 02:14:08 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -43,6 +43,7 @@
 #include <x86/cpuvar.h>
 #include <x86/cpu_msr.h>
 #include <x86/machdep.h>
+#include <x86/x86/tsc.h>
 
 #include <dev/acpi/acpica.h>
 #include <dev/acpi/acpi_cpu.h>
@@ -162,6 +163,16 @@
         */
        val |= ACPICPU_FLAG_C_APIC | ACPICPU_FLAG_C_TSC;
 
+       /*
+        * Detect whether TSC is invariant. If it is not, we keep the flag to
+        * note that TSC will not run at constant rate. Depending on the CPU,
+        * this may affect P- and T-state changes, but especially relevant
+        * are C-states; with variant TSC, states larger than C1 may
+        * completely stop the counter.
+        */
+       if (tsc_is_invariant())
+               val &= ~ACPICPU_FLAG_C_TSC;
+
        switch (cpu_vendor) {
 
        case CPUVENDOR_IDT:
@@ -214,24 +225,6 @@
                                val &= ~ACPICPU_FLAG_C_APIC;
                }
 
-               /*
-                * Detect whether TSC is invariant. If it is not,
-                * we keep the flag to note that TSC will not run
-                * at constant rate. Depending on the CPU, this may
-                * affect P- and T-state changes, but especially
-                * relevant are C-states; with variant TSC, states
-                * larger than C1 may completely stop the counter.
-                */
-               x86_cpuid(0x80000000, regs);
-
-               if (regs[0] >= 0x80000007) {
-
-                       x86_cpuid(0x80000007, regs);
-
-                       if ((regs[3] & __BIT(8)) != 0)
-                               val &= ~ACPICPU_FLAG_C_TSC;
-               }
-
                break;
 
        case CPUVENDOR_AMD:
@@ -284,13 +277,10 @@
                case 0x15: /* AMD Bulldozer */
 
                        /*
-                        * Like with Intel, detect invariant TSC,
-                        * MSR-based P-states, and AMD's "turbo"
-                        * (Core Performance Boost), respectively.
+                        * Like with Intel, detect MSR-based P-states,
+                        * and AMD's "turbo" (Core Performance Boost),
+                        * respectively.
                         */
-                       if ((regs[3] & CPUID_APM_TSC) != 0)
-                               val &= ~ACPICPU_FLAG_C_TSC;
-
                        if ((regs[3] & CPUID_APM_HWP) != 0)
                                val |= ACPICPU_FLAG_P_FFH;
 
diff -r 57f290c2edbe -r 1acc9a688869 sys/arch/x86/x86/tsc.c
--- a/sys/arch/x86/x86/tsc.c    Wed Dec 11 01:29:29 2013 +0000
+++ b/sys/arch/x86/x86/tsc.c    Wed Dec 11 02:14:08 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tsc.c,v 1.34 2013/12/08 04:07:38 msaitoh Exp $ */
+/*     $NetBSD: tsc.c,v 1.35 2013/12/11 02:14:08 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.34 2013/12/08 04:07:38 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.35 2013/12/11 02:14:08 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -63,23 +63,19 @@
        .tc_quality = 3000,
 };
 
-void
-tsc_tc_init(void)
+bool
+tsc_is_invariant(void)
 {
        struct cpu_info *ci;
        uint32_t descs[4];
        uint32_t family;
        bool invariant;
 
-       if (!cpu_hascounter()) {
-               return;
-       }
+       if (!cpu_hascounter())
+               return false;
 
        ci = curcpu();
        invariant = false;
-       tsc_freq = ci->ci_data.cpu_cc_freq;
-       tsc_good = (cpu_feature[0] & CPUID_MSR) != 0 &&
-           (rdmsr(MSR_TSC) != 0 || rdmsr(MSR_TSC) != 0);
 
        if (cpu_vendor == CPUVENDOR_INTEL) {
                /*
@@ -140,6 +136,24 @@
                }
        }
 
+       return invariant;
+}
+
+void
+tsc_tc_init(void)
+{
+       struct cpu_info *ci;
+       bool invariant;
+
+       if (!cpu_hascounter())
+               return;
+
+       ci = curcpu();
+       tsc_freq = ci->ci_data.cpu_cc_freq;
+       tsc_good = (cpu_feature[0] & CPUID_MSR) != 0 &&
+           (rdmsr(MSR_TSC) != 0 || rdmsr(MSR_TSC) != 0);
+
+       invariant = tsc_is_invariant();
        if (!invariant) {
                aprint_debug("TSC not known invariant on this CPU\n");
                tsc_timecounter.tc_quality = -100;
diff -r 57f290c2edbe -r 1acc9a688869 sys/arch/x86/x86/tsc.h
--- a/sys/arch/x86/x86/tsc.h    Wed Dec 11 01:29:29 2013 +0000
+++ b/sys/arch/x86/x86/tsc.h    Wed Dec 11 02:14:08 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tsc.h,v 1.4 2008/05/10 16:12:32 ad Exp $       */
+/*     $NetBSD: tsc.h,v 1.5 2013/12/11 02:14:08 msaitoh Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -26,6 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+bool   tsc_is_invariant(void);
 void   tsc_tc_init(void);
 void   tsc_sync_ap(struct cpu_info *);
 void   tsc_sync_bp(struct cpu_info *);



Home | Main Index | Thread Index | Old Index