]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix event test timer checks on kernels with HZ=100
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 2 Dec 2009 11:53:42 +0000 (11:53 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 2 Dec 2009 11:53:42 +0000 (11:53 +0000)
On kernels with HZ=100, the resolution of sleeps in poll() is
quite bad. Doing a precise check on the expiry time vs the
current time will thus often thing the timer has not expired
even though we're within 10ms of the expected expiry time. This
then causes another pointless sleep in poll() for <10ms. Timers
do not need to have such precise expiration, so we treat a timer
as expired if it is within 20ms of the expected expiry time. This
also fixes the eventtest.c test suite on kernels with HZ=100

* daemon/event.c: Add 20ms fuzz when checking for timer expiry

daemon/event.c

index 10847c4049d3c2300f1890ef800041da7da40b3f..2218a3e489de32edf27955c96f8ae96a637f7134 100644 (file)
@@ -413,7 +413,12 @@ static int virEventDispatchTimeouts(void) {
         if (eventLoop.timeouts[i].deleted || eventLoop.timeouts[i].frequency < 0)
             continue;
 
-        if (eventLoop.timeouts[i].expiresAt <= now) {
+        /* Add 20ms fuzz so we don't pointlessly spin doing
+         * <10ms sleeps, particularly on kernels with low HZ
+         * it is fine that a timer expires 20ms earlier than
+         * requested
+         */
+        if (eventLoop.timeouts[i].expiresAt <= (now+20)) {
             virEventTimeoutCallback cb = eventLoop.timeouts[i].cb;
             int timer = eventLoop.timeouts[i].timer;
             void *opaque = eventLoop.timeouts[i].opaque;