Archive-only list for patches
 help / color / mirror / Atom feed
* [PATCH] ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed
@ 2025-04-08 17:22 Jason Gunthorpe
  2025-04-28  2:34 ` Vineet Gupta
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2025-04-08 17:22 UTC (permalink / raw)
  To: Boqun Feng, linux-snps-arc, Peter Zijlstra, Vineet Gupta,
	Will Deacon
  Cc: Mark Rutland, patches

The core atomic code has a number of macros where it elaborates
architecture primitives into more functions. ARC uses
arch_atomic64_cmpxchg() as it's architecture primitive which disable alot
of the additional functions.

Instead provide arch_cmpxchg64_relaxed() as the primitive and rely on the
core macros to create arch_cmpxchg64().

The macros will also provide other functions, for instance,
try_cmpxchg64_release(), giving a more complete implementation.

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/Z0747n5bSep4_1VX@J2N7QTR9R3
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 arch/arc/include/asm/atomic64-arcv2.h | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/arch/arc/include/asm/atomic64-arcv2.h b/arch/arc/include/asm/atomic64-arcv2.h
index 9b5791b8547133..73080a664369b4 100644
--- a/arch/arc/include/asm/atomic64-arcv2.h
+++ b/arch/arc/include/asm/atomic64-arcv2.h
@@ -137,12 +137,9 @@ ATOMIC64_OPS(xor, xor, xor)
 #undef ATOMIC64_OP_RETURN
 #undef ATOMIC64_OP
 
-static inline s64
-arch_atomic64_cmpxchg(atomic64_t *ptr, s64 expected, s64 new)
+static inline u64 __arch_cmpxchg64_relaxed(volatile void *ptr, u64 old, u64 new)
 {
-	s64 prev;
-
-	smp_mb();
+	u64 prev;
 
 	__asm__ __volatile__(
 	"1:	llockd  %0, [%1]	\n"
@@ -152,14 +149,12 @@ arch_atomic64_cmpxchg(atomic64_t *ptr, s64 expected, s64 new)
 	"	bnz     1b		\n"
 	"2:				\n"
 	: "=&r"(prev)
-	: "r"(ptr), "ir"(expected), "r"(new)
-	: "cc");	/* memory clobber comes from smp_mb() */
-
-	smp_mb();
+	: "r"(ptr), "ir"(old), "r"(new)
+	: "memory", "cc");
 
 	return prev;
 }
-#define arch_atomic64_cmpxchg arch_atomic64_cmpxchg
+#define arch_cmpxchg64_relaxed __arch_cmpxchg64_relaxed
 
 static inline s64 arch_atomic64_xchg(atomic64_t *ptr, s64 new)
 {

base-commit: ea8f6ee2111cd78b32d0363ea630ba9b08ada22d
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed
  2025-04-08 17:22 [PATCH] ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed Jason Gunthorpe
@ 2025-04-28  2:34 ` Vineet Gupta
  2025-06-09 13:14   ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Vineet Gupta @ 2025-04-28  2:34 UTC (permalink / raw)
  To: Jason Gunthorpe, Boqun Feng, linux-snps-arc, Peter Zijlstra,
	Vineet Gupta, Will Deacon
  Cc: Mark Rutland, patches

On 4/8/25 10:22, Jason Gunthorpe wrote:
> The core atomic code has a number of macros where it elaborates
> architecture primitives into more functions. ARC uses
> arch_atomic64_cmpxchg() as it's architecture primitive which disable alot
> of the additional functions.
>
> Instead provide arch_cmpxchg64_relaxed() as the primitive and rely on the
> core macros to create arch_cmpxchg64().
>
> The macros will also provide other functions, for instance,
> try_cmpxchg64_release(), giving a more complete implementation.
>
> Suggested-by: Mark Rutland <mark.rutland@arm.com>
> Link: https://lore.kernel.org/r/Z0747n5bSep4_1VX@J2N7QTR9R3
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Acked-by: Vineet Gupta <vgupta@kernel.org>

> ---
>  arch/arc/include/asm/atomic64-arcv2.h | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arc/include/asm/atomic64-arcv2.h b/arch/arc/include/asm/atomic64-arcv2.h
> index 9b5791b8547133..73080a664369b4 100644
> --- a/arch/arc/include/asm/atomic64-arcv2.h
> +++ b/arch/arc/include/asm/atomic64-arcv2.h
> @@ -137,12 +137,9 @@ ATOMIC64_OPS(xor, xor, xor)
>  #undef ATOMIC64_OP_RETURN
>  #undef ATOMIC64_OP
>  
> -static inline s64
> -arch_atomic64_cmpxchg(atomic64_t *ptr, s64 expected, s64 new)
> +static inline u64 __arch_cmpxchg64_relaxed(volatile void *ptr, u64 old, u64 new)
>  {
> -	s64 prev;
> -
> -	smp_mb();
> +	u64 prev;
>  
>  	__asm__ __volatile__(
>  	"1:	llockd  %0, [%1]	\n"
> @@ -152,14 +149,12 @@ arch_atomic64_cmpxchg(atomic64_t *ptr, s64 expected, s64 new)
>  	"	bnz     1b		\n"
>  	"2:				\n"
>  	: "=&r"(prev)
> -	: "r"(ptr), "ir"(expected), "r"(new)
> -	: "cc");	/* memory clobber comes from smp_mb() */
> -
> -	smp_mb();
> +	: "r"(ptr), "ir"(old), "r"(new)
> +	: "memory", "cc");
>  
>  	return prev;
>  }
> -#define arch_atomic64_cmpxchg arch_atomic64_cmpxchg
> +#define arch_cmpxchg64_relaxed __arch_cmpxchg64_relaxed
>  
>  static inline s64 arch_atomic64_xchg(atomic64_t *ptr, s64 new)
>  {
>
> base-commit: ea8f6ee2111cd78b32d0363ea630ba9b08ada22d

Thx for this.

FWIW I missed the cmpxchg API when the rest of atomics were relaxed in commit
301014cf6d728 ("ARC: atomic_cmpxchg/atomic_xchg: implement relaxed variants")

Added to ARC for-curr (for next)

Thx,
-Vineet

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed
  2025-04-28  2:34 ` Vineet Gupta
@ 2025-06-09 13:14   ` Jason Gunthorpe
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2025-06-09 13:14 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Boqun Feng, linux-snps-arc, Peter Zijlstra, Will Deacon,
	Mark Rutland, patches

On Sun, Apr 27, 2025 at 07:34:55PM -0700, Vineet Gupta wrote:
> Thx for this.
> 
> FWIW I missed the cmpxchg API when the rest of atomics were relaxed in commit
> 301014cf6d728 ("ARC: atomic_cmpxchg/atomic_xchg: implement relaxed variants")
> 
> Added to ARC for-curr (for next)

I'm looking at v6.16-rc1 and I don't see this patch???

It is in linux-next though:

commit ef7647b215c919a82ee3235b80998c9bb3a915a3
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date:   Tue Apr 8 14:22:56 2025 -0300

    ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-09 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 17:22 [PATCH] ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed Jason Gunthorpe
2025-04-28  2:34 ` Vineet Gupta
2025-06-09 13:14   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox