On 2025/05/28 0:01, Paolo Bonzini wrote:
On Tue, May 27, 2025 at 5:01 AM Akihiko Odaki <akihiko.od...@daynix.com> wrote:
I'd like to submit it with "[PATCH v4 05/11] qemu-thread: Avoid futex
abstraction for non-Linux" because it aligns the implementations of
Linux and non-Linux versions to rely on a store-release of EV_SET in
qemu_event_set().

Ok, I see what you mean - you would like the xchg to be an
xchg_release essentially.

There is actually one case in which skipping the xchg has an effect.
If you have the following:

- one side does

   s.foo = 1;
   qemu_event_set(&s.ev);

- the other side never reaches the qemu_event_reset(&s.ev)

then skipping the xchg might allow the cacheline for ev to remain
shared. This is unlikely to *make* a difference, though it does
*exist* as a difference, so I will review the patch, but I really
prefer to place it last.  It's safer to take a known-working
algorithm, apply it to all OSes (or at least Linux and Windows), and
only then you refine it. It also makes my queue shorter.

Compilers and processors are free to make such an optimization so the contract between us and them does not change in that sense.

On the other hand, the removal of smb_mb() does change the contract; now compilers and processors are free to reorder loads and stores specified before qemu_event_set() after the load of ev->value, which was not possible in the past.

I'm confident that the change of the contract is safe, but it makes sense to pay extra caution. I'll reorder the patches with the next version.

Regards,
Akihiko Odaki

Reply via email to