Skip to content

Commit

Permalink
utils/calc: support osdev subtypes in -N and -I
Browse files Browse the repository at this point in the history
eg: hwloc-calc -I net node:2

Thanks to Clement Foyer for the suggestion.

Refs open-mpi#538

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Jul 19, 2022
1 parent 4c7838f commit f9987ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
17 changes: 17 additions & 0 deletions utils/hwloc/hwloc-calc.1in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type|depth>\fR
Find the list of objects of the given type or depth that intersect the CPU set and
Expand All @@ -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 <type1>.<type2>...\fR
Find the list of objects of type <type2> that intersect the CPU set and
Expand Down Expand Up @@ -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 <the modified bitmask was corrected parsed by resctrl>

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
Expand Down
17 changes: 14 additions & 3 deletions utils/hwloc/hwloc-calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f9987ac

Please sign in to comment.