summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_clock.c
diff options
context:
space:
mode:
authortholo <tholo@openbsd.org>2004-06-24 19:35:22 +0000
committertholo <tholo@openbsd.org>2004-06-24 19:35:22 +0000
commitc247527514ab9a1b328cae8b6e13b0ff68eb2a76 (patch)
tree276db6e65e12534fa619a2bf272017ece0e3f6b6 /sys/kern/kern_clock.c
parentregress test for re-exec corner cases (diff)
downloadwireguard-openbsd-c247527514ab9a1b328cae8b6e13b0ff68eb2a76.tar.xz
wireguard-openbsd-c247527514ab9a1b328cae8b6e13b0ff68eb2a76.zip
This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions that makes sure locking is done as needed. It also cleans up some uses of wall time vs. uptime some places, but there is sure to be more of these needed as well, particularily in MD code. Also, many current calls to microtime() should probably be changed to getmicrotime(), or to the {,get}microuptime() versions. ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others "Oh, that is not your problem!" from miod@
Diffstat (limited to 'sys/kern/kern_clock.c')
-rw-r--r--sys/kern/kern_clock.c82
1 files changed, 76 insertions, 6 deletions
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index 55a63e0bf61..15c958bbf6b 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_clock.c,v 1.45 2004/06/21 23:50:35 tholo Exp $ */
+/* $OpenBSD: kern_clock.c,v 1.46 2004/06/24 19:35:24 tholo Exp $ */
/* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */
/*-
@@ -266,9 +266,9 @@ int
hzto(tv)
struct timeval *tv;
{
+ struct timeval now;
unsigned long ticks;
long sec, usec;
- int s;
/*
* If the number of usecs in the whole seconds part of the time
@@ -290,10 +290,9 @@ hzto(tv)
* If ints have 32 bits, then the maximum value for any timeout in
* 10ms ticks is 248 days.
*/
- s = splhigh();
- sec = tv->tv_sec - time.tv_sec;
- usec = tv->tv_usec - time.tv_usec;
- splx(s);
+ getmicrotime(&now);
+ sec = tv->tv_sec - now.tv_sec;
+ usec = tv->tv_usec - now.tv_usec;
if (usec < 0) {
sec--;
usec += 1000000;
@@ -539,3 +538,74 @@ sysctl_clockrate(where, sizep)
clkinfo.stathz = stathz ? stathz : hz;
return (sysctl_rdstruct(where, sizep, NULL, &clkinfo, sizeof(clkinfo)));
}
+
+/*
+ * Placeholders until everyone uses the timecounters code.
+ * Won't improve anything except maybe removing a bunch of bugs in fixed code.
+ */
+
+void
+getmicrotime(struct timeval *tvp)
+{
+ int s;
+
+ s = splhigh();
+ *tvp = time;
+ splx(s);
+}
+
+void
+nanotime(struct timespec *tsp)
+{
+ struct timeval tv;
+
+ microtime(&tv);
+ TIMEVAL_TO_TIMESPEC(&tv, tsp);
+}
+
+void
+getnanotime(struct timespec *tsp)
+{
+ struct timeval tv;
+
+ getmicrotime(&tv);
+ TIMEVAL_TO_TIMESPEC(&tv, tsp);
+}
+
+void
+nanouptime(struct timespec *tsp)
+{
+ struct timeval tv;
+
+ microuptime(&tv);
+ TIMEVAL_TO_TIMESPEC(&tv, tsp);
+}
+
+
+void
+getnanouptime(struct timespec *tsp)
+{
+ struct timeval tv;
+
+ getmicrouptime(&tv);
+ TIMEVAL_TO_TIMESPEC(&tv, tsp);
+}
+
+void
+microuptime(struct timeval *tvp)
+{
+ struct timeval tv;
+
+ microtime(&tv);
+ timersub(&tv, &boottime, tvp);
+}
+
+void
+getmicrouptime(struct timeval *tvp)
+{
+ int s;
+
+ s = splhigh();
+ *tvp = mono_time;
+ splx(s);
+}