Skip to content

Commit 40e6e3a

Browse files
committed
opal/memory: add query function to opal/memory structure
This commit makes it possible to set relative priorities for components. Before the addition of the patched component there was only one component that would run on any system but that is no longer the case. When determining which component to open each component's query function is called and the one that returns the highest priority is opened. The default priority of the patcher component is set slightly higher than the old ptmalloc2/ummunotify component. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
1 parent 1f819ad commit 40e6e3a

File tree

7 files changed

+98
-21
lines changed

7 files changed

+98
-21
lines changed

opal/mca/memory/base/memory_base_open.c

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2016 Research Organization for Information Science
1515
* and Technology (RIST). All rights reserved.
16+
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
17+
* reserved.
1618
* $COPYRIGHT$
1719
*
1820
* Additional copyrights may follow
@@ -43,20 +45,22 @@ static int empty_process(void)
4345
return OPAL_SUCCESS;
4446
}
4547

48+
static int empty_query (int *priority)
49+
{
50+
*priority = 0;
51+
return OPAL_SUCCESS;
52+
}
4653

4754
/*
4855
* Local variables
4956
*/
5057
static opal_memory_base_component_2_0_0_t empty_component = {
51-
/* Don't care about the version info */
52-
{ 0, },
53-
/* Don't care about the data */
54-
{ 0, },
5558
/* Empty / safe functions to call if no memory componet is selected */
56-
empty_process,
57-
opal_memory_base_component_register_empty,
58-
opal_memory_base_component_deregister_empty,
59-
opal_memory_base_component_set_alignment_empty,
59+
.memoryc_query = empty_query,
60+
.memoryc_process = empty_process,
61+
.memoryc_register = opal_memory_base_component_register_empty,
62+
.memoryc_deregister = opal_memory_base_component_deregister_empty,
63+
.memoryc_set_alignment = opal_memory_base_component_set_alignment_empty,
6064
};
6165

6266

@@ -73,23 +77,36 @@ opal_memory_base_component_2_0_0_t *opal_memory = &empty_component;
7377
*/
7478
static int opal_memory_base_open(mca_base_open_flag_t flags)
7579
{
80+
mca_base_component_list_item_t *item, *next;
81+
opal_memory_base_component_2_0_0_t *tmp;
82+
int priority, highest_priority = 0;
7683
int ret;
7784

78-
/* Open up all available components */
85+
/* can only be zero or one */
86+
OPAL_LIST_FOREACH(item, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) {
87+
tmp = (opal_memory_base_component_2_0_0_t *) item->cli_component;
88+
ret = tmp->memoryc_query (&priority);
89+
if (OPAL_SUCCESS != ret || priority < highest_priority) {
90+
continue;
91+
}
92+
93+
highest_priority = priority;
94+
opal_memory = tmp;
95+
}
96+
97+
OPAL_LIST_FOREACH_SAFE(item, next, &opal_memory_base_framework.framework_components, mca_base_component_list_item_t) {
98+
if ((void *) opal_memory != (void *) item->cli_component) {
99+
mca_base_component_unload (item->cli_component, opal_memory_base_framework.framework_output);
100+
opal_list_remove_item (&opal_memory_base_framework.framework_components, &item->super);
101+
}
102+
}
103+
104+
/* open remaining component */
79105
ret = mca_base_framework_components_open (&opal_memory_base_framework, flags);
80106
if (ret != OPAL_SUCCESS) {
81107
return ret;
82108
}
83109

84-
/* can only be zero or one */
85-
if (opal_list_get_size(&opal_memory_base_framework.framework_components) == 1) {
86-
mca_base_component_list_item_t *item;
87-
item = (mca_base_component_list_item_t*)
88-
opal_list_get_first(&opal_memory_base_framework.framework_components);
89-
opal_memory = (opal_memory_base_component_2_0_0_t*)
90-
item->cli_component;
91-
}
92-
93110
/* All done */
94111
return OPAL_SUCCESS;
95112
}

