qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzju@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: stefanha@redhat.com, "Lukáš Doktor" <ldoktor@redhat.com>
Subject: Re: [PATCH v3 2/3] thread-pool: replace semaphore with condition variable
Date: Tue, 17 May 2022 16:37:45 +0200	[thread overview]
Message-ID: <f2012b0a303f95df3a85a9a12df5307195619962.camel@redhat.com> (raw)
In-Reply-To: <ecf91e34-b588-f3ee-45eb-34fbde597cad@redhat.com>

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;
> > >   
> > > -        do {
> > > +        if (QTAILQ_EMPTY(&pool->request_list)) {
> > >               pool->idle_threads++;
> > > -            qemu_mutex_unlock(&pool->lock);
> > > -            ret = qemu_sem_timedwait(&pool->sem, 10000);
> > > -            qemu_mutex_lock(&pool->lock);
> > > +            ret = qemu_cond_timedwait(&pool->request_cond, &pool->lock, 10000);
> > >               pool->idle_threads--;
> > > -        } while (back_to_sleep(pool, ret));
> > > -        if (ret == -1 || pool->stopping ||
> > > -            pool->cur_threads > pool->max_threads) {
> > > -            break;
> > > +            if (ret == 0 &&
> > > +                QTAILQ_EMPTY(&pool->request_list) &&
> > > +                pool->cur_threads > pool->min_threads) {
> > > +                /* Timed out + no work to do + no need for warm threads = exit.  */
> > > +                break;
> > > +            }
> > 
> >   Some comments:
> > 
> > - A completely idle pool will now never be able to lose its threads, as the
> >    'pool->cur_threads <= pool->max_threads' condition is only checked after a
> >    non-timeout wakeup.
> 
> Are you sure?  The full code is:
> 
>              ret = qemu_cond_timedwait(&pool->request_cond, &pool->lock, 10000);
>              pool->idle_threads--;
>              if (ret == 0 &&
>                  QTAILQ_EMPTY(&pool->request_list) &&
>                  pool->cur_threads > pool->min_threads) {
>                  /* Timed out + no work to do + no need for warm threads  exit.  */
>                  break;
>              }
>              /*
>               * Even if there was some work to do, check if there aren't
>               * too many worker threads before picking it up.
>               */
>              continue;
> 

OK, I somehow missed this 'continue', I wonder if I managed to re-review v2 by
accident... Anyway, it looks fine to me now.

Regards,

-- 
Nicolás Sáenz



  reply	other threads:[~2022-05-17 14:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-14  6:50 [PATCH v3 0/3] thread-pool: fix performance regression Paolo Bonzini
2022-05-14  6:50 ` [PATCH v3 1/3] thread-pool: optimize scheduling of completion bottom half Paolo Bonzini
2022-05-17 15:20   ` Stefan Hajnoczi
2022-05-14  6:50 ` [PATCH v3 2/3] thread-pool: replace semaphore with condition variable Paolo Bonzini
2022-05-17 12:46   ` Nicolas Saenz Julienne
2022-05-17 14:18     ` Paolo Bonzini
2022-05-17 14:37       ` Nicolas Saenz Julienne [this message]
2022-05-17 15:19   ` Stefan Hajnoczi
2022-05-17 15:21     ` Paolo Bonzini
2022-05-14  6:50 ` [PATCH v3 3/3] thread-pool: remove stopping variable Paolo Bonzini
2022-05-17 15:20   ` Stefan Hajnoczi
2022-05-17 14:30 ` [PATCH v3 0/3] thread-pool: fix performance regression Nicolas Saenz Julienne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2012b0a303f95df3a85a9a12df5307195619962.camel@redhat.com \
    --to=nsaenzju@redhat.com \
    --cc=ldoktor@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).