So here is a diff that implements what I proposed recently. This
recognizes that atomic instructions on amd64 already include an
implicit memory barrier and allows us to write optimized code that
avoids a redundant memory barrier.
Note that I don't have a use-case for membar_exit_before_atomic() yet;
I merely added it for symmetry reasons. I can leave it out if that's
what people prefer.
This should allow us to use a generic mutex implementation written in
C without a significant penalty.
ok?
Index: sys/atomic.h
===================================================================
RCS file: /cvs/src/sys/sys/atomic.h,v
retrieving revision 1.4
diff -u -p -r1.4 atomic.h
--- sys/atomic.h 24 Jan 2017 22:22:20 -0000 1.4
+++ sys/atomic.h 23 May 2017 15:01:34 -0000
@@ -219,4 +219,12 @@ atomic_sub_long_nv(volatile unsigned lon
#define membar_sync() __sync_synchronize()
#endif
+#ifndef membar_enter_after_atomic
+#define membar_enter_after_atomic() membar_enter()
+#endif
+
+#ifndef membar_exit_before_atomic
+#define membar_exit_before_atomic() membar_exit()
+#endif
+
#endif /* _SYS_ATOMIC_H_ */
Index: arch/amd64/include/atomic.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/atomic.h,v
retrieving revision 1.19
diff -u -p -r1.19 atomic.h
--- arch/amd64/include/atomic.h 12 May 2017 08:47:03 -0000 1.19
+++ arch/amd64/include/atomic.h 23 May 2017 15:02:23 -0000
@@ -276,6 +276,9 @@ _atomic_sub_long_nv(volatile unsigned lo
#define membar_sync() __membar("")
#endif
+#define membar_enter_after_atomic() __membar("")
+#define membar_exit_before_atomic() __membar("")
+
#ifdef _KERNEL
/* virtio needs MP membars even on SP kernels */