Skip to content

Commit 4ac5059

Browse files
committed
Make atomic memory barriers mandatory
The atomic memory barrier interface was de facto mandatory, as none of the code making opal_atomic_mb() calls bother with the ifdefs. Since all the supported platforms have atomic memory barrier implementations, just make them required. At the same time, clean up the code to reflect that there are no longer non-inline versions of the memory barrier assembly. Signed-off-by: Brian Barrett <[email protected]>
1 parent ca545d1 commit 4ac5059

File tree

7 files changed

+27
-40
lines changed

7 files changed

+27
-40
lines changed

opal/include/opal/sys/arm64/atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#ifndef OPAL_SYS_ARCH_ATOMIC_H
3131
#define OPAL_SYS_ARCH_ATOMIC_H 1
3232

33-
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
3433
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
3534
#define OPAL_HAVE_ATOMIC_SWAP_32 1
3635
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1
@@ -46,6 +45,7 @@
4645
#define OPAL_HAVE_ATOMIC_XOR_64 1
4746
#define OPAL_HAVE_ATOMIC_SUB_64 1
4847

48+
4949
/**********************************************************************
5050
*
5151
* Memory Barriers

opal/include/opal/sys/atomic.h

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
* The following #defines will be true / false based on
4242
* assembly support:
4343
*
44-
* - \c OPAL_HAVE_ATOMIC_MEM_BARRIER atomic memory barriers
4544
* - \c OPAL_HAVE_ATOMIC_SPINLOCKS atomic spinlocks
4645
*
4746
* Note that for the Atomic math, atomic add/sub may be implemented as
@@ -95,7 +94,6 @@ typedef struct opal_atomic_lock_t opal_atomic_lock_t;
9594
* files if we need to specify them as inline or non-inline
9695
*
9796
*********************************************************************/
98-
#define OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER 1
9997
#define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_32 1
10098
#define OPAL_HAVE_INLINE_ATOMIC_COMPARE_EXCHANGE_64 1
10199
#define OPAL_HAVE_INLINE_ATOMIC_ADD_32 1
@@ -166,18 +164,12 @@ enum { OPAL_ATOMIC_LOCK_UNLOCKED = 0, OPAL_ATOMIC_LOCK_LOCKED = 1 };
166164
# endif
167165
# endif /* DOXYGEN */
168166

167+
169168
/**********************************************************************
170169
*
171-
* Memory Barriers - defined here if running doxygen or have barriers
172-
* but can't inline
170+
* Memory Barriers
173171
*
174172
*********************************************************************/
175-
# if !defined(OPAL_HAVE_ATOMIC_MEM_BARRIER) && !defined(DOXYGEN)
176-
/* no way to emulate in C code */
177-
# define OPAL_HAVE_ATOMIC_MEM_BARRIER 0
178-
# endif
179-
180-
# if defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MEM_BARRIER
181173
/**
182174
* Memory barrier
183175
*
@@ -191,12 +183,7 @@ enum { OPAL_ATOMIC_LOCK_UNLOCKED = 0, OPAL_ATOMIC_LOCK_LOCKED = 1 };
191183
* generally grinding the memory controller's performance. Use only
192184
* if you need *both* read and write barriers.
193185
*/
194-
195-
# if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER
196-
static inline
197-
# endif
198-
void
199-
opal_atomic_mb(void);
186+
static inline void opal_atomic_mb(void);
200187

201188
/**
202189
* Read memory barrier
@@ -207,12 +194,7 @@ static inline
207194
* next read. Nothing is said about the ordering of writes when using
208195
* \c opal_atomic_rmb().
209196
*/
210-
211-
# if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER
212-
static inline
213-
# endif
214-
void
215-
opal_atomic_rmb(void);
197+
static inline void opal_atomic_rmb(void);
216198

217199
/**
218200
* Write memory barrier.
@@ -223,14 +205,8 @@ static inline
223205
* next write. Nothing is said about the ordering of reads when using
224206
* \c opal_atomic_wmb().
225207
*/
208+
static inline void opal_atomic_wmb(void);
226209

