Module Name: src
Committed By: martin
Date: Wed Jul 15 17:25:08 UTC 2020
Modified Files:
src/sys/arch/x86/conf [netbsd-9]: files.x86
src/sys/arch/x86/include [netbsd-9]: apicvar.h cpu.h
src/sys/arch/x86/x86 [netbsd-9]: cpu.c hyperv.c tsc.c
src/sys/arch/xen/conf [netbsd-9]: files.xen
Log Message:
Pull up the following, requested by msaitoh in ticket #1015
sys/arch/x86/conf/files.x86 1.108 (via patch)
sys/arch/x86/include/apicvar.h 1.7 (via patch)
sys/arch/x86/include/cpu.h 1.121 (via patch)
sys/arch/x86/x86/cpu.c 1.185 (via patch)
sys/arch/x86/x86/hyperv.c 1.7 (via patch)
sys/arch/x86/x86/tsc.c 1.41 (via patch)
sys/arch/xen/conf/files.xen 1.181 (via patch)
Get TSC frequency from CPUID 0x15 and/or x16 if it's available.
This change fixes a problem that newer Intel processors' timer
counts very slowly.
To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.107.4.1 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/arch/x86/include/apicvar.h
cvs rdiff -u -r1.107 -r1.107.2.1 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.171.2.1 -r1.171.2.2 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.4.4.1 -r1.4.4.2 src/sys/arch/x86/x86/hyperv.c
cvs rdiff -u -r1.37.8.1 -r1.37.8.2 src/sys/arch/x86/x86/tsc.c
cvs rdiff -u -r1.178 -r1.178.4.1 src/sys/arch/xen/conf/files.xen
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/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.107 src/sys/arch/x86/conf/files.x86:1.107.4.1
--- src/sys/arch/x86/conf/files.x86:1.107 Fri Feb 15 08:54:01 2019
+++ src/sys/arch/x86/conf/files.x86 Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.x86,v 1.107 2019/02/15 08:54:01 nonaka Exp $
+# $NetBSD: files.x86,v 1.107.4.1 2020/07/15 17:25:08 martin Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -91,6 +91,7 @@ file arch/x86/x86/efi.c machdep
file arch/x86/x86/errata.c machdep
file arch/x86/x86/genfb_machdep.c machdep
file arch/x86/x86/identcpu.c machdep
+file arch/x86/x86/identcpu_subr.c machdep
file arch/x86/x86/i8259.c machdep
file arch/x86/x86/intr.c machdep
file arch/x86/x86/kgdb_machdep.c kgdb
Index: src/sys/arch/x86/include/apicvar.h
diff -u src/sys/arch/x86/include/apicvar.h:1.6 src/sys/arch/x86/include/apicvar.h:1.6.2.1
--- src/sys/arch/x86/include/apicvar.h:1.6 Fri Jun 14 09:23:42 2019
+++ src/sys/arch/x86/include/apicvar.h Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: apicvar.h,v 1.6 2019/06/14 09:23:42 msaitoh Exp $ */
+/* $NetBSD: apicvar.h,v 1.6.2.1 2020/07/15 17:25:08 martin Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -54,4 +54,7 @@ struct apic_attach_args {
void apic_format_redir(const char *, const char *, int, int, uint32_t,
uint32_t);
+/* For lapic.c */
+extern uint32_t lapic_per_second;
+
#endif /* !_X86_APICVAR_H_ */
Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.107 src/sys/arch/x86/include/cpu.h:1.107.2.1
--- src/sys/arch/x86/include/cpu.h:1.107 Wed Jun 26 12:29:00 2019
+++ src/sys/arch/x86/include/cpu.h Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.107 2019/06/26 12:29:00 mgorny Exp $ */
+/* $NetBSD: cpu.h,v 1.107.2.1 2020/07/15 17:25:08 martin Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
@@ -483,6 +483,9 @@ void cpu_probe(struct cpu_info *);
void cpu_identify(struct cpu_info *);
void identify_hypervisor(void);
+/* identcpu_subr.c */
+uint64_t cpu_tsc_freq_cpuid(struct cpu_info *);
+
typedef enum vm_guest {
VM_GUEST_NO = 0,
VM_GUEST_VM,
Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.171.2.1 src/sys/arch/x86/x86/cpu.c:1.171.2.2
--- src/sys/arch/x86/x86/cpu.c:1.171.2.1 Tue Jan 21 11:36:36 2020
+++ src/sys/arch/x86/x86/cpu.c Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.171.2.1 2020/01/21 11:36:36 martin Exp $ */
+/* $NetBSD: cpu.c,v 1.171.2.2 2020/07/15 17:25:08 martin Exp $ */
/*
* Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.171.2.1 2020/01/21 11:36:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.171.2.2 2020/07/15 17:25:08 martin Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -1261,12 +1261,20 @@ cpu_shutdown(device_t dv, int how)
return cpu_stop(dv);
}
+/* Get the TSC frequency and set it to ci->ci_data.cpu_cc_freq. */
void
cpu_get_tsc_freq(struct cpu_info *ci)
{
- uint64_t last_tsc;
+ uint64_t freq = 0, last_tsc;
- if (cpu_hascounter()) {
+ if (cpu_hascounter())
+ freq = cpu_tsc_freq_cpuid(ci);
+
+ if (freq != 0) {
+ /* Use TSC frequency taken from CPUID. */
+ ci->ci_data.cpu_cc_freq = freq;
+ } else {
+ /* Calibrate TSC frequency. */
last_tsc = cpu_counter_serializing();
x86_delay(100000);
ci->ci_data.cpu_cc_freq =
Index: src/sys/arch/x86/x86/hyperv.c
diff -u src/sys/arch/x86/x86/hyperv.c:1.4.4.1 src/sys/arch/x86/x86/hyperv.c:1.4.4.2
--- src/sys/arch/x86/x86/hyperv.c:1.4.4.1 Sun Dec 8 13:09:28 2019
+++ src/sys/arch/x86/x86/hyperv.c Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hyperv.c,v 1.4.4.1 2019/12/08 13:09:28 martin Exp $ */
+/* $NetBSD: hyperv.c,v 1.4.4.2 2020/07/15 17:25:08 martin Exp $ */
/*-
* Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
#ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.4.4.1 2019/12/08 13:09:28 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.4.4.2 2020/07/15 17:25:08 martin Exp $");
#endif
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -67,6 +67,7 @@ __FBSDID("$FreeBSD: head/sys/dev/hyperv/
#include <machine/cputypes.h>
#include <machine/cpuvar.h>
#include <machine/cpu_counter.h>
+#include <x86/apicvar.h>
#include <x86/efi.h>
#include <dev/wsfb/genfbvar.h>
@@ -536,11 +537,8 @@ hyperv_init(void)
#if NLAPIC > 0
if ((hyperv_features & CPUID_HV_MSR_TIME_FREQ) &&
- (hyperv_features3 & CPUID3_HV_TIME_FREQ)) {
- extern uint32_t lapic_per_second;
-
+ (hyperv_features3 & CPUID3_HV_TIME_FREQ))
lapic_per_second = rdmsr(MSR_HV_APIC_FREQUENCY);
- }
#endif
return hyperv_init_hypercall();
Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.37.8.1 src/sys/arch/x86/x86/tsc.c:1.37.8.2
--- src/sys/arch/x86/x86/tsc.c:1.37.8.1 Tue Apr 14 17:15:02 2020
+++ src/sys/arch/x86/x86/tsc.c Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: tsc.c,v 1.37.8.1 2020/04/14 17:15:02 martin Exp $ */
+/* $NetBSD: tsc.c,v 1.37.8.2 2020/07/15 17:25:08 martin Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.37.8.1 2020/04/14 17:15:02 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.37.8.2 2020/07/15 17:25:08 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -142,6 +142,11 @@ tsc_is_invariant(void)
return invariant;
}
+/*
+ * Initialize timecounter(9) of TSC.
+ * This function is called after all secondary processors were up and
+ * calculated the drift.
+ */
void
tsc_tc_init(void)
{
Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.178 src/sys/arch/xen/conf/files.xen:1.178.4.1
--- src/sys/arch/xen/conf/files.xen:1.178 Thu Feb 14 08:18:26 2019
+++ src/sys/arch/xen/conf/files.xen Wed Jul 15 17:25:08 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.xen,v 1.178 2019/02/14 08:18:26 cherry Exp $
+# $NetBSD: files.xen,v 1.178.4.1 2020/07/15 17:25:08 martin Exp $
# NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp
# NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp
@@ -145,6 +145,7 @@ file arch/x86/x86/bus_space.c machdep
file arch/xen/x86/consinit.c machdep & xenpv
file arch/x86/x86/consinit.c machdep & xenpvhvm
file arch/x86/x86/identcpu.c machdep
+file arch/x86/x86/identcpu_subr.c machdep
file arch/xen/x86/pintr.c machdep & dom0ops & xenpv
file arch/xen/x86/xen_ipi.c multiprocessor & xenpv
file arch/x86/x86/idt.c machdep