All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 4/5] locking/atomic: openrisc: Refactor xchg_small to use atomic_fetch_and_or
@ 2021-07-28 11:49 Rui Wang
  0 siblings, 0 replies; only message in thread
From: Rui Wang @ 2021-07-28 11:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Arnd Bergmann
  Cc: Waiman Long, Boqun Feng, Guo Ren, linux-arch, Rui Wang, hev,
	Xuefeng Li, Huacai Chen, Jiaxun Yang, Huacai Chen

From: wangrui <wangrui@loongson.cn>

Signed-by-off: Rui Wang <wangrui@loongson.cn>
Signed-by-off: hev <r@hev.cc>
---
 arch/openrisc/include/asm/cmpxchg.h | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/openrisc/include/asm/cmpxchg.h b/arch/openrisc/include/asm/cmpxchg.h
index 79fd16162ccb..c69b91ed4b48 100644
--- a/arch/openrisc/include/asm/cmpxchg.h
+++ b/arch/openrisc/include/asm/cmpxchg.h
@@ -99,16 +99,10 @@ static inline u32 xchg_small(volatile void *ptr, u32 x, int size)
 	int bitoff = off * BITS_PER_BYTE;
 #endif
 	u32 bitmask = ((0x1 << size * BITS_PER_BYTE) - 1) << bitoff;
-	u32 oldv, newv;
-	u32 ret;
-
-	do {
-		oldv = READ_ONCE(*p);
-		ret = (oldv & bitmask) >> bitoff;
-		newv = (oldv & ~bitmask) | (x << bitoff);
-	} while (cmpxchg_u32(p, oldv, newv) != oldv);
+	u32 oldv;
 
-	return ret;
+	oldv = atomic_fetch_and_or(p, ~bitmask, x << bitoff);
+	return (oldv & bitmask) >> bitoff;
 }
 
 /*
-- 
2.32.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-28 11:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 11:49 [RFC PATCH v1 4/5] locking/atomic: openrisc: Refactor xchg_small to use atomic_fetch_and_or Rui Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.