Skip to content

Commit 1e90bb0

Browse files
committed
mpid/shm: remove MPIDU_shm_seg_t and refactor
MPIDU_shm_seg_t was used by mpidu_shm_alloc.c, mpidu_init_shm.c, and mpidu_init_shm_alloc.c. However, the usages are all slightly different and some fields are only used in one but not the other. It is simpler to locally define it or, in the case of mpidu_init_shm.c, just use static globals.
1 parent 3d4ee33 commit 1e90bb0

File tree

4 files changed

+44
-50
lines changed

4 files changed

+44
-50
lines changed

src/mpid/common/shm/mpidu_init_shm.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "mpl_shm.h"
99
#include "mpidimpl.h"
1010
#include "mpir_pmi.h"
11-
#include "mpidu_shm_seg.h"
1211

1312
static int init_shm_initialized;
1413

@@ -58,7 +57,10 @@ typedef struct Init_shm_barrier {
5857
MPL_atomic_int_t wait;
5958
} Init_shm_barrier_t;
6059

61-
static MPIDU_shm_seg_t memory;
60+
static size_t init_shm_len;
61+
static MPL_shm_hnd_t init_shm_hnd;
62+
static char *init_shm_addr;
63+
6264
static Init_shm_barrier_t *barrier;
6365
static void *baseaddr;
6466

@@ -70,7 +72,7 @@ static int Init_shm_barrier_init(int is_root)
7072

7173
MPIR_FUNC_ENTER;
7274

73-
barrier = (Init_shm_barrier_t *) memory.base_addr;
75+
barrier = (Init_shm_barrier_t *) init_shm_addr;
7476
if (is_root) {
7577
MPL_atomic_store_int(&barrier->val, 0);
7678
MPL_atomic_store_int(&barrier->wait, 0);
@@ -136,20 +138,20 @@ int MPIDU_Init_shm_init(void)
136138
char *serialized_hnd = NULL;
137139
int serialized_hnd_size = 0;
138140

139-
mpl_err = MPL_shm_hnd_init(&(memory.hnd));
141+
mpl_err = MPL_shm_hnd_init(&init_shm_hnd);
140142
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**alloc_shar_mem");
141143

142-
memory.segment_len = segment_len;
144+
init_shm_len = segment_len;
143145

144146
if (MPIDU_Init_shm_local_rank == 0) {
145147
/* root prepare shm segment */
146-
mpl_err = MPL_shm_seg_create_and_attach(memory.hnd, memory.segment_len,
147-
(void **) &(memory.base_addr), 0);
148+
mpl_err = MPL_shm_seg_create_and_attach(init_shm_hnd, init_shm_len,
149+
(void **) &(init_shm_addr), 0);
148150
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**alloc_shar_mem");
149151

150152
MPIR_Assert(MPIR_Process.node_local_map[0] == MPIR_Process.rank);
151153

152-
mpl_err = MPL_shm_hnd_get_serialized_by_ref(memory.hnd, &serialized_hnd);
154+
mpl_err = MPL_shm_hnd_get_serialized_by_ref(init_shm_hnd, &serialized_hnd);
153155
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**alloc_shar_mem");
154156
serialized_hnd_size = strlen(serialized_hnd) + 1;
155157
MPIR_Assert(serialized_hnd_size < MPIR_pmi_max_val_size());
@@ -169,11 +171,10 @@ int MPIDU_Init_shm_init(void)
169171

170172
if (MPIDU_Init_shm_local_rank > 0) {
171173
/* non-root attach shm segment */
172-
mpl_err = MPL_shm_hnd_deserialize(memory.hnd, serialized_hnd, strlen(serialized_hnd));
174+
mpl_err = MPL_shm_hnd_deserialize(init_shm_hnd, serialized_hnd, strlen(serialized_hnd));
173175
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**alloc_shar_mem");
174176

175-
mpl_err = MPL_shm_seg_attach(memory.hnd, memory.segment_len,
176-
(void **) &memory.base_addr, 0);
177+
mpl_err = MPL_shm_seg_attach(init_shm_hnd, init_shm_len, (void **) &init_shm_addr, 0);
177178
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**attach_shar_mem");
178179

179180
mpi_errno = Init_shm_barrier_init(FALSE);
@@ -184,13 +185,12 @@ int MPIDU_Init_shm_init(void)
184185
MPIR_ERR_CHECK(mpi_errno);
185186

186187
if (MPIDU_Init_shm_local_rank == 0) {
187-
/* memory->hnd no longer needed */
188-
mpl_err = MPL_shm_seg_remove(memory.hnd);
188+
/* init_shm_hnd no longer needed */
189+
mpl_err = MPL_shm_seg_remove(init_shm_hnd);
189190
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**remove_shar_mem");
190191
}
191192

192-
baseaddr = memory.base_addr + MPIDU_SHM_CACHE_LINE_LEN;
193-
memory.symmetrical = 0;
193+
baseaddr = init_shm_addr + MPIDU_SHM_CACHE_LINE_LEN;
194194

195195
mpi_errno = Init_shm_barrier();
196196
}
@@ -215,10 +215,10 @@ int MPIDU_Init_shm_finalize(void)
215215
goto fn_exit;
216216
}
217217

218-
mpl_err = MPL_shm_seg_detach(memory.hnd, (void **) &(memory.base_addr), memory.segment_len);
218+
mpl_err = MPL_shm_seg_detach(init_shm_hnd, (void **) &(init_shm_addr), init_shm_len);
219219
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**detach_shar_mem");
220220

221-
MPL_shm_hnd_finalize(&(memory.hnd));
221+
MPL_shm_hnd_finalize(&(init_shm_hnd));
222222

223223
init_shm_initialized = 0;
224224

src/mpid/common/shm/mpidu_init_shm_alloc.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <mpidimpl.h>
77
#include "mpl_shm.h"
88
#include "mpidu_init_shm.h"
9-
#include "mpidu_shm_seg.h"
109

1110
#include <stdlib.h>
1211
#ifdef HAVE_UNISTD_H
@@ -22,16 +21,24 @@
2221
extern int MPIDU_Init_shm_local_size;
2322
extern int MPIDU_Init_shm_local_rank;
2423

24+
struct memory_seg {
25+
size_t segment_len;
26+
MPL_shm_hnd_t hnd;
27+
char *base_addr;
28+
bool symmetrical;
29+
bool is_shm;
30+
};
31+
2532
typedef struct memory_list {
2633
void *ptr;
27-
MPIDU_shm_seg_t *memory;
34+
struct memory_seg *memory;
2835
struct memory_list *next;
2936
} memory_list_t;
3037

3138
static memory_list_t *memory_head = NULL;
3239
static memory_list_t *memory_tail = NULL;
3340

34-
static int check_alloc(MPIDU_shm_seg_t * memory);
41+
static int check_alloc(struct memory_seg *memory);
3542

3643
/* MPIDU_Init_shm_alloc(len, ptr_p)
3744
@@ -42,7 +49,7 @@ int MPIDU_Init_shm_alloc(size_t len, void **ptr)
4249
int mpi_errno = MPI_SUCCESS, mpl_err = 0;
4350
void *current_addr;
4451
size_t segment_len = len;
45-
MPIDU_shm_seg_t *memory = NULL;
52+
struct memory_seg *memory = NULL;
4653
memory_list_t *memory_node = NULL;
4754
MPIR_CHKPMEM_DECL();
4855

@@ -101,7 +108,8 @@ int MPIDU_Init_shm_alloc(size_t len, void **ptr)
101108
MPIR_ERR_CHKANDJUMP(mpl_err, mpi_errno, MPI_ERR_OTHER, "**remove_shar_mem");
102109
}
103110
current_addr = memory->base_addr;
104-
memory->symmetrical = 0;
111+
memory->symmetrical = false;
112+
memory->is_shm = true;
105113

106114
mpi_errno = check_alloc(memory);
107115
MPIR_ERR_CHECK(mpi_errno);
@@ -134,7 +142,7 @@ int MPIDU_Init_shm_alloc(size_t len, void **ptr)
134142
int MPIDU_Init_shm_free(void *ptr)
135143
{
136144
int mpi_errno = MPI_SUCCESS, mpl_err = 0;
137-
MPIDU_shm_seg_t *memory = NULL;
145+
struct memory_seg *memory = NULL;
138146
memory_list_t *el = NULL;
139147

140148
MPIR_FUNC_ENTER;
@@ -193,7 +201,7 @@ int MPIDU_Init_shm_is_symm(void *ptr)
193201
/* check_alloc() checks to see whether the shared memory segment is
194202
allocated at the same virtual memory address at each process.
195203
*/
196-
static int check_alloc(MPIDU_shm_seg_t * memory)
204+
static int check_alloc(struct memory_seg *memory)
197205
{
198206
int mpi_errno = MPI_SUCCESS;
199207
int is_sym;
@@ -226,9 +234,9 @@ static int check_alloc(MPIDU_shm_seg_t * memory)
226234
}
227235

228236
if (is_sym) {
229-
memory->symmetrical = 1;
237+
memory->symmetrical = true;
230238
} else {
231-
memory->symmetrical = 0;
239+
memory->symmetrical = false;
232240
}
233241

234242
MPIR_FUNC_EXIT;

src/mpid/common/shm/mpidu_shm_alloc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <mpidimpl.h>
77
#include "mpl_shm.h"
88
#include "mpidu_shm.h"
9-
#include "mpidu_shm_seg.h"
109

1110
#include <stdlib.h>
1211
#ifdef HAVE_UNISTD_H
@@ -58,6 +57,16 @@ enum {
5857
SYMSHM_OTHER_FAIL /* other failure reported by MPL shm */
5958
};
6059

60+
typedef struct MPIDU_shm_seg {
61+
size_t segment_len;
62+
/* Handle to shm seg */
63+
MPL_shm_hnd_t hnd;
64+
/* Pointers */
65+
char *base_addr;
66+
/* Misc */
67+
int symmetrical;
68+
} MPIDU_shm_seg_t;
69+
6170
/* Linked list internally used to keep track
6271
* of allocate shared memory segments */
6372
typedef struct seg_list {

src/mpid/common/shm/mpidu_shm_seg.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)