Module Name:    src
Committed By:   christos
Date:           Thu Oct 27 16:12:53 UTC 2011

Modified Files:
        src/sys/kern: kern_time.c
        src/sys/sys: time.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/kern/kern_time.c
cvs rdiff -u -r1.64 -r1.65 src/sys/sys/time.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/kern_time.c
diff -u src/sys/kern/kern_time.c:1.169 src/sys/kern/kern_time.c:1.170
--- src/sys/kern/kern_time.c:1.169	Wed Jul 27 10:35:34 2011
+++ src/sys/kern/kern_time.c	Thu Oct 27 12:12:52 2011
@@ -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 @@ struct pool ptimer_pool, ptimers_pool;
 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 @@ adjtime1(const struct timeval *delta, st
  * 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 @@ timer_create1(timer_t *tid, clockid_t id
 
 	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 @@ dogetitimer(struct proc *p, int which, s
 	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 @@ sys___setitimer50(struct lwp *l, const s
 	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 @@ dosetitimer(struct proc *p, int which, s
 	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 @@ dosetitimer(struct proc *p, int which, s
 
 		switch (which) {
 		case ITIMER_REAL:
+		case ITIMER_MONOTONIC:
 			pt->pt_ev.sigev_signo = SIGALRM;
 			break;
 		case ITIMER_VIRTUAL:
@@ -1180,11 +1180,23 @@ dosetitimer(struct proc *p, int which, s
 	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);

Index: src/sys/sys/time.h
diff -u src/sys/sys/time.h:1.64 src/sys/sys/time.h:1.65
--- src/sys/sys/time.h:1.64	Fri Mar 27 07:06:26 2009
+++ src/sys/sys/time.h	Thu Oct 27 12:12:52 2011
@@ -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 @@ timeval2bintime(const struct timeval *tv
 /*
  * 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 */

Reply via email to