opal/mca/memory/linux/hooks.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ void opal_memory_linux_malloc_init_hook(void)
744744
check_result_t r1, lp, lpp;
745745
bool want_rcache = false, found_driver = false;
746746

747+
if (!opal_memory_linux_opened) {
748+
return;
749+
}
750+
747751
/* First, check for a FAKEROOT environment. If we're in a
748752
fakeroot, then access() (and likely others) have been replaced
749753
and are not safe to call here in this pre-main environment. So

opal/mca/memory/linux/memory_linux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ OPAL_DECLSPEC void opal_memory_linux_malloc_init_hook(void);
8383
OPAL_DECLSPEC void opal_memory_linux_malloc_set_alignment(int use_memalign, size_t memalign_threshold);
8484
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
8585

86+
extern bool opal_memory_linux_opened;
87+
8688
END_C_DECLS
8789

8890
#endif

opal/mca/memory/linux/memory_linux_component.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2013-2016 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2016 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
@@ -60,6 +60,7 @@
6060
static int linux_open(void);
6161
static int linux_close(void);
6262
static int linux_register(void);
63+
static int linux_query(int *);
6364

6465
#if MEMORY_LINUX_UMMUNOTIFY
6566
static bool ummunotify_opened = false;
@@ -69,6 +70,9 @@ static bool ptmalloc2_opened = false;
6970
#endif
7071

7172
bool opal_memory_linux_disable = false;
73+
static int mca_memory_linux_priority;
74+
75+
bool opal_memory_linux_opened = false;
7276

7377
opal_memory_linux_component_t mca_memory_linux_component = {
7478
/* First, the opal_memory_base_component_2_0_0_t */
@@ -96,6 +100,7 @@ opal_memory_linux_component_t mca_memory_linux_component = {
96100
/* Memory framework functions. These function pointer values
97101
are replaced by memory_linux_ummunotify.c at run time if we
98102
end up using ummunotify support. */
103+
.memoryc_query = linux_query,
99104
.memoryc_register = opal_memory_base_component_register_empty,
100105
.memoryc_deregister = opal_memory_base_component_deregister_empty,
101106
#if MEMORY_LINUX_MALLOC_ALIGN_ENABLED
@@ -243,11 +248,25 @@ static int linux_register(void)
243248
if (0 > ret) {
244249
return ret;
245250
}
251+
252+
mca_memory_linux_priority = 50;
253+
ret = mca_base_component_var_register (&mca_memory_linux_component.super.memoryc_version,
254+
"priority", "Priority of the linux memory hook component",
255+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5,
256+
MCA_BASE_VAR_SCOPE_CONSTANT, &mca_memory_linux_priority);
257+
if (0 > ret) {
258+
return ret;
259+
}
246260
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
247261

248262
return (0 > ret) ? ret : OPAL_SUCCESS;
249263
}
250264

265+
static int linux_query (int *priority)
266+
{
267+
*priority = mca_memory_linux_priority;
268+
return OPAL_SUCCESS;
269+
}
251270

252271
static int linux_open(void)
253272
{
@@ -318,6 +337,7 @@ static int linux_open(void)
318337
__malloc_hook = _opal_memory_linux_malloc_align_hook;
319338
}
320339
#endif /* MEMORY_LINUX_MALLOC_ALIGN_ENABLED */
340+
opal_memory_linux_opened = true;
321341

322342
return OPAL_SUCCESS;
323343
}

opal/mca/memory/malloc_solaris/memory_malloc_solaris_component.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2007-2011 Oracle and/or its affiliates. All rights reserved.
1414
* Copyright (c) 2009-2011 Cisco Systems, Inc. All rights reserved.
15-
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
15+
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
@@ -46,6 +46,7 @@ int __munmap(caddr_t addr, size_t len);
4646
#endif
4747

4848
static int opal_memory_malloc_open(void);
49+
static int opal_memory_malloc_query(int *);
4950

