From f9987ac4b8181a4ffe12449a0add41b094f3d089 Mon Sep 17 00:00:00 2001 From: Brice Goglin Date: Tue, 19 Jul 2022 13:25:41 +0200 Subject: [PATCH] utils/calc: support osdev subtypes in -N and -I eg: hwloc-calc -I net node:2 Thanks to Clement Foyer for the suggestion. Refs #538 Signed-off-by: Brice Goglin --- utils/hwloc/hwloc-calc.1in | 17 +++++++++++++++++ utils/hwloc/hwloc-calc.c | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/utils/hwloc/hwloc-calc.1in b/utils/hwloc/hwloc-calc.1in index 04e7d01c64..4f85fca75d 100644 --- a/utils/hwloc/hwloc-calc.1in +++ b/utils/hwloc/hwloc-calc.1in @@ -130,6 +130,9 @@ in a machine. When combined with \fB\-\-nodeset\fR or \fB\-\-nodeset-output\fR, the nodeset is considered instead of the CPU set for finding matching objects. This is useful when reporting the output as a number or set of NUMA nodes. + +If an OS device subtype such as \fIgpu\fR is given instead of \fIosdev\fR, +only the os devices of that subtype will be counted. .TP \fB\-I \-\-intersect \fR Find the list of objects of the given type or depth that intersect the CPU set and @@ -145,6 +148,9 @@ objects are strictly included inside the input objects. When combined with \fB\-\-nodeset\fR or \fB\-\-nodeset-output\fR, the nodeset is considered instead of the CPU set for finding matching objects. This is useful when reporting the output as a number or set of NUMA nodes. + +If an OS device subtype such as \fIgpu\fR is given instead of \fIosdev\fR, +only the os devices of that subtype will be returned. .TP \fB\-H \-\-hierarchical ....\fR Find the list of objects of type that intersect the CPU set and @@ -427,6 +433,17 @@ To export bitmask in a format that is acceptable by the resctrl Linux subsystem # cat /sys/fs/resctrl/test/cpus 00000000,00000380,00000000,00000380 +OS devices may also be filtered by subtype. In this example, there are +8 OS devices in the system, 4 of them are near NUMA node #1, and only +2 of these are CoProcessors: + + $ utils/hwloc/hwloc-calc -I osdev all + 0,1,2,3,4,5,6,7,8 + $ utils/hwloc/hwloc-calc -I osdev node:1 + 5,6,7,8 + $ utils/hwloc/hwloc-calc -I coproc node:1 + 7,8 + . .\" ************************** .\" Return value section diff --git a/utils/hwloc/hwloc-calc.c b/utils/hwloc/hwloc-calc.c index 789f92dea3..a8d1381976 100644 --- a/utils/hwloc/hwloc-calc.c +++ b/utils/hwloc/hwloc-calc.c @@ -70,7 +70,9 @@ static int logicalo = 1; static int nodeseti = 0; static int nodeseto = 0; static int numberofdepth = -1; +static union hwloc_obj_attr_u numberofattr; static int intersectdepth = -1; +static union hwloc_obj_attr_u intersectattr; static int hiernblevels = 0; static int *hierdepth = NULL; static int local_numanodes = 0; @@ -188,8 +190,13 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set } else if (numberofdepth != -1) { unsigned nb = 0; hwloc_obj_t obj = NULL; - while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth(topology, set, nodeseto, numberofdepth, obj)) != NULL) + while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth(topology, set, nodeseto, numberofdepth, obj)) != NULL) { + if (numberofdepth == HWLOC_TYPE_DEPTH_OS_DEVICE + && numberofattr.osdev.type != (hwloc_obj_osdev_type_t) -1 + && numberofattr.osdev.type != obj->attr->osdev.type) + continue; nb++; + } printf("%u\n", nb); } else if (intersectdepth != -1) { hwloc_obj_t obj = NULL; @@ -198,6 +205,10 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set sep = ","; while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth(topology, set, nodeseto, intersectdepth, obj)) != NULL) { unsigned idx; + if (intersectdepth == HWLOC_TYPE_DEPTH_OS_DEVICE + && intersectattr.osdev.type != (hwloc_obj_osdev_type_t) -1 + && intersectattr.osdev.type != obj->attr->osdev.type) + continue; if (!first) printf("%s", sep); idx = logicalo ? obj->logical_index : obj->os_index; @@ -651,10 +662,10 @@ int main(int argc, char *argv[]) argv += opt+1; } - if (numberoftype && hwloc_calc_type_depth(topology, numberoftype, &numberofdepth, NULL, "--number-of") < 0) + if (numberoftype && hwloc_calc_type_depth(topology, numberoftype, &numberofdepth, &numberofattr, "--number-of") < 0) goto out; - if (intersecttype && hwloc_calc_type_depth(topology, intersecttype, &intersectdepth, NULL, "--intersect") < 0) + if (intersecttype && hwloc_calc_type_depth(topology, intersecttype, &intersectdepth, &intersectattr, "--intersect") < 0) goto out; if (hiertype) {