qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wei Wang <wei.w.wang@intel.com>
To: quintela@redhat.com, peterx@redhat.com, qemu-devel@nongnu.org
Cc: Wei Wang <wei.w.wang@intel.com>
Subject: [PATCH v1] migration/multifd: always post the sync semaphores when sendesr exit
Date: Wed, 24 May 2023 16:09:06 +0800	[thread overview]
Message-ID: <20230524080906.531440-1-wei.w.wang@intel.com> (raw)

The sem_sync and channels_ready semaphores are used by the multifd
sender threads to synchronize with the migration thread. It is possible
that one of the sender threads exits due to an error (e.g. occured when
writing to the socket). The error thread sets multifd_send_state->exiting
to force other sender threads to exit. Those threads exit (due to the
setting of multifd_send_state->exiting) won't post the sem_sync and
channels_ready semaphores, as they didn't encounter any error (i.e. ret
will be 0 when exits). In this case, if the migration thread is waiting on
the sem_sync semaphores from all the sender threads, it will wait there
forever, which is not expected.

Change the sender threads to always post the sem_sync and channels_ready
semaphores when exit. This will unblock the migration thread in the
above case to exit. If the main thread isn't waiting on the semaphores
when the sender threads exits, posting on the semaphores will just be
like a noop.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
 migration/multifd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/migration/multifd.c b/migration/multifd.c
index 0bf5958a9c..1ff461675e 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -757,10 +757,8 @@ out:
      * Error happen, I will exit, but I can't just leave, tell
      * who pay attention to me.
      */
-    if (ret != 0) {
-        qemu_sem_post(&p->sem_sync);
-        qemu_sem_post(&multifd_send_state->channels_ready);
-    }
+    qemu_sem_post(&p->sem_sync);
+    qemu_sem_post(&multifd_send_state->channels_ready);
 
     qemu_mutex_lock(&p->mutex);
     p->running = false;
-- 
2.27.0



                 reply	other threads:[~2023-05-24  8:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230524080906.531440-1-wei.w.wang@intel.com \
    --to=wei.w.wang@intel.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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).