Skip to content

Commit 9a8fd8d

Browse files
committed
Wrap atomic types with structs and add relaxed load/store
1 parent 9977df7 commit 9a8fd8d

File tree

22 files changed

+145
-87
lines changed

22 files changed

+145
-87
lines changed

ompi/communicator/comm_cid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#include "pmix.h"
5959

6060
/* for use when we don't have a PMIx that supports CID generation */
61-
opal_atomic_int64_t ompi_comm_next_base_cid = 1;
61+
opal_atomic_int64_t ompi_comm_next_base_cid = OPAL_ATOMIC_VAR_INIT(1);
6262

6363
/* A macro comparing two CIDs */
6464
#define OMPI_COMM_CID_IS_LOWER(comm1,comm2) ( ((comm1)->c_index < (comm2)->c_index)? 1:0)

ompi/communicator/comm_request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int ompi_comm_request_schedule_append_w_flags(ompi_comm_request_t *request, ompi
109109
static int ompi_comm_request_progress (void)
110110
{
111111
ompi_comm_request_t *request, *next;
112-
static opal_atomic_int32_t progressing = 0;
112+
static opal_atomic_int32_t progressing = OPAL_ATOMIC_VAR_INIT(0);
113113
int completed = 0;
114114

115115
/* don't allow re-entry */
@@ -175,7 +175,7 @@ static int ompi_comm_request_progress (void)
175175
}
176176

177177
opal_mutex_unlock (&ompi_comm_request_mutex);
178-
progressing = 0;
178+
opal_atomic_store(&progressing, 0);
179179

180180
return completed;
181181
}

ompi/communicator/ft/comm_ft_detector.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static opal_event_base_t* fd_event_base = NULL;
9494
static void fd_event_cb(int fd, short flags, void* pdetector);
9595

9696
static bool comm_detector_use_thread = false;
97-
static opal_atomic_int32_t fd_thread_active = 0;
97+
static opal_atomic_int32_t fd_thread_active = OPAL_ATOMIC_VAR_INIT(0);
9898
static opal_thread_t fd_thread;
9999
static void* fd_progress(opal_object_t* obj);
100100

@@ -168,8 +168,8 @@ int ompi_comm_failure_detector_init(void) {
168168
fd_thread.t_arg = NULL;
169169
ret = opal_thread_start(&fd_thread);
170170
if( OPAL_SUCCESS != ret ) goto cleanup;
171-
while( 0 == fd_thread_active ); /* wait for the fd thread initialization */
172-
if( 0 > fd_thread_active ) goto cleanup;
171+
while( 0 == opal_atomic_load(&fd_thread_active) ); /* wait for the fd thread initialization */
172+
if( 0 > opal_atomic_load(&fd_thread_active) ) goto cleanup;
173173
}
174174

175175
return OMPI_SUCCESS;
@@ -218,18 +218,18 @@ int ompi_comm_failure_detector_finalize(void) {
218218
#endif
219219
while( observing == detector->hb_observing ) {
220220
/* If observed process changed, recheck if local*/
221-
if( !(0 < fd_thread_active) )
221+
if( !(0 < opal_atomic_load(&fd_thread_active)) )
222222
{
223223
opal_progress();
224224
}
225225
}
226226
}
227227

