提交 89943de1 编写于 作者: P Pranith Kumar 提交者: Paolo Bonzini

atomics: Use __atomic_*_n() variant primitives

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: NPranith Kumar <bobby.prani@gmail.com>
Message-Id: <20160829171701.14025-1-bobby.prani@gmail.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 705ac1ca
...@@ -96,15 +96,12 @@ ...@@ -96,15 +96,12 @@
#define atomic_read(ptr) \ #define atomic_read(ptr) \
({ \ ({ \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof_strip_qual(*ptr) _val; \ __atomic_load_n(ptr, __ATOMIC_RELAXED); \
__atomic_load(ptr, &_val, __ATOMIC_RELAXED); \
_val; \
}) })
#define atomic_set(ptr, i) do { \ #define atomic_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof(*ptr) _val = (i); \ __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
__atomic_store(ptr, &_val, __ATOMIC_RELAXED); \
} while(0) } while(0)
/* See above: most compilers currently treat consume and acquire the /* See above: most compilers currently treat consume and acquire the
...@@ -129,8 +126,7 @@ ...@@ -129,8 +126,7 @@
#define atomic_rcu_set(ptr, i) do { \ #define atomic_rcu_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof(*ptr) _val = (i); \ __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \
__atomic_store(ptr, &_val, __ATOMIC_RELEASE); \
} while(0) } while(0)
/* atomic_mb_read/set semantics map Java volatile variables. They are /* atomic_mb_read/set semantics map Java volatile variables. They are
...@@ -153,9 +149,8 @@ ...@@ -153,9 +149,8 @@
#define atomic_mb_set(ptr, i) do { \ #define atomic_mb_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof(*ptr) _val = (i); \
smp_wmb(); \ smp_wmb(); \
__atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \
smp_mb(); \ smp_mb(); \
} while(0) } while(0)
#else #else
...@@ -169,8 +164,7 @@ ...@@ -169,8 +164,7 @@
#define atomic_mb_set(ptr, i) do { \ #define atomic_mb_set(ptr, i) do { \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof(*ptr) _val = (i); \ __atomic_store_n(ptr, i, __ATOMIC_SEQ_CST); \
__atomic_store(ptr, &_val, __ATOMIC_SEQ_CST); \
} while(0) } while(0)
#endif #endif
...@@ -179,17 +173,15 @@ ...@@ -179,17 +173,15 @@
#define atomic_xchg(ptr, i) ({ \ #define atomic_xchg(ptr, i) ({ \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof_strip_qual(*ptr) _new = (i), _old; \ __atomic_exchange_n(ptr, i, __ATOMIC_SEQ_CST); \
__atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \
_old; \
}) })
/* Returns the eventual value, failed or not */ /* Returns the eventual value, failed or not */
#define atomic_cmpxchg(ptr, old, new) \ #define atomic_cmpxchg(ptr, old, new) \
({ \ ({ \
QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
typeof_strip_qual(*ptr) _old = (old), _new = (new); \ typeof_strip_qual(*ptr) _old = (old); \
__atomic_compare_exchange(ptr, &_old, &_new, false, \ __atomic_compare_exchange_n(ptr, &_old, new, false, \
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
_old; \ _old; \
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册