Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lakio-0000bJ-ES for qemu-devel@nongnu.org; Sat, 21 Feb 2009 00:48:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lakin-0000aR-D2 for qemu-devel@nongnu.org; Sat, 21 Feb 2009 00:48:17 -0500 Received: from [199.232.76.173] (port=55312 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lakin-0000aD-3X for qemu-devel@nongnu.org; Sat, 21 Feb 2009 00:48:17 -0500 Received: from savannah.gnu.org ([199.232.41.3]:33728 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lakim-0006pu-O4 for qemu-devel@nongnu.org; Sat, 21 Feb 2009 00:48:16 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1Lakim-0006Mu-87 for qemu-devel@nongnu.org; Sat, 21 Feb 2009 05:48:16 +0000 Received: from malc by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1Lakim-0006Mq-2v for qemu-devel@nongnu.org; Sat, 21 Feb 2009 05:48:16 +0000 MIME-Version: 1.0 Errors-To: malc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: malc Message-Id: Date: Sat, 21 Feb 2009 05:48:16 +0000 Subject: [Qemu-devel] [6632] Avoid thundering herd problem Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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; }