summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorkevlo <kevlo@openbsd.org>2003-08-11 05:37:59 +0000
committerkevlo <kevlo@openbsd.org>2003-08-11 05:37:59 +0000
commit1c3ef8cbb54ed7127e50e34879b7d7f55ae43aad (patch)
tree36b34e6b090e4c7ac6e08264b43cde3e39be1cb3 /sys
parentmake dmesg prints closer to the rest of the drivers (diff)
downloadwireguard-openbsd-1c3ef8cbb54ed7127e50e34879b7d7f55ae43aad.tar.xz
wireguard-openbsd-1c3ef8cbb54ed7127e50e34879b7d7f55ae43aad.zip
implement CLOCK_MONOTONIC from NetBSD; ok marc@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_time.c47
-rw-r--r--sys/sys/time.h3
2 files changed, 35 insertions, 15 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index 7986aa79acd..02ab73c593a 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.34 2003/06/02 23:28:06 millert Exp $ */
+/* $OpenBSD: kern_time.c,v 1.35 2003/08/11 05:38:05 kevlo Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -120,12 +120,23 @@ sys_clock_gettime(p, v, retval)
clockid_t clock_id;
struct timeval atv;
struct timespec ats;
+ int s;
clock_id = SCARG(uap, clock_id);
- if (clock_id != CLOCK_REALTIME)
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ microtime(&atv);
+ break;
+ case CLOCK_MONOTONIC:
+ /* XXX "hz" granularity */
+ s = splclock();
+ atv = mono_time;
+ splx(s);
+ break;
+ default:
return (EINVAL);
+ }
- microtime(&atv);
TIMEVAL_TO_TIMESPEC(&atv,&ats);
return copyout(&ats, SCARG(uap, tp), sizeof(ats));
@@ -151,17 +162,22 @@ sys_clock_settime(p, v, retval)
return (error);
clock_id = SCARG(uap, clock_id);
- if (clock_id != CLOCK_REALTIME)
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ TIMESPEC_TO_TIMEVAL(&atv, &ats);
+ if ((error = settime(&atv)) != 0)
+ return (error);
+ break;
+ case CLOCK_MONOTONIC:
+ return (EINVAL); /* read-only clock */
+ default:
return (EINVAL);
+ }
if ((error = copyin(SCARG(uap, tp), &ats, sizeof(ats))) != 0)
return (error);
- TIMESPEC_TO_TIMEVAL(&atv,&ats);
-
- error = settime(&atv);
-
- return (error);
+ return (0);
}
int
@@ -179,15 +195,18 @@ sys_clock_getres(p, v, retval)
int error = 0;
clock_id = SCARG(uap, clock_id);
- if (clock_id != CLOCK_REALTIME)
- return (EINVAL);
-
- if (SCARG(uap, tp)) {
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ case CLOCK_MONOTONIC:
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / hz;
+ break;
+ default:
+ return (EINVAL);
+ }
+ if (SCARG(uap, tp))
error = copyout(&ts, SCARG(uap, tp), sizeof (ts));
- }
return error;
}
diff --git a/sys/sys/time.h b/sys/sys/time.h
index c4f12b5f594..fc23d91daf3 100644
--- a/sys/sys/time.h
+++ b/sys/sys/time.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.h,v 1.15 2003/06/02 23:28:22 millert Exp $ */
+/* $OpenBSD: time.h,v 1.16 2003/08/11 05:37:59 kevlo Exp $ */
/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
/*
@@ -154,6 +154,7 @@ struct clockinfo {
#define CLOCK_REALTIME 0
#define CLOCK_VIRTUAL 1
#define CLOCK_PROF 2
+#define CLOCK_MONOTONIC 3
#define TIMER_RELTIME 0x0 /* relative timer */
#define TIMER_ABSTIME 0x1 /* absolute timer */