All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alberto Garcia <berto@igalia.com>
To: Jorge Merlino <jorge.merlino@canonical.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Hanna Reitz <hreitz@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [PATCH] throttle-group: fix race condition when using iothreads
Date: Wed, 11 Mar 2026 12:59:42 +0100	[thread overview]
Message-ID: <abFZLuP2251dNhUp@igalia.com> (raw)
In-Reply-To: <20260310-fix-race-condition-b4-v1-1-09b9b9262a58@canonical.com>

On Tue, Mar 10, 2026 at 08:08:36PM -0300, Jorge Merlino wrote:
>  void throttle_group_restart_tgm(ThrottleGroupMember *tgm)
>  {
>      ThrottleDirection dir;
> +    ThrottleState *ts = tgm->throttle_state;
> +    ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
>  
>      if (tgm->throttle_state) {
>          for (dir = THROTTLE_READ; dir < THROTTLE_MAX; dir++) {
>              QEMUTimer *t = tgm->throttle_timers.timers[dir];
> +            qemu_mutex_lock(&tg->lock);
>              if (timer_pending(t)) {
> +                qemu_mutex_unlock(&tg->lock);

I think I was too fast with my patch, I overlooked this part.

Maybe we need something like this for that function:

 for (...) {

   qemu_mutex_lock();

   if (timer_pending()) {
      /* We had a timer, delete it, we'll restart the queue now */
      timer_del(...);
   } else if (tg->any_timer_armed) {
      /* Someone else had a timer, let's wait for that request to be
       * scheduled so we can go next */
      qemu_mutex_unlock();
      continue;
   } else {
      /* There are no timers in this group, let's run our request now.
         Set any_timer_armed so no one else does it in the meantime */
      tg->any_timer_armed = true;
   }

   qemu_mutex_unlock();
   throttle_group_restart_queue();

 }

Maybe any_timer_armed needs a new name in this case.

Berto


      parent reply	other threads:[~2026-03-11 12:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 23:08 [PATCH] throttle-group: fix race condition when using iothreads Jorge Merlino
2026-03-11  9:37 ` Kevin Wolf
2026-03-11 11:59 ` Alberto Garcia [this message]

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=abFZLuP2251dNhUp@igalia.com \
    --to=berto@igalia.com \
    --cc=hreitz@redhat.com \
    --cc=jorge.merlino@canonical.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.