linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rui Wang <wangrui@loongson.cn>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>
Cc: Waiman Long <longman@redhat.com>,
	Boqun Feng <boqun.feng@gmail.com>, Guo Ren <guoren@kernel.org>,
	linux-arch@vger.kernel.org, Rui Wang <wangrui@loongson.cn>,
	hev <r@hev.cc>, Xuefeng Li <lixuefeng@loongson.cn>,
	Huacai Chen <chenhuacai@gmail.com>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	Huacai Chen <chenhuacai@loongson.cn>
Subject: [RFC PATCH v1 3/5] locking/atomic: mips: Refactor xchg_small to use atomic_fetch_and_or
Date: Wed, 28 Jul 2021 19:49:36 +0800	[thread overview]
Message-ID: <20210728114936.1344-1-wangrui@loongson.cn> (raw)

From: wangrui <wangrui@loongson.cn>

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

diff --git a/arch/mips/kernel/cmpxchg.c b/arch/mips/kernel/cmpxchg.c
index ac9c8cfb2ba9..34ef35194cbe 100644
--- a/arch/mips/kernel/cmpxchg.c
+++ b/arch/mips/kernel/cmpxchg.c
@@ -9,7 +9,7 @@
 
 unsigned long __xchg_small(volatile void *ptr, unsigned long val, unsigned int size)
 {
-	u32 old32, new32, load32, mask;
+	u32 old32, mask;
 	volatile u32 *ptr32;
 	unsigned int shift;
 
@@ -36,15 +36,9 @@ unsigned long __xchg_small(volatile void *ptr, unsigned long val, unsigned int s
 	 * includes our byte of interest, and load its value.
 	 */
 	ptr32 = (volatile u32 *)((unsigned long)ptr & ~0x3);
-	load32 = *ptr32;
-
-	do {
-		old32 = load32;
-		new32 = (load32 & ~mask) | (val << shift);
-		load32 = arch_cmpxchg(ptr32, old32, new32);
-	} while (load32 != old32);
+	old32 = atomic_fetch_and_or(ptr32, ~mask, val << shift);
 
-	return (load32 & mask) >> shift;
+	return (old32 & mask) >> shift;
 }
 
 unsigned long __cmpxchg_small(volatile void *ptr, unsigned long old,
-- 
2.32.0


                 reply	other threads:[~2021-07-28 11:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210728114936.1344-1-wangrui@loongson.cn \
    --to=wangrui@loongson.cn \
    --cc=arnd@arndb.de \
    --cc=boqun.feng@gmail.com \
    --cc=chenhuacai@gmail.com \
    --cc=chenhuacai@loongson.cn \
    --cc=guoren@kernel.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=r@hev.cc \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).