locking/qrwlock: Cleanup queued_write_lock_slowpath()

Make the code more readable by replacing the atomic_cmpxchg_acquire()
by an equivalent atomic_try_cmpxchg_acquire() and change atomic_add()
to atomic_or().

For architectures that use qrwlock, I do not find one that has an
atomic_add() defined but not an atomic_or(). I guess it should be fine
by changing atomic_add() to atomic_or().

Note that the previous use of atomic_add() isn't wrong as only one
writer that is the wait_lock owner can set the waiting flag and the
flag will be cleared later on when acquiring the write lock.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lkml.kernel.org/r/20210426185017.19815-1-longman@redhat.com

authored by

Waiman Long and committed by
Peter Zijlstra
28ce0e70 1139aeb1

+3 -3
+3 -3
kernel/locking/qrwlock.c
··· 66 66 arch_spin_lock(&lock->wait_lock); 67 67 68 68 /* Try to acquire the lock directly if no reader is present */ 69 - if (!atomic_read(&lock->cnts) && 70 - (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0)) 69 + if (!(cnts = atomic_read(&lock->cnts)) && 70 + atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)) 71 71 goto unlock; 72 72 73 73 /* Set the waiting flag to notify readers that a writer is pending */ 74 - atomic_add(_QW_WAITING, &lock->cnts); 74 + atomic_or(_QW_WAITING, &lock->cnts); 75 75 76 76 /* When no more readers or writers, set the locked flag */ 77 77 do {