Module Name:    src
Committed By:   rmind
Date:           Sun Nov  1 21:46:09 UTC 2009

Modified Files:
        src/sys/kern: subr_time.c sys_lwp.c sys_mqueue.c sys_select.c
        src/sys/sys: mqueue.h timevar.h

Log Message:
- Move inittimeleft() and gettimeleft() to subr_time.c, where they belong.
- Move abstimeout2timo() there too and export.  Use it in lwp_park().


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/kern/subr_time.c
cvs rdiff -u -r1.47 -r1.48 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.25 -r1.26 src/sys/kern/sys_mqueue.c
cvs rdiff -u -r1.17 -r1.18 src/sys/kern/sys_select.c
cvs rdiff -u -r1.11 -r1.12 src/sys/sys/mqueue.h
cvs rdiff -u -r1.26 -r1.27 src/sys/sys/timevar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.4 src/sys/kern/subr_time.c:1.5
--- src/sys/kern/subr_time.c:1.4	Tue Jul 15 16:18:08 2008
+++ src/sys/kern/subr_time.c	Sun Nov  1 21:46:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.4 2008/07/15 16:18:08 christos Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.5 2009/11/01 21:46:09 rmind Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.4 2008/07/15 16:18:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.5 2009/11/01 21:46:09 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -169,3 +169,54 @@
 		ts->tv_nsec = tick * 1000;
 	return (0);
 }
+
+int
+inittimeleft(struct timespec *ts, struct timespec *sleepts)
+{
+
+	if (itimespecfix(ts)) {
+		return -1;
+	}
+	getnanouptime(sleepts);
+	return 0;
+}
+
+int
+gettimeleft(struct timespec *ts, struct timespec *sleepts)
+{
+	struct timespec sleptts;
+
+	/*
+	 * Reduce ts by elapsed time based on monotonic time scale.
+	 */
+	getnanouptime(&sleptts);
+	timespecadd(ts, sleepts, ts);
+	timespecsub(ts, &sleptts, ts);
+	*sleepts = sleptts;
+
+	return tstohz(ts);
+}
+
+/*
+ * Calculate delta and convert from struct timespec to the ticks.
+ */
+int
+abstimeout2timo(struct timespec *ts, int *timo)
+{
+	struct timespec tsd;
+	int error;
+
+	getnanotime(&tsd);
+	timespecsub(ts, &tsd, &tsd);
+	if (tsd.tv_sec < 0 || (tsd.tv_sec == 0 && tsd.tv_nsec <= 0)) {
+		return ETIMEDOUT;
+	}
+	error = itimespecfix(&tsd);
+	if (error) {
+		return error;
+	}
+	*timo = tstohz(&tsd);
+	KASSERT(*timo != 0);
+
+	return 0;
+}

Index: src/sys/kern/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.47 src/sys/kern/sys_lwp.c:1.48
--- src/sys/kern/sys_lwp.c:1.47	Thu Oct 22 13:12:47 2009
+++ src/sys/kern/sys_lwp.c	Sun Nov  1 21:46:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_lwp.c,v 1.47 2009/10/22 13:12:47 rmind Exp $	*/
+/*	$NetBSD: sys_lwp.c,v 1.48 2009/11/01 21:46:09 rmind 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.47 2009/10/22 13:12:47 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.48 2009/11/01 21:46:09 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -539,7 +539,6 @@
 int
 lwp_park(struct timespec *ts, const void *hint)
 {
-	struct timespec tsx;
 	sleepq_t *sq;
 	kmutex_t *mp;
 	wchan_t wchan;
@@ -548,16 +547,14 @@
 
 	/* Fix up the given timeout value. */
 	if (ts != NULL) {
-		getnanotime(&tsx);
-		timespecsub(ts, &tsx, &tsx);
-		if (tsx.tv_sec < 0 || (tsx.tv_sec == 0 && tsx.tv_nsec <= 0))
-			return ETIMEDOUT;
-		if ((error = itimespecfix(&tsx)) != 0)
+		error = abstimeout2timo(ts, &timo);
+		if (error) {
 			return error;
-		timo = tstohz(&tsx);
+		}
 		KASSERT(timo != 0);
-	} else
+	} else {
 		timo = 0;
+	}
 
 	/* Find and lock the sleep queue. */
 	l = curlwp;

