Skip to content

Commit 889221c

Browse files
committed
s390/spinlock: Use flag output constraint for arch_cmpxchg_niai8()
Add a new variant of arch_cmpxchg_niai8() which makes use of the flag output constraint, which allows the compiler to generate slightly better code. Also rename arch_cmpxchg_niai8() to arch_try_cmpxchg_niai8() which reflects the purpose of the function and makes it consistent with other "try" variants. Signed-off-by: Heiko Carstens <[email protected]>
1 parent 84ac965 commit 889221c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

arch/s390/lib/spinlock.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/percpu.h>
1616
#include <linux/io.h>
1717
#include <asm/alternative.h>
18+
#include <asm/asm.h>
1819

1920
int spin_retry = -1;
2021

@@ -81,7 +82,24 @@ static inline int arch_load_niai4(int *lock)
8182
return owner;
8283
}
8384

84-
static inline int arch_cmpxchg_niai8(int *lock, int old, int new)
85+
#ifdef __HAVE_ASM_FLAG_OUTPUTS__
86+
87+
static inline int arch_try_cmpxchg_niai8(int *lock, int old, int new)
88+
{
89+
int cc;
90+
91+
asm_inline volatile(
92+
ALTERNATIVE("nop", ".insn rre,0xb2fa0000,8,0", ALT_FACILITY(49)) /* NIAI 8 */
93+
" cs %[old],%[new],%[lock]\n"
94+
: [old] "+d" (old), [lock] "+Q" (*lock), "=@cc" (cc)
95+
: [new] "d" (new)
96+
: "memory");
97+
return cc == 0;
98+
}
99+
100+
#else /* __HAVE_ASM_FLAG_OUTPUTS__ */
101+
102+
static inline int arch_try_cmpxchg_niai8(int *lock, int old, int new)
85103
{
86104
int expected = old;
87105

@@ -94,6 +112,8 @@ static inline int arch_cmpxchg_niai8(int *lock, int old, int new)
94112
return expected == old;
95113
}
96114

115+
#endif /* __HAVE_ASM_FLAG_OUTPUTS__ */
116+
97117
static inline struct spin_wait *arch_spin_decode_tail(int lock)
98118
{
99119
int ix, cpu;
@@ -226,7 +246,7 @@ static inline void arch_spin_lock_classic(arch_spinlock_t *lp)
226246
/* Try to get the lock if it is free. */
227247
if (!owner) {
228248
new = (old & _Q_TAIL_MASK) | lockval;
229-
if (arch_cmpxchg_niai8(&lp->lock, old, new)) {
249+
if (arch_try_cmpxchg_niai8(&lp->lock, old, new)) {
230250
/* Got the lock */
231251
return;
232252
}

0 commit comments

Comments
 (0)