227-
# if OPAL_HAVE_INLINE_ATOMIC_MEM_BARRIER
228-
static inline
229-
# endif
230-
void
231-
opal_atomic_wmb(void);
232-
233-
# endif /* defined(DOXYGEN) || OPAL_HAVE_ATOMIC_MEM_BARRIER */
234210

235211
/**********************************************************************
236212
*

opal/include/opal/sys/atomic_stdc.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Copyright (c) 2019-2021 Google, LLC. All rights reserved.
88
* Copyright (c) 2019 Triad National Security, LLC. All rights
99
* reserved.
10+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
11+
* All Rights reserved.
1012
* $COPYRIGHT$
1113
*
1214
* Additional copyrights may follow
@@ -30,8 +32,6 @@
3032
# include <stdatomic.h>
3133
# include <stdint.h>
3234

33-
# define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
34-
3535
# define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
3636
# define OPAL_HAVE_ATOMIC_SWAP_32 1
3737

@@ -58,6 +58,13 @@
5858

5959
# define OPAL_HAVE_ATOMIC_SPINLOCKS 1
6060

61+
62+
/**********************************************************************
63+
*
64+
* Memory Barriers
65+
*
66+
*********************************************************************/
67+
6168
static inline void opal_atomic_mb(void)
6269
{
6370
atomic_thread_fence(memory_order_seq_cst);

opal/include/opal/sys/gcc_builtin/atomic.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* Copyright (c) 2018 Triad National Security, LLC. All rights
1919
* reserved.
2020
* Copyright (c) 2021 Google, LLC. All rights reserved.
21+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
22+
* All Rights reserved.
2123
* $COPYRIGHT$
2224
*
2325
* Additional copyrights may follow
@@ -33,7 +35,6 @@
3335
* Memory Barriers
3436
*
3537
*********************************************************************/
36-
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
3738

3839
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
3940
#define OPAL_HAVE_ATOMIC_ADD_32 1
@@ -50,6 +51,12 @@
5051
#define OPAL_HAVE_ATOMIC_SUB_64 1
5152
#define OPAL_HAVE_ATOMIC_SWAP_64 1
5253

54+
55+
/**********************************************************************
56+
*
57+
* Memory Barriers
58+
*
59+
*********************************************************************/
5360
#if (OPAL_ASSEMBLY_ARCH == OPAL_X86_64) && defined (__GNUC__) && !defined(__llvm) && (__GNUC__ < 6)
5461
/* work around a bug in older gcc versions where ACQUIRE seems to get
5562
* treated as a no-op instead */

opal/include/opal/sys/powerpc/atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
* Define constants for PowerPC 64
3636
*
3737
*********************************************************************/
38-
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
3938

4039
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
4140
#define OPAL_HAVE_ATOMIC_SWAP_32 1
@@ -55,6 +54,7 @@
5554
#define OPAL_HAVE_ATOMIC_XOR_64 1
5655
#define OPAL_HAVE_ATOMIC_SUB_64 1
5756

57+
5858
/**********************************************************************
5959
*
6060
* Memory Barriers

opal/include/opal/sys/x86_64/atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
* Define constants for AMD64 / x86_64 / EM64T / ...
3939
*
4040
*********************************************************************/
41-
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
4241

4342
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
4443

4544
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1
4645

46+
4747
/**********************************************************************
4848
*
4949
* Memory Barriers

test/asm/atomic_barrier.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
14+
* All Rights reserved.
1315
* $COPYRIGHT$
1416
*
1517
* Additional copyrights may follow
@@ -24,8 +26,6 @@
2426

2527
int main(int argc, char *argv[])
2628
{
27-
#if OPAL_HAVE_ATOMIC_MEM_BARRIER
28-
2929
/* there really isn't a great way to test that the barriers
3030
actually barrier, but at least make sure they don't kill the
3131
machine.*/
@@ -35,7 +35,4 @@ int main(int argc, char *argv[])
3535
opal_atomic_wmb();
3636

3737
return 0;
38-
#else
39-
return 77;
40-
#endif
4138
}

0 commit comments

Comments
 (0)