Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Centralize the computation of struct timespec to th...
details: https://anonhg.NetBSD.org/src/rev/fd6346388b1b
branches: trunk
changeset: 785746:fd6346388b1b
user: christos <christos%NetBSD.org@localhost>
date: Fri Mar 29 01:08:17 2013 +0000
description:
Centralize the computation of struct timespec to the int timo.
Make lwp_park take the regular arguments for specifying what kind
of timeout we supply like clock_nanosleep(), namely clockid_t and flags.
diffstat:
sys/kern/kern_time.c | 17 ++++++-----------
sys/kern/subr_time.c | 34 ++++++++++++++++++++++------------
sys/kern/sys_lwp.c | 18 +++++++++---------
sys/kern/sys_mqueue.c | 10 ++++++----
sys/kern/syscalls.master | 7 +++++--
sys/kern/uipc_sem.c | 7 ++++---
6 files changed, 52 insertions(+), 41 deletions(-)
diffs (255 lines):
diff -r 0c25aba5fd48 -r fd6346388b1b sys/kern/kern_time.c
--- a/sys/kern/kern_time.c Fri Mar 29 01:04:30 2013 +0000
+++ b/sys/kern/kern_time.c Fri Mar 29 01:08:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_time.c,v 1.175 2012/10/02 01:44:28 christos Exp $ */
+/* $NetBSD: kern_time.c,v 1.176 2013/03/29 01:08:17 christos Exp $ */
/*-
* Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.175 2012/10/02 01:44:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.176 2013/03/29 01:08:17 christos Exp $");
#include <sys/param.h>
#include <sys/resourcevar.h>
@@ -346,16 +346,11 @@
struct timespec rmtstart;
int error, timo;
- if ((error = clock_gettime1(clock_id, &rmtstart)) != 0)
- return ENOTSUP;
+ if ((error = ts2timo(clock_id, flags, rqt, &timo, &rmtstart)) != 0) {
+ if (error == ETIMEDOUT)
+ timo = 0;
+ }
- if (flags & TIMER_ABSTIME)
- timespecsub(rqt, &rmtstart, rqt);
-
- if ((error = itimespecfix(rqt)) != 0)
- return error;
-
- timo = tstohz(rqt);
/*
* Avoid inadvertently sleeping forever
*/
diff -r 0c25aba5fd48 -r fd6346388b1b sys/kern/subr_time.c
--- a/sys/kern/subr_time.c Fri Mar 29 01:04:30 2013 +0000
+++ b/sys/kern/subr_time.c Fri Mar 29 01:08:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_time.c,v 1.9 2011/12/18 22:30:25 christos Exp $ */
+/* $NetBSD: subr_time.c,v 1.10 2013/03/29 01:08:17 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.9 2011/12/18 22:30:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.10 2013/03/29 01:08:17 christos Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -216,21 +216,31 @@
* Calculate delta and convert from struct timespec to the ticks.
*/
int
-abstimeout2timo(struct timespec *ts, int *timo)
+ts2timo(clockid_t clock_id, int flags, struct timespec *ts,
+ int *timo, struct timespec *start)
{
+ int error;
struct timespec tsd;
- int error;
+
+ flags &= TIMER_ABSTIME;
+
+ if (start == NULL || flags)
+ start = &tsd;
- getnanotime(&tsd);
- timespecsub(ts, &tsd, &tsd);
- if (tsd.tv_sec < 0 || (tsd.tv_sec == 0 && tsd.tv_nsec <= 0)) {
+ if (start)
+ if ((error = clock_gettime1(clock_id, start)) != 0)
+ return error;
+
+ if (flags)
+ timespecsub(ts, start, ts);
+
+ if (ts->tv_sec < 0 || (ts->tv_sec == 0 && ts->tv_nsec <= 0))
return ETIMEDOUT;
- }
- error = itimespecfix(&tsd);
- if (error) {
+
+ if ((error = itimespecfix(ts)) != 0)
return error;
- }
- *timo = tstohz(&tsd);
+
+ *timo = tstohz(ts);
KASSERT(*timo != 0);
return 0;
diff -r 0c25aba5fd48 -r fd6346388b1b sys/kern/sys_lwp.c
--- a/sys/kern/sys_lwp.c Fri Mar 29 01:04:30 2013 +0000
+++ b/sys/kern/sys_lwp.c Fri Mar 29 01:08:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_lwp.c,v 1.55 2012/09/27 20:43:15 rmind Exp $ */
+/* $NetBSD: sys_lwp.c,v 1.56 2013/03/29 01:08:17 christos Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.55 2012/09/27 20:43:15 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.56 2013/03/29 01:08:17 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -532,7 +532,7 @@
}
int
-lwp_park(struct timespec *ts, const void *hint)
+lwp_park(clockid_t clock_id, int flags, struct timespec *ts, const void *hint)
{
sleepq_t *sq;
kmutex_t *mp;
@@ -540,12 +540,9 @@
int timo, error;
lwp_t *l;
- /* Fix up the given timeout value. */
if (ts != NULL) {
- error = abstimeout2timo(ts, &timo);
- if (error) {
+ if ((error = ts2timo(clock_id, flags, ts, &timo, NULL)) != 0)
return error;
- }
KASSERT(timo != 0);
} else {
timo = 0;
@@ -591,10 +588,12 @@
* requests that it be unparked.
*/
int
-sys____lwp_park50(struct lwp *l, const struct sys____lwp_park50_args *uap,
+sys____lwp_park60(struct lwp *l, const struct sys____lwp_park60_args *uap,
register_t *retval)
{
/* {
+ syscallarg(clockid_t) clock_id;
+ syscallarg(int) flags;
syscallarg(const struct timespec *) ts;
syscallarg(lwpid_t) unpark;
syscallarg(const void *) hint;
@@ -618,7 +617,8 @@
return error;
}
- return lwp_park(tsp, SCARG(uap, hint));
+ return lwp_park(SCARG(uap, clock_id), SCARG(uap, flags), tsp,
+ SCARG(uap, hint));
}
int
diff -r 0c25aba5fd48 -r fd6346388b1b sys/kern/sys_mqueue.c
--- a/sys/kern/sys_mqueue.c Fri Mar 29 01:04:30 2013 +0000
+++ b/sys/kern/sys_mqueue.c Fri Mar 29 01:08:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_mqueue.c,v 1.34 2012/03/13 18:40:53 elad Exp $ */
+/* $NetBSD: sys_mqueue.c,v 1.35 2013/03/29 01:08:17 christos Exp $ */
/*
* Copyright (c) 2007-2011 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.34 2012/03/13 18:40:53 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.35 2013/03/29 01:08:17 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -655,7 +655,8 @@
goto error;
}
if (ts) {
- error = abstimeout2timo(ts, &t);
+ error = ts2timo(CLOCK_REALTIME, TIMER_ABSTIME, ts, &t,
+ NULL);
if (error)
goto error;
} else
@@ -835,7 +836,8 @@
goto error;
}
if (ts) {
- error = abstimeout2timo(ts, &t);
+ error = ts2timo(CLOCK_REALTIME, TIMER_ABSTIME, ts, &t,
+ NULL);
if (error)
goto error;
} else
diff -r 0c25aba5fd48 -r fd6346388b1b sys/kern/syscalls.master
--- a/sys/kern/syscalls.master Fri Mar 29 01:04:30 2013 +0000
+++ b/sys/kern/syscalls.master Fri Mar 29 01:08:17 2013 +0000
@@ -1,4 +1,4 @@
- $NetBSD: syscalls.master,v 1.261 2012/10/02 01:44:28 christos Exp $
+ $NetBSD: syscalls.master,v 1.262 2013/03/29 01:08:17 christos Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@@ -834,7 +834,7 @@
433 STD MODULAR { ssize_t|sys|50|mq_timedreceive(mqd_t mqdes, \
char *msg_ptr, size_t msg_len, unsigned *msg_prio, \
const struct timespec *abs_timeout); }
-434 STD { int|sys|50|_lwp_park(const struct timespec *ts, \
+434 COMPAT_60 MODULAR { int|sys||_lwp_park(const struct timespec *ts, \
lwpid_t unpark, const void *hint, \
const void *unparkhint); }
435 STD RUMP { int|sys|50|kevent(int fd, \
@@ -941,3 +941,6 @@
477 STD { int|sys||clock_nanosleep(clockid_t clock_id, \
int flags, const struct timespec *rqtp, \
struct timespec *rmtp); }
+478 STD { int|sys|60|_lwp_park(clockid_t clock_id, int flags, \
+ const struct timespec *ts, lwpid_t unpark, \
+ const void *hint, const void *unparkhint); }
diff -r 0c25aba5fd48 -r fd6346388b1b sys/kern/uipc_sem.c
--- a/sys/kern/uipc_sem.c Fri Mar 29 01:04:30 2013 +0000
+++ b/sys/kern/uipc_sem.c Fri Mar 29 01:08:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_sem.c,v 1.39 2012/11/25 01:05:04 christos Exp $ */
+/* $NetBSD: uipc_sem.c,v 1.40 2013/03/29 01:08:17 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.39 2012/11/25 01:05:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.40 2013/03/29 01:08:17 christos Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -686,7 +686,8 @@
while (ks->ks_value == 0) {
ks->ks_waiters++;
if (!try && abstime != NULL) {
- error = abstimeout2timo(abstime, &timeo);
+ error = ts2timo(CLOCK_REALTIME, TIMER_ABSTIME, abstime,
+ &timeo, NULL);
if (error != 0)
goto out;
} else {
Home |
Main Index |
Thread Index |
Old Index