Commit 5d47e3728bbd589701f74bb494c9c9825ba23c88

Authored by malc
1 parent 30525aff

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
Showing 1 changed file with 4 additions and 4 deletions
posix-aio-compat.c
... ... @@ -61,10 +61,10 @@ static int cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
61 61 return ret;
62 62 }
63 63  
64   -static void cond_broadcast(pthread_cond_t *cond)
  64 +static void cond_signal(pthread_cond_t *cond)
65 65 {
66   - int ret = pthread_cond_broadcast(cond);
67   - if (ret) die2(ret, "pthread_cond_broadcast");
  66 + int ret = pthread_cond_signal(cond);
  67 + if (ret) die2(ret, "pthread_cond_signal");
68 68 }
69 69  
70 70 static void thread_create(pthread_t *thread, pthread_attr_t *attr,
... ... @@ -186,7 +186,7 @@ static int qemu_paio_submit(struct qemu_paiocb *aiocb, int is_write)
186 186 spawn_thread();
187 187 TAILQ_INSERT_TAIL(&request_list, aiocb, node);
188 188 mutex_unlock(&lock);
189   - cond_broadcast(&cond);
  189 + cond_signal(&cond);
190 190  
191 191 return 0;
192 192 }
... ...