Skip to content

Commit 15e7e5c

Browse files
wildea01Russell King
authored andcommitted
ARM: 7749/1: spinlock: retry trylock operation if strex fails on free lock
An exclusive store instruction may fail for reasons other than lock contention (e.g. a cache eviction during the critical section) so, in line with other architectures using similar exclusive instructions (alpha, mips, powerpc), retry the trylock operation if the lock appears to be free but the strex reported failure. Reported-by: Tony Thompson <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent 1aa2b3b commit 15e7e5c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

arch/arm/include/asm/spinlock.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,22 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
9797

9898
static inline int arch_spin_trylock(arch_spinlock_t *lock)
9999
{
100-
unsigned long tmp;
100+
unsigned long contended, res;
101101
u32 slock;
102102

103-
__asm__ __volatile__(
104-
" ldrex %0, [%2]\n"
105-
" subs %1, %0, %0, ror #16\n"
106-
" addeq %0, %0, %3\n"
107-
" strexeq %1, %0, [%2]"
108-
: "=&r" (slock), "=&r" (tmp)
109-
: "r" (&lock->slock), "I" (1 << TICKET_SHIFT)
110-
: "cc");
111-
112-
if (tmp == 0) {
103+
do {
104+
__asm__ __volatile__(
105+
" ldrex %0, [%3]\n"
106+
" mov %2, #0\n"
107+
" subs %1, %0, %0, ror #16\n"
108+
" addeq %0, %0, %4\n"
109+
" strexeq %2, %0, [%3]"
110+
: "=&r" (slock), "=&r" (contended), "=r" (res)
111+
: "r" (&lock->slock), "I" (1 << TICKET_SHIFT)
112+
: "cc");
113+
} while (res);
114+
115+
if (!contended) {
113116
smp_mb();
114117
return 1;
115118
} else {

0 commit comments

Comments
 (0)