Introduce lttng smp_store_release smp_load_acquire wrappers
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Nov 2020 16:11:39 +0000 (11:11 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Nov 2020 16:16:35 +0000 (11:16 -0500)
Kernels prior to 3.14 do not implement smp_store_release nor
smp_load_acquire. Implement our own wrappers with smp_mb instead for
those older kernels.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/wrapper/barrier.h [new file with mode: 0644]
src/lttng-abi.c
src/lttng-event-notifier-notification.c

diff --git a/include/wrapper/barrier.h b/include/wrapper/barrier.h
new file mode 100644 (file)
index 0000000..c2f0545
--- /dev/null
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * wrapper/barrier.h
+ *
+ * wrapper around asm/barrier.h.
+ *
+ * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#ifndef _LTTNG_WRAPPER_BARRIER_H
+#define _LTTNG_WRAPPER_BARRIER_H
+
+#include <linux/version.h>
+#include <asm/barrier.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
+
+#define lttng_smp_store_release(x, v) smp_store_release(x, v)
+#define lttng_smp_load_acquire(x) smp_load_acquire(x)
+
+#else
+
+/*
+ * Acquire-release semantics act as a one-way permeable barrier when
+ * pairing a store with a release. Use a full memory barrier to emulate
+ * the acquire-release semantic with a stronger barrier on older
+ * kernels.
+ */
+
+#define lttng_smp_store_release(x, v)          \
+       do {                                    \
+               smp_mb();                       \
+               ACCESS_ONCE(*(x)) = (v);        \
+       } while (0)
+
+#define lttng_smp_load_acquire(x)              \
+       ({                                      \
+               __typeof__(*(x)) ___ret;        \
+                                               \
+               ___ret = ACCESS_ONCE(*(x));     \
+               smp_mb();                       \
+               ___ret;                         \
+       })
+
+#endif
+
+#endif /* _LTTNG_WRAPPER_BARRIER_H */
index 838534368d0c018b9ac8cce9940a2a8ad77296fe..7096daf7a544358202e14f49ae210d13397c48b2 100644 (file)
@@ -37,6 +37,7 @@
 #include <wrapper/poll.h>
 #include <wrapper/file.h>
 #include <wrapper/kref.h>
+#include <wrapper/barrier.h>
 #include <lttng/string-utils.h>
 #include <lttng/abi.h>
 #include <lttng/abi-old.h>
@@ -2150,7 +2151,7 @@ long lttng_abi_event_notifier_group_create_error_counter(
         * in record_error. Ensures the counter is created and the
         * error_counter_len is set before they are used.
         */
-       smp_store_release(&event_notifier_group->error_counter, counter);
+       lttng_smp_store_release(&event_notifier_group->error_counter, counter);
 
        counter->file = counter_file;
        counter->owner = event_notifier_group->file;
index 77e72842d410782e89aaa21bdb9f1e835e0ad936..52b5593ac9325b5324c9169f72ff736044a49cac 100644 (file)
@@ -11,6 +11,7 @@
 #include <lttng/events.h>
 #include <lttng/msgpack.h>
 #include <lttng/event-notifier-notification.h>
+#include <wrapper/barrier.h>
 
 /*
  * The capture buffer size needs to be below 1024 bytes to avoid the
@@ -357,11 +358,11 @@ void record_error(struct lttng_event_notifier *event_notifier)
        int ret;
 
        /*
-        * smp_load_acquire paired with smp_store_release orders
+        * lttng_smp_load_acquire paired with lttng_smp_store_release orders
         * creation of the error counter and setting error_counter_len
         * before the error_counter is used.
         */
-       error_counter = smp_load_acquire(&event_notifier_group->error_counter);
+       error_counter = lttng_smp_load_acquire(&event_notifier_group->error_counter);
        /* This group may not have an error counter attached to it. */
        if (!error_counter)
                return;
This page took 0.027833 seconds and 4 git commands to generate.