Module Name: src
Committed By: msaitoh
Date: Tue May 12 06:32:05 UTC 2020
Modified Files:
src/sys/arch/x86/x86: cpu.c identcpu_subr.c
Log Message:
Don't use TSC freq value from CPUID if calibration works.
- When it's the first call of cpu_get_tsc_freq() the HPET is not initialized,
so try to use CPUID to get TSC freq.
- If it's the 2nd call, don't use CPUID. Instead, print the difference
between the calibrated value and CPUID's value if the verbose mode is set.
To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/identcpu_subr.c
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/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.190 src/sys/arch/x86/x86/cpu.c:1.191
--- src/sys/arch/x86/x86/cpu.c:1.190 Fri May 8 22:01:55 2020
+++ src/sys/arch/x86/x86/cpu.c Tue May 12 06:32:05 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.190 2020/05/08 22:01:55 ad Exp $ */
+/* $NetBSD: cpu.c,v 1.191 2020/05/12 06:32:05 msaitoh Exp $ */
/*
* Copyright (c) 2000-2020 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.190 2020/05/08 22:01:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.191 2020/05/12 06:32:05 msaitoh Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -1320,11 +1320,19 @@ cpu_shutdown(device_t dv, int how)
void
cpu_get_tsc_freq(struct cpu_info *ci)
{
- uint64_t freq = 0, t0, t1;
+ uint64_t freq = 0, freq_from_cpuid, t0, t1;
int64_t overhead;
if ((ci->ci_flags & CPUF_PRIMARY) != 0 && cpu_hascounter()) {
- freq = cpu_tsc_freq_cpuid(ci);
+ /*
+ * If it's the first call of this function, try to get TSC
+ * freq from CPUID by calling cpu_tsc_freq_cpuid().
+ * The function also set lapic_per_second variable if it's
+ * known. This is required for Intel's Comet Lake and newer
+ * processors to set LAPIC timer correctly.
+ */
+ if (ci->ci_data.cpu_cc_freq == 0)
+ freq = freq_from_cpuid = cpu_tsc_freq_cpuid(ci);
#if NHPET > 0
if (freq == 0)
freq = hpet_tsc_freq();
@@ -1352,6 +1360,13 @@ cpu_get_tsc_freq(struct cpu_info *ci)
t1 = cpu_counter();
freq = (t1 - t0 - overhead) * 10;
}
+ if (ci->ci_data.cpu_cc_freq != 0) {
+ freq_from_cpuid = cpu_tsc_freq_cpuid(ci);
+ if ((freq_from_cpuid != 0)
+ && (freq != freq_from_cpuid))
+ aprint_verbose_dev(ci->ci_dev, "TSC freq "
+ "calibrated %" PRIu64 " Hz\n", freq);
+ }
} else {
freq = cpu_info_primary.ci_data.cpu_cc_freq;
}
Index: src/sys/arch/x86/x86/identcpu_subr.c
diff -u src/sys/arch/x86/x86/identcpu_subr.c:1.3 src/sys/arch/x86/x86/identcpu_subr.c:1.4
--- src/sys/arch/x86/x86/identcpu_subr.c:1.3 Sat Apr 25 15:26:18 2020
+++ src/sys/arch/x86/x86/identcpu_subr.c Tue May 12 06:32:05 2020
@@ -33,7 +33,7 @@
* See src/usr.sbin/cpuctl/{Makefile, arch/i386.c}).
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu_subr.c,v 1.3 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu_subr.c,v 1.4 2020/05/12 06:32:05 msaitoh Exp $");
#ifdef _KERNEL_OPT
#include "lapic.h"
@@ -139,8 +139,8 @@ cpu_tsc_freq_cpuid(struct cpu_info *ci)
#endif
}
if (freq != 0)
- aprint_verbose_dev(ci->ci_dev, "TSC freq %" PRIu64 " Hz\n",
- freq);
+ aprint_verbose_dev(ci->ci_dev, "TSC freq CPUID %" PRIu64
+ " Hz\n", freq);
return freq;
}