228-
if( 0 < fd_thread_active ) {
228+
if( 0 < opal_atomic_load(&fd_thread_active) ) {
229229
void* tret;
230230
/* this is not a race condition. Accesses are serialized, we use the
231231
* atomic for the mfence part of it. */
232-
OPAL_THREAD_ADD_FETCH32(&fd_thread_active, -fd_thread_active);
232+
OPAL_THREAD_ADD_FETCH32(&fd_thread_active, -opal_atomic_load(&fd_thread_active));
233233
opal_event_base_loopbreak(fd_event_base);
234234
opal_thread_join(&fd_thread, &tret);
235235
}
@@ -587,9 +587,9 @@ void* fd_progress(opal_object_t* obj) {
587587
return OPAL_THREAD_CANCELLED;
588588
}
589589
OPAL_THREAD_ADD_FETCH32(&fd_thread_active, 1);
590-
while( 1 == fd_thread_active ); /* wait for init stage 2: start_detector */
590+
while( 1 == opal_atomic_load(&fd_thread_active) ); /* wait for init stage 2: start_detector */
591591
ret = MCA_PML_CALL(irecv(NULL, 0, MPI_BYTE, 0, MCA_COLL_BASE_TAG_FT_END, &ompi_mpi_comm_self.comm, &req));
592-
while( fd_thread_active ) {
592+
while( opal_atomic_load(&fd_thread_active) ) {
593593
opal_event_loop(fd_event_base, OPAL_EVLOOP_ONCE);
594594
#if 0
595595
/* This test disabled because rdma emulation over TCP would not work without

ompi/errhandler/errhandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ extern opal_atomic_int32_t ompi_instance_count;
213213
*/
214214
#define OMPI_ERR_INIT_FINALIZE(name) \
215215
{ \
216-
if (OPAL_UNLIKELY(0 == ompi_instance_count)) { \
216+
if (OPAL_UNLIKELY(0 == opal_atomic_load(&ompi_instance_count))) { \
217217
ompi_errhandler_invoke(NULL, NULL, -1, \
218218
ompi_errcode_get_mpi_code(MPI_ERR_ARG), \
219219
name); \

ompi/instance/instance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ enum {
9090
OMPI_INSTANCE_FINALIZING = -2,
9191
};
9292

93-
opal_atomic_int32_t ompi_instance_count = 0;
93+
opal_atomic_int32_t ompi_instance_count = OPAL_ATOMIC_VAR_INIT(0);
9494

9595
static const char *ompi_instance_builtin_psets[] = {
9696
"mpi://WORLD",

ompi/mca/coll/xhc/coll_xhc_intrinsic.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ typedef size_t __attribute__((aligned(SIZEOF_SIZE_T))) xf_size_t;
4343
// https://github.com/open-mpi/ompi/issues/9722
4444

4545
#if OPAL_USE_GCC_BUILTIN_ATOMICS || OPAL_USE_C11_ATOMICS
46-
#define xhc_atomic_load_int(addr) __atomic_load_n(addr, __ATOMIC_RELAXED)
47-
#define xhc_atomic_store_int(addr, val) __atomic_store_n(addr, val, __ATOMIC_RELAXED)
46+
#define xhc_atomic_load_int(addr) opal_atomic_load((opal_atomic_int_t *)(addr))
47+
#define xhc_atomic_store_int(addr, val) \
48+
opal_atomic_store((opal_atomic_int_t *)(addr), (val))
4849

49-
#define xhc_atomic_load_size_t(addr) __atomic_load_n(addr, __ATOMIC_RELAXED)
50-
#define xhc_atomic_store_size_t(addr, val) __atomic_store_n(addr, val, __ATOMIC_RELAXED)
50+
#define xhc_atomic_load_size_t(addr) opal_atomic_load((opal_atomic_size_t *)(addr))
51+
#define xhc_atomic_store_size_t(addr, val) \
52+
opal_atomic_store((opal_atomic_size_t *)(addr), (val))
5153
#else
5254
#define xhc_atomic_load_int(addr) (*(addr))
5355
#define xhc_atomic_store_int(addr, val) (*(addr) = (val))

ompi/mca/common/monitoring/common_monitoring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
/*** Monitoring specific variables ***/
4141
/* Keep tracks of how many components are currently using the common part */
42-
static opal_atomic_int32_t mca_common_monitoring_hold = 0;
42+
static opal_atomic_int32_t mca_common_monitoring_hold = OPAL_ATOMIC_VAR_INIT(0);
4343
/* Output parameters */
4444
int mca_common_monitoring_output_stream_id = -1;
4545
static opal_output_stream_t mca_common_monitoring_output_stream_obj = {

ompi/mca/common/ompio/common_ompio_buffer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static opal_mutex_t mca_common_ompio_buffer_mutex; /* lock for thread s
3535
static mca_allocator_base_component_t* mca_common_ompio_allocator_component=NULL;
3636
static mca_allocator_base_module_t* mca_common_ompio_allocator=NULL;
3737

38-
static opal_atomic_int32_t mca_common_ompio_buffer_init = 0;
38+
static opal_atomic_int32_t mca_common_ompio_buffer_init = OPAL_ATOMIC_VAR_INIT(0);
3939
static int32_t mca_common_ompio_pagesize=4096;
4040
static void* mca_common_ompio_buffer_alloc_seg ( void *ctx, size_t *size );
4141
static void mca_common_ompio_buffer_free_seg ( void *ctx, void *buf );
@@ -145,7 +145,7 @@ void *mca_common_ompio_alloc_buf ( ompio_file_t *fh, size_t bufsize )
145145
{
146146
char *tmp=NULL;
147147

148-
if ( !mca_common_ompio_buffer_init ){
148+
if ( !opal_atomic_load(&mca_common_ompio_buffer_init) ){
149149
mca_common_ompio_buffer_alloc_init ();
150150
}
151151

@@ -159,7 +159,7 @@ void *mca_common_ompio_alloc_buf ( ompio_file_t *fh, size_t bufsize )
159159
void mca_common_ompio_release_buf ( ompio_file_t *fh, void *buf )
160160
{
161161

162-
if ( !mca_common_ompio_buffer_init ){
162+
if ( !opal_atomic_load(&mca_common_ompio_buffer_init) ){
163163
/* Should not happen. You can not release a buf without
164164
** having it allocated first.
165165
*/

ompi/mca/osc/monitoring/osc_monitoring_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
OSC_MONITORING_SET_TEMPLATE_FCT_NAME(template) (ompi_osc_base_module_t*module) \
5151
{ \
5252
/* Define the ompi_osc_monitoring_module_## template ##_init_done variable */ \
53-
opal_atomic_int32_t init_done = 0; \
53+
opal_atomic_int32_t init_done = OPAL_ATOMIC_VAR_INIT(0); \
5454
/* Define and set the ompi_osc_monitoring_## template \
5555
* ##_template variable. The functions recorded here are \
5656
* linked to the original functions of the original \

ompi/mca/pml/base/pml_base_bsend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static size_t mca_pml_bsend_size; /* adjusted size of user buffe
5454
static size_t mca_pml_bsend_count; /* number of outstanding requests */
5555
static size_t mca_pml_bsend_pagesz; /* mmap page size */
5656
static int mca_pml_bsend_pagebits; /* number of bits in pagesz */
57-
static opal_atomic_int32_t mca_pml_bsend_init = 0;
57+
static opal_atomic_int32_t mca_pml_bsend_init = OPAL_ATOMIC_VAR_INIT(0);
5858

5959
/* defined in pml_base_open.c */
6060
extern char *ompi_pml_base_bsend_allocator_name;

0 commit comments

Comments
 (0)