Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Fix monotonic interval timers.
details: https://anonhg.NetBSD.org/src/rev/5b3038f49bf7
branches: trunk
changeset: 772110:5b3038f49bf7
user: christos <christos%NetBSD.org@localhost>
date: Sun Dec 18 22:30:25 2011 +0000
description:
Fix monotonic interval timers.
diffstat:
sys/kern/kern_time.c | 18 +++++++++++++-----
sys/kern/subr_time.c | 16 ++++++++++++++--
sys/sys/timevar.h | 3 ++-
3 files changed, 29 insertions(+), 8 deletions(-)
diffs (107 lines):
diff -r 33739e0ab23e -r 5b3038f49bf7 sys/kern/kern_time.c
--- a/sys/kern/kern_time.c Sun Dec 18 22:25:20 2011 +0000
+++ b/sys/kern/kern_time.c Sun Dec 18 22:30:25 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_time.c,v 1.170 2011/10/27 16:12:52 christos Exp $ */
+/* $NetBSD: kern_time.c,v 1.171 2011/12/18 22:30:25 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.170 2011/10/27 16:12:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.171 2011/12/18 22:30:25 christos Exp $");
#include <sys/param.h>
#include <sys/resourcevar.h>
@@ -674,7 +674,10 @@
* Don't need to check tshzto() return value, here.
* callout_reset() does it for us.
*/
- callout_reset(&pt->pt_ch, tshzto(&pt->pt_time.it_value),
+ callout_reset(&pt->pt_ch,
+ pt->pt_type == CLOCK_MONOTONIC ?
+ tshztoup(&pt->pt_time.it_value) :
+ tshzto(&pt->pt_time.it_value),
realtimerexpire, pt);
}
} else {
@@ -1004,7 +1007,11 @@
return;
}
- getnanotime(&now);
+ if (pt->pt_type == CLOCK_MONOTONIC) {
+ getnanouptime(&now);
+ } else {
+ getnanotime(&now);
+ }
backwards = (timespeccmp(&pt->pt_time.it_value, &now, >));
timespecadd(&pt->pt_time.it_value, &pt->pt_time.it_interval, &next);
/* Handle the easy case of non-overflown timers first. */
@@ -1031,7 +1038,8 @@
* Don't need to check tshzto() return value, here.
* callout_reset() does it for us.
*/
- callout_reset(&pt->pt_ch, tshzto(&pt->pt_time.it_value),
+ callout_reset(&pt->pt_ch, pt->pt_type == CLOCK_MONOTONIC ?
+ tshztoup(&pt->pt_time.it_value) : tshzto(&pt->pt_time.it_value),
realtimerexpire, pt);
mutex_spin_exit(&timer_lock);
}
diff -r 33739e0ab23e -r 5b3038f49bf7 sys/kern/subr_time.c
--- a/sys/kern/subr_time.c Sun Dec 18 22:25:20 2011 +0000
+++ b/sys/kern/subr_time.c Sun Dec 18 22:30:25 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_time.c,v 1.8 2011/01/26 19:15:13 drochner Exp $ */
+/* $NetBSD: subr_time.c,v 1.9 2011/12/18 22:30:25 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.8 2011/01/26 19:15:13 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.9 2011/12/18 22:30:25 christos Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -129,6 +129,18 @@
timespecsub(&ts, &now, &ts);
return tstohz(&ts);
}
+
+int
+tshztoup(const struct timespec *tsp)
+{
+ struct timespec now, ts;
+
+ ts = *tsp; /* Don't modify original tsp. */
+ getnanouptime(&now);
+ timespecsub(&ts, &now, &ts);
+ return tstohz(&ts);
+}
+
/*
* Compute number of ticks in the specified amount of time.
*/
diff -r 33739e0ab23e -r 5b3038f49bf7 sys/sys/timevar.h
--- a/sys/sys/timevar.h Sun Dec 18 22:25:20 2011 +0000
+++ b/sys/sys/timevar.h Sun Dec 18 22:30:25 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: timevar.h,v 1.29 2010/04/08 11:51:13 njoly Exp $ */
+/* $NetBSD: timevar.h,v 1.30 2011/12/18 22:30:25 christos Exp $ */
/*
* Copyright (c) 2005, 2008 The NetBSD Foundation.
@@ -156,6 +156,7 @@
int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int,
struct proc *);
int tshzto(const struct timespec *);
+int tshztoup(const struct timespec *);
int tvhzto(const struct timeval *);
void inittimecounter(void);
int itimerfix(struct timeval *);
Home |
Main Index |
Thread Index |
Old Index