Skip to content

Commit b23eb63

Browse files
committed
s390/atomic: get rid of gcc atomic builtins
s390 is the only architecture in the kernel which makes use of gcc's atomic builtin functions. Even though I don't see any technical problem with that right now, remove this code and open-code compare-and-swap loops again, like every other architecture is doing it also. We can switch to a generic implementation when other architectures are doing that also. See also https://lwn.net/Articles/586838/ for forther details. Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent ca897bb commit b23eb63

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

arch/s390/include/asm/atomic_ops.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,46 @@ __ATOMIC64_OPS(__atomic64_xor, "xgr")
156156

157157
static inline int __atomic_cmpxchg(int *ptr, int old, int new)
158158
{
159-
return __sync_val_compare_and_swap(ptr, old, new);
159+
asm volatile(
160+
" cs %[old],%[new],%[ptr]"
161+
: [old] "+d" (old), [ptr] "+Q" (*ptr)
162+
: [new] "d" (new)
163+
: "cc", "memory");
164+
return old;
160165
}
161166

162-
static inline int __atomic_cmpxchg_bool(int *ptr, int old, int new)
167+
static inline bool __atomic_cmpxchg_bool(int *ptr, int old, int new)
163168
{
164-
return __sync_bool_compare_and_swap(ptr, old, new);
169+
int old_expected = old;
170+
171+
asm volatile(
172+
" cs %[old],%[new],%[ptr]"
173+
: [old] "+d" (old), [ptr] "+Q" (*ptr)
174+
: [new] "d" (new)
175+
: "cc", "memory");
176+
return old == old_expected;
165177
}
166178

167179
static inline long __atomic64_cmpxchg(long *ptr, long old, long new)
168180
{
169-
return __sync_val_compare_and_swap(ptr, old, new);
181+
asm volatile(
182+
" csg %[old],%[new],%[ptr]"
183+
: [old] "+d" (old), [ptr] "+S" (*ptr)
184+
: [new] "d" (new)
185+
: "cc", "memory");
186+
return old;
170187
}
171188

172-
static inline long __atomic64_cmpxchg_bool(long *ptr, long old, long new)
189+
static inline bool __atomic64_cmpxchg_bool(long *ptr, long old, long new)
173190
{
174-
return __sync_bool_compare_and_swap(ptr, old, new);
191+
long old_expected = old;
192+
193+
asm volatile(
194+
" csg %[old],%[new],%[ptr]"
195+
: [old] "+d" (old), [ptr] "+S" (*ptr)
196+
: [new] "d" (new)
197+
: "cc", "memory");
198+
return old == old_expected;
175199
}
176200

177201
#endif /* __ARCH_S390_ATOMIC_OPS__ */

0 commit comments

Comments
 (0)