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 If the the TSC timecounter is good then use...
details: https://anonhg.NetBSD.org/src/rev/73527ac38ad2
branches: trunk
changeset: 933150:73527ac38ad2
user: ad <ad%NetBSD.org@localhost>
date: Tue May 19 21:43:36 2020 +0000
description:
If the the TSC timecounter is good then use the TSC for DELAY() too.
diffstat:
sys/arch/x86/x86/tsc.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diffs (69 lines):
diff -r 2a1ed4015d2e -r 73527ac38ad2 sys/arch/x86/x86/tsc.c
--- a/sys/arch/x86/x86/tsc.c Tue May 19 21:40:55 2020 +0000
+++ b/sys/arch/x86/x86/tsc.c Tue May 19 21:43:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tsc.c,v 1.44 2020/05/08 22:01:55 ad Exp $ */
+/* $NetBSD: tsc.c,v 1.45 2020/05/19 21:43:36 ad Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.44 2020/05/08 22:01:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.45 2020/05/19 21:43:36 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -52,6 +52,8 @@
u_int tsc_get_timecount(struct timecounter *);
+static void tsc_delay(unsigned int);
+
uint64_t tsc_freq; /* exported for sysctl */
static int64_t tsc_drift_max = 1000; /* max cycles */
static int64_t tsc_drift_observed;
@@ -145,9 +147,11 @@
}
/*
- * Initialize timecounter(9) of TSC.
- * This function is called after all secondary processors were up and
- * calculated the drift.
+ * Initialize timecounter(9) and DELAY() function of TSC.
+ *
+ * This function is called after all secondary processors were brought up
+ * and drift has been measured, and after any other potential delay funcs
+ * have been installed (e.g. lapic_delay()).
*/
void
tsc_tc_init(void)
@@ -169,6 +173,9 @@
(long long)tsc_drift_observed);
tsc_timecounter.tc_quality = -100;
invariant = false;
+ } else if (vm_guest == VM_GUEST_NO) {
+ delay_func = tsc_delay;
+ x86_delay = tsc_delay;
}
if (tsc_freq != 0) {
@@ -324,3 +331,16 @@
return cpu_feature[0] & CPUID_TSC;
}
+
+static void
+tsc_delay(unsigned int us)
+{
+ uint64_t start, delta;
+
+ start = cpu_counter();
+ delta = (uint64_t)us * cpu_frequency(&cpu_info_primary) / 1000000;
+
+ while ((cpu_counter() - start) < delta) {
+ x86_pause();
+ }
+}
Home |
Main Index |
Thread Index |
Old Index