Add a few smp_ helpers from Linux.
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 11 Apr 2018 20:47:01 +0000 (16:47 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 30 Apr 2018 18:38:29 +0000 (14:38 -0400)
I'll need these for RCU - at least to keep that code a little cleaner.

From commit 569dbb88e80d ("Linux 4.13").

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/riscv/membar.h
kern/arch/x86/membar.h
scripts/spatch/linux/funcs.cocci

index 18f0926..d8ed748 100644 (file)
@@ -1 +1,10 @@
 #include <ros/arch/membar.h>
+
+#error "implement me (grab from linux)"
+
+#define smp_store_release(p, v)
+#define smp_load_acquire(p)
+#define smp_mb__before_atomic()
+#define smp_mb__after_atomic()
+
+#define smp_read_barrier_depends()
index 18f0926..97c9491 100644 (file)
@@ -1 +1,37 @@
 #include <ros/arch/membar.h>
+
+/*************************
+ * From Linux commit 569dbb88e80d ("Linux 4.13")
+ * arch/x86/include/asm/barrier.h
+ *
+ * Note that their barrier() is our cmb(), but we actually have both available.
+ * barrier() comes from e.g. <linux/compiler-gcc.h>.
+ */
+
+#define __smp_store_release(p, v)                                      \
+do {                                                                   \
+       compiletime_assert_atomic_type(*p);                             \
+       barrier();                                                      \
+       WRITE_ONCE(*p, v);                                              \
+} while (0)
+
+#define __smp_load_acquire(p)                                          \
+({                                                                     \
+       typeof(*p) ___p1 = READ_ONCE(*p);                               \
+       compiletime_assert_atomic_type(*p);                             \
+       barrier();                                                      \
+       ___p1;                                                          \
+})
+
+/* Atomic operations are already serializing on x86 */
+#define __smp_mb__before_atomic()      barrier()
+#define __smp_mb__after_atomic()       barrier()
+
+/************************* End Linux barrier.h */
+
+#define smp_store_release(p, v) __smp_store_release(p, v)
+#define smp_load_acquire(p) __smp_load_acquire(p)
+#define smp_mb__before_atomic() __smp_mb__before_atomic()
+#define smp_mb__after_atomic() __smp_mb__after_atomic()
+
+#define smp_read_barrier_depends()
index 27143ca..9afe806 100644 (file)
@@ -17,18 +17,6 @@ expression TMAX;
 -barrier();
 +cmb();
 
-// akaros RMW, locking atomics provide hw memory barriers.
-// (excluding set, init, and read)
-@@
-@@
--smp_mb__before_atomic();
-+cmb();
-
-@@
-@@
--smp_mb__after_atomic();
-+cmb();
-
 @@
 @@
 -smp_mb();