diff options
| author | Mark Rutland <mark.rutland@arm.com> | 2018-09-04 06:48:26 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2018-11-01 06:00:46 -0400 |
| commit | 9fa45070a2e59a871e1cd3370173369f3a4f61e2 (patch) | |
| tree | bf28d28903a0d5077452edceef78f260c2111ccb /include/linux | |
| parent | ace9bad4df2684f31cbfe8c4ce7a0f5d92b27925 (diff) | |
locking/atomics: Switch to generated fallbacks
As a step to ensuring the atomic* APIs are consistent, switch to fallbacks
generated by gen-atomic-fallback.sh.
These are checked in rather than generated with Kbuild, since:
* This allows inspection of the atomics with git grep and ctags on a
pristine tree, which Linus strongly prefers being able to do.
* The fallbacks are not affected by machine details or configuration
options, so it is not necessary to regenerate them to take these into
account.
* These are included by files required *very* early in the build process
(e.g. for generating bounds.h), and we'd rather not complicate the
top-level Kbuild file with dependencies.
The new fallback header should be equivalent to the old fallbacks in
<linux/atomic.h>, but:
* It is formatted a little differently due to scripting ensuring things
are more regular than they used to be.
* Fallbacks are now expanded in-place as static inline functions rather
than macros.
* The prototypes for fallbacks are arragned consistently with the return
type on a separate line to try to keep to a sensible line length.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com
Cc: linuxdrivers@attotech.com
Cc: dvyukov@google.com
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: arnd@arndb.de
Cc: aryabinin@virtuozzo.com
Cc: glider@google.com
Link: http://lkml.kernel.org/r/20180904104830.2975-3-mark.rutland@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/atomic-fallback.h | 2294 | ||||
| -rw-r--r-- | include/linux/atomic.h | 1241 |
2 files changed, 2295 insertions, 1240 deletions
diff --git a/include/linux/atomic-fallback.h b/include/linux/atomic-fallback.h new file mode 100644 index 000000000000..1c02c0112fbb --- /dev/null +++ b/include/linux/atomic-fallback.h | |||
| @@ -0,0 +1,2294 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | |||
| 3 | // Generated by scripts/atomic/gen-atomic-fallback.sh | ||
| 4 | // DO NOT MODIFY THIS FILE DIRECTLY | ||
| 5 | |||
| 6 | #ifndef _LINUX_ATOMIC_FALLBACK_H | ||
| 7 | #define _LINUX_ATOMIC_FALLBACK_H | ||
| 8 | |||
| 9 | #ifndef xchg_relaxed | ||
| 10 | #define xchg_relaxed xchg | ||
| 11 | #define xchg_acquire xchg | ||
| 12 | #define xchg_release xchg | ||
| 13 | #else /* xchg_relaxed */ | ||
| 14 | |||
| 15 | #ifndef xchg_acquire | ||
| 16 | #define xchg_acquire(...) \ | ||
| 17 | __atomic_op_acquire(xchg, __VA_ARGS__) | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #ifndef xchg_release | ||
| 21 | #define xchg_release(...) \ | ||
| 22 | __atomic_op_release(xchg, __VA_ARGS__) | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #ifndef xchg | ||
| 26 | #define xchg(...) \ | ||
| 27 | __atomic_op_fence(xchg, __VA_ARGS__) | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #endif /* xchg_relaxed */ | ||
| 31 | |||
| 32 | #ifndef cmpxchg_relaxed | ||
| 33 | #define cmpxchg_relaxed cmpxchg | ||
| 34 | #define cmpxchg_acquire cmpxchg | ||
| 35 | #define cmpxchg_release cmpxchg | ||
| 36 | #else /* cmpxchg_relaxed */ | ||
| 37 | |||
| 38 | #ifndef cmpxchg_acquire | ||
| 39 | #define cmpxchg_acquire(...) \ | ||
| 40 | __atomic_op_acquire(cmpxchg, __VA_ARGS__) | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifndef cmpxchg_release | ||
| 44 | #define cmpxchg_release(...) \ | ||
| 45 | __atomic_op_release(cmpxchg, __VA_ARGS__) | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #ifndef cmpxchg | ||
| 49 | #define cmpxchg(...) \ | ||
| 50 | __atomic_op_fence(cmpxchg, __VA_ARGS__) | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #endif /* cmpxchg_relaxed */ | ||
| 54 | |||
| 55 | #ifndef cmpxchg64_relaxed | ||
| 56 | #define cmpxchg64_relaxed cmpxchg64 | ||
| 57 | #define cmpxchg64_acquire cmpxchg64 | ||
| 58 | #define cmpxchg64_release cmpxchg64 | ||
| 59 | #else /* cmpxchg64_relaxed */ | ||
| 60 | |||
| 61 | #ifndef cmpxchg64_acquire | ||
| 62 | #define cmpxchg64_acquire(...) \ | ||
| 63 | __atomic_op_acquire(cmpxchg64, __VA_ARGS__) | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifndef cmpxchg64_release | ||
| 67 | #define cmpxchg64_release(...) \ | ||
| 68 | __atomic_op_release(cmpxchg64, __VA_ARGS__) | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #ifndef cmpxchg64 | ||
| 72 | #define cmpxchg64(...) \ | ||
| 73 | __atomic_op_fence(cmpxchg64, __VA_ARGS__) | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #endif /* cmpxchg64_relaxed */ | ||
| 77 | |||
| 78 | #ifndef atomic_read_acquire | ||
| 79 | static inline int | ||
| 80 | atomic_read_acquire(const atomic_t *v) | ||
| 81 | { | ||
| 82 | return smp_load_acquire(&(v)->counter); | ||
| 83 | } | ||
| 84 | #define atomic_read_acquire atomic_read_acquire | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #ifndef atomic_set_release | ||
| 88 | static inline void | ||
| 89 | atomic_set_release(atomic_t *v, int i) | ||
| 90 | { | ||
| 91 | smp_store_release(&(v)->counter, i); | ||
| 92 | } | ||
| 93 | #define atomic_set_release atomic_set_release | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #ifndef atomic_add_return_relaxed | ||
| 97 | #define atomic_add_return_acquire atomic_add_return | ||
| 98 | #define atomic_add_return_release atomic_add_return | ||
| 99 | #define atomic_add_return_relaxed atomic_add_return | ||
| 100 | #else /* atomic_add_return_relaxed */ | ||
| 101 | |||
| 102 | #ifndef atomic_add_return_acquire | ||
| 103 | static inline int | ||
| 104 | atomic_add_return_acquire(int i, atomic_t *v) | ||
| 105 | { | ||
| 106 | int ret = atomic_add_return_relaxed(i, v); | ||
| 107 | __atomic_acquire_fence(); | ||
| 108 | return ret; | ||
| 109 | } | ||
| 110 | #define atomic_add_return_acquire atomic_add_return_acquire | ||
| 111 | #endif | ||
| 112 | |||
| 113 | #ifndef atomic_add_return_release | ||
| 114 | static inline int | ||
| 115 | atomic_add_return_release(int i, atomic_t *v) | ||
| 116 | { | ||
| 117 | __atomic_release_fence(); | ||
| 118 | return atomic_add_return_relaxed(i, v); | ||
| 119 | } | ||
| 120 | #define atomic_add_return_release atomic_add_return_release | ||
| 121 | #endif | ||
| 122 | |||
| 123 | #ifndef atomic_add_return | ||
| 124 | static inline int | ||
| 125 | atomic_add_return(int i, atomic_t *v) | ||
| 126 | { | ||
| 127 | int ret; | ||
| 128 | __atomic_pre_full_fence(); | ||
| 129 | ret = atomic_add_return_relaxed(i, v); | ||
| 130 | __atomic_post_full_fence(); | ||
| 131 | return ret; | ||
| 132 | } | ||
| 133 | #define atomic_add_return atomic_add_return | ||
| 134 | #endif | ||
| 135 | |||
| 136 | #endif /* atomic_add_return_relaxed */ | ||
| 137 | |||
| 138 | #ifndef atomic_fetch_add_relaxed | ||
| 139 | #define atomic_fetch_add_acquire atomic_fetch_add | ||
| 140 | #define atomic_fetch_add_release atomic_fetch_add | ||
| 141 | #define atomic_fetch_add_relaxed atomic_fetch_add | ||
| 142 | #else /* atomic_fetch_add_relaxed */ | ||
| 143 | |||
| 144 | #ifndef atomic_fetch_add_acquire | ||
| 145 | static inline int | ||
| 146 | atomic_fetch_add_acquire(int i, atomic_t *v) | ||
| 147 | { | ||
| 148 | int ret = atomic_fetch_add_relaxed(i, v); | ||
| 149 | __atomic_acquire_fence(); | ||
| 150 | return ret; | ||
| 151 | } | ||
| 152 | #define atomic_fetch_add_acquire atomic_fetch_add_acquire | ||
| 153 | #endif | ||
| 154 | |||
| 155 | #ifndef atomic_fetch_add_release | ||
| 156 | static inline int | ||
| 157 | atomic_fetch_add_release(int i, atomic_t *v) | ||
| 158 | { | ||
| 159 | __atomic_release_fence(); | ||
| 160 | return atomic_fetch_add_relaxed(i, v); | ||
| 161 | } | ||
| 162 | #define atomic_fetch_add_release atomic_fetch_add_release | ||
| 163 | #endif | ||
| 164 | |||
| 165 | #ifndef atomic_fetch_add | ||
| 166 | static inline int | ||
| 167 | atomic_fetch_add(int i, atomic_t *v) | ||
| 168 | { | ||
| 169 | int ret; | ||
| 170 | __atomic_pre_full_fence(); | ||
| 171 | ret = atomic_fetch_add_relaxed(i, v); | ||
| 172 | __atomic_post_full_fence(); | ||
| 173 | return ret; | ||
| 174 | } | ||
| 175 | #define atomic_fetch_add atomic_fetch_add | ||
| 176 | #endif | ||
| 177 | |||
| 178 | #endif /* atomic_fetch_add_relaxed */ | ||
| 179 | |||
| 180 | #ifndef atomic_sub_return_relaxed | ||
| 181 | #define atomic_sub_return_acquire atomic_sub_return | ||
| 182 | #define atomic_sub_return_release atomic_sub_return | ||
| 183 | #define atomic_sub_return_relaxed atomic_sub_return | ||
| 184 | #else /* atomic_sub_return_relaxed */ | ||
| 185 | |||
| 186 | #ifndef atomic_sub_return_acquire | ||
| 187 | static inline int | ||
| 188 | atomic_sub_return_acquire(int i, atomic_t *v) | ||
| 189 | { | ||
| 190 | int ret = atomic_sub_return_relaxed(i, v); | ||
| 191 | __atomic_acquire_fence(); | ||
| 192 | return ret; | ||
| 193 | } | ||
| 194 | #define atomic_sub_return_acquire atomic_sub_return_acquire | ||
| 195 | #endif | ||
| 196 | |||
| 197 | #ifndef atomic_sub_return_release | ||
| 198 | static inline int | ||
| 199 | atomic_sub_return_release(int i, atomic_t *v) | ||
| 200 | { | ||
| 201 | __atomic_release_fence(); | ||
| 202 | return atomic_sub_return_relaxed(i, v); | ||
| 203 | } | ||
| 204 | #define atomic_sub_return_release atomic_sub_return_release | ||
| 205 | #endif | ||
| 206 | |||
