Skip to content

Commit 0740983

Browse files
committed
core: remove nodeset comparison from main insertion routine
This was added several years ago when multiple levels of NUMA nodes were envisioned. It appears it's not needed anymore. Now we either insert CPU-side object by cpuset only, or find a CPU-side parent by cpuset and attach memory by nodeset below it. Update the API group insert function to build a cpuset from the nodeset if needed. Signed-off-by: Brice Goglin <[email protected]>
1 parent 766d93e commit 0740983

File tree

1 file changed

+32
-51
lines changed

1 file changed

+32
-51
lines changed

hwloc/topology.c

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,12 +1130,10 @@ hwloc_type_cmp(hwloc_obj_t obj1, hwloc_obj_t obj2)
11301130
/*
11311131
* How to compare objects based on cpusets.
11321132
*/
1133-
11341133
static int
11351134
hwloc_obj_cmp_sets(hwloc_obj_t obj1, hwloc_obj_t obj2)
11361135
{
11371136
hwloc_bitmap_t set1, set2;
1138-
int res = HWLOC_OBJ_DIFFERENT;
11391137

11401138
assert(!hwloc__obj_type_is_special(obj1->type));
11411139
assert(!hwloc__obj_type_is_special(obj2->type));
@@ -1148,45 +1146,10 @@ hwloc_obj_cmp_sets(hwloc_obj_t obj1, hwloc_obj_t obj2)
11481146
set1 = obj1->cpuset;
11491147
set2 = obj2->cpuset;
11501148
}
1151-
if (set1 && set2 && !hwloc_bitmap_iszero(set1) && !hwloc_bitmap_iszero(set2)) {
1152-
res = hwloc_bitmap_compare_inclusion(set1, set2);
1153-
if (res == HWLOC_OBJ_INTERSECTS)
1154-
return HWLOC_OBJ_INTERSECTS;
1155-
}
1156-
1157-
/* then compare nodesets, and combine the results */
1158-
if (obj1->complete_nodeset && obj2->complete_nodeset) {
1159-
set1 = obj1->complete_nodeset;
1160-
set2 = obj2->complete_nodeset;
1161-
} else {
1162-
set1 = obj1->nodeset;
1163-
set2 = obj2->nodeset;
1164-
}
1165-
if (set1 && set2 && !hwloc_bitmap_iszero(set1) && !hwloc_bitmap_iszero(set2)) {
1166-
int noderes = hwloc_bitmap_compare_inclusion(set1, set2);
1167-
/* deal with conflicting cpusets/nodesets inclusions */
1168-
if (noderes == HWLOC_OBJ_INCLUDED) {
1169-
if (res == HWLOC_OBJ_CONTAINS)
1170-
/* contradicting order for cpusets and nodesets */
1171-
return HWLOC_OBJ_INTERSECTS;
1172-
res = HWLOC_OBJ_INCLUDED;
1173-
1174-
} else if (noderes == HWLOC_OBJ_CONTAINS) {
1175-
if (res == HWLOC_OBJ_INCLUDED)
1176-
/* contradicting order for cpusets and nodesets */
1177-
return HWLOC_OBJ_INTERSECTS;
1178-
res = HWLOC_OBJ_CONTAINS;
1179-
1180-
} else if (noderes == HWLOC_OBJ_INTERSECTS) {
1181-
return HWLOC_OBJ_INTERSECTS;
1182-
1183-
} else {
1184-
/* nodesets are different, keep the cpuset order */
1185-
1186-
}
1187-
}
1149+
if (set1 && set2 && !hwloc_bitmap_iszero(set1) && !hwloc_bitmap_iszero(set2))
1150+
return hwloc_bitmap_compare_inclusion(set1, set2);
11881151

1189-
return res;
1152+
return HWLOC_OBJ_DIFFERENT;
11901153
}
11911154

11921155
/* Compare object cpusets based on complete_cpuset if defined (always correctly ordered),
@@ -1201,10 +1164,6 @@ hwloc__object_cpusets_compare_first(hwloc_obj_t obj1, hwloc_obj_t obj2)
12011164
return hwloc_bitmap_compare_first(obj1->complete_cpuset, obj2->complete_cpuset);
12021165
else if (obj1->cpuset && obj2->cpuset)
12031166
return hwloc_bitmap_compare_first(obj1->cpuset, obj2->cpuset);
1204-
else if (obj1->complete_nodeset && obj2->complete_nodeset)
1205-
return hwloc_bitmap_compare_first(obj1->complete_nodeset, obj2->complete_nodeset);
1206-
else if (obj1->nodeset && obj2->nodeset)
1207-
return hwloc_bitmap_compare_first(obj1->nodeset, obj2->nodeset);
12081167
return 0;
12091168
}
12101169

@@ -1343,7 +1302,11 @@ hwloc__insert_try_merge_group(hwloc_obj_t old, hwloc_obj_t new)
13431302
return NULL;
13441303
}
13451304

1346-
/* Try to insert OBJ in CUR, recurse if needed.
1305+
/*
1306+
* The main insertion routine, only used for CPU-side object (normal types)
1307+
* uisng cpuset only (or complete_cpuset).
1308+
*
1309+
* Try to insert OBJ in CUR, recurse if needed.
13471310
* Returns the object if it was inserted,
13481311
* the remaining object it was merged,
13491312
* NULL if failed to insert.
@@ -1817,12 +1780,30 @@ hwloc_topology_insert_group_object(struct hwloc_topology *topology, hwloc_obj_t
18171780
hwloc_bitmap_and(obj->complete_nodeset, obj->complete_nodeset, root->complete_nodeset);
18181781

18191782
if ((!obj->cpuset || hwloc_bitmap_iszero(obj->cpuset))
1820-
&& (!obj->complete_cpuset || hwloc_bitmap_iszero(obj->complete_cpuset))
1821-
&& (!obj->nodeset || hwloc_bitmap_iszero(obj->nodeset))
1822-
&& (!obj->complete_nodeset || hwloc_bitmap_iszero(obj->complete_nodeset))) {
1823-
hwloc_free_unlinked_object(obj);
1824-
errno = EINVAL;
1825-
return NULL;
1783+
&& (!obj->complete_cpuset || hwloc_bitmap_iszero(obj->complete_cpuset))) {
1784+
/* we'll insert by cpuset, so build cpuset from the nodeset */
1785+
hwloc_const_bitmap_t nodeset = obj->nodeset ? obj->nodeset : obj->complete_nodeset;
1786+
hwloc_obj_t numa;
1787+
1788+
if ((!obj->nodeset || hwloc_bitmap_iszero(obj->nodeset))
1789+
&& (!obj->complete_nodeset || hwloc_bitmap_iszero(obj->complete_nodeset))) {
1790+
hwloc_free_unlinked_object(obj);
1791+
errno = EINVAL;
1792+
return NULL;
1793+
}
1794+
1795+
if (!obj->cpuset) {
1796+
obj->cpuset = hwloc_bitmap_alloc();
1797+
if (!obj->cpuset) {
1798+
hwloc_free_unlinked_object(obj);
1799+
return NULL;
1800+
}
1801+
}
1802+
1803+
numa = NULL;
1804+
while ((numa = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, numa)) != NULL)
1805+
if (hwloc_bitmap_isset(nodeset, numa->os_index))
1806+
hwloc_bitmap_or(obj->cpuset, obj->cpuset, numa->cpuset);
18261807
}
18271808

18281809
cmp = hwloc_obj_cmp_sets(obj, root);

0 commit comments

Comments
 (0)