Skip to content

Commit c8f524e

Browse files
committed
utils: fix the searching of CPU-less objects
We fixed the search for CPU-less NUMA nodes in hwloc-calc, hwloc-bind and friends in e6b9e7f (in 1.11.3) but we broke it again in 3df864a (in 1.11.5) because issue #215 required CPU-less objects to be ignored in hwloc_get_*obj*_inside_cpuset_by_*. Indeed hwloc-calc and friends use these functions and therefore cannot find CPU-less NUMA nodes anymore. Fix this by looking for both cpuset and nodeset in utils instead of only cpuset. In theory, an object cannot be CPU-less and node-less, but in practice it can because of cgroups. Such objects still need to be ignored. Thanks to Gilles Gouaillardet for the report. Fixes #233. Signed-off-by: Brice Goglin <[email protected]>
1 parent d0b4690 commit c8f524e

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

utils/hwloc/hwloc-calc.h

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2016 Inria. All rights reserved.
3+
* Copyright © 2009-2017 Inria. All rights reserved.
44
* Copyright © 2009-2012 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -69,20 +69,47 @@ hwloc_calc_append_set(hwloc_bitmap_t set, hwloc_const_bitmap_t newset,
6969
return 0;
7070
}
7171

72-
static __hwloc_inline hwloc_obj_t __hwloc_attribute_pure
73-
hwloc_calc_get_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_bitmap_t rootset,
74-
unsigned depth, unsigned i, int logical)
72+
static __hwloc_inline unsigned
73+
hwloc_calc_get_nbobjs_inside_sets_by_depth(hwloc_topology_t topology,
74+
hwloc_const_bitmap_t cpuset, hwloc_const_bitmap_t nodeset,
75+
unsigned depth)
7576
{
76-
if (logical) {
77-
return hwloc_get_obj_inside_cpuset_by_depth(topology, rootset, depth, i);
78-
} else {
79-
hwloc_obj_t obj = NULL;
80-
while ((obj = hwloc_get_next_obj_inside_cpuset_by_depth(topology, rootset, depth, obj)) != NULL) {
77+
hwloc_obj_t obj = NULL;
78+
unsigned n = 0;
79+
while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
80+
if (!hwloc_bitmap_isincluded(obj->cpuset, cpuset))
81+
continue;
82+
if (!hwloc_bitmap_isincluded(obj->nodeset, nodeset))
83+
continue;
84+
assert(!hwloc_bitmap_iszero(obj->cpuset) || !hwloc_bitmap_iszero(obj->nodeset));
85+
n++;
86+
}
87+
return n;
88+
}
89+
90+
static __hwloc_inline hwloc_obj_t
91+
hwloc_calc_get_obj_inside_sets_by_depth(hwloc_topology_t topology,
92+
hwloc_const_bitmap_t cpuset, hwloc_const_bitmap_t nodeset,
93+
unsigned depth, unsigned ind, int logical)
94+
{
95+
hwloc_obj_t obj = NULL;
96+
unsigned i = 0;
97+
while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
98+
if (!hwloc_bitmap_isincluded(obj->cpuset, cpuset))
99+
continue;
100+
if (!hwloc_bitmap_isincluded(obj->nodeset, nodeset))
101+
continue;
102+
assert(!hwloc_bitmap_iszero(obj->cpuset) || !hwloc_bitmap_iszero(obj->nodeset));
103+
if (logical) {
104+
if (i == ind)
105+
return obj;
106+
i++;
107+
} else {
81108
if (obj->os_index == i)
82-
return obj;
109+
return obj;
83110
}
84-
return NULL;
85111
}
112+
return NULL;
86113
}
87114

88115
static __hwloc_inline int
@@ -221,7 +248,7 @@ hwloc_calc_parse_range(const char *_string,
221248

222249
static __hwloc_inline int
223250
hwloc_calc_append_object_range(hwloc_topology_t topology, unsigned topodepth,
224-
hwloc_const_bitmap_t rootset, int depth,
251+
hwloc_const_bitmap_t rootcpuset, hwloc_const_bitmap_t rootnodeset, int depth,
225252
const char *string, /* starts with indexes following the colon */
226253
int logical,
227254
void (*cbfunc)(void *, hwloc_obj_t, int), void *cbdata,
@@ -265,29 +292,31 @@ hwloc_calc_append_object_range(hwloc_topology_t topology, unsigned topodepth,
265292
}
266293
}
267294

268-
width = hwloc_get_nbobjs_inside_cpuset_by_depth(topology, rootset, depth);
295+
width = hwloc_calc_get_nbobjs_inside_sets_by_depth(topology, rootcpuset, rootnodeset, depth);
269296
if (amount == -1)
270297
amount = (width-first+step-1)/step;
271298

272299
for(i=first, j=0; j<(unsigned)amount; i+=step, j++) {
273300
if (wrap && i>=width)
274301
i = 0;
275302

276-
obj = hwloc_calc_get_obj_inside_cpuset_by_depth(topology, rootset, depth, i, logical);
303+
obj = hwloc_calc_get_obj_inside_sets_by_depth(topology, rootcpuset, rootnodeset, depth, i, logical);
277304
if (verbose > 0 || (!obj && verbose >= 0)) {
278-
char *s;
279-
hwloc_bitmap_asprintf(&s, rootset);
305+
char *sc, *sn;
306+
hwloc_bitmap_asprintf(&sc, rootcpuset);
307+
hwloc_bitmap_asprintf(&sn, rootnodeset);
280308
if (obj)
281-
printf("using object #%u depth %u below cpuset %s\n",
282-
i, depth, s);
309+
printf("using object #%u depth %u below cpuset %s nodeset %s\n",
310+
i, depth, sc, sn);
283311
else
284-
fprintf(stderr, "object #%u depth %u below cpuset %s does not exist\n",
285-
i, depth, s);
286-
free(s);
312+
fprintf(stderr, "object #%u depth %u below cpuset %s nodeset %s does not exist\n",
313+
i, depth, sc, sn);
314+
free(sc);
315+
free(sn);
287316
}
288317
if (obj) {
289318
if (dot) {
290-
hwloc_calc_append_object_range(topology, topodepth, obj->cpuset, nextdepth, nextsep+1, logical, cbfunc, cbdata, verbose);
319+
hwloc_calc_append_object_range(topology, topodepth, obj->cpuset, obj->nodeset, nextdepth, nextsep+1, logical, cbfunc, cbdata, verbose);
291320
} else {
292321
/* add to the temporary cpuset
293322
* and let the caller add/clear/and/xor for the actual final cpuset depending on cmdline options
@@ -483,7 +512,10 @@ hwloc_calc_process_type_arg(hwloc_topology_t topology, unsigned topodepth,
483512
}
484513

485514
/* look at indexes following this type/depth */
486-
return hwloc_calc_append_object_range(topology, topodepth, hwloc_topology_get_complete_cpuset(topology), depth, sep+1, logical, cbfunc, cbdata, verbose);
515+
return hwloc_calc_append_object_range(topology, topodepth,
516+
hwloc_topology_get_complete_cpuset(topology),
517+
hwloc_topology_get_complete_nodeset(topology),
518+
depth, sep+1, logical, cbfunc, cbdata, verbose);
487519
}
488520

489521
struct hwloc_calc_process_arg_cpuset_cbdata_s {

0 commit comments

Comments
 (0)