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 v5 09/13] migration/postcopy: Replace QemuSemaphore with QemuEvent
Date: Thu, 29 May 2025 14:45:58 +0900 [thread overview]
Message-ID: <20250529-event-v5-9-53b285203794@daynix.com> (raw)
In-Reply-To: <20250529-event-v5-0-53b285203794@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>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
---
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 aaec471c00f8..739289de9342 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
next prev parent reply other threads:[~2025-05-29 5:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-29 5:45 [PATCH v5 00/13] Improve futex usage Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 01/13] futex: Check value after qemu_futex_wait() Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 02/13] futex: Support Windows Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 03/13] qemu-thread: Replace __linux__ with CONFIG_LINUX Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 04/13] qemu-thread: Avoid futex abstraction for non-Linux Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 05/13] qemu-thread: Use futex for QemuEvent on Windows Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 06/13] qemu-thread: Use futex if available for QemuLockCnt Akihiko Odaki
2025-05-29 5:45 ` [PATCH v5 07/13] migration: Replace QemuSemaphore with QemuEvent Akihiko Odaki
2025-05-29 14:28 ` Peter Xu
2025-05-29 5:45 ` [PATCH v5 08/13] migration/colo: " Akihiko Odaki
2025-05-29 5:45 ` Akihiko Odaki [this message]
2025-05-29 5:45 ` [PATCH v5 10/13] hw/display/apple-gfx: " Akihiko Odaki
2025-05-29 5:46 ` [PATCH v5 11/13] qemu-thread: Remove qatomic_read() in qemu_event_set() Akihiko Odaki
2025-05-29 5:46 ` [PATCH v5 12/13] qemu-thread: Document QemuEvent Akihiko Odaki
2025-05-29 5:46 ` [PATCH v5 13/13] qemu-thread: Document QemuEvent memory ordering Akihiko Odaki
2025-06-05 13:24 ` [PATCH v5 00/13] Improve futex usage Paolo Bonzini
2025-06-06 9:46 ` Akihiko Odaki
2025-06-06 20:38 ` Paolo Bonzini
2025-06-07 4:35 ` 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=20250529-event-v5-9-53b285203794@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).