Re: [PATCH v3 2/3] thread-pool: replace semaphore with condition variable

2022-05-17 Thread Paolo Bonzini
On Tue, May 17, 2022 at 5:20 PM Stefan Hajnoczi wrote: > > On Sat, May 14, 2022 at 08:50:11AM +0200, Paolo Bonzini wrote: > > @@ -134,6 +122,12 @@ static void *worker_thread(void *opaque) > > pool->cur_threads--; > > qemu_cond_signal(&pool->worker_stopped); > > qemu_mutex_unlock(&po

Re: [PATCH v3 2/3] thread-pool: replace semaphore with condition variable

2022-05-17 Thread Stefan Hajnoczi
On Sat, May 14, 2022 at 08:50:11AM +0200, Paolo Bonzini wrote: > @@ -134,6 +122,12 @@ static void *worker_thread(void *opaque) > pool->cur_threads--; > qemu_cond_signal(&pool->worker_stopped); > qemu_mutex_unlock(&pool->lock); > + > +/* > + * Wake up another thread, in case w

Re: [PATCH v3 2/3] thread-pool: replace semaphore with condition variable

2022-05-17 Thread Paolo Bonzini
On 5/17/22 14:46, Nicolas Saenz Julienne wrote: -while (!pool->stopping) { +while (!pool->stopping && pool->cur_threads <= pool->max_threads) { ThreadPoolElement *req; int ret; -do { +if (QTAILQ_EMPTY(&pool->request_list)) { pool->idle

Re: [PATCH v3 2/3] thread-pool: replace semaphore with condition variable

2022-05-17 Thread Nicolas Saenz Julienne
On Tue, 2022-05-17 at 16:18 +0200, Paolo Bonzini wrote: > On 5/17/22 14:46, Nicolas Saenz Julienne wrote: > > > -while (!pool->stopping) { > > > +while (!pool->stopping && pool->cur_threads <= pool->max_threads) { > > > ThreadPoolElement *req; > > > int ret; > > > > >

Re: [PATCH v3 2/3] thread-pool: replace semaphore with condition variable

2022-05-17 Thread Nicolas Saenz Julienne
Hi Paolo, On Sat, 2022-05-14 at 08:50 +0200, Paolo Bonzini wrote: [...] > static void *worker_thread(void *opaque) > { > ThreadPool *pool = opaque; > @@ -99,20 +82,25 @@ static void *worker_thread(void *opaque) > pool->pending_threads--; > do_spawn_thread(pool); > > -while

[PATCH v3 2/3] thread-pool: replace semaphore with condition variable

2022-05-14 Thread Paolo Bonzini
Since commit f9fc8932b1 ("thread-posix: remove the posix semaphore support", 2022-04-06) QemuSemaphore has its own mutex and condition variable; this adds unnecessary overhead on I/O with small block sizes. Check the QTAILQ directly instead of adding the indirection of a semaphore's count. Using