Commit a9e4252a authored by Michael S. Tsirkin's avatar Michael S. Tsirkin

asm-generic: add __smp_xxx wrappers

On !SMP, most architectures define their
barriers as compiler barriers.
On SMP, most need an actual barrier.

Make it possible to remove the code duplication for
!SMP by defining low-level __smp_xxx barriers
which do not depend on the value of SMP, then
use them from asm-generic conditionally.

Besides reducing code duplication, these low level APIs will also be
useful for virtualization, where a barrier is sometimes needed even if
!SMP since we might be talking to another kernel on the same SMP system.

Both virtio and Xen drivers will benefit.

The smp_xxx variants should use __smp_XXX ones or barrier() depending on
SMP, identically for all architectures.

We keep ifndef guards around them for now - once/if all
architectures are converted to use the generic
code, we'll be able to remove these.
Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
parent 300b06d4
...@@ -54,22 +54,38 @@ ...@@ -54,22 +54,38 @@
#define read_barrier_depends() do { } while (0) #define read_barrier_depends() do { } while (0)
#endif #endif
#ifndef __smp_mb
#define __smp_mb() mb()
#endif
#ifndef __smp_rmb
#define __smp_rmb() rmb()
#endif
#ifndef __smp_wmb
#define __smp_wmb() wmb()
#endif
#ifndef __smp_read_barrier_depends
#define __smp_read_barrier_depends() read_barrier_depends()
#endif
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
#ifndef smp_mb #ifndef smp_mb
#define smp_mb() mb() #define smp_mb() __smp_mb()
#endif #endif
#ifndef smp_rmb #ifndef smp_rmb
#define smp_rmb() rmb() #define smp_rmb() __smp_rmb()
#endif #endif
#ifndef smp_wmb #ifndef smp_wmb
#define smp_wmb() wmb() #define smp_wmb() __smp_wmb()
#endif #endif
#ifndef smp_read_barrier_depends #ifndef smp_read_barrier_depends
#define smp_read_barrier_depends() read_barrier_depends() #define smp_read_barrier_depends() __smp_read_barrier_depends()
#endif #endif
#else /* !CONFIG_SMP */ #else /* !CONFIG_SMP */
...@@ -92,23 +108,78 @@ ...@@ -92,23 +108,78 @@
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
#ifndef __smp_store_mb
#define __smp_store_mb(var, value) do { WRITE_ONCE(var, value); __smp_mb(); } while (0)
#endif
#ifndef __smp_mb__before_atomic
#define __smp_mb__before_atomic() __smp_mb()
#endif
#ifndef __smp_mb__after_atomic
#define __smp_mb__after_atomic() __smp_mb()
#endif
#ifndef __smp_store_release
#define __smp_store_release(p, v) \
do { \
compiletime_assert_atomic_type(*p); \
__smp_mb(); \
WRITE_ONCE(*p, v); \
} while (0)
#endif
#ifndef __smp_load_acquire
#define __smp_load_acquire(p) \
({ \
typeof(*p) ___p1 = READ_ONCE(*p); \
compiletime_assert_atomic_type(*p); \
__smp_mb(); \
___p1; \
})
#endif
#ifdef CONFIG_SMP
#ifndef smp_store_mb
#define smp_store_mb(var, value) __smp_store_mb(var, value)
#endif
#ifndef smp_mb__before_atomic
#define smp_mb__before_atomic() __smp_mb__before_atomic()
#endif
#ifndef smp_mb__after_atomic
#define smp_mb__after_atomic() __smp_mb__after_atomic()
#endif
#ifndef smp_store_release
#define smp_store_release(p, v) __smp_store_release(p, v)
#endif
#ifndef smp_load_acquire
#define smp_load_acquire(p) __smp_load_acquire(p)
#endif
#else /* !CONFIG_SMP */
#ifndef smp_store_mb #ifndef smp_store_mb
#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) #define smp_store_mb(var, value) do { WRITE_ONCE(var, value); barrier(); } while (0)
#endif #endif
#ifndef smp_mb__before_atomic #ifndef smp_mb__before_atomic
#define smp_mb__before_atomic() smp_mb() #define smp_mb__before_atomic() barrier()
#endif #endif
#ifndef smp_mb__after_atomic #ifndef smp_mb__after_atomic
#define smp_mb__after_atomic() smp_mb() #define smp_mb__after_atomic() barrier()
#endif #endif
#ifndef smp_store_release #ifndef smp_store_release
#define smp_store_release(p, v) \ #define smp_store_release(p, v) \
do { \ do { \
compiletime_assert_atomic_type(*p); \ compiletime_assert_atomic_type(*p); \
smp_mb(); \ barrier(); \
WRITE_ONCE(*p, v); \ WRITE_ONCE(*p, v); \
} while (0) } while (0)
#endif #endif
...@@ -118,10 +189,12 @@ do { \ ...@@ -118,10 +189,12 @@ do { \
({ \ ({ \
typeof(*p) ___p1 = READ_ONCE(*p); \ typeof(*p) ___p1 = READ_ONCE(*p); \
compiletime_assert_atomic_type(*p); \ compiletime_assert_atomic_type(*p); \
smp_mb(); \ barrier(); \
___p1; \ ___p1; \
}) })
#endif #endif
#endif
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
#endif /* __ASM_GENERIC_BARRIER_H */ #endif /* __ASM_GENERIC_BARRIER_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment