Skip to content

Commit 7afd613

Browse files
committed
opal/mca/hwloc: More cleanup/code removal.
- Remove some dead symbols and macros in hwloc/base/base.h. - Make opal_hwloc_base_free_topology(), opal_hwloc_base_mbfa, private. - This required making topo_in_shmem shared across two files. I don't see another clean way without exposing something else in base.h. Signed-off-by: Austen Lauria <awlauria@us.ibm.com> (cherry picked from commit d11d227)
1 parent cf75de0 commit 7afd613

File tree

4 files changed

+57
-139
lines changed

4 files changed

+57
-139
lines changed

opal/mca/hwloc/base/base.h

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ BEGIN_C_DECLS
3939
* hwloc_topology_load() can be expensive (and/or serialized by the
4040
* OS); it may not be desireable to call this function in every MPI
4141
* process on a machine. Hence, it is the responsibility for an upper
42-
* layer to both fill opal_hwloc_topology in some scalable way, as
43-
* well as to invoke opal_hwloc_base_set_process_membind_policy()
44-
* (after opal_hwloc_topology has been loaded) to set the process-wide
45-
* memory affinity policy.
42+
* layer to both fill opal_hwloc_topology in some scalable way.
4643
*/
4744

4845
/**
@@ -53,63 +50,6 @@ OPAL_DECLSPEC extern bool opal_hwloc_topology_inited;
5350

5451
OPAL_DECLSPEC extern mca_base_framework_t opal_hwloc_base_framework;
5552

56-
/* we always must have some minimal locality support */
57-
#define OPAL_HWLOC_PRINT_MAX_SIZE 50
58-
#define OPAL_HWLOC_PRINT_NUM_BUFS 16
59-
typedef struct {
60-
char *buffers[OPAL_HWLOC_PRINT_NUM_BUFS];
61-
int cntr;
62-
} opal_hwloc_print_buffers_t;
63-
opal_hwloc_print_buffers_t *opal_hwloc_get_print_buffer(void);
64-
65-
/* convenience macro for debugging */
66-
#define OPAL_HWLOC_SHOW_BINDING(n, v, t) \
67-
do { \
68-
char tmp1[1024]; \
69-
hwloc_cpuset_t bind; \
70-
bind = opal_hwloc_alloc(); \
71-
if (hwloc_get_cpubind(t, bind, HWLOC_CPUBIND_PROCESS) < 0) { \
72-
opal_output_verbose(n, v, "CANNOT DETERMINE BINDING AT %s:%d", __FILE__, __LINE__); \
73-
} else { \
74-
opal_hwloc_base_cset2mapstr(tmp1, sizeof(tmp1), t, bind); \
75-
opal_output_verbose(n, v, "BINDINGS AT %s:%d: %s", __FILE__, __LINE__, tmp1); \
76-
} \
77-
hwloc_bitmap_free(bind); \
78-
} while (0);
79-
80-
#if HWLOC_API_VERSION < 0x20000
81-
# define OPAL_HWLOC_MAKE_OBJ_CACHE(level, obj, cache_level) \
82-
do { \
83-
obj = HWLOC_OBJ_CACHE; \
84-
cache_level = level; \
85-
} while (0)
86-
#else
87-
# define OPAL_HWLOC_MAKE_OBJ_CACHE(level, obj, cache_level) \
88-
do { \
89-
obj = HWLOC_OBJ_L##level##CACHE; \
90-
cache_level = 0; \
91-
} while (0)
92-
#endif
93-
94-
struct opal_rmaps_numa_node_t {
95-
opal_list_item_t super;
96-
int index;
97-
float dist_from_closed;
98-
};
99-
typedef struct opal_rmaps_numa_node_t opal_rmaps_numa_node_t;
100-
OBJ_CLASS_DECLARATION(opal_rmaps_numa_node_t);
101-
102-
/**
103-
* Enum for what memory allocation policy we want for user allocations.
104-
* MAP = memory allocation policy.
105-
*/
106-
typedef enum { OPAL_HWLOC_BASE_MAP_NONE, OPAL_HWLOC_BASE_MAP_LOCAL_ONLY } opal_hwloc_base_map_t;
107-
108-
/**
109-
* Global reflecting the MAP (set by MCA param).
110-
*/
111-
OPAL_DECLSPEC extern opal_hwloc_base_map_t opal_hwloc_base_map;
112-
11353
/**
11454
* Enum for what to do if the hwloc framework tries to bind memory
11555
* and fails. BFA = bind failure action.
@@ -120,21 +60,12 @@ typedef enum {
12060
OPAL_HWLOC_BASE_MBFA_ERROR
12161
} opal_hwloc_base_mbfa_t;
12262

123-
/**
124-
* Global reflecting the BFA (set by MCA param).
125-
*/
126-
OPAL_DECLSPEC extern opal_hwloc_base_mbfa_t opal_hwloc_base_mbfa;
127-
12863
/**
12964
* Discover / load the hwloc topology (i.e., call hwloc_topology_init() and
13065
* hwloc_topology_load()).
13166
*/
13267
OPAL_DECLSPEC int opal_hwloc_base_get_topology(void);
13368

134-
/**
135-
* Free the hwloc topology.
136-
*/
137-
OPAL_DECLSPEC void opal_hwloc_base_free_topology(hwloc_topology_t topo);
13869
OPAL_DECLSPEC unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo,
13970
hwloc_obj_type_t target,
14071
unsigned cache_level,
@@ -146,29 +77,12 @@ OPAL_DECLSPEC hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo,
14677
unsigned int instance,
14778
opal_hwloc_resource_type_t rtype);
14879

149-
/**
150-
* This function sets the process-wide memory affinity policy
151-
* according to opal_hwloc_base_map and opal_hwloc_base_mbfa. It needs
152-
* to be a separate, standalone function (as opposed to being done
153-
* during opal_hwloc_base_open()) because opal_hwloc_topology is not
154-
* loaded by opal_hwloc_base_open(). Hence, an upper layer needs to
155-
* invoke this function after opal_hwloc_topology has been loaded.
156-
*/
157-
OPAL_DECLSPEC int opal_hwloc_base_set_process_membind_policy(void);
158-
15980
OPAL_DECLSPEC int opal_hwloc_base_membind(opal_hwloc_base_memory_segment_t *segs, size_t count,
16081
int node_id);
16182

16283
OPAL_DECLSPEC int opal_hwloc_base_memory_set(opal_hwloc_base_memory_segment_t *segments,
16384
size_t num_segments);
16485

165-
/**
166-
* Make a prettyprint string for a hwloc_cpuset_t (e.g., "socket
167-
* 2[core 3]").
168-
*/
169-
OPAL_DECLSPEC int opal_hwloc_base_cset2str(char *str, int len, hwloc_topology_t topo,
170-
hwloc_cpuset_t cpuset);
171-
17286
/* extract a location from the locality string */
17387
OPAL_DECLSPEC char *opal_hwloc_base_get_location(char *locality, hwloc_obj_type_t type,
17488
unsigned index);

opal/mca/hwloc/base/hwloc_base_frame.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ hwloc_topology_t opal_hwloc_topology = NULL;
3939
hwloc_cpuset_t opal_hwloc_my_cpuset = NULL;
4040
opal_hwloc_base_mbfa_t opal_hwloc_base_mbfa = OPAL_HWLOC_BASE_MBFA_WARN;
4141

42+
extern bool opal_hwloc_topo_in_shmem;
43+
4244
static mca_base_var_enum_value_t hwloc_failure_action[] = {{OPAL_HWLOC_BASE_MBFA_SILENT, "silent"},
4345
{OPAL_HWLOC_BASE_MBFA_WARN, "warn"},
4446
{OPAL_HWLOC_BASE_MBFA_ERROR, "error"},
@@ -95,6 +97,48 @@ static int opal_hwloc_base_open(mca_base_open_flag_t flags)
9597
return OPAL_SUCCESS;
9698
}
9799

100+
static void free_object(hwloc_obj_t obj)
101+
{
102+
opal_hwloc_obj_data_t *data;
103+
unsigned k;
104+
105+
/* free any data hanging on this object */
106+
if (NULL != obj->userdata) {
107+
data = (opal_hwloc_obj_data_t *) obj->userdata;
108+
OBJ_RELEASE(data);
109+
obj->userdata = NULL;
110+
}
111+
112+
/* loop thru our children */
113+
for (k = 0; k < obj->arity; k++) {
114+
free_object(obj->children[k]);
115+
}
116+
}
117+
118+
static void free_topology(hwloc_topology_t topo)
119+
{
120+
hwloc_obj_t obj;
121+
opal_hwloc_topo_data_t *rdata;
122+
unsigned k;
123+
124+
if (!opal_hwloc_topo_in_shmem) {
125+
obj = hwloc_get_root_obj(topo);
126+
/* release the root-level userdata */
127+
if (NULL != obj->userdata) {
128+
rdata = (opal_hwloc_topo_data_t *) obj->userdata;
129+
OBJ_RELEASE(rdata);
130+
obj->userdata = NULL;
131+
}
132+
/* now recursively descend and release userdata
133+
* in the rest of the objects
134+
*/
135+
for (k = 0; k < obj->arity; k++) {
136+
free_object(obj->children[k]);
137+
}
138+
}
139+
hwloc_topology_destroy(topo);
140+
}
141+
98142
static int opal_hwloc_base_close(void)
99143
{
100144
int ret;
@@ -118,7 +162,7 @@ static int opal_hwloc_base_close(void)
118162

119163
/* destroy the topology */
120164
if (NULL != opal_hwloc_topology) {
121-
opal_hwloc_base_free_topology(opal_hwloc_topology);
165+
free_topology(opal_hwloc_topology);
122166
opal_hwloc_topology = NULL;
123167
}
124168

@@ -171,5 +215,3 @@ static void topo_data_dest(opal_hwloc_topo_data_t *ptr)
171215
ptr->userdata = NULL;
172216
}
173217
OBJ_CLASS_INSTANCE(opal_hwloc_topo_data_t, opal_object_t, topo_data_const, topo_data_dest);
174-
175-
OBJ_CLASS_INSTANCE(opal_rmaps_numa_node_t, opal_list_item_t, NULL, NULL);

