Re: [PATCH] ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed

2025-04-27 Thread Vineet Gupta
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 
> Link: https://lore.kernel.org/r/Z0747n5bSep4_1VX@J2N7QTR9R3
> Signed-off-by: Jason Gunthorpe 

Acked-by: Vineet Gupta 

> ---
>  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

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH] ARC: unwind: Use built-in sort swap to reduce code size and improve performance

2025-04-27 Thread Vineet Gupta
On 4/9/25 10:11, Yu-Chun Lin wrote:
> The custom swap function used in sort() was identical to the default
> built-in sort swap. Remove the custom swap function and passes NULL to
> sort(), allowing it to use the default swap function.
>
> This change reduces code size and improves performance, particularly when
> CONFIG_MITIGATION_RETPOLINE is enabled. With RETPOLINE mitigation, indirect
> function calls incur significant overhead, and using the default swap
> function avoids this cost.
>
> $ ./scripts/bloat-o-meter ./unwind.o.old ./unwind.o.new
> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-22 (-22)
> Function old new   delta
> init_unwind_hdr.constprop544 540  -4
> swap_eh_frame_hdr_table_entries   18   - -18
> Total: Before=4410, After=4388, chg -0.50%
>
> Signed-off-by: Yu-Chun Lin 

Acked-by: Vineet Gupta 

Added to for-curr.

Thx,
-Vineet

> ---
> Compile test only
>
>  arch/arc/kernel/unwind.c | 11 +--
>  1 file changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/arch/arc/kernel/unwind.c b/arch/arc/kernel/unwind.c
> index d8969dab12d4..789cfb9ea14e 100644
> --- a/arch/arc/kernel/unwind.c
> +++ b/arch/arc/kernel/unwind.c
> @@ -241,15 +241,6 @@ static int cmp_eh_frame_hdr_table_entries(const void 
> *p1, const void *p2)
>   return (e1->start > e2->start) - (e1->start < e2->start);
>  }
>  
> -static void swap_eh_frame_hdr_table_entries(void *p1, void *p2, int size)
> -{
> - struct eh_frame_hdr_table_entry *e1 = p1;
> - struct eh_frame_hdr_table_entry *e2 = p2;
> -
> - swap(e1->start, e2->start);
> - swap(e1->fde, e2->fde);
> -}
> -
>  static void init_unwind_hdr(struct unwind_table *table,
>   void *(*alloc) (unsigned long))
>  {
> @@ -345,7 +336,7 @@ static void init_unwind_hdr(struct unwind_table *table,
>   sort(header->table,
>n,
>sizeof(*header->table),
> -  cmp_eh_frame_hdr_table_entries, swap_eh_frame_hdr_table_entries);
> +  cmp_eh_frame_hdr_table_entries, NULL);
>  
>   table->hdrsz = hdrSize;
>   smp_wmb();


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc