From d41eccfcfc2bef93ccc4830fef8e0451f5d2b458 Mon Sep 17 00:00:00 2001 From: Jes Sorensen <Jes.Sorensen@redhat.com> Date: Tue, 6 Jul 2010 11:44:49 -0300 Subject: [PATCH 2/2] Avoid thundering herd problem RH-Author: Jes Sorensen <Jes.Sorensen@redhat.com> Message-id: <1278416689-30416-3-git-send-email-Jes.Sorensen@redhat.com> Patchwork-id: 10496 O-Subject: [PATCH 2/2] Avoid thundering herd problem Bugzilla: 587049 RH-Acked-by: Christoph Hellwig <chellwig@redhat.com> RH-Acked-by: Kevin Wolf <kwolf@redhat.com> RH-Acked-by: Juan Quintela <quintela@redhat.com> From: Jes Sorensen <Jes.Sorensen@redhat.com> Backport of 5d47e3728bbd589701f74bb494c9c9825ba23c88: >From: malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162> Date: Sat, 21 Feb 2009 05:48:15 +0000 Subject: [PATCH 3/3] 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) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6632 c046a42c-6fe2-441c-8c8c-71466251a162 Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> --- qemu/posix-aio-compat.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/posix-aio-compat.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qemu/posix-aio-compat.c b/qemu/posix-aio-compat.c index 59f9d9a..fbf1958 100644 --- a/qemu/posix-aio-compat.c +++ b/qemu/posix-aio-compat.c @@ -65,10 +65,10 @@ static int cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, 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, @@ -202,7 +202,7 @@ static int qemu_paio_submit(struct qemu_paiocb *aiocb, int aio_type) spawn_thread(); TAILQ_INSERT_TAIL(&request_list, aiocb, node); mutex_unlock(&lock); - cond_broadcast(&cond); + cond_signal(&cond); return 0; } -- 1.7.0.3