Skip to content

Commit 06e31a1

Browse files
committed
API: add a misc support array for a "imported_support" feature
Passing HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT won't import anything if the XML comes from hwloc 2.2-. This new feature bit will be set on success to import support. The XML export doesn't contain that feature bit explicitly because it's only meaningful locally. But it now contains a custom/fake feature bit "custom.exported_support" that it always set on 2.3 export. Then the importer knows whether support was unsupported in the exporter, or just empty (likely rare, only on non-supported OS). Signed-off-by: Brice Goglin <[email protected]>
1 parent 524858e commit 06e31a1

39 files changed

+86
-12
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Version 2.3.0
2323
* API
2424
+ The new topology flag HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT causes
2525
support arrays to be loaded from XML exported with hwloc 2.3+.
26+
- hwloc_topology_get_support() now returns an additional "misc"
27+
array with feature "imported_support" set when support was imported.
2628
* Backends
2729
+ Add a ROCm SMI backend and a hwloc/rsmi.h helper file for getting
2830
the locality of AMD GPUs, now exposed as "rsmi" OS devices.

doc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ man3_configuration_DATA = \
440440
$(DOX_MAN_DIR)/man3/hwloc_topology_discovery_support.3 \
441441
$(DOX_MAN_DIR)/man3/hwloc_topology_cpubind_support.3 \
442442
$(DOX_MAN_DIR)/man3/hwloc_topology_membind_support.3 \
443+
$(DOX_MAN_DIR)/man3/hwloc_topology_misc_support.3 \
443444
$(DOX_MAN_DIR)/man3/hwloc_topology_support.3 \
444445
$(DOX_MAN_DIR)/man3/hwloc_type_filter_e.3 \
445446
$(DOX_MAN_DIR)/man3/HWLOC_TYPE_FILTER_KEEP_ALL.3 \

hwloc/shmem.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2017-2019 Inria. All rights reserved.
2+
* Copyright © 2017-2020 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -214,11 +214,13 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
214214
new->support.discovery = malloc(sizeof(*new->support.discovery));
215215
new->support.cpubind = malloc(sizeof(*new->support.cpubind));
216216
new->support.membind = malloc(sizeof(*new->support.membind));
217-
if (!new->support.discovery || !new->support.cpubind || !new->support.membind)
217+
new->support.misc = malloc(sizeof(*new->support.misc));
218+
if (!new->support.discovery || !new->support.cpubind || !new->support.membind || !new->support.misc)
218219
goto out_with_support;
219220
memcpy(new->support.discovery, old->support.discovery, sizeof(*new->support.discovery));
220221
memcpy(new->support.cpubind, old->support.cpubind, sizeof(*new->support.cpubind));
221222
memcpy(new->support.membind, old->support.membind, sizeof(*new->support.membind));
223+
memcpy(new->support.misc, old->support.misc, sizeof(*new->support.misc));
222224
hwloc_set_binding_hooks(new);
223225
/* clear userdata callbacks pointing to the writer process' functions */
224226
new->userdata_export_cb = NULL;
@@ -236,6 +238,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
236238
free(new->support.discovery);
237239
free(new->support.cpubind);
238240
free(new->support.membind);
241+
free(new->support.misc);
239242
free(new);
240243
out_with_components:
241244
hwloc_components_fini();
@@ -252,6 +255,7 @@ hwloc__topology_disadopt(hwloc_topology_t topology)
252255
free(topology->support.discovery);
253256
free(topology->support.cpubind);
254257
free(topology->support.membind);
258+
free(topology->support.misc);
255259
free(topology);
256260
}
257261

hwloc/topology-xml.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,10 +1262,11 @@ hwloc__xml_v2import_support(hwloc_topology_t topology,
12621262

12631263
if (name && topology->flags & HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT) {
12641264
#ifdef HWLOC_DEBUG
1265-
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_support) == 3*sizeof(void*));
1265+
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_support) == 4*sizeof(void*));
12661266
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_discovery_support) == 5);
12671267
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_cpubind_support) == 11);
12681268
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_membind_support) == 15);
1269+
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_misc_support) == 1);
12691270
#endif
12701271

12711272
#define DO(_cat,_name) if (!strcmp(#_cat "." #_name, name)) topology->support._cat->_name = value
@@ -1300,6 +1301,11 @@ hwloc__xml_v2import_support(hwloc_topology_t topology,
13001301
else DO(membind,nexttouch_membind);
13011302
else DO(membind,migrate_membind);
13021303
else DO(membind,get_area_memlocation);
1304+
1305+
else if (!strcmp("custom.exported_support", name))
1306+
/* support was exported in a custom/fake field, mark it as imported here */
1307+
topology->support.misc->imported_support = 1;
1308+
13031309
#undef DO
13041310
}
13051311

@@ -2702,10 +2708,11 @@ hwloc__xml_v2export_support(hwloc__xml_export_state_t parentstate, hwloc_topolog
27022708
char tmp[11];
27032709

27042710
#ifdef HWLOC_DEBUG
2705-
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_support) == 3*sizeof(void*));
2711+
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_support) == 4*sizeof(void*));
27062712
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_discovery_support) == 5);
27072713
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_cpubind_support) == 11);
27082714
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_membind_support) == 15);
2715+
HWLOC_BUILD_ASSERT(sizeof(struct hwloc_topology_misc_support) == 1);
27092716
#endif
27102717

27112718
#define DO(_cat,_name) do { \
@@ -2752,6 +2759,15 @@ hwloc__xml_v2export_support(hwloc__xml_export_state_t parentstate, hwloc_topolog
27522759
DO(membind,migrate_membind);
27532760
DO(membind,get_area_memlocation);
27542761

2762+
/* misc.imported_support would be meaningless in the remote importer,
2763+
* but the importer needs to know whether we exported support or not
2764+
* (in case there are no support bit set at all),
2765+
* use a custom/fake field to do so.
2766+
*/
2767+
parentstate->new_child(parentstate, &state, "support");
2768+
state.new_prop(&state, "name", "custom.exported_support");
2769+
state.end_object(&state, "support");
2770+
27552771
#undef DO
27562772
}
27572773

hwloc/topology.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ hwloc__topology_dup(hwloc_topology_t *newp,
970970
memcpy(new->support.discovery, old->support.discovery, sizeof(*old->support.discovery));
971971
memcpy(new->support.cpubind, old->support.cpubind, sizeof(*old->support.cpubind));
972972
memcpy(new->support.membind, old->support.membind, sizeof(*old->support.membind));
973+
memcpy(new->support.misc, old->support.misc, sizeof(*old->support.misc));
973974

974975
new->allowed_cpuset = hwloc_bitmap_tma_dup(tma, old->allowed_cpuset);
975976
new->allowed_nodeset = hwloc_bitmap_tma_dup(tma, old->allowed_nodeset);
@@ -3519,6 +3520,7 @@ hwloc_topology_setup_defaults(struct hwloc_topology *topology)
35193520
memset(topology->support.discovery, 0, sizeof(*topology->support.discovery));
35203521
memset(topology->support.cpubind, 0, sizeof(*topology->support.cpubind));
35213522
memset(topology->support.membind, 0, sizeof(*topology->support.membind));
3523+
memset(topology->support.misc, 0, sizeof(*topology->support.misc));
35223524

35233525
/* Only the System object on top by default */
35243526
topology->next_gp_index = 1; /* keep 0 as an invalid value */
@@ -3595,6 +3597,7 @@ hwloc__topology_init (struct hwloc_topology **topologyp,
35953597
topology->support.discovery = hwloc_tma_malloc(tma, sizeof(*topology->support.discovery));
35963598
topology->support.cpubind = hwloc_tma_malloc(tma, sizeof(*topology->support.cpubind));
35973599
topology->support.membind = hwloc_tma_malloc(tma, sizeof(*topology->support.membind));
3600+
topology->support.misc = hwloc_tma_malloc(tma, sizeof(*topology->support.misc));
35983601

35993602
topology->nb_levels_allocated = nblevels; /* enough for default 10 levels = Mach+Pack+Die+NUMA+L3+L2+L1d+L1i+Co+PU */
36003603
topology->levels = hwloc_tma_calloc(tma, topology->nb_levels_allocated * sizeof(*topology->levels));
@@ -3863,6 +3866,7 @@ hwloc_topology_destroy (struct hwloc_topology *topology)
38633866
free(topology->support.discovery);
38643867
free(topology->support.cpubind);
38653868
free(topology->support.membind);
3869+
free(topology->support.misc);
38663870
free(topology);
38673871
}
38683872

include/hwloc.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,10 @@ enum hwloc_topology_flags_e {
19501950
* supported feature bits reported by hwloc_topology_get_support().
19511951
*
19521952
* The flag ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT actually imports
1953-
* support bits from the remote machine.
1953+
* support bits from the remote machine. It also sets the flag
1954+
* \p imported_support in the struct hwloc_topology_misc_support array.
1955+
* If the imported XML did not contain any support information
1956+
* (exporter hwloc is too old), this flag is not set.
19541957
*
19551958
* Note that these supported features are only relevant for the hwloc
19561959
* installation that actually exported the XML topology
@@ -2074,6 +2077,13 @@ struct hwloc_topology_membind_support {
20742077
unsigned char get_area_memlocation;
20752078
};
20762079

2080+
/** \brief Flags describing miscellaneous features.
2081+
*/
2082+
struct hwloc_topology_misc_support {
2083+
/** Support was imported when importing another topology, see ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT. */
2084+
unsigned char imported_support;
2085+
};
2086+
20772087
/** \brief Set of flags describing actual support for this topology.
20782088
*
20792089
* This is retrieved with hwloc_topology_get_support() and will be valid until
@@ -2084,6 +2094,7 @@ struct hwloc_topology_support {
20842094
struct hwloc_topology_discovery_support *discovery;
20852095
struct hwloc_topology_cpubind_support *cpubind;
20862096
struct hwloc_topology_membind_support *membind;
2097+
struct hwloc_topology_misc_support *misc;
20872098
};
20882099

20892100
/** \brief Retrieve the topology support.
@@ -2104,7 +2115,8 @@ struct hwloc_topology_support {
21042115
*
21052116
* Topology flag ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT may be used
21062117
* to report the supported features of the original remote machine
2107-
* instead.
2118+
* instead. If it was successfully imported, \p imported_support
2119+
* will be set in the struct hwloc_topology_misc_support array.
21082120
*/
21092121
HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology);
21102122

include/hwloc/rename.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ extern "C" {
135135
#define hwloc_topology_discovery_support HWLOC_NAME(topology_discovery_support)
136136
#define hwloc_topology_cpubind_support HWLOC_NAME(topology_cpubind_support)
137137
#define hwloc_topology_membind_support HWLOC_NAME(topology_membind_support)
138+
#define hwloc_topology_misc_support HWLOC_NAME(topology_misc_support)
138139
#define hwloc_topology_support HWLOC_NAME(topology_support)
139140
#define hwloc_topology_get_support HWLOC_NAME(topology_get_support)
140141

include/private/private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2019 Inria. All rights reserved.
3+
* Copyright © 2009-2020 Inria. All rights reserved.
44
* Copyright © 2009-2012, 2020 Université Bordeaux
55
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
66
*
@@ -40,7 +40,7 @@
4040
#endif
4141
#include <string.h>
4242

43-
#define HWLOC_TOPOLOGY_ABI 0x20100 /* version of the layout of struct topology */
43+
#define HWLOC_TOPOLOGY_ABI 0x20300 /* version of the layout of struct topology */
4444

4545
/*****************************************************
4646
* WARNING:

tests/hwloc/hwloc_topology_abi.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ int main(void)
6161
assert(offset == 648);
6262

6363
offset = offsetof(struct hwloc_topology, first_dist);
64-
assert(offset == 696);
64+
assert(offset == 704);
6565
size = sizeof(struct hwloc_internal_distances_s);
6666
assert(size == 88);
6767

6868
offset = offsetof(struct hwloc_topology, grouping_next_subkind);
69-
assert(offset == 748);
69+
assert(offset == 756);
7070

7171
/* fields after this one aren't needed after discovery */
7272

@@ -126,13 +126,15 @@ int main(void)
126126
assert(size == 16);
127127

128128
size = sizeof(struct hwloc_topology_support);
129-
assert(size == 24);
129+
assert(size == 32);
130130
size = sizeof(struct hwloc_topology_discovery_support);
131131
assert(size == 5);
132132
size = sizeof(struct hwloc_topology_cpubind_support);
133133
assert(size == 11);
134134
size = sizeof(struct hwloc_topology_membind_support);
135135
assert(size == 15);
136+
size = sizeof(struct hwloc_topology_misc_support);
137+
assert(size == 1);
136138

137139
size = sizeof(struct hwloc_distances_s);
138140
assert(size == 32);

tests/hwloc/xml/16-2gr2gr2n2c+misc.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,5 @@
139139
<support name="membind.interleave_membind"/>
140140
<support name="membind.migrate_membind"/>
141141
<support name="membind.get_area_memlocation"/>
142+
<support name="custom.exported_support"/>
142143
</topology>

0 commit comments

Comments
 (0)