atomic: Consolidate atomic_full_barrier implementation

All ABIs save for sparcv9 and s390 defines it to __sync_synchronize,
which can be mapped to __atomic_thread_fence (__ATOMIC_SEQ_CST).

For Sparc, it uses a stricter #StoreStore|#LoadStore|#StoreLoad|#LoadLoad
instead of the #StoreLoad generated by __sync_synchronize.

For s390x, it defaults to a memory barrier where __sync_synchronize
emits a 'bcr 15,0' (which the manual describes as pipeline synchronization).

The barrier is used only in one place (pthread_mutex_setprioceiling),
and using a stricter barrier for s390 is ok performance-wise.

Co-authored-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
This commit is contained in:
Adhemerval Zanella 2025-09-11 10:49:44 -03:00
parent c797303237
commit 70ee250fb8
14 changed files with 1 additions and 60 deletions

View File

@ -103,7 +103,7 @@
#ifndef atomic_full_barrier #ifndef atomic_full_barrier
# define atomic_full_barrier() __asm ("" ::: "memory") # define atomic_full_barrier() __atomic_thread_fence (__ATOMIC_SEQ_CST)
#endif #endif

View File

@ -22,7 +22,4 @@
#define __HAVE_64B_ATOMICS 1 #define __HAVE_64B_ATOMICS 1
#define ATOMIC_EXCHANGE_USES_CAS 0 #define ATOMIC_EXCHANGE_USES_CAS 0
/* Barrier macro. */
#define atomic_full_barrier() __sync_synchronize()
#endif #endif

View File

@ -22,6 +22,5 @@
/* XXX Is this actually correct? */ /* XXX Is this actually correct? */
#define ATOMIC_EXCHANGE_USES_CAS 1 #define ATOMIC_EXCHANGE_USES_CAS 1
#define atomic_full_barrier() __asm ("mb" : : : "memory");
#define atomic_read_barrier() __asm ("mb" : : : "memory"); #define atomic_read_barrier() __asm ("mb" : : : "memory");
#define atomic_write_barrier() __asm ("wmb" : : : "memory"); #define atomic_write_barrier() __asm ("wmb" : : : "memory");

View File

@ -25,6 +25,4 @@
is not as optimal as LLOCK/SCOND specially for SMP. */ is not as optimal as LLOCK/SCOND specially for SMP. */
#define ATOMIC_EXCHANGE_USES_CAS 1 #define ATOMIC_EXCHANGE_USES_CAS 1
#define atomic_full_barrier() ({ asm volatile ("dmb 3":::"memory"); })
#endif /* _ARC_BITS_ATOMIC_H */ #endif /* _ARC_BITS_ATOMIC_H */

View File

@ -18,5 +18,3 @@
#define __HAVE_64B_ATOMICS 0 #define __HAVE_64B_ATOMICS 0
#define ATOMIC_EXCHANGE_USES_CAS 1 #define ATOMIC_EXCHANGE_USES_CAS 1
#define atomic_full_barrier() __sync_synchronize ()

View File

@ -22,10 +22,6 @@
#include <atomic.h> #include <atomic.h>
#ifndef atomic_full_barrier
# define atomic_full_barrier() __asm ("" ::: "memory")
#endif
#ifndef atomic_read_barrier #ifndef atomic_read_barrier
# define atomic_read_barrier() atomic_full_barrier () # define atomic_read_barrier() atomic_full_barrier ()
#endif #endif

View File

@ -18,8 +18,6 @@
#ifndef _ATOMIC_MACHINE_H #ifndef _ATOMIC_MACHINE_H
#define _ATOMIC_MACHINE_H 1 #define _ATOMIC_MACHINE_H 1
#define atomic_full_barrier() __sync_synchronize ()
#define __HAVE_64B_ATOMICS 0 #define __HAVE_64B_ATOMICS 0
/* XXX Is this actually correct? */ /* XXX Is this actually correct? */

View File

@ -19,8 +19,6 @@
#ifndef _LINUX_LOONGARCH_BITS_ATOMIC_H #ifndef _LINUX_LOONGARCH_BITS_ATOMIC_H
#define _LINUX_LOONGARCH_BITS_ATOMIC_H 1 #define _LINUX_LOONGARCH_BITS_ATOMIC_H 1
#define atomic_full_barrier() __sync_synchronize ()
#define __HAVE_64B_ATOMICS (__loongarch_grlen >= 64) #define __HAVE_64B_ATOMICS (__loongarch_grlen >= 64)
#define ATOMIC_EXCHANGE_USES_CAS 0 #define ATOMIC_EXCHANGE_USES_CAS 0