Index: src/sys/kern/sys_mqueue.c
diff -u src/sys/kern/sys_mqueue.c:1.25 src/sys/kern/sys_mqueue.c:1.26
--- src/sys/kern/sys_mqueue.c:1.25	Mon Oct  5 23:49:46 2009
+++ src/sys/kern/sys_mqueue.c	Sun Nov  1 21:46:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_mqueue.c,v 1.25 2009/10/05 23:49:46 rmind Exp $	*/
+/*	$NetBSD: sys_mqueue.c,v 1.26 2009/11/01 21:46:09 rmind Exp $	*/
 
 /*
  * Copyright (c) 2007-2009 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.25 2009/10/05 23:49:46 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_mqueue.c,v 1.26 2009/11/01 21:46:09 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -294,31 +294,6 @@
 	}
 }
 
-/*
- * Calculate delta and convert from struct timespec to the ticks.
- * Used by mq_timedreceive(), mq_timedsend().
- */
-int
-abstimeout2timo(struct timespec *ts, int *timo)
-{
-	struct timespec tsd;
-	int error;
-
-	getnanotime(&tsd);
-	timespecsub(ts, &tsd, &tsd);
-	if (tsd.tv_sec < 0 || (tsd.tv_sec == 0 && tsd.tv_nsec <= 0)) {
-		return ETIMEDOUT;
-	}
-	error = itimespecfix(&tsd);
-	if (error) {
-		return error;
-	}
-	*timo = tstohz(&tsd);
-	KASSERT(*timo != 0);
-
-	return 0;
-}
-
 static int
 mq_stat_fop(file_t *fp, struct stat *st)
 {

Index: src/sys/kern/sys_select.c
diff -u src/sys/kern/sys_select.c:1.17 src/sys/kern/sys_select.c:1.18
--- src/sys/kern/sys_select.c:1.17	Sun Nov  1 21:14:21 2009
+++ src/sys/kern/sys_select.c	Sun Nov  1 21:46:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_select.c,v 1.17 2009/11/01 21:14:21 rmind Exp $	*/
+/*	$NetBSD: sys_select.c,v 1.18 2009/11/01 21:46:09 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.17 2009/11/01 21:14:21 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.18 2009/11/01 21:46:09 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -157,33 +157,6 @@
 }
 
 int
-inittimeleft(struct timespec *ts, struct timespec *sleepts)
-{
-	if (itimespecfix(ts))
-		return -1;
-	getnanouptime(sleepts);
-	return 0;
-}
-
-int
-gettimeleft(struct timespec *ts, struct timespec *sleepts)
-{
-	/*
-	 * We have to recalculate the timeout on every retry.
-	 */
-	struct timespec sleptts;
-	/*
-	 * reduce ts by elapsed time
-	 * based on monotonic time scale
-	 */
-	getnanouptime(&sleptts);
-	timespecadd(ts, sleepts, ts);
-	timespecsub(ts, &sleptts, ts);
-	*sleepts = sleptts;
-	return tstohz(ts);
-}
-
-int
 sys___select50(struct lwp *l, const struct sys___select50_args *uap,
     register_t *retval)
 {

Index: src/sys/sys/mqueue.h
diff -u src/sys/sys/mqueue.h:1.11 src/sys/sys/mqueue.h:1.12
--- src/sys/sys/mqueue.h:1.11	Mon Oct  5 23:49:46 2009
+++ src/sys/sys/mqueue.h	Sun Nov  1 21:46:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: mqueue.h,v 1.11 2009/10/05 23:49:46 rmind Exp $	*/
+/*	$NetBSD: mqueue.h,v 1.12 2009/11/01 21:46:09 rmind Exp $	*/
 
 /*
  * Copyright (c) 2007-2009 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -109,7 +109,6 @@
 
 /* Prototypes */
 void	mqueue_print_list(void (*pr)(const char *, ...));
-int	abstimeout2timo(struct timespec *, int *);
 int	mq_send1(mqd_t, const char *, size_t, u_int, struct timespec *);
 int	mq_recv1(mqd_t, void *, size_t, u_int *, struct timespec *, ssize_t *);
 

Index: src/sys/sys/timevar.h
diff -u src/sys/sys/timevar.h:1.26 src/sys/sys/timevar.h:1.27
--- src/sys/sys/timevar.h:1.26	Sat Oct  3 20:48:42 2009
+++ src/sys/sys/timevar.h	Sun Nov  1 21:46:09 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: timevar.h,v 1.26 2009/10/03 20:48:42 elad Exp $	*/
+/*	$NetBSD: timevar.h,v 1.27 2009/11/01 21:46:09 rmind Exp $	*/
 
 /*
  *  Copyright (c) 2005, 2008 The NetBSD Foundation.
@@ -145,6 +145,7 @@
 void	getmicrotime(struct timeval *);
 
 /* Other functions */
+int	abstimeout2timo(struct timespec *, int *);
 void	adjtime1(const struct timeval *, struct timeval *, struct proc *);
 int	clock_settime1(struct proc *, clockid_t, const struct timespec *, bool);
 int	dogetitimer(struct proc *, int, struct itimerval *);

Reply via email to