Source-Changes-HG archive

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

[src/trunk]: src/sys There is no reason not to support CLOCK_MONOTONIC in {g, ...



details:   https://anonhg.NetBSD.org/src/rev/77a416904a3a
branches:  trunk
changeset: 770642:77a416904a3a
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Oct 27 16:12:52 2011 +0000

description:
There is no reason not to support CLOCK_MONOTONIC in {g,s}etitimer() since
the underlying implementation already supports it, so add it.

diffstat:

 sys/kern/kern_time.c |  40 ++++++++++++++++++++++++++--------------
 sys/sys/time.h       |  10 ++++++----
 2 files changed, 32 insertions(+), 18 deletions(-)

diffs (137 lines):

diff -r 6ac6b5924395 -r 77a416904a3a sys/kern/kern_time.c
--- a/sys/kern/kern_time.c      Thu Oct 27 16:10:37 2011 +0000
+++ b/sys/kern/kern_time.c      Thu Oct 27 16:12:52 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_time.c,v 1.169 2011/07/27 14:35:34 uebayasi Exp $ */
+/*     $NetBSD: kern_time.c,v 1.170 2011/10/27 16:12:52 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.169 2011/07/27 14:35:34 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.170 2011/10/27 16:12:52 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/resourcevar.h>
@@ -99,6 +99,7 @@
 CTASSERT(ITIMER_REAL == CLOCK_REALTIME);
 CTASSERT(ITIMER_VIRTUAL == CLOCK_VIRTUAL);
 CTASSERT(ITIMER_PROF == CLOCK_PROF);
+CTASSERT(ITIMER_MONOTONIC == CLOCK_MONOTONIC);
 
 /*
  * Initialize timekeeping.
@@ -500,9 +501,9 @@
  * All timers are kept in an array pointed to by p_timers, which is
  * allocated on demand - many processes don't use timers at all. The
  * first three elements in this array are reserved for the BSD timers:
- * element 0 is ITIMER_REAL, element 1 is ITIMER_VIRTUAL, and element
- * 2 is ITIMER_PROF. The rest may be allocated by the timer_create()
- * syscall.
+ * element 0 is ITIMER_REAL, element 1 is ITIMER_VIRTUAL, element
+ * 2 is ITIMER_PROF, and element 3 is ITIMER_MONOTONIC. The rest may be
+ * allocated by the timer_create() syscall.
  *
  * Realtime timers are kept in the ptimer structure as an absolute
  * time; virtual time timers are kept as a linked list of deltas.
@@ -543,8 +544,7 @@
 
        p = l->l_proc;
 
-       if (id != CLOCK_REALTIME && id != CLOCK_VIRTUAL &&
-           id != CLOCK_PROF && id != CLOCK_MONOTONIC)
+       if ((u_int)id > CLOCK_MONOTONIC)
                return (EINVAL);
 
        if ((pts = p->p_timers) == NULL)
@@ -1063,7 +1063,7 @@
        struct ptimer *pt;
        struct itimerspec its;
 
-       if ((u_int)which > ITIMER_PROF)
+       if ((u_int)which > ITIMER_MONOTONIC)
                return (EINVAL);
 
        mutex_spin_enter(&timer_lock);
@@ -1099,7 +1099,7 @@
        struct itimerval aitv;
        int error;
 
-       if ((u_int)which > ITIMER_PROF)
+       if ((u_int)which > ITIMER_MONOTONIC)
                return (EINVAL);
        itvp = SCARG(uap, itv);
        if (itvp &&
@@ -1124,8 +1124,7 @@
        struct ptimers *pts;
        struct ptimer *pt, *spare;
 
-       KASSERT(which == CLOCK_REALTIME || which == CLOCK_VIRTUAL ||
-           which == CLOCK_PROF);
+       KASSERT((u_int)which <= CLOCK_MONOTONIC);
        if (itimerfix(&itvp->it_value) || itimerfix(&itvp->it_interval))
                return (EINVAL);
 
@@ -1165,6 +1164,7 @@
 
                switch (which) {
                case ITIMER_REAL:
+               case ITIMER_MONOTONIC:
                        pt->pt_ev.sigev_signo = SIGALRM;
                        break;
                case ITIMER_VIRTUAL:
@@ -1180,11 +1180,23 @@
        TIMEVAL_TO_TIMESPEC(&itvp->it_value, &pt->pt_time.it_value);
        TIMEVAL_TO_TIMESPEC(&itvp->it_interval, &pt->pt_time.it_interval);
 
-       if ((which == ITIMER_REAL) && timespecisset(&pt->pt_time.it_value)) {
+       if (timespecisset(&pt->pt_time.it_value)) {
                /* Convert to absolute time */
                /* XXX need to wrap in splclock for timecounters case? */
-               getnanotime(&now);
-               timespecadd(&pt->pt_time.it_value, &now, &pt->pt_time.it_value);
+               switch (which) {
+               case ITIMER_REAL:
+                       getnanotime(&now);
+                       timespecadd(&pt->pt_time.it_value, &now,
+                           &pt->pt_time.it_value);
+                       break;
+               case ITIMER_MONOTONIC:
+                       getnanouptime(&now);
+                       timespecadd(&pt->pt_time.it_value, &now,
+                           &pt->pt_time.it_value);
+                       break;
+               default:
+                       break;
+               }
        }
        timer_settime(pt);
        mutex_spin_exit(&timer_lock);
diff -r 6ac6b5924395 -r 77a416904a3a sys/sys/time.h
--- a/sys/sys/time.h    Thu Oct 27 16:10:37 2011 +0000
+++ b/sys/sys/time.h    Thu Oct 27 16:12:52 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: time.h,v 1.64 2009/03/27 11:06:26 drochner Exp $       */
+/*     $NetBSD: time.h,v 1.65 2011/10/27 16:12:52 christos Exp $       */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -227,10 +227,12 @@
 /*
  * Names of the interval timers, and structure
  * defining a timer setting.
+ * NB: Must match the CLOCK_ constants below.
  */
-#define        ITIMER_REAL     0
-#define        ITIMER_VIRTUAL  1
-#define        ITIMER_PROF     2
+#define        ITIMER_REAL             0
+#define        ITIMER_VIRTUAL          1
+#define        ITIMER_PROF             2
+#define        ITIMER_MONOTONIC        3
 
 struct itimerval {
        struct  timeval it_interval;    /* timer interval */



Home | Main Index | Thread Index | Old Index