qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: Paolo Bonzini <pbonzini@redhat.com>, Stefan Weil <sw@weilnetz.de>,
	 Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
	 Hailiang Zhang <zhanghailiang@xfusion.com>
Cc: "Phil Dennis-Jordan" <phil@philjordan.eu>,
	qemu-devel@nongnu.org, devel@daynix.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Akihiko Odaki" <akihiko.odaki@daynix.com>
Subject: [PATCH v3 09/10] migration/postcopy: Replace QemuSemaphore with QemuEvent
Date: Sun, 11 May 2025 15:08:26 +0900	[thread overview]
Message-ID: <20250511-event-v3-9-f7f69247d303@daynix.com> (raw)
In-Reply-To: <20250511-event-v3-0-f7f69247d303@daynix.com>

thread_sync_sem is an one-shot event so it can be converted into
QemuEvent, which is more lightweight.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 migration/migration.h    |  4 ++--
 migration/postcopy-ram.c | 10 +++++-----
 migration/savevm.c       |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/migration/migration.h b/migration/migration.h
index eec49bf3f893..fd45a0f20c0f 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -98,9 +98,9 @@ struct MigrationIncomingState {
     void (*transport_cleanup)(void *data);
     /*
      * Used to sync thread creations.  Note that we can't create threads in
-     * parallel with this sem.
+     * parallel with this event.
      */
-    QemuSemaphore  thread_sync_sem;
+    QemuEvent  thread_sync_event;
     /*
      * Free at the start of the main state load, set as the main thread finishes
      * loading state.
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 995614b38c9d..75fd310fb2b0 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -90,10 +90,10 @@ void postcopy_thread_create(MigrationIncomingState *mis,
                             QemuThread *thread, const char *name,
                             void *(*fn)(void *), int joinable)
 {
-    qemu_sem_init(&mis->thread_sync_sem, 0);
+    qemu_event_init(&mis->thread_sync_event, false);
     qemu_thread_create(thread, name, fn, mis, joinable);
-    qemu_sem_wait(&mis->thread_sync_sem);
-    qemu_sem_destroy(&mis->thread_sync_sem);
+    qemu_event_wait(&mis->thread_sync_event);
+    qemu_event_destroy(&mis->thread_sync_event);
 }
 
 /* Postcopy needs to detect accesses to pages that haven't yet been copied
@@ -964,7 +964,7 @@ static void *postcopy_ram_fault_thread(void *opaque)
     trace_postcopy_ram_fault_thread_entry();
     rcu_register_thread();
     mis->last_rb = NULL; /* last RAMBlock we sent part of */
-    qemu_sem_post(&mis->thread_sync_sem);
+    qemu_event_set(&mis->thread_sync_event);
 
     struct pollfd *pfd;
     size_t pfd_len = 2 + mis->postcopy_remote_fds->len;
@@ -1716,7 +1716,7 @@ void *postcopy_preempt_thread(void *opaque)
 
     rcu_register_thread();
 
-    qemu_sem_post(&mis->thread_sync_sem);
+    qemu_event_set(&mis->thread_sync_event);
 
     /*
      * The preempt channel is established in asynchronous way.  Wait
diff --git a/migration/savevm.c b/migration/savevm.c
index 006514c3e301..52105dd2f10b 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2078,7 +2078,7 @@ static void *postcopy_ram_listen_thread(void *opaque)
 
     migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                                    MIGRATION_STATUS_POSTCOPY_ACTIVE);
-    qemu_sem_post(&mis->thread_sync_sem);
+    qemu_event_set(&mis->thread_sync_event);
     trace_postcopy_ram_listen_thread_start();
 
     rcu_register_thread();

-- 
2.49.0



  parent reply	other threads:[~2025-05-11  6:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-11  6:08 [PATCH v3 00/10] Improve futex usage Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 01/10] futex: Check value after qemu_futex_wait() Akihiko Odaki
2025-05-13 14:39   ` Peter Xu
2025-05-14  7:34     ` Akihiko Odaki
2025-05-14 17:06       ` Peter Xu
2025-05-16  5:34         ` Akihiko Odaki
2025-05-16 14:53           ` Peter Xu
2025-05-17  5:01             ` Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 02/10] futex: Support Windows Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 03/10] futex: Replace __linux__ with CONFIG_LINUX Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 04/10] qemu-thread: Avoid futex abstraction for non-Linux Akihiko Odaki
2025-05-14  0:51   ` Paolo Bonzini
2025-05-14 12:57     ` Akihiko Odaki
2025-05-16 11:09       ` Paolo Bonzini
2025-05-16 12:58         ` Akihiko Odaki
2025-05-16 14:25           ` Paolo Bonzini
2025-05-17  5:40             ` Akihiko Odaki
2025-05-17 10:24               ` Paolo Bonzini
2025-05-17 16:30                 ` Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 05/10] qemu-thread: Use futex for QemuEvent on Windows Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 06/10] qemu-thread: Use futex if available for QemuLockCnt Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 07/10] migration: Replace QemuSemaphore with QemuEvent Akihiko Odaki
2025-05-13 19:13   ` Peter Xu
2025-05-14 12:36     ` Akihiko Odaki
2025-05-11  6:08 ` [PATCH v3 08/10] migration/colo: " Akihiko Odaki
2025-05-12 15:12   ` Fabiano Rosas
2025-05-11  6:08 ` Akihiko Odaki [this message]
2025-05-12 15:12   ` [PATCH v3 09/10] migration/postcopy: " Fabiano Rosas
2025-05-11  6:08 ` [PATCH v3 10/10] hw/display/apple-gfx: " Akihiko Odaki

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=20250511-event-v3-9-f7f69247d303@daynix.com \
    --to=akihiko.odaki@daynix.com \
    --cc=berrange@redhat.com \
    --cc=devel@daynix.com \
    --cc=farosas@suse.de \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=phil@philjordan.eu \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    --cc=zhanghailiang@xfusion.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).