Thread (2 messages) 2 messages, 2 authors, 2021-07-28

[RFC PATCH v1 2/5] locking/qspinlock: Refactor xchg_tail to use atomic_fetch_and_or

STALE1891d

From: Rui Wang <hidden>
Date: 2021-07-28 11:49:39
Subsystem: locking primitives, the rest · Maintainers: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng, Linus Torvalds

From: wangrui <redacted>

Signed-by-off: Rui Wang [off-list ref]
Signed-by-off: hev [off-list ref]
---
 kernel/locking/qspinlock.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
index cbff6ba53d56..350363e14e38 100644
--- a/kernel/locking/qspinlock.c
+++ b/kernel/locking/qspinlock.c
@@ -219,22 +219,8 @@ static __always_inline void clear_pending_set_locked(struct qspinlock *lock)
  */
 static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail)
 {
-	u32 old, new, val = atomic_read(&lock->val);
-
-	for (;;) {
-		new = (val & _Q_LOCKED_PENDING_MASK) | tail;
-		/*
-		 * We can use relaxed semantics since the caller ensures that
-		 * the MCS node is properly initialized before updating the
-		 * tail.
-		 */
-		old = atomic_cmpxchg_relaxed(&lock->val, val, new);
-		if (old == val)
-			break;
-
-		val = old;
-	}
-	return old;
+	const u32 mask = _Q_LOCKED_PENDING_MASK;
+	return atomic_fetch_and_or_relaxed(mask, tail, &lock->val);
 }
 #endif /* _Q_PENDING_BITS == 8 */
 
-- 
2.32.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help