Commit | Line | Data |
---|---|---|
6657edec MD |
1 | /* SPDX-License-Identifier: GPL-2.0-only |
2 | * | |
3 | * wrapper/barrier.h | |
4 | * | |
5 | * wrapper around asm/barrier.h. | |
6 | * | |
7 | * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | */ | |
9 | ||
10 | #ifndef _LTTNG_WRAPPER_BARRIER_H | |
11 | #define _LTTNG_WRAPPER_BARRIER_H | |
12 | ||
5f4c791e MJ |
13 | #include <lttng/kernel-version.h> |
14 | #if LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,4,0) | |
6657edec | 15 | #include <asm/barrier.h> |
6e49a8d5 MJ |
16 | #else |
17 | #include <asm/system.h> | |
18 | #endif | |
6657edec | 19 | |
5f4c791e | 20 | #if LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,14,0) |
6657edec MD |
21 | |
22 | #define lttng_smp_store_release(x, v) smp_store_release(x, v) | |
23 | #define lttng_smp_load_acquire(x) smp_load_acquire(x) | |
24 | ||
25 | #else | |
26 | ||
27 | /* | |
28 | * Acquire-release semantics act as a one-way permeable barrier when | |
29 | * pairing a store with a release. Use a full memory barrier to emulate | |
30 | * the acquire-release semantic with a stronger barrier on older | |
31 | * kernels. | |
32 | */ | |
33 | ||
34 | #define lttng_smp_store_release(x, v) \ | |
35 | do { \ | |
36 | smp_mb(); \ | |
37 | ACCESS_ONCE(*(x)) = (v); \ | |
38 | } while (0) | |
39 | ||
40 | #define lttng_smp_load_acquire(x) \ | |
41 | ({ \ | |
42 | __typeof__(*(x)) ___ret; \ | |
43 | \ | |
44 | ___ret = ACCESS_ONCE(*(x)); \ | |
45 | smp_mb(); \ | |
46 | ___ret; \ | |
47 | }) | |
48 | ||
49 | #endif | |
50 | ||
51 | #endif /* _LTTNG_WRAPPER_BARRIER_H */ |