View File

@ -33,15 +33,6 @@
#define __HAVE_64B_ATOMICS 1 #define __HAVE_64B_ATOMICS 1
#endif #endif
/* See the comments in <sys/asm.h> about the use of the sync instruction. */
#ifndef MIPS_SYNC
# define MIPS_SYNC sync
#endif
#define MIPS_SYNC_STR_2(X) #X
#define MIPS_SYNC_STR_1(X) MIPS_SYNC_STR_2(X)
#define MIPS_SYNC_STR MIPS_SYNC_STR_1(MIPS_SYNC)
/* MIPS is an LL/SC machine. However, XLP has a direct atomic exchange /* MIPS is an LL/SC machine. However, XLP has a direct atomic exchange
instruction which will be used by __atomic_exchange_n. */ instruction which will be used by __atomic_exchange_n. */
#ifdef _MIPS_ARCH_XLP #ifdef _MIPS_ARCH_XLP
@ -50,15 +41,4 @@
# define ATOMIC_EXCHANGE_USES_CAS 1 # define ATOMIC_EXCHANGE_USES_CAS 1
#endif #endif
#ifdef __mips16
# define atomic_full_barrier() __sync_synchronize ()
#else /* !__mips16 */
# define atomic_full_barrier() \
__asm__ __volatile__ (".set push\n\t" \
MIPS_PUSH_MIPS2 \
MIPS_SYNC_STR "\n\t" \
".set pop" : : : "memory")
#endif /* !__mips16 */
#endif /* atomic-machine.h */ #endif /* atomic-machine.h */

View File

@ -478,20 +478,4 @@ symbol = value
# define MTC0 dmtc0 # define MTC0 dmtc0
#endif #endif
/* The MIPS architectures do not have a uniform memory model. Particular
platforms may provide additional guarantees - for instance, the R4000
LL and SC instructions implicitly perform a SYNC, and the 4K promises
strong ordering.
However, in the absence of those guarantees, we must assume weak ordering
and SYNC explicitly where necessary.
Some obsolete MIPS processors may not support the SYNC instruction. This
applies to "true" MIPS I processors; most of the processors which compile
using MIPS I implement parts of MIPS II. */
#ifndef MIPS_SYNC
# define MIPS_SYNC sync
#endif
#endif /* sys/asm.h */ #endif /* sys/asm.h */

View File

@ -22,6 +22,4 @@
#define __HAVE_64B_ATOMICS 0 #define __HAVE_64B_ATOMICS 0
#define ATOMIC_EXCHANGE_USES_CAS 1 #define ATOMIC_EXCHANGE_USES_CAS 1
#define atomic_full_barrier() ({ asm volatile ("l.msync" ::: "memory"); })
#endif /* atomic-machine.h */ #endif /* atomic-machine.h */

View File

@ -57,6 +57,4 @@
# define atomic_write_barrier() __asm ("sync" ::: "memory") # define atomic_write_barrier() __asm ("sync" ::: "memory")
#endif #endif
#define atomic_full_barrier() __asm ("sync" ::: "memory")
#endif #endif

View File

@ -19,8 +19,6 @@
#ifndef _LINUX_RISCV_BITS_ATOMIC_H #ifndef _LINUX_RISCV_BITS_ATOMIC_H
#define _LINUX_RISCV_BITS_ATOMIC_H 1 #define _LINUX_RISCV_BITS_ATOMIC_H 1
#define atomic_full_barrier() __sync_synchronize ()
#ifdef __riscv_atomic #ifdef __riscv_atomic
# define __HAVE_64B_ATOMICS (__riscv_xlen >= 64) # define __HAVE_64B_ATOMICS (__riscv_xlen >= 64)

View File

@ -31,7 +31,6 @@
#define ATOMIC_EXCHANGE_USES_CAS 0 #define ATOMIC_EXCHANGE_USES_CAS 0
#define atomic_full_barrier() __sync_synchronize ()
#define atomic_read_barrier() __asm ("" ::: "memory") #define atomic_read_barrier() __asm ("" ::: "memory")
#define atomic_write_barrier() __asm ("" ::: "memory") #define atomic_write_barrier() __asm ("" ::: "memory")