diff options
author | Kevin Lo <kevlo@cvs.openbsd.org> | 2003-08-11 05:38:06 +0000 |
---|---|---|
committer | Kevin Lo <kevlo@cvs.openbsd.org> | 2003-08-11 05:38:06 +0000 |
commit | ecfc294939048931f95bd235205183d29146563f (patch) | |
tree | 679d9832d28c11718bccde9ce2c2d2d3386bc605 | |
parent | c450a44e46615b60372c7f8e4147b73c70711c33 (diff) |
implement CLOCK_MONOTONIC from NetBSD; ok marc@
-rw-r--r-- | lib/libc/sys/clock_gettime.2 | 8 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 47 | ||||
-rw-r--r-- | sys/sys/time.h | 3 |
3 files changed, 40 insertions, 18 deletions
diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2 index e9746ecdd5f..2545fd67be4 100644 --- a/lib/libc/sys/clock_gettime.2 +++ b/lib/libc/sys/clock_gettime.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: clock_gettime.2,v 1.13 2003/06/02 20:18:39 millert Exp $ +.\" $OpenBSD: clock_gettime.2,v 1.14 2003/08/11 05:38:02 kevlo Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -59,9 +59,11 @@ for time that increments as a wall clock should, .Dv CLOCK_VIRTUAL for time that increments only when -the CPU is running in user mode on behalf of the calling process, or +the CPU is running in user mode on behalf of the calling process, .Dv CLOCK_PROF -for time that increments when the CPU is running in user or kernel mode. +for time that increments when the CPU is running in user or kernel mode, or +.Dv CLOCK_MONOTONIC +for time that increments at a steady rate (monotonically). .Pp The structure pointed to by .Fa tp 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 */ |