[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 45/58] atomics: Use __atomic_*_n() variant primitives
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 45/58] atomics: Use __atomic_*_n() variant primitives |
Date: |
Tue, 13 Sep 2016 19:16:16 +0200 |
From: Pranith Kumar <address@hidden>
Use the __atomic_*_n() primitives which take the value as argument. It
is not necessary to store the value locally before calling the
primitive, hence saving us a stack store and load.
Signed-off-by: Pranith Kumar <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qemu/atomic.h | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
index 8348ecc..0cce246 100644
--- a/include/qemu/atomic.h
+++ b/include/qemu/atomic.h
@@ -96,15 +96,12 @@
#define atomic_read(ptr) \
({ \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof_strip_qual(*ptr) _val; \
- __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
- _val; \
+ __atomic_load_n(ptr, __ATOMIC_RELAXED); \
})
#define atomic_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof(*ptr) _val = (i); \
- __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \
+ __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
} while(0)
/* See above: most compilers currently treat consume and acquire the
@@ -129,8 +126,7 @@
#define atomic_rcu_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof(*ptr) _val = (i); \
- __atomic_store(ptr, &_val, __ATOMIC_RELEASE); \
+ __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \
} while(0)
/* atomic_mb_read/set semantics map Java volatile variables. They are
@@ -153,9 +149,8 @@
#define atomic_mb_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof(*ptr) _val = (i); \
smp_wmb(); \
- __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \
+ __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
smp_mb(); \
} while(0)
#else
@@ -169,8 +164,7 @@
#define atomic_mb_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof(*ptr) _val = (i); \
- __atomic_store(ptr, &_val, __ATOMIC_SEQ_CST); \
+ __atomic_store_n(ptr, i, __ATOMIC_SEQ_CST); \
} while(0)
#endif
@@ -179,17 +173,15 @@
#define atomic_xchg(ptr, i) ({ \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof_strip_qual(*ptr) _new = (i), _old; \
- __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \
- _old; \
+ __atomic_exchange_n(ptr, i, __ATOMIC_SEQ_CST); \
})
/* Returns the eventual value, failed or not */
#define atomic_cmpxchg(ptr, old, new) \
({ \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
- typeof_strip_qual(*ptr) _old = (old), _new = (new); \
- __atomic_compare_exchange(ptr, &_old, &_new, false, \
+ typeof_strip_qual(*ptr) _old = (old); \
+ __atomic_compare_exchange_n(ptr, &_old, new, false, \
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
_old; \
})
--
1.8.3.1
- [Qemu-devel] [PULL 33/58] scsi: pvscsi: limit loop to fetch SG list, (continued)
- [Qemu-devel] [PULL 33/58] scsi: pvscsi: limit loop to fetch SG list, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 34/58] default-configs: remove CONFIG_PAM, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 38/58] sclpconsolelm: remove bogus check for -EAGAIN, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 37/58] ipmi: check return of qemu_chr_fe_write() for errors, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 40/58] char: convert qemu_chr_fe_write to qemu_chr_fe_write_all, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 39/58] hw: replace most use of qemu_chr_fe_write with qemu_chr_fe_write_all, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 42/58] i8257: Make device "i8257" unavailable with -device, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 43/58] kvm-all: drop kvm_setup_guest_memory, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 41/58] Revert "megasas: remove useless check for cmd->frame", Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 36/58] default-configs: remove CONFIG_PIIX_PCI, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 45/58] atomics: Use __atomic_*_n() variant primitives,
Paolo Bonzini <=
- [Qemu-devel] [PULL 44/58] atomics: Remove redundant barrier()'s, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 46/58] checkpatch: Fix whitespace checks for documentation code blocks, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 47/58] optionrom: do not rely on compiler's bswap optimization, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 51/58] cutils: Remove SPLAT macro, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 54/58] cutils: Remove aarch64 buffer zero checking, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 49/58] ppc: do not redefine CPUPPCState, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 53/58] cutils: Rearrange buffer_is_zero acceleration, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 50/58] cutils: Move buffer_is_zero and subroutines to a new file, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 52/58] cutils: Export only buffer_is_zero, Paolo Bonzini, 2016/09/13
- [Qemu-devel] [PULL 56/58] cutils: Add test for buffer_is_zero, Paolo Bonzini, 2016/09/13