summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--share/man/man9/Makefile3
-rw-r--r--share/man/man9/tvtohz.918
-rw-r--r--sys/kern/kern_clock.c20
-rw-r--r--sys/sys/systm.h4
4 files changed, 36 insertions, 9 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index af4cfbc4f2d..7b1753d88f2 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.176 2013/01/29 01:19:27 dlg Exp $
+# $OpenBSD: Makefile,v 1.177 2013/04/24 17:29:02 matthew Exp $
# $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
@@ -329,6 +329,7 @@ MLINKS+=timeout.9 timeout_add.9 timeout.9 timeout_set.9 \
timeout.9 timeout_add_usec.9 \
timeout.9 timeout_add_nsec.9
MLINKS+=tsleep.9 wakeup.9 tsleep.9 msleep.9
+MLINKS+=tvtohz.9 tstohz.9
MLINKS+=uiomove.9 uio.9
MLINKS+=uvm.9 uvm_init.9 uvm.9 uvm_init_limits.9 uvm.9 uvm_setpagesize.9 \
uvm.9 uvm_swap_init.9 uvm.9 uvm_map.9 uvm.9 uvm_map_pageable.9 \
diff --git a/share/man/man9/tvtohz.9 b/share/man/man9/tvtohz.9
index 90ebd3a5e99..eca8a0d2953 100644
--- a/share/man/man9/tvtohz.9
+++ b/share/man/man9/tvtohz.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tvtohz.9,v 1.5 2010/08/20 22:03:22 matthew Exp $
+.\" $OpenBSD: tvtohz.9,v 1.6 2013/04/24 17:29:02 matthew Exp $
.\"
.\" Copyright (c) 1999 Marc Espie
.\" All rights reserved.
@@ -23,11 +23,12 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: August 20 2010 $
+.Dd $Mdocdate: April 24 2013 $
.Dt TVTOHZ 9
.Os
.Sh NAME
-.Nm tvtohz
+.Nm tvtohz ,
+.Nm tstohz
.Nd translate time period to timeout delay
.Sh SYNOPSIS
.Fd #include <sys/types.h>
@@ -35,16 +36,21 @@
.Fd #include <sys/systm.h>
.Ft int
.Fn tvtohz "const struct timeval *tv"
+.Ft int
+.Fn tstohz "const struct timespec *ts"
.Sh DESCRIPTION
The
.Fn tvtohz
-function computes the number of
+and
+.Fn tstohz
+functions compute the number of
.Va hz
in the specified amount of time.
-This is mainly used to translate a timeval into a suitable argument for
+These are mainly used to translate a timeval or timespec
+into a suitable argument for
.Xr timeout 9 .
.Sh CODE REFERENCES
-This function is implemented in the file
+These functions are implemented in the file
.Pa sys/kern/kern_clock.c .
.Sh SEE ALSO
.Xr hz 9 ,
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.
*
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index a7b039864fa..1d145f5edf2 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systm.h,v 1.98 2013/04/06 03:53:25 tedu Exp $ */
+/* $OpenBSD: systm.h,v 1.99 2013/04/24 17:29:02 matthew Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
@@ -221,8 +221,10 @@ int copyin(const void *, void *, size_t)
int copyout(const void *, void *, size_t);
struct timeval;
+struct timespec;
int hzto(const struct timeval *);
int tvtohz(const struct timeval *);
+int tstohz(const struct timespec *);
void realitexpire(void *);
struct clockframe;