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 v5 00/13] Improve futex usage
Date: Thu, 29 May 2025 14:45:49 +0900	[thread overview]
Message-ID: <20250529-event-v5-0-53b285203794@daynix.com> (raw)

In a recent discussion, Phil Dennis-Jordan pointed out a quirk in
QemuEvent destruction due to futex-like abstraction, which prevented
the usage of QemuEvent in new and existing code[1]. With some more
thoughts after this discussion, I also found other problem and room
of improvement in futex usage. Here is a stack of patches to resolve
them.

Patch "futex: Check value after qemu_futex_wait()" ensures
qemu_futex_wait() is used in loops as suggested in the man page.

Patch "futex: Support Windows" implements futex functions for Windows.

Patch "qemu-thread: Avoid futex abstraction for non-Linux" and
"qemu-thread: Use futex for QemuEvent on Windows" enable destroying
QemuEvent immediately after qemu_event_wait().

Patch "qemu-thread: Use futex for QemuEvent on Windows" and
"qemu-thread: Use futex if available for QemuLockCnt" make the use of
futex functions added for Windows.

Patches "migration: Replace QemuSemaphore with QemuEvent",
"migration/colo: Replace QemuSemaphore with QemuEvent",
"migration/postcopy: Replace QemuSemaphore with QemuEvent", and
"hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent" replace
some QemuSemaphores with QemuEvents, which can utilize futex. Some of
them rely on that QemuEvent can be destroyed immediately after
qemu_event_wait().

[1]: https://lore.kernel.org/r/CAAibmn3HZeDeK8FrYhHa1GGwc+N8rBuB2VvMRm7LCt0mUGmsYQ@mail.gmail.com

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
Changes in v5:
- Updated the documentation of the state transitions for the non-futex
  variant.
- Placed patch "qemu-thread: Remove qatomic_read() in qemu_event_set()"
  after all other code changes.
- Added patches "qemu-thread: Document QemuEvent" and
  "qemu-thread: Document QemuEvent memory ordering".
- Link to v4: https://lore.kernel.org/qemu-devel/20250526-event-v4-0-5b784cc8e1de@daynix.com

Changes in v4:
- Added patch "qemu-thread: Remove qatomic_read() in qemu_event_set()".
- Renamed patch "futex: Replace __linux__ with CONFIG_LINUX" to
  "qemu-thread: Replace __linux__ with CONFIG_LINUX".
- Reverted changes to convert rp_pong_acks to QemuEvent.
- Link to v3: https://lore.kernel.org/qemu-devel/20250511-event-v3-0-f7f69247d303@daynix.com

Changes in v3:
- Fixed race between qemu_event_reset() and qemu_event_set().
- Prepared for spurious pthread_cond_wait() wakeups.
- Added patch "futex: Replace __linux__ with CONFIG_LINUX".
- Link to v2: https://lore.kernel.org/qemu-devel/20250510-event-v2-0-7953177ce1b8@daynix.com

Changes in v2:
- Rebased.
- Added patch
  "hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent".
- Link to v1: https://lore.kernel.org/r/20241225-event-v1-0-a58c8d63eb70@daynix.com

---
Akihiko Odaki (13):
      futex: Check value after qemu_futex_wait()
      futex: Support Windows
      qemu-thread: Replace __linux__ with CONFIG_LINUX
      qemu-thread: Avoid futex abstraction for non-Linux
      qemu-thread: Use futex for QemuEvent on Windows
      qemu-thread: Use futex if available for QemuLockCnt
      migration: Replace QemuSemaphore with QemuEvent
      migration/colo: Replace QemuSemaphore with QemuEvent
      migration/postcopy: Replace QemuSemaphore with QemuEvent
      hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent
      qemu-thread: Remove qatomic_read() in qemu_event_set()
      qemu-thread: Document QemuEvent
      qemu-thread: Document QemuEvent memory ordering

 meson.build                       |   2 +
 include/qemu/futex.h              |  44 +++++++++++-
 include/qemu/lockcnt.h            |   2 +-
 include/qemu/thread-posix.h       |   9 ---
 include/qemu/thread-win32.h       |   6 --
 include/qemu/thread.h             |  40 ++++++++++-
 migration/migration.h             |  12 ++--
 migration/colo.c                  |  20 +++---
 migration/migration.c             |  21 +++---
 migration/postcopy-ram.c          |  10 +--
 migration/savevm.c                |   2 +-
 tests/unit/test-aio-multithread.c |   6 +-
 util/event.c                      | 139 +++++++++++++++++++++++++++++++++++
 util/lockcnt.c                    |   9 +--
 util/qemu-thread-posix.c          | 148 --------------------------------------
 util/qemu-thread-win32.c          | 129 ---------------------------------
 hw/display/apple-gfx.m            |  10 +--
 util/meson.build                  |   3 +-
 18 files changed, 269 insertions(+), 343 deletions(-)
---
base-commit: f0737158b483e7ec2b2512145aeab888b85cc1f7
change-id: 20241031-event-785a2f0dda4a

Best regards,
-- 
Akihiko Odaki <akihiko.odaki@daynix.com>



             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 Akihiko Odaki [this message]
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 ` [PATCH v5 09/13] migration/postcopy: " Akihiko Odaki
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-0-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).