[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/8] qatomic: add smp_mb__before/after_rmw()
From: |
Richard Henderson |
Subject: |
Re: [PATCH 1/8] qatomic: add smp_mb__before/after_rmw() |
Date: |
Sun, 5 Mar 2023 10:57:11 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 |
On 3/3/23 09:19, Paolo Bonzini wrote:
This nasty difference between Linux and C11 read-modify-write operations
has already caused issues in util/async.c and more are being found.
Provide something similar to Linux smp_mb__before/after_atomic(); this
has the double function of documenting clearly why there is a memory
barrier, and avoiding a double barrier on x86 and s390x systems.
It does make me question our choice to use neither the Linux nor the C11 model.
+ +--------------------------------+
+ | QEMU (incorrect) |
+ +================================+
+ | :: |
+ | |
+ | a = qatomic_fetch_add(&x, 2);|
+ | smp_mb__after_rmw(); |
+ | b = qatomic_read(&y); |
+ +--------------------------------+
Correct, surely.
+/*
+ * SEQ_CST is weaker than the older __sync_* builtins and Linux
+ * kernel read-modify-write atomics. Provide a macro to obtain
+ * the same semantics.
+ */
+#if !defined(QEMU_SANITIZE_THREAD) && \
+ (defined(__i386__) || defined(__x86_64__) || defined(__s390x__))
+# define smp_mb__before_rmw() signal_barrier()
+# define smp_mb__after_rmw() signal_barrier()
+#else
+# define smp_mb__before_rmw() smp_mb()
+# define smp_mb__after_rmw() smp_mb()
+#endif
I notice you never actually use smp_mb__before_rmw(), but I suppose since we're trying to
mirror smp_mb__before(), we should keep the interface whole.
Other than the "incorrect" above,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
- [PATCH 0/8] Fix missing memory barriers on ARM, Paolo Bonzini, 2023/03/03
- [PATCH 1/8] qatomic: add smp_mb__before/after_rmw(), Paolo Bonzini, 2023/03/03
- [PATCH 2/8] qemu-thread-posix: cleanup, fix, document QemuEvent, Paolo Bonzini, 2023/03/03
- [PATCH 3/8] qemu-thread-win32: cleanup, fix, document QemuEvent, Paolo Bonzini, 2023/03/03