[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire
From: |
Pranith Kumar |
Subject: |
Re: [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire and store-release |
Date: |
Thu, 20 Oct 2016 14:36:07 -0400 |
Hi,
On Mon, Oct 10, 2016 at 9:59 AM, Paolo Bonzini <address@hidden> wrote:
> This introduces load-acquire and store-release operations in QEMU.
> For now, just use them as an implementation detail of atomic_mb_read
> and atomic_mb_set.
>
> Since docs/atomics.txt documents that atomic_mb_read only synchronizes
> with an atomic_mb_set of the same variable, we can use the new implementation
> everywhere instead of seq-cst loads and stores.
>
> Signed-off-by: Paolo Bonzini <address@hidden>
> ---
> docs/atomics.txt | 5 +--
> include/qemu/atomic.h | 93
> +++++++++++++++++----------------------------------
> 2 files changed, 34 insertions(+), 64 deletions(-)
>
> diff --git a/docs/atomics.txt b/docs/atomics.txt
> index 5cd8e32..9a1f8aa 100644
> --- a/docs/atomics.txt
> +++ b/docs/atomics.txt
> @@ -374,8 +374,9 @@ and memory barriers, and the equivalents in QEMU:
> note that smp_store_mb() is a little weaker than atomic_mb_set().
> atomic_mb_read() compiles to the same instructions as Linux's
> smp_load_acquire(), but this should be treated as an implementation
> - detail. If required, QEMU might later add atomic_load_acquire() and
> - atomic_store_release() macros.
> + detail. QEMU does have atomic_load_acquire() and atomic_store_release()
> + macros, but for now they are only used within atomic.h. This may
> + change in the future.
>
>
> SOURCES
> diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
> index b108df0..d940e98 100644
> --- a/include/qemu/atomic.h
> +++ b/include/qemu/atomic.h
> @@ -135,44 +135,18 @@
> __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \
> } while(0)
>
> -/* atomic_mb_read/set semantics map Java volatile variables. They are
> - * less expensive on some platforms (notably POWER & ARMv7) than fully
> - * sequentially consistent operations.
> - *
> - * As long as they are used as paired operations they are safe to
> - * use. See docs/atomic.txt for more discussion.
> - */
> -
> -#if defined(_ARCH_PPC)
> -#define atomic_mb_read(ptr) \
> - ({ \
> - QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> - typeof_strip_qual(*ptr) _val; \
> - __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
> - smp_mb_acquire(); \
> - _val; \
> - })
> -
> -#define atomic_mb_set(ptr, i) do { \
> - QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> - smp_mb_release(); \
> - __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
> - smp_mb(); \
> -} while(0)
> -#else
> -#define atomic_mb_read(ptr) \
> +#define atomic_load_acquire(ptr) \
> ({ \
> QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
> typeof_strip_qual(*ptr) _val; \
> - __atomic_load(ptr, &_val, __ATOMIC_SEQ_CST); \
> + __atomic_load(ptr, &_val, __ATOMIC_ACQUIRE); \
> _val; \
> })
>
Is there any reason we are not using __atomic_load_n() here?
--
Pranith
- [Qemu-devel] [PATCH 3/5] qemu-thread: use acquire/release to clarify semantics of QemuEvent, (continued)
- [Qemu-devel] [PATCH 3/5] qemu-thread: use acquire/release to clarify semantics of QemuEvent, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 1/5] atomic: introduce smp_mb_acquire and smp_mb_release, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 4/5] rcu: simplify memory barriers, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire and store-release, Paolo Bonzini, 2016/10/10
- Re: [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements, no-reply, 2016/10/10
- Re: [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements, no-reply, 2016/10/11
- Re: [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements, Alex Bennée, 2016/10/12
- Re: [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements, Emilio G. Cota, 2016/10/12
- Re: [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements, Alex Bennée, 2016/10/21