summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_clock.c
diff options
context:
space:
mode:
authormatthew <matthew@openbsd.org>2013-04-24 17:29:02 +0000
committermatthew <matthew@openbsd.org>2013-04-24 17:29:02 +0000
commitc4cc3043c816b960fba08ddffb29729258361c4b (patch)
treeda97d779331434927b8316ae9fe79f068b9a471b /sys/kern/kern_clock.c
parentremove extra parens noticed by nicm (diff)
downloadwireguard-openbsd-c4cc3043c816b960fba08ddffb29729258361c4b.tar.xz
wireguard-openbsd-c4cc3043c816b960fba08ddffb29729258361c4b.zip
Add tstohz(9) as the timespec analog to tvtohz(9).
ok miod
Diffstat (limited to 'sys/kern/kern_clock.c')
-rw-r--r--sys/kern/kern_clock.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index 5f8ff077fc1..9fc529c7270 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_clock.c,v 1.80 2013/03/28 16:55:25 deraadt Exp $ */
+/* $OpenBSD: kern_clock.c,v 1.81 2013/04/24 17:29:02 matthew Exp $ */
/* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */
/*-
@@ -329,6 +329,24 @@ tvtohz(const struct timeval *tv)
return ((int)ticks);
}
+int
+tstohz(const struct timespec *ts)
+{
+ struct timeval tv;
+ TIMESPEC_TO_TIMEVAL(&tv, ts);
+
+ /* Round up. */
+ if ((ts->tv_nsec % 1000) != 0) {
+ tv.tv_usec += 1;
+ if (tv.tv_usec >= 1000000) {
+ tv.tv_usec -= 1000000;
+ tv.tv_sec += 1;
+ }
+ }
+
+ return (tvtohz(&tv));
+}
+
/*
* Start profiling on a process.
*