Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x86/x86 Don't use TSC freq value from CPUID if cali...
details: https://anonhg.NetBSD.org/src/rev/c4bf437c46c9
branches: trunk
changeset: 971991:c4bf437c46c9
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Tue May 12 06:32:05 2020 +0000
description:
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.
diffstat:
sys/arch/x86/x86/cpu.c | 23 +++++++++++++++++++----
sys/arch/x86/x86/identcpu_subr.c | 6 +++---
2 files changed, 22 insertions(+), 7 deletions(-)
diffs (77 lines):
diff -r f5822475f248 -r c4bf437c46c9 sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c Tue May 12 06:23:07 2020 +0000
+++ b/sys/arch/x86/x86/cpu.c Tue May 12 06:32:05 2020 +0000
@@ -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 @@
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 @@
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;
}
diff -r f5822475f248 -r c4bf437c46c9 sys/arch/x86/x86/identcpu_subr.c
--- a/sys/arch/x86/x86/identcpu_subr.c Tue May 12 06:23:07 2020 +0000
+++ b/sys/arch/x86/x86/identcpu_subr.c Tue May 12 06:32:05 2020 +0000
@@ -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 @@
#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;
}
Home |
Main Index |
Thread Index |
Old Index