summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-06-24 22:03:46 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-06-24 22:03:46 +0000
commitca98724d303a2d2852e5afc6ca4f8df91ce7c4f1 (patch)
tree78c03b913ca4a13ca82e30fea2eea3633977a5a0 /sys/arch
parentd5d00fdfec2707a72d8f409ed3069c27bc916b04 (diff)
kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)
time_second(9) and time_uptime(9) are widely used in the kernel to quickly get the system UTC or system uptime as a time_t. However, time_t is 64-bit everywhere, so it is not generally safe to use them on 32-bit platforms: you have a split-read problem if your hardware cannot perform atomic 64-bit reads. This patch replaces time_second(9) with gettime(9), a safer successor interface, throughout the kernel. Similarly, time_uptime(9) is replaced with getuptime(9). There is a performance cost on 32-bit platforms in exchange for eliminating the split-read problem: instead of two register reads you now have a lockless read loop to pull the values from the timehands. This is really not *too* bad in the grand scheme of things, but compared to what we were doing before it is several times slower. There is no performance cost on 64-bit (__LP64__) platforms. With input from visa@, dlg@, and tedu@. Several bugs squashed by visa@. ok kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/i386/i386/apm.c4
-rw-r--r--sys/arch/loongson/dev/apm.c4
-rw-r--r--sys/arch/sparc64/sparc64/intr.c6
3 files changed, 7 insertions, 7 deletions
diff --git a/sys/arch/i386/i386/apm.c b/sys/arch/i386/i386/apm.c
index 840f1f398b7..3fc4cf7d547 100644
--- a/sys/arch/i386/i386/apm.c
+++ b/sys/arch/i386/i386/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.124 2020/05/29 04:42:23 deraadt Exp $ */
+/* $OpenBSD: apm.c,v 1.125 2020/06/24 22:03:40 cheloha Exp $ */
/*-
* Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
@@ -270,7 +270,7 @@ apm_suspend(int state)
i8254_startclock();
if (initclock_func == i8254_initclocks)
rtcstart(); /* in i8254 mode, rtc is profclock */
- inittodr(time_second);
+ inittodr(gettime());
config_suspend_all(DVACT_RESUME);
cold = 0;
diff --git a/sys/arch/loongson/dev/apm.c b/sys/arch/loongson/dev/apm.c
index 42b3d7c61ba..250d69d248e 100644
--- a/sys/arch/loongson/dev/apm.c
+++ b/sys/arch/loongson/dev/apm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apm.c,v 1.37 2020/05/29 04:42:24 deraadt Exp $ */
+/* $OpenBSD: apm.c,v 1.38 2020/06/24 22:03:40 cheloha Exp $ */
/*-
* Copyright (c) 2001 Alexander Guy. All rights reserved.
@@ -415,7 +415,7 @@ apm_suspend(int state)
if (rv == 0)
rv = sys_platform->resume();
}
- inittodr(time_second); /* Move the clock forward */
+ inittodr(gettime()); /* Move the clock forward */
config_suspend_all(DVACT_RESUME);
cold = 0;
diff --git a/sys/arch/sparc64/sparc64/intr.c b/sys/arch/sparc64/sparc64/intr.c
index c5a29a26b34..45abf2f94b7 100644
--- a/sys/arch/sparc64/sparc64/intr.c
+++ b/sys/arch/sparc64/sparc64/intr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intr.c,v 1.60 2020/06/23 01:21:29 jmatthew Exp $ */
+/* $OpenBSD: intr.c,v 1.61 2020/06/24 22:03:40 cheloha Exp $ */
/* $NetBSD: intr.c,v 1.39 2001/07/19 23:38:11 eeh Exp $ */
/*
@@ -102,12 +102,12 @@ strayintr(const struct trapframe64 *fp, int vectored)
"vectored=%d\n", fp->tf_pil, fp->tf_pc, fp->tf_npc,
fp->tf_tstate >> TSTATE_PSTATE_SHIFT, PSTATE_BITS, vectored);
- timesince = time_second - straytime;
+ timesince = gettime() - straytime;
if (timesince <= 10) {
if (++nstray > 500)
panic("crazy interrupts");
} else {
- straytime = time_second;
+ straytime = gettime();
nstray = 1;
}
#ifdef DDB