qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzju@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: kwolf@redhat.com, fam@euphon.net, berrange@redhat.com,
	qemu-block@nongnu.org, michael.roth@amd.com, mtosatti@redhat.com,
	qemu-devel@nongnu.org, armbru@redhat.com, eduardo@habkost.net,
	hreitz@redhat.com, pbonzini@redhat.com, eblake@redhat.com
Subject: Re: [PATCH v2 4/4] util/event-loop-base: Introduce options to set the thread pool size
Date: Fri, 11 Mar 2022 11:40:30 +0100	[thread overview]
Message-ID: <93fee44e8b4aa58dcfd8c088a0f03ec2dedd3b03.camel@redhat.com> (raw)
In-Reply-To: <YinWxsS+gF9kt1hb@stefanha-x1.localdomain>

On Thu, 2022-03-10 at 10:45 +0000, Stefan Hajnoczi wrote:
> On Thu, Mar 03, 2022 at 04:13:07PM +0100, Nicolas Saenz Julienne wrote:
> > @@ -537,10 +546,19 @@
> >  #                 0 means that the engine will use its default
> >  #                 (default:0, since 6.1)
> >  #
> > +# @thread-pool-min: minimum number of threads readily available in the thread
> > +#                   pool
> > +#                   (default:0, since 6.2)
> > +#
> > +# @thread-pool-max: maximum number of threads the thread pool can contain
> > +#                   (default:64, since 6.2)
> 
> Here and elsewhere:
> s/6.2/7.1/

Yes, forgot to mention it was a placeholder, as I wasn't sure what version to
target.

> > @@ -294,6 +314,36 @@ void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg)
> >      thread_pool_submit_aio(pool, func, arg, NULL, NULL);
> >  }
> >  
> > +void thread_pool_update_params(ThreadPool *pool, AioContext *ctx)
> > +{
> > +    qemu_mutex_lock(&pool->lock);
> > +
> > +    pool->min_threads = ctx->thread_pool_min;
> > +    pool->max_threads = ctx->thread_pool_max;
> > +
> > +    /*
> > +     * We either have to:
> > +     *  - Increase the number available of threads until over the min_threads
> > +     *    threshold.
> > +     *  - Decrease the number of available threads until under the max_threads
> > +     *    threshold.
> > +     *  - Do nothing. the current number of threads fall in between the min and
> > +     *    max thresholds. We'll let the pool manage itself.
> > +     */
> > +    for (int i = pool->cur_threads; i < pool->min_threads; i++) {
> > +        spawn_thread(pool);
> > +    }
> > +
> > +    while (pool->cur_threads > pool->max_threads) {
> > +        qemu_sem_post(&pool->sem);
> > +        qemu_mutex_unlock(&pool->lock);
> > +        qemu_cond_wait(&pool->worker_stopped, &pool->lock);
> > +        qemu_mutex_lock(&pool->lock);
> 
> Same question as Patch 1. This looks incorrect because qemu_cond_wait()
> already drops pool->lock if it needs to block.

Yes, I'll fix that.

> Also, why wait? If worker threads are blocked for some reason then our
> thread will block too.

Exiting thread_pool_update_params() before honoring the new constraints is a
source of potential race conditions (having to worry for situations where
cur_threads > max_threads), and on systems where determinism is important it's
crucial to have a clear boundary between 'unsafe' and 'safe' states.

Thanks,

-- 
Nicolás Sáenz



  reply	other threads:[~2022-03-11 10:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 14:58 [PATCH v2 0/4] util/thread-pool: Expose minimun and maximum size Nicolas Saenz Julienne
2022-03-03 14:58 ` [PATCH v2 1/4] util/thread-pool: Fix thread pool freeing locking Nicolas Saenz Julienne
2022-03-10  9:20   ` Stefan Hajnoczi
2022-03-10 10:09     ` Nicolas Saenz Julienne
2022-03-03 14:58 ` [PATCH v2 2/4] Introduce event-loop-base abstract class Nicolas Saenz Julienne
2022-03-10 10:25   ` Stefan Hajnoczi
2022-03-11 10:17     ` Nicolas Saenz Julienne
2022-03-14 13:33       ` Stefan Hajnoczi
2022-03-14 13:34         ` Nicolas Saenz Julienne
2022-03-03 14:58 ` [PATCH v2 3/4] util/main-loop: Introduce the main loop into QOM Nicolas Saenz Julienne
2022-03-10 10:27   ` Stefan Hajnoczi
2022-03-03 15:13 ` [PATCH v2 4/4] util/event-loop-base: Introduce options to set the thread pool size Nicolas Saenz Julienne
2022-03-10 10:45   ` Stefan Hajnoczi
2022-03-11 10:40     ` Nicolas Saenz Julienne [this message]
2022-03-14 13:35       ` Stefan Hajnoczi
2022-03-14 17:19         ` 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=93fee44e8b4aa58dcfd8c088a0f03ec2dedd3b03.camel@redhat.com \
    --to=nsaenzju@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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).