opal/mca/hwloc/base/hwloc_base_maffinity.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include "opal/mca/hwloc/base/base.h"
1717
#include "opal/mca/hwloc/hwloc-internal.h"
1818

19+
/**
20+
* Global reflecting the BFA (set by MCA param).
21+
*/
22+
extern opal_hwloc_base_mbfa_t opal_hwloc_base_mbfa;
23+
1924
/**
2025
* Report a bind failure using the normal mechanisms if a component
2126
* fails to bind memory -- according to the value of the

opal/mca/hwloc/base/hwloc_base_util.c

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#include "opal/mca/hwloc/base/base.h"
6363
#include "opal/mca/hwloc/hwloc-internal.h"
6464

65-
static bool topo_in_shmem = false;
65+
bool opal_hwloc_topo_in_shmem = false;
6666

6767
static void fill_cache_line_size(void)
6868
{
@@ -249,7 +249,7 @@ int opal_hwloc_base_get_topology(void)
249249
} else {
250250
opal_output_verbose(2, opal_hwloc_base_framework.framework_output,
251251
"hwloc:base: topology in shared memory");
252-
topo_in_shmem = true;
252+
opal_hwloc_topo_in_shmem = true;
253253
goto done;
254254
}
255255
}
@@ -332,48 +332,6 @@ int opal_hwloc_base_get_topology(void)
332332
return OPAL_SUCCESS;
333333
}
334334

335-
static void free_object(hwloc_obj_t obj)
336-
{
337-
opal_hwloc_obj_data_t *data;
338-
unsigned k;
339-
340-
/* free any data hanging on this object */
341-
if (NULL != obj->userdata) {
342-
data = (opal_hwloc_obj_data_t *) obj->userdata;
343-
OBJ_RELEASE(data);
344-
obj->userdata = NULL;
345-
}
346-
347-
/* loop thru our children */
348-
for (k = 0; k < obj->arity; k++) {
349-
free_object(obj->children[k]);
350-
}
351-
}
352-
353-
void opal_hwloc_base_free_topology(hwloc_topology_t topo)
354-
{
355-
hwloc_obj_t obj;
356-
opal_hwloc_topo_data_t *rdata;
357-
unsigned k;
358-
359-
if (!topo_in_shmem) {
360-
obj = hwloc_get_root_obj(topo);
361-
/* release the root-level userdata */
362-
if (NULL != obj->userdata) {
363-
rdata = (opal_hwloc_topo_data_t *) obj->userdata;
364-
OBJ_RELEASE(rdata);
365-
obj->userdata = NULL;
366-
}
367-
/* now recursively descend and release userdata
368-
* in the rest of the objects
369-
*/
370-
for (k = 0; k < obj->arity; k++) {
371-
free_object(obj->children[k]);
372-
}
373-
}
374-
hwloc_topology_destroy(topo);
375-
}
376-
377335
/* hwloc treats cache objects as special
378336
* cases. Instead of having a unique type for each cache level,
379337
* there is a single cache object type, and the level is encoded
@@ -442,7 +400,7 @@ static hwloc_obj_t df_search(hwloc_topology_t topo, hwloc_obj_t start, hwloc_obj
442400
hwloc_obj_t root;
443401
opal_hwloc_topo_data_t *rdata = NULL;
444402
root = hwloc_get_root_obj(topo);
445-
if (false == topo_in_shmem) {
403+
if (false == opal_hwloc_topo_in_shmem) {
446404
rdata = (opal_hwloc_topo_data_t *) root->userdata;
447405
}
448406
hwloc_cpuset_t constrained_cpuset;
@@ -514,12 +472,12 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, hwloc_obj
514472
obj = hwloc_get_root_obj(topo);
515473

516474
/* first see if the topology already has this summary */
517-
if (false == topo_in_shmem) {
475+
if (false == opal_hwloc_topo_in_shmem) {
518476
data = (opal_hwloc_topo_data_t *) obj->userdata;
519477
}
520478
if (NULL == data) {
521479
data = OBJ_NEW(opal_hwloc_topo_data_t);
522-
if (false == topo_in_shmem) {
480+
if (false == opal_hwloc_topo_in_shmem) {
523481
// Can't touch userdata if in read-only shmem!
524482
// We have to protect here for the case where obj->userdata
525483
// is in shmem and it is NULL.
@@ -555,7 +513,7 @@ unsigned int opal_hwloc_base_get_nbobjs_by_type(hwloc_topology_t topo, hwloc_obj
555513
return num_objs;
556514
}
557515

558-
/* as above, only return the Nth instance of the specified object
516+
/* Return the Nth instance of the specified object
559517
* type from inside the topology
560518
*/
561519
hwloc_obj_t opal_hwloc_base_get_obj_by_type(hwloc_topology_t topo, hwloc_obj_type_t target,
@@ -708,4 +666,3 @@ opal_hwloc_locality_t opal_hwloc_compute_relative_locality(char *loc1, char *loc
708666
hwloc_bitmap_free(bit2);
709667
return locality;
710668
}
711-

0 commit comments

Comments
 (0)