qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [6632] Avoid thundering herd problem


From: malc
Subject: [Qemu-devel] [6632] Avoid thundering herd problem
Date: Sat, 21 Feb 2009 05:48:16 +0000

Revision: 6632
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6632
Author:   malc
Date:     2009-02-21 05:48:15 +0000 (Sat, 21 Feb 2009)

Log Message:
-----------
Avoid thundering herd problem

Broadcast was used so that the I/O threads would wakeup, reset their
ts values and all but one go to sleep, in other words an optimization
to prevent threads from exiting in presence of continuing I/O
activity. Spurious wakeups make the looping around cond_timedwait with
ever reinitialized ts potentially unsafe and as such ts in no longer
reinitilized inside the loop, hence switch to signal is warranted and
this benefits of this particlaur optimization are lost.

(It's worth noting that timed variants of pthread calls use realtime
clock by default, and therefore can hang "forever" should the host
time be changed. Unfortunatelly not all host systems QEMU runs on
support CLOCK_MONOTONIC and/or pthread_condattr_setclock with this
value)

Modified Paths:
--------------
    trunk/posix-aio-compat.c

Modified: trunk/posix-aio-compat.c
===================================================================
--- trunk/posix-aio-compat.c    2009-02-21 05:48:13 UTC (rev 6631)
+++ trunk/posix-aio-compat.c    2009-02-21 05:48:15 UTC (rev 6632)
@@ -61,10 +61,10 @@
     return ret;
 }
 
-static void cond_broadcast(pthread_cond_t *cond)
+static void cond_signal(pthread_cond_t *cond)
 {
-    int ret = pthread_cond_broadcast(cond);
-    if (ret) die2(ret, "pthread_cond_broadcast");
+    int ret = pthread_cond_signal(cond);
+    if (ret) die2(ret, "pthread_cond_signal");
 }
 
 static void thread_create(pthread_t *thread, pthread_attr_t *attr,
@@ -186,7 +186,7 @@
         spawn_thread();
     TAILQ_INSERT_TAIL(&request_list, aiocb, node);
     mutex_unlock(&lock);
-    cond_broadcast(&cond);
+    cond_signal(&cond);
 
     return 0;
 }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]