diff options
author | 2013-10-06 01:27:49 +0000 | |
---|---|---|
committer | 2013-10-06 01:27:49 +0000 | |
commit | e206ca2e95145f116d06a0b130e6c30106e6c835 (patch) | |
tree | e879c5cfe966c130496cfc17873f412cc4532599 | |
parent | Back out POLLHUP change until a problem with xterm hanging on close (diff) | |
download | wireguard-openbsd-e206ca2e95145f116d06a0b130e6c30106e6c835.tar.xz wireguard-openbsd-e206ca2e95145f116d06a0b130e6c30106e6c835.zip |
Add CLOCK_UPTIME, a clock which measures time-running-not-suspended, so
that mlarkin@ can fix programs that report rates-over-uptime.
ok kettenis@
manpage corrections jmc@ (which I've probably broken again)
-rw-r--r-- | lib/libc/sys/clock_gettime.2 | 31 | ||||
-rw-r--r-- | sys/kern/kern_tc.c | 11 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 9 | ||||
-rw-r--r-- | sys/sys/_time.h | 5 | ||||
-rw-r--r-- | sys/sys/kernel.h | 4 |
5 files changed, 49 insertions, 11 deletions
diff --git a/lib/libc/sys/clock_gettime.2 b/lib/libc/sys/clock_gettime.2 index e7b36d7121f..c5d52f0a16c 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.21 2013/06/17 19:11:54 guenther Exp $ +.\" $OpenBSD: clock_gettime.2,v 1.22 2013/10/06 01:27:50 guenther Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: June 17 2013 $ +.Dd $Mdocdate: October 6 2013 $ .Dt CLOCK_GETTIME 2 .Os .Sh NAME @@ -73,7 +73,13 @@ time that increments when the CPU is running in user or kernel mode on behalf of the calling thread .It Dv CLOCK_MONOTONIC time that increments as a wall clock should but whose absolute value -is meaningless and cannot jump, providing accurate interval measurement +is meaningless and cannot jump, +providing accurate realtime interval measurement, +even across suspend and resume +.It Dv CLOCK_UPTIME +time whose absolute value is the time the system has been running +and not suspended, +providing accurate uptime measurement, both absolute and interval .El .Pp The structure pointed to by @@ -153,3 +159,22 @@ and .Fn clock_settime functions conform to .St -p1003.1-2008 . +.Pp +The +.Dv CLOCK_UPTIME +clock is an extension to that. +.Sh HISTORY +The +.Dv CLOCK_PROCESS_CPUTIME_ID +and +.Dv CLOCK_THREAD_CPUTIME_ID +clocks appeared in +.Ox 5.4 . +The +.Dv CLOCK_UPTIME +clock first appeared in +.Fx 7.0 +and was added to +.Ox +in +.Ox 5.5 . diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 7b988a33dfc..241aaa9e080 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $OpenBSD: kern_tc.c,v 1.20 2013/06/03 16:55:22 guenther Exp $ + * $OpenBSD: kern_tc.c,v 1.21 2013/10/06 01:27:49 guenther Exp $ * $FreeBSD: src/sys/kern/kern_tc.c,v 1.148 2003/03/18 08:45:23 phk Exp $ */ @@ -95,7 +95,7 @@ static struct timecounter *timecounters = &dummy_timecounter; volatile time_t time_second = 1; volatile time_t time_uptime = 0; -extern struct timeval adjtimedelta; +struct bintime naptime; static struct bintime boottimebin; static int timestepwarnings; @@ -339,9 +339,13 @@ tc_setclock(struct timespec *ts) bt2 = timehands->th_offset; timehands->th_offset = bt; + /* XXX fiddle all the little crinkly bits around the fiords... */ + tc_windup(); + #ifndef SMALL_KERNEL /* convert the bintime to ticks */ bintime_sub(&bt, &bt2); + bintime_add(&naptime, &bt); adj_ticks = (long long)hz * bt.sec + (((uint64_t)1000000 * (uint32_t)(bt.frac >> 32)) >> 32) / tick; if (adj_ticks > 0) { @@ -350,9 +354,6 @@ tc_setclock(struct timespec *ts) timeout_adjust_ticks(adj_ticks); } #endif - - /* XXX fiddle all the little crinkly bits around the fiords... */ - tc_windup(); } /* diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index cb700263911..3e5ca31ef7a 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.82 2013/09/14 01:35:01 guenther Exp $ */ +/* $OpenBSD: kern_time.c,v 1.83 2013/10/06 01:27:50 guenther Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -111,12 +111,18 @@ settime(struct timespec *ts) int clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp) { + struct bintime bt; struct proc *q; switch (clock_id) { case CLOCK_REALTIME: nanotime(tp); break; + case CLOCK_UPTIME: + binuptime(&bt); + bintime_sub(&bt, &naptime); + bintime2timespec(&bt, tp); + break; case CLOCK_MONOTONIC: nanouptime(tp); break; @@ -217,6 +223,7 @@ sys_clock_getres(struct proc *p, void *v, register_t *retval) switch (clock_id) { case CLOCK_REALTIME: case CLOCK_MONOTONIC: + case CLOCK_UPTIME: case CLOCK_PROCESS_CPUTIME_ID: case CLOCK_THREAD_CPUTIME_ID: ts.tv_sec = 0; diff --git a/sys/sys/_time.h b/sys/sys/_time.h index 61bc78932f9..97892f978ef 100644 --- a/sys/sys/_time.h +++ b/sys/sys/_time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: _time.h,v 1.5 2013/09/14 01:35:02 guenther Exp $ */ +/* $OpenBSD: _time.h,v 1.6 2013/10/06 01:27:49 guenther Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -37,8 +37,11 @@ #define CLOCK_PROCESS_CPUTIME_ID 2 #define CLOCK_MONOTONIC 3 #define CLOCK_THREAD_CPUTIME_ID 4 +#define CLOCK_UPTIME 5 #if __BSD_VISIBLE +#define __CLOCK_USE_TICKET_LOCKS 8 /* flag for __thrsleep() */ + /* * Per-process and per-thread clocks encode the PID or TID into the * high bits, with the type in the bottom bits diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h index 651f4a9916a..2668266c02c 100644 --- a/sys/sys/kernel.h +++ b/sys/sys/kernel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kernel.h,v 1.14 2013/06/03 16:55:22 guenther Exp $ */ +/* $OpenBSD: kernel.h,v 1.15 2013/10/06 01:27:49 guenther Exp $ */ /* $NetBSD: kernel.h,v 1.11 1995/03/03 01:24:16 cgd Exp $ */ /*- @@ -61,3 +61,5 @@ extern int lbolt; /* once a second sleep address */ extern int tickdelta; extern long timedelta; +extern struct timeval adjtimedelta; /* unapplied time correction */ +extern struct bintime naptime; /* time spent suspended */ |