[Midnightbsd-cvs] src [7954] trunk/sys/kern/kern_event.c: Make the interval timings for EVFILT_TIMER more accurate.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Sep 14 18:35:01 EDT 2016


Revision: 7954
          http://svnweb.midnightbsd.org/src/?rev=7954
Author:   laffer1
Date:     2016-09-14 18:35:01 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
Make the interval timings for EVFILT_TIMER more accurate.  tvtohz() always
adds an extra tick to account for the current partial clock tick.  However,
that is not appropriate for a repeating timer when the exact tvtohz() value
should be used for subsequent intervals.  Fix repeating callouts for
EVFILT_TIMER by subtracting 1 tick from the tvtohz() result similar to the
fix used in realitexpire() for interval timers.

While here, update a few comments to note that if the EVFILT_TIMER code
were to move out of kern_event.c, it should move to kern_time.c (where the
interval timer code it mimics lives) rather than kern_timeout.c.

Obtained from: FreeBSD svn rev 239915

Revision Links:
--------------
    http://svnweb.midnightbsd.org/src/?rev=239915

Modified Paths:
--------------
    trunk/sys/kern/kern_event.c

Modified: trunk/sys/kern/kern_event.c
===================================================================
--- trunk/sys/kern/kern_event.c	2016-09-14 22:23:25 UTC (rev 7953)
+++ trunk/sys/kern/kern_event.c	2016-09-14 22:35:01 UTC (rev 7954)
@@ -513,6 +513,10 @@
 	list->kl_unlock(list->kl_lockarg);
 }
 
+/*
+ * XXX: EVFILT_TIMER should perhaps live in kern_time.c beside the
+ * interval timer support code.
+ */
 static int
 timertoticks(intptr_t data)
 {
@@ -526,7 +530,6 @@
 	return tticks;
 }
 
-/* XXX - move to kern_timeout.c? */
 static void
 filt_timerexpire(void *knx)
 {
@@ -536,9 +539,16 @@
 	kn->kn_data++;
 	KNOTE_ACTIVATE(kn, 0);	/* XXX - handle locking */
 
+	/*
+	 * timertoticks() uses tvtohz() which always adds 1 to allow
+	 * for the time until the next clock interrupt being strictly
+	 * less than 1 clock tick.  We don't want that here since we
+	 * want to appear to be in sync with the clock interrupt even
+	 * when we're delayed.
+	 */
 	if ((kn->kn_flags & EV_ONESHOT) != EV_ONESHOT) {
 		calloutp = (struct callout *)kn->kn_hook;
-		callout_reset_curcpu(calloutp, timertoticks(kn->kn_sdata),
+		callout_reset_curcpu(calloutp, timertoticks(kn->kn_sdata) - 1,
 		    filt_timerexpire, kn);
 	}
 }
@@ -546,7 +556,6 @@
 /*
  * data contains amount of time to sleep, in milliseconds
  */
-/* XXX - move to kern_timeout.c? */
 static int
 filt_timerattach(struct knote *kn)
 {
@@ -570,7 +579,6 @@
 	return (0);
 }
 
-/* XXX - move to kern_timeout.c? */
 static void
 filt_timerdetach(struct knote *kn)
 {
@@ -583,7 +591,6 @@
 	kn->kn_status |= KN_DETACHED;	/* knlist_remove usually clears it */
 }
 
-/* XXX - move to kern_timeout.c? */
 static int
 filt_timer(struct knote *kn, long hint)
 {



More information about the Midnightbsd-cvs mailing list