Module Name: src
Committed By: msaitoh
Date: Wed Dec 11 02:14:08 UTC 2013
Modified Files:
src/sys/arch/x86/acpi: acpi_cpu_md.c
src/sys/arch/x86/x86: tsc.c tsc.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/x86/acpi/acpi_cpu_md.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/x86/x86/tsc.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/x86/tsc.h
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/acpi/acpi_cpu_md.c
diff -u src/sys/arch/x86/acpi/acpi_cpu_md.c:1.74 src/sys/arch/x86/acpi/acpi_cpu_md.c:1.75
--- src/sys/arch/x86/acpi/acpi_cpu_md.c:1.74 Wed Nov 20 13:52:30 2013
+++ src/sys/arch/x86/acpi/acpi_cpu_md.c Wed Dec 11 02:14:08 2013
@@ -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 <[email protected]>
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.
#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 @@ acpicpu_md_flags(void)
*/
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 @@ acpicpu_md_flags(void)
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 @@ acpicpu_md_flags(void)
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;
Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.34 src/sys/arch/x86/x86/tsc.c:1.35
--- src/sys/arch/x86/x86/tsc.c:1.34 Sun Dec 8 04:07:38 2013
+++ src/sys/arch/x86/x86/tsc.c Wed Dec 11 02:14:08 2013
@@ -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 @@ static struct timecounter tsc_timecounte
.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 @@ tsc_tc_init(void)
}
}
+ 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;
Index: src/sys/arch/x86/x86/tsc.h
diff -u src/sys/arch/x86/x86/tsc.h:1.4 src/sys/arch/x86/x86/tsc.h:1.5
--- src/sys/arch/x86/x86/tsc.h:1.4 Sat May 10 16:12:32 2008
+++ src/sys/arch/x86/x86/tsc.h Wed Dec 11 02:14:08 2013
@@ -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 *);