Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Move inittimeleft() and gettimeleft() to subr_time.c, ...



details:   https://anonhg.NetBSD.org/src/rev/7ac947e882c5
branches:  trunk
changeset: 748690:7ac947e882c5
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Nov 01 21:46:09 2009 +0000

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

diffstat:

 sys/kern/subr_time.c  |  55 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/kern/sys_lwp.c    |  17 ++++++---------
 sys/kern/sys_mqueue.c |  29 +-------------------------
 sys/kern/sys_select.c |  31 +--------------------------
 sys/sys/mqueue.h      |   3 +-
 sys/sys/timevar.h     |   3 +-
 6 files changed, 67 insertions(+), 71 deletions(-)

diffs (257 lines):

diff -r 96d01a2d8b03 -r 7ac947e882c5 sys/kern/subr_time.c
--- a/sys/kern/subr_time.c      Sun Nov 01 21:14:21 2009 +0000
+++ b/sys/kern/subr_time.c      Sun Nov 01 21:46:09 2009 +0000
@@ -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;
+}
diff -r 96d01a2d8b03 -r 7ac947e882c5 sys/kern/sys_lwp.c
--- a/sys/kern/sys_lwp.c        Sun Nov 01 21:14:21 2009 +0000
+++ b/sys/kern/sys_lwp.c        Sun Nov 01 21:46:09 2009 +0000
@@ -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;
diff -r 96d01a2d8b03 -r 7ac947e882c5 sys/kern/sys_mqueue.c
--- a/sys/kern/sys_mqueue.c     Sun Nov 01 21:14:21 2009 +0000
+++ b/sys/kern/sys_mqueue.c     Sun Nov 01 21:46:09 2009 +0000
@@ -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)
 {
diff -r 96d01a2d8b03 -r 7ac947e882c5 sys/kern/sys_select.c
--- a/sys/kern/sys_select.c     Sun Nov 01 21:14:21 2009 +0000
+++ b/sys/kern/sys_select.c     Sun Nov 01 21:46:09 2009 +0000
@@ -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)
 {
diff -r 96d01a2d8b03 -r 7ac947e882c5 sys/sys/mqueue.h
--- a/sys/sys/mqueue.h  Sun Nov 01 21:14:21 2009 +0000
+++ b/sys/sys/mqueue.h  Sun Nov 01 21:46:09 2009 +0000
@@ -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 *);
 
diff -r 96d01a2d8b03 -r 7ac947e882c5 sys/sys/timevar.h
--- a/sys/sys/timevar.h Sun Nov 01 21:14:21 2009 +0000
+++ b/sys/sys/timevar.h Sun Nov 01 21:46:09 2009 +0000
@@ -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 *);



Home | Main Index | Thread Index | Old Index