Skip to content

Commit e9c4e82

Browse files
committed
utils: use the new struct hwloc_calc_level when counting/iterating over objects
Signed-off-by: Brice Goglin <[email protected]>
1 parent ef9f9f7 commit e9c4e82

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

utils/hwloc/hwloc-calc.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
struct hwloc_calc_location_context_s {
2626
hwloc_topology_t topology;
2727
int topodepth;
28-
int only_hbm; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes */
28+
int only_hbm; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes
29+
* stored by caller, and passed to struct hwloc_calc_level for actual filtering
30+
*/
2931
int logical;
3032
int verbose;
3133
};
@@ -35,6 +37,7 @@ struct hwloc_calc_level {
3537
int depth;
3638
hwloc_obj_type_t type;
3739
union hwloc_obj_attr_u attr;
40+
int only_hbm; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes */
3841
};
3942

4043
typedef enum hwloc_calc_append_mode_e {
@@ -87,13 +90,13 @@ hwloc_calc_append_set(hwloc_bitmap_t set, hwloc_const_bitmap_t newset,
8790
static __hwloc_inline unsigned
8891
hwloc_calc_get_nbobjs_inside_sets_by_depth(struct hwloc_calc_location_context_s *lcontext,
8992
hwloc_const_bitmap_t cpuset, hwloc_const_bitmap_t nodeset,
90-
int depth)
93+
struct hwloc_calc_level *level)
9194
{
9295
hwloc_topology_t topology = lcontext->topology;
93-
int only_hbm = lcontext->only_hbm;
96+
int only_hbm = level->only_hbm;
9497
hwloc_obj_t obj = NULL;
9598
unsigned n = 0;
96-
while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
99+
while ((obj = hwloc_get_next_obj_by_depth(topology, level->depth, obj)) != NULL) {
97100
if (!hwloc_bitmap_iszero(obj->cpuset) && !hwloc_bitmap_intersects(obj->cpuset, cpuset))
98101
continue;
99102
if (!hwloc_bitmap_iszero(obj->nodeset) && !hwloc_bitmap_intersects(obj->nodeset, nodeset))
@@ -115,14 +118,14 @@ hwloc_calc_get_nbobjs_inside_sets_by_depth(struct hwloc_calc_location_context_s
115118
static __hwloc_inline hwloc_obj_t
116119
hwloc_calc_get_obj_inside_sets_by_depth(struct hwloc_calc_location_context_s *lcontext,
117120
hwloc_const_bitmap_t cpuset, hwloc_const_bitmap_t nodeset,
118-
int depth, unsigned ind)
121+
struct hwloc_calc_level *level, unsigned ind)
119122
{
120123
hwloc_topology_t topology = lcontext->topology;
121-
int only_hbm = lcontext->only_hbm;
124+
int only_hbm = level->only_hbm;
122125
int logical = lcontext->logical;
123126
hwloc_obj_t obj = NULL;
124127
unsigned i = 0;
125-
while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
128+
while ((obj = hwloc_get_next_obj_by_depth(topology, level->depth, obj)) != NULL) {
126129
if (!hwloc_bitmap_iszero(obj->cpuset) && !hwloc_bitmap_intersects(obj->cpuset, cpuset))
127130
continue;
128131
if (!hwloc_bitmap_iszero(obj->nodeset) && !hwloc_bitmap_intersects(obj->nodeset, nodeset))
@@ -158,6 +161,10 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
158161
char *endptr;
159162
int err;
160163

164+
level->only_hbm = -1;
165+
if (lcontext)
166+
level->only_hbm = lcontext->only_hbm;
167+
161168
level->depth = HWLOC_TYPE_DEPTH_UNKNOWN;
162169

163170
if (typelen >= sizeof(typestring))
@@ -175,8 +182,7 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
175182
}
176183

177184
if (!strcasecmp(typestring, "HBM") || !strcasecmp(typestring, "MCDRAM")) {
178-
if (lcontext && lcontext->only_hbm == -1)
179-
lcontext->only_hbm = 1;
185+
level->only_hbm = 1;
180186
level->type = HWLOC_OBJ_NUMANODE;
181187
level->depth = HWLOC_TYPE_DEPTH_NUMANODE;
182188
return 0;
@@ -292,7 +298,7 @@ hwloc_calc_parse_range(const char *_string,
292298

293299
static __hwloc_inline int
294300
hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
295-
hwloc_const_bitmap_t rootcpuset, hwloc_const_bitmap_t rootnodeset, int depth,
301+
hwloc_const_bitmap_t rootcpuset, hwloc_const_bitmap_t rootnodeset, struct hwloc_calc_level *level,
296302
const char *string, /* starts with indexes following the colon */
297303
void (*cbfunc)(struct hwloc_calc_location_context_s *, void *, hwloc_obj_t), void *cbdata)
298304
{
@@ -301,7 +307,7 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
301307
hwloc_obj_t obj;
302308
unsigned width;
303309
const char *dot, *nextsep = NULL;
304-
int nextdepth = -1;
310+
struct hwloc_calc_level nextlevel;
305311
int first, wrap, amount, step;
306312
unsigned i,j;
307313
int found = 0;
@@ -321,7 +327,6 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
321327
if (dot) {
322328
/* parse the next string before calling ourself recursively */
323329
size_t typelen;
324-
struct hwloc_calc_level level;
325330
const char *nextstring = dot+1;
326331
typelen = strspn(nextstring, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
327332
if (!typelen || nextstring[typelen] != ':') {
@@ -331,55 +336,54 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
331336
}
332337
nextsep = &nextstring[typelen];
333338

334-
err = hwloc_calc_parse_level(lcontext, topology, nextstring, typelen, &level);
339+
err = hwloc_calc_parse_level(lcontext, topology, nextstring, typelen, &nextlevel);
335340
if (err < 0) {
336-
if (level.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
341+
if (nextlevel.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
337342
if (verbose >= 0)
338343
fprintf(stderr, "could not find level specified by location %s\n", nextstring);
339344
return -1;
340345
}
341-
if (level.depth == HWLOC_TYPE_DEPTH_MULTIPLE) {
346+
if (nextlevel.depth == HWLOC_TYPE_DEPTH_MULTIPLE) {
342347
if (verbose >= 0)
343348
fprintf(stderr, "found multiple levels for location %s\n", nextstring);
344349
return -1;
345350
}
346351
}
347-
nextdepth = level.depth;
348352

349353
/* we need an object with a cpuset, that's depth>=0 or memory */
350-
if (nextdepth < 0 && nextdepth != HWLOC_TYPE_DEPTH_NUMANODE) {
354+
if (nextlevel.depth < 0 && nextlevel.depth != HWLOC_TYPE_DEPTH_NUMANODE) {
351355
if (verbose >= 0)
352356
fprintf(stderr, "hierarchical location %s only supported with normal object types\n", string);
353357
return -1;
354358
}
355359
}
356360

357-
width = hwloc_calc_get_nbobjs_inside_sets_by_depth(lcontext, rootcpuset, rootnodeset, depth);
361+
width = hwloc_calc_get_nbobjs_inside_sets_by_depth(lcontext, rootcpuset, rootnodeset, level);
358362
if (amount == -1)
359363
amount = (width-first+step-1)/step;
360364

361365
for(i=first, j=0; j<(unsigned)amount; i+=step, j++) {
362366
if (wrap && i>=width)
363367
i = 0;
364368

365-
obj = hwloc_calc_get_obj_inside_sets_by_depth(lcontext, rootcpuset, rootnodeset, depth, i);
369+
obj = hwloc_calc_get_obj_inside_sets_by_depth(lcontext, rootcpuset, rootnodeset, level, i);
366370
if (verbose > 0 || (!obj && verbose >= 0)) {
367371
char *sc, *sn;
368372
hwloc_bitmap_asprintf(&sc, rootcpuset);
369373
hwloc_bitmap_asprintf(&sn, rootnodeset);
370374
if (obj)
371375
printf("using object #%u depth %d below cpuset %s nodeset %s\n",
372-
i, depth, sc, sn);
376+
i, level->depth, sc, sn);
373377
else
374378
fprintf(stderr, "object #%u depth %d below cpuset %s nodeset %s does not exist\n",
375-
i, depth, sc, sn);
379+
i, level->depth, sc, sn);
376380
free(sc);
377381
free(sn);
378382
}
379383
if (obj) {
380384
found++;
381385
if (dot) {
382-
hwloc_calc_append_object_range(lcontext, obj->cpuset, obj->nodeset, nextdepth, nextsep+1, cbfunc, cbdata);
386+
hwloc_calc_append_object_range(lcontext, obj->cpuset, obj->nodeset, &nextlevel, nextsep+1, cbfunc, cbdata);
383387
} else {
384388
/* add to the temporary cpuset
385389
* and let the caller add/clear/and/xor for the actual final cpuset depending on cmdline options
@@ -629,7 +633,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
629633
return hwloc_calc_append_object_range(lcontext,
630634
hwloc_topology_get_complete_cpuset(topology),
631635
hwloc_topology_get_complete_nodeset(topology),
632-
level.depth, sep+1, cbfunc, cbdata);
636+
&level, sep+1, cbfunc, cbdata);
633637
}
634638

635639
struct hwloc_calc_set_context_s {

utils/hwloc/hwloc-info.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,14 @@ hwloc_calc_process_location_info_cb(struct hwloc_calc_location_context_s *lconte
530530
} else if (show_descendants_depth != HWLOC_TYPE_DEPTH_UNKNOWN) {
531531
if (show_descendants_depth >= 0) {
532532
/* normal level */
533-
unsigned i = 0;
534-
unsigned n = hwloc_calc_get_nbobjs_inside_sets_by_depth(lcontext, obj->cpuset, obj->nodeset, show_descendants_depth);
533+
struct hwloc_calc_level level;
534+
unsigned i = 0, n;
535+
level.type = HWLOC_OBJ_TYPE_NONE;
536+
level.depth = show_descendants_depth;
537+
level.only_hbm = -1;
538+
n = hwloc_calc_get_nbobjs_inside_sets_by_depth(lcontext, obj->cpuset, obj->nodeset, &level);
535539
for(i=0; i<n; i++) {
536-
hwloc_obj_t child = hwloc_calc_get_obj_inside_sets_by_depth(lcontext, obj->cpuset, obj->nodeset, show_descendants_depth, i);
540+
hwloc_obj_t child = hwloc_calc_get_obj_inside_sets_by_depth(lcontext, obj->cpuset, obj->nodeset, &level, i);
537541
if (show_index_prefix)
538542
snprintf(prefix, sizeof(prefix), "%u.%u: ", current_obj, i);
539543
hwloc_info_show_descendant(topology, child, obj, objs, i, prefix, verbose);

0 commit comments

Comments
 (0)