Skip to content

Commit 83c2ab7

Browse files
committed
oshmem: memheap: refactor component selection code
Do not call component's init function until the component has been selected. Use mca_base_select() instead of the custom component selection code. Signed-off-by: Alex Mikheev <[email protected]>
1 parent 6d59b47 commit 83c2ab7

File tree

6 files changed

+41
-182
lines changed

6 files changed

+41
-182
lines changed

oshmem/mca/memheap/base/base.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,13 @@ OSHMEM_DECLSPEC int mca_memheap_base_select(void);
3131
/*
3232
* Globals
3333
*/
34-
OSHMEM_DECLSPEC extern struct mca_memheap_base_module_t* mca_memheap_base_module_initialized;
3534

3635
/* only used within base -- no need to DECLSPEC */
3736
#define MEMHEAP_BASE_MIN_ORDER 3 /* forces 64 bit alignment */
3837
#define MEMHEAP_BASE_PAGE_ORDER 21
3938
#define MEMHEAP_BASE_PRIVATE_SIZE (1ULL << MEMHEAP_BASE_PAGE_ORDER) /* should be at least the same as a huge page size */
4039
#define MEMHEAP_BASE_MIN_SIZE (1ULL << MEMHEAP_BASE_PAGE_ORDER) /* must fit into at least one huge page */
4140

42-
extern char* mca_memheap_base_include;
43-
extern char* mca_memheap_base_exclude;
4441
extern int mca_memheap_base_already_opened;
4542
extern int mca_memheap_base_key_exchange;
4643

oshmem/mca/memheap/base/memheap_base_frame.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333

3434
int mca_memheap_base_output = -1;
3535
int mca_memheap_base_key_exchange = 1;
36-
char* mca_memheap_base_include = NULL;
37-
char* mca_memheap_base_exclude = NULL;
3836
opal_list_t mca_memheap_base_components_opened = {{0}};
39-
struct mca_memheap_base_module_t* mca_memheap_base_module_initialized = NULL;
4037
int mca_memheap_base_already_opened = 0;
4138
mca_memheap_map_t mca_memheap_base_map = {{{{0}}}};
4239

@@ -55,39 +52,6 @@ static int mca_memheap_base_register(mca_base_register_flag_t flags)
5552
MCA_BASE_VAR_SCOPE_READONLY,
5653
&mca_memheap_base_key_exchange);
5754

58-
(void) mca_base_var_register("oshmem",
59-
"memheap",
60-
"base",
61-
"include",
62-
"Specify a specific MEMHEAP implementation to use",
63-
MCA_BASE_VAR_TYPE_STRING,
64-
NULL,
65-
0,
66-
MCA_BASE_VAR_FLAG_SETTABLE,
67-
OPAL_INFO_LVL_9,
68-
MCA_BASE_VAR_SCOPE_READONLY,
69-
&mca_memheap_base_include);
70-
71-
if (NULL == mca_memheap_base_include) {
72-
mca_memheap_base_include = getenv(SHMEM_HEAP_TYPE);
73-
if (NULL == mca_memheap_base_include)
74-
mca_memheap_base_include = strdup("");
75-
else
76-
mca_memheap_base_include = strdup(mca_memheap_base_include);
77-
}
78-
79-
(void) mca_base_var_register("oshmem",
80-
"memheap",
81-
"base",
82-
"exclude",
83-
"Specify excluded MEMHEAP implementations",
84-
MCA_BASE_VAR_TYPE_STRING,
85-
NULL,
86-
0,
87-
MCA_BASE_VAR_FLAG_SETTABLE,
88-
OPAL_INFO_LVL_9,
89-
MCA_BASE_VAR_SCOPE_READONLY,
90-
&mca_memheap_base_exclude);
9155

9256
return OSHMEM_SUCCESS;
9357
}

oshmem/mca/memheap/base/memheap_base_select.c