5051
const opal_memory_base_component_2_0_0_t mca_memory_malloc_solaris_component = {
5152
/* First, the mca_component_t struct containing meta information
@@ -68,6 +69,7 @@ const opal_memory_base_component_2_0_0_t mca_memory_malloc_solaris_component = {
6869

6970
/* This component doesn't need these functions, but need to
7071
provide safe/empty register/deregister functions to call */
72+
.memoryc_query = opal_memory_malloc_query,
7173
.memoryc_register = opal_memory_base_component_register_empty,
7274
.memoryc_deregister = opal_memory_base_component_deregister_empty,
7375
.memoryc_set_alignment = opal_memory_base_component_set_alignment_empty,
@@ -93,6 +95,11 @@ opal_memory_malloc_open(void)
9395
return OPAL_SUCCESS;
9496
}
9597

98+
static int opal_memory_malloc_query (int *priority)
99+
{
100+
*priority = 79;
101+
return OPAL_SUCCESS;
102+
}
96103

97104
/*
98105
* Three ways to call munmap. Prefered is to call __munmap, which

opal/mca/memory/memory.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2016 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
@@ -78,6 +78,12 @@ BEGIN_C_DECLS
7878
*/
7979
typedef int (*opal_memory_base_component_process_fn_t)(void);
8080

81+
/**
82+
* Prototype for a function that is invoked when the memory base is
83+
* trying to select a component. This funtionality is required.
84+
*/
85+
typedef int (*opal_memory_base_component_query_fn_t)(int *priority);
86+
8187
/**
8288
* Prototype for a function that is invoked when Open MPI starts to
8389
* "care" about a specific memory region. That is, Open MPI declares
@@ -128,6 +134,8 @@ typedef struct opal_memory_base_component_2_0_0_t {
128134
/** MCA base data */
129135
mca_base_component_data_t memoryc_data;
130136

137+
opal_memory_base_component_query_fn_t memoryc_query;
138+
131139
/** Function to call when something has changed, as indicated by
132140
opal_memory_changed(). Will be ignored if the component does
133141
not provide an opal_memory_changed() macro that returns

opal/mca/memory/patcher/memory_patcher_component.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
static int patcher_open(void);
4848
static int patcher_close(void);
4949
static int patcher_register(void);
50+
static int patcher_query (int *);
51+
52+
static int mca_memory_patcher_priority;
5053

5154
opal_memory_patcher_component_t mca_memory_patcher_component = {
5255
.super = {
@@ -69,6 +72,7 @@ opal_memory_patcher_component_t mca_memory_patcher_component = {
6972
},
7073

7174
/* Memory framework functions. */
75+
.memoryc_query = patcher_query,
7276
.memoryc_register = opal_memory_base_component_register_empty,
7377
.memoryc_deregister = opal_memory_base_component_deregister_empty,
7478
.memoryc_set_alignment = opal_memory_base_component_set_alignment_empty,
@@ -226,6 +230,18 @@ static int intercept_brk (void *addr)
226230

227231
static int patcher_register (void)
228232
{
233+
mca_memory_patcher_priority = 80;
234+
mca_base_component_var_register (&mca_memory_patcher_component.super.memoryc_version,
235+
"priority", "Priority of the patcher memory hook component",
236+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5,
237+
MCA_BASE_VAR_SCOPE_CONSTANT, &mca_memory_patcher_priority);
238+
239+
return OPAL_SUCCESS;
240+
}
241+
242+
static int patcher_query (int *priority)
243+
{
244+
*priority = mca_memory_patcher_priority;
229245
return OPAL_SUCCESS;
230246
}
231247

@@ -240,6 +256,9 @@ static int patcher_open (void)
240256

241257
was_executed_already = 1;
242258

259+
/* set memory hooks support level */
260+
opal_mem_hooks_set_support (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT);
261+
243262
rc = opal_patch_symbol ("mmap", (uintptr_t) intercept_mmap);
244263
if (OPAL_SUCCESS != rc) {
245264
return rc;

0 commit comments

Comments
 (0)