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.
This commit is contained in:
christos 2013-03-29 01:08:17 +00:00
parent 14184f73a9
commit 4cec95f0ea
6 changed files with 52 additions and 41 deletions

View File

@ -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 @@ nanosleep1(struct lwp *l, clockid_t clock_id, int flags, struct timespec *rqt,
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
*/

View File

@ -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 @@ gettimeleft(struct timespec *ts, struct timespec *sleepts)
* 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)
{
struct timespec tsd;
int error;
struct timespec tsd;
getnanotime(&tsd);
timespecsub(ts, &tsd, &tsd);
if (tsd.tv_sec < 0 || (tsd.tv_sec == 0 && tsd.tv_nsec <= 0)) {
flags &= TIMER_ABSTIME;
if (start == NULL || flags)
start = &tsd;
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;

View File

@ -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 @@ lwp_unpark(lwpid_t target, const void *hint)
}
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 @@ lwp_park(struct timespec *ts, const void *hint)
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 @@ lwp_park(struct timespec *ts, const void *hint)
* 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 @@ sys____lwp_park50(struct lwp *l, const struct sys____lwp_park50_args *uap,
return error;
}
return lwp_park(tsp, SCARG(uap, hint));
return lwp_park(SCARG(uap, clock_id), SCARG(uap, flags), tsp,
SCARG(uap, hint));
}
int

View File

@ -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 @@ mq_recv1(mqd_t mqdes, void *msg_ptr, size_t msg_len, u_int *msg_prio,
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 @@ mq_send1(mqd_t mqdes, const char *msg_ptr, size_t msg_len, u_int msg_prio,
goto error;
}
if (ts) {
error = abstimeout2timo(ts, &t);
error = ts2timo(CLOCK_REALTIME, TIMER_ABSTIME, ts, &t,
NULL);
if (error)
goto error;
} else

View File

@ -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); }

View File

@ -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 @@ do_ksem_wait(lwp_t *l, intptr_t id, bool try, struct timespec *abstime)
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 {