Compiler implementations may provide sub-optimal support for a memory_order passed in as a run-time value (ref. https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html).
Document that OVS atomics require the memory order to be passed in as a compile-time constant. It should be noted, however, that when inlining is disabled (i.e., compiling without optimization) even compile-time constants may be passed as run-time values to (non-inlined) functions. Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com> --- lib/ovs-atomic-gcc4+.h | 10 ++++------ lib/ovs-atomic.h | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ovs-atomic-gcc4+.h b/lib/ovs-atomic-gcc4+.h index 9a79f7e..bb889c6 100644 --- a/lib/ovs-atomic-gcc4+.h +++ b/lib/ovs-atomic-gcc4+.h @@ -63,7 +63,7 @@ atomic_thread_fence_if_seq_cst(memory_order order) } static inline void -atomic_signal_fence(memory_order order OVS_UNUSED) +atomic_signal_fence(memory_order order) { if (order != memory_order_relaxed) { asm volatile("" : : : "memory"); @@ -80,12 +80,11 @@ atomic_signal_fence(memory_order order OVS_UNUSED) ({ \ typeof(DST) dst__ = (DST); \ typeof(SRC) src__ = (SRC); \ - memory_order order__ = (ORDER); \ \ if (IS_LOCKLESS_ATOMIC(*dst__)) { \ - atomic_thread_fence(order__); \ + atomic_thread_fence(ORDER); \ *dst__ = src__; \ - atomic_thread_fence_if_seq_cst(order__); \ + atomic_thread_fence_if_seq_cst(ORDER); \ } else { \ atomic_store_locked(dst__, src__); \ } \ @@ -97,10 +96,9 @@ atomic_signal_fence(memory_order order OVS_UNUSED) ({ \ typeof(DST) dst__ = (DST); \ typeof(SRC) src__ = (SRC); \ - memory_order order__ = (ORDER); \ \ if (IS_LOCKLESS_ATOMIC(*src__)) { \ - atomic_thread_fence_if_seq_cst(order__); \ + atomic_thread_fence_if_seq_cst(ORDER); \ *dst__ = *src__; \ } else { \ atomic_read_locked(src__, dst__); \ diff --git a/lib/ovs-atomic.h b/lib/ovs-atomic.h index d9c506a..b9a3203 100644 --- a/lib/ovs-atomic.h +++ b/lib/ovs-atomic.h @@ -181,6 +181,10 @@ * whole system, providing a total order for stores an all atomic * variables. * + * OVS atomics require the memory_order to be passed as a compile-time constant + * value, as some compiler implementations may perform poorly if the memory + * order parameter is passed in as a run-time value. + * * The following functions insert explicit barriers. Most of the other atomic * functions also include barriers. * -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev