Skip to content

Commit a323bf3

Browse files
committed
utils: allow to filter locations by [subtype]
Useful for NUMA subtypes (HBM, etc). Signed-off-by: Brice Goglin <[email protected]>
1 parent d491920 commit a323bf3

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

utils/hwloc/hwloc-calc.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct hwloc_calc_level {
3737
int depth;
3838
hwloc_obj_type_t type;
3939
union hwloc_obj_attr_u attr;
40+
char subtype[32];
4041
int pci_vendor, pci_device;
4142
int only_hbm; /* -1 for everything, 0 for only non-HBM, 1 for only HBM numa nodes */
4243
};
@@ -111,6 +112,10 @@ hwloc_calc_get_nbobjs_inside_sets_by_depth(struct hwloc_calc_location_context_s
111112
if (only_hbm != obj_is_hbm)
112113
continue;
113114
}
115+
if (level->subtype[0]) {
116+
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
117+
continue;
118+
}
114119
n++;
115120
}
116121
return n;
@@ -140,6 +145,10 @@ hwloc_calc_get_obj_inside_sets_by_depth(struct hwloc_calc_location_context_s *lc
140145
if (only_hbm != obj_is_hbm)
141146
continue;
142147
}
148+
if (level->subtype[0]) {
149+
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
150+
continue;
151+
}
143152
if (logical) {
144153
if (i == ind)
145154
return obj;
@@ -181,6 +190,13 @@ hwloc_calc_parse_level_filter(hwloc_topology_t topology __hwloc_attribute_unused
181190
struct hwloc_calc_level *level)
182191
{
183192
const char *current = filter;
193+
const char *end;
194+
unsigned subtypelen;
195+
196+
if (!strncmp(current, "subtype=", 8)) {
197+
current += 8;
198+
goto subtype;
199+
}
184200

185201
if (level->type == HWLOC_OBJ_PCI_DEVICE) {
186202
/* try to match by [vendor:device] */
@@ -202,12 +218,15 @@ hwloc_calc_parse_level_filter(hwloc_topology_t topology __hwloc_attribute_unused
202218
fprintf(stderr, "invalid PCI vendor:device filter specification %s\n", filter);
203219
return -1;
204220
}
205-
206-
} else {
207-
fprintf(stderr, "invalid filter specification %s\n", filter);
208-
return -1;
209221
}
210222

223+
subtype:
224+
/* assume it's a subtype */
225+
end = strchr(current, ']');
226+
subtypelen = end - current;
227+
if (subtypelen >= sizeof(level->subtype))
228+
subtypelen = sizeof(level->subtype) - 1;
229+
snprintf(level->subtype, subtypelen+1, "%s", current);
211230
return 0;
212231
}
213232

@@ -221,6 +240,7 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
221240
char *endptr;
222241
int err;
223242

243+
level->subtype[0] = '\0';
224244
level->pci_device = level->pci_vendor = -1;
225245
level->only_hbm = -1;
226246
if (lcontext)
@@ -536,6 +556,11 @@ hwloc_calc_append_iodev_by_index(struct hwloc_calc_location_context_s *lcontext,
536556
continue;
537557
}
538558

559+
if (level->subtype[0]) {
560+
if (!obj->subtype || strcasecmp(level->subtype, obj->subtype))
561+
continue;
562+
}
563+
539564
if (first--)
540565
continue;
541566

utils/hwloc/hwloc-info.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ hwloc_calc_process_location_info_cb(struct hwloc_calc_location_context_s *lconte
535535
level.type = HWLOC_OBJ_TYPE_NONE;
536536
level.depth = show_descendants_depth;
537537
level.only_hbm = -1;
538+
level.subtype[0] = '\0';
538539
level.pci_vendor = level.pci_device = -1;
539540
n = hwloc_calc_get_nbobjs_inside_sets_by_depth(lcontext, obj->cpuset, obj->nodeset, &level);
540541
for(i=0; i<n; i++) {

0 commit comments

Comments
 (0)