Lines changed: 23 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -45,133 +45,43 @@ static memheap_context_t* _memheap_create(void);
4545
*/
4646
int mca_memheap_base_select()
4747
{
48-
int priority = 0;
49-
int max_priority = 0;
50-
mca_base_component_list_item_t *cli, *next;
51-
mca_memheap_base_component_t *component = NULL;
52-
mca_memheap_base_component_t *max_priority_component = NULL;
53-
mca_memheap_base_module_t *module = NULL;
54-
memheap_context_t *context = NULL;
55-
56-
char** include = opal_argv_split(mca_memheap_base_include, ',');
57-
char** exclude = opal_argv_split(mca_memheap_base_exclude, ',');
58-
59-
context = _memheap_create();
60-
if (!context) {
61-
opal_argv_free(include);
62-
opal_argv_free(exclude);
48+
int best_priority;
49+
memheap_context_t *context;
50+
mca_memheap_base_component_t *best_component = NULL;
51+
mca_memheap_base_module_t *best_module = NULL;
52+
53+
if( OPAL_SUCCESS != mca_base_select("memheap", oshmem_memheap_base_framework.framework_output,
54+
&oshmem_memheap_base_framework.framework_components,
55+
(mca_base_module_t **) &best_module,
56+
(mca_base_component_t **) &best_component,
57+
&best_priority) ) {
6358
return OSHMEM_ERROR;
6459
}
6560

66-
OPAL_LIST_FOREACH_SAFE(cli, next, &oshmem_memheap_base_framework.framework_components, mca_base_component_list_item_t) {
67-
component = (mca_memheap_base_component_t *) cli->cli_component;
68-
69-
/* Verify if the component is in the include or the exclude list. */
70-
/* If there is an include list - item must be in the list to be included */
71-
if (NULL != include) {
72-
char** argv = include;
73-
bool found = false;
74-
while (argv && *argv) {
75-
if (strcmp(component->memheap_version.mca_component_name, *argv)
76-
== 0) {
77-
found = true;
78-
break;
79-
}
80-
argv++;
81-
}
82-
/* If not in the list do not choose this component */
83-
if (found == false) {
84-
continue;
85-
}
86-
87-
/* Otherwise - check the exclude list to see if this item has been specifically excluded */
88-
} else if (NULL != exclude) {
89-
char** argv = exclude;
90-
bool found = false;
91-
while (argv && *argv) {
92-
if (strcmp(component->memheap_version.mca_component_name, *argv)
93-
== 0) {
94-
found = true;
95-
break;
96-
}
97-
argv++;
98-
}
99-
if (found == true) {
100-
continue;
101-
}
102-
}
103-
104-
/* Verify that the component has an init function */
105-
if (NULL == component->memheap_init) {
106-
MEMHEAP_VERBOSE(10,
107-
"select: no init function; for component %s. No component selected",
108-
component->memheap_version.mca_component_name);
109-
} else {
110-
111-
MEMHEAP_VERBOSE(5,
112-
"select: component %s size : user %d private: %d",
113-
component->memheap_version.mca_component_name, (int)context->user_size, (int)context->private_size);
114-
115-
/* Init the component in order to get its priority */
116-
module = component->memheap_init(context, &priority);
117-
118-
/* If the component didn't initialize, remove it from the opened list, remove it from the component repository and return an error */
119-
if (NULL == module) {
120-
MEMHEAP_VERBOSE(10,
121-
"select: init of component %s returned failure",
122-
component->memheap_version.mca_component_name);
123-
124-
opal_list_remove_item(&oshmem_memheap_base_framework.framework_components, &cli->super);
125-
mca_base_component_close((mca_base_component_t *) component,
126-
oshmem_memheap_base_framework.framework_output);
127-
} else {
128-
/* Calculate memheap size in case it was not set during component initialization */
129-
module->memheap_size = context->user_size;
130-
}
131-
}
132-
133-
/* Init max priority component */
134-
if (NULL == max_priority_component) {
135-
max_priority_component = component;
136-
mca_memheap_base_module_initialized = module;
137-
max_priority = priority;
138-
}
139-
140-
/* Update max priority component if current component has greater priority */
141-
if (priority > max_priority) {
142-
max_priority = priority;
143-
max_priority_component = component;
144-
mca_memheap_base_module_initialized = module;
145-
}
146-
}
147-
148-
opal_argv_free(include);
149-
opal_argv_free(exclude);
150-
151-
/* Verify that a component was selected */
152-
if (NULL == max_priority_component) {
153-
MEMHEAP_VERBOSE(10, "select: no component selected");
61+
context = _memheap_create();
62+
if (NULL == context) {
15463
return OSHMEM_ERROR;
15564
}
15665

157-
/* Verify that some module was initialized */
158-
if (NULL == mca_memheap_base_module_initialized) {
66+
if (OSHMEM_SUCCESS != best_component->memheap_init(context)) {
15967
opal_show_help("help-oshmem-memheap.txt",
16068
"find-available:none-found",
16169
true,
16270
"memheap");
163-
orte_errmgr.abort(1, NULL );
71+
return OSHMEM_ERROR;
16472
}
16573

166-
MEMHEAP_VERBOSE(10,
167-
"SELECTED %s component %s",
168-
max_priority_component->memheap_version.mca_type_name, max_priority_component->memheap_version.mca_component_name);
169-
74+
/* Calculate memheap size in case it was not set during component initialization */
75+
best_module->memheap_size = context->user_size;
17076
setenv(SHMEM_HEAP_TYPE,
171-
max_priority_component->memheap_version.mca_component_name,
172-
1);
77+
best_component->memheap_version.mca_component_name, 1);
17378

174-
mca_memheap = *mca_memheap_base_module_initialized;
79+
mca_memheap = *best_module;
80+
81+
MEMHEAP_VERBOSE(10,
82+
"SELECTED %s component %s",
83+
best_component->memheap_version.mca_type_name,
84+
best_component->memheap_version.mca_component_name);
17585

17686
return OSHMEM_SUCCESS;
17787
}

oshmem/mca/memheap/buddy/memheap_buddy_component.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
#include "memheap_buddy_component.h"
1919

2020
static int mca_memheap_buddy_component_close(void);
21-
static mca_memheap_base_module_t* mca_memheap_buddy_component_init(memheap_context_t *,
22-
int *);
21+
static int mca_memheap_buddy_component_query(mca_base_module_t **module, int *priority);
2322

2423
static int _basic_open(void);
2524

@@ -33,12 +32,13 @@ mca_memheap_base_component_t mca_memheap_buddy_component = {
3332

3433
.mca_open_component = _basic_open,
3534
.mca_close_component = mca_memheap_buddy_component_close,
35+
.mca_query_component = mca_memheap_buddy_component_query,
3636
},
3737
.memheap_data = {
3838
/* The component is checkpoint ready */
3939
MCA_BASE_METADATA_PARAM_CHECKPOINT
4040
},
41-
.memheap_init = mca_memheap_buddy_component_init,
41+
.memheap_init = mca_memheap_buddy_module_init
4242
};
4343

4444
/* Open component */
@@ -47,19 +47,13 @@ static int _basic_open(void)
4747
return OSHMEM_SUCCESS;
4848
}
4949

50-
/* Initialize component */
51-
mca_memheap_base_module_t* mca_memheap_buddy_component_init(memheap_context_t *context,
52-
int *priority)
50+
/* query component */
51+
static int
52+
mca_memheap_buddy_component_query(mca_base_module_t **module, int *priority)
5353
{
54-
int rc;
55-
5654
*priority = memheap_buddy.priority;
57-
rc = mca_memheap_buddy_module_init(context);
58-
if (OSHMEM_SUCCESS != rc) {
59-
return NULL ;
60-
}
61-
62-
return &(memheap_buddy.super);
55+
*module = (mca_base_module_t *)&memheap_buddy.super;
56+
return OSHMEM_SUCCESS;
6357
}
6458

6559
/*

oshmem/mca/memheap/memheap.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ typedef struct memheap_context
3535
/**
3636
* Component initialize
3737
*/
38-
typedef struct mca_memheap_base_module_t* (*mca_memheap_base_component_init_fn_t)(memheap_context_t *,
39-
int *priority);
38+
typedef int (*mca_memheap_base_component_init_fn_t)(memheap_context_t *);
4039

4140
/*
4241
* Symmetric heap allocation. Malloc like interface

oshmem/mca/memheap/ptmalloc/memheap_ptmalloc_component.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "memheap_ptmalloc_component.h"
1919

2020
static int mca_memheap_ptmalloc_component_close(void);
21-
static mca_memheap_base_module_t* mca_memheap_ptmalloc_component_init(memheap_context_t *,
22-
int *);
21+
static int mca_memheap_ptmalloc_component_query(mca_base_module_t **module,
22+
int *priority);
2323

2424
static int _basic_open(void);
2525

@@ -33,12 +33,13 @@ mca_memheap_base_component_t mca_memheap_ptmalloc_component = {
3333

3434
.mca_open_component = _basic_open,
3535
.mca_close_component = mca_memheap_ptmalloc_component_close,
36+
.mca_query_component = mca_memheap_ptmalloc_component_query,
3637
},
3738
.memheap_data = {
3839
/* The component is checkpoint ready */
3940
MCA_BASE_METADATA_PARAM_CHECKPOINT
4041
},
41-
.memheap_init = mca_memheap_ptmalloc_component_init,
42+
.memheap_init = mca_memheap_ptmalloc_module_init,
4243
};
4344

4445
/* Open component */
@@ -47,19 +48,13 @@ static int _basic_open(void)
4748
return OSHMEM_SUCCESS;
4849
}
4950

50-
/* Initialize component */
51-
mca_memheap_base_module_t* mca_memheap_ptmalloc_component_init(memheap_context_t *context,
52-
int *priority)
51+
/* query component */
52+
static int
53+
mca_memheap_ptmalloc_component_query(mca_base_module_t **module, int *priority)
5354
{
54-
int rc;
55-
5655
*priority = memheap_ptmalloc.priority;
57-
rc = mca_memheap_ptmalloc_module_init(context);
58-
if (OSHMEM_SUCCESS != rc) {
59-
return NULL ;
60-
}
61-
62-
return &(memheap_ptmalloc.super);
56+
*module = (mca_base_module_t *)&memheap_ptmalloc.super;
57+
return OSHMEM_SUCCESS;
6358
}
6459

6560
/*

0 commit comments

Comments
 (0)