Skip to content

Commit 3ea7710

Browse files
committed
lstopo: rework --only using the hwloc_calc_level structure
Allow --only with filters as other tools do. Signed-off-by: Brice Goglin <[email protected]>
1 parent 211dd69 commit 3ea7710

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

utils/lstopo/lstopo-no-graphics.1in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ otherwise it will imply \fB\-\-cpuset\fR.
163163
.TP
164164
\fB\-\-only\fR <type>
165165
Only show objects of the given type in the textual output.
166+
167+
\fI<type>\fR may contain a filter to select specific objects among
168+
the type. For instance \fB\-\-only "numa[mcdram]"\fR only shows MCDRAM NUMA nodes on KNL.
166169
.TP
167170
\fB\-\-filter\fR <type>:<kind>, \fB\-\-filter\fR <type>
168171
Filter objects of type <type>, or of any type if <type> is "all".

utils/lstopo/lstopo-text.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,28 @@ output_only (struct lstopo_output *loutput, hwloc_obj_t l)
192192
{
193193
FILE *output = loutput->file;
194194
hwloc_obj_t child;
195-
if (loutput->show_only == l->type) {
196-
output_console_obj (loutput, l, 0);
197-
fprintf (output, "\n");
195+
if (loutput->show_only.type == l->type
196+
|| loutput->show_only.depth == l->depth) {
197+
if (!hwloc_calc_check_object_filtered(l, &loutput->show_only)) {
198+
output_console_obj (loutput, l, 0);
199+
fprintf (output, "\n");
200+
}
198201
}
199202
/* there can be anything below normal children */
200203
for_each_child(child, l)
201204
output_only (loutput, child);
202205
/* there can be only memory or Misc below memory children */
203-
if (hwloc_obj_type_is_memory(loutput->show_only) || loutput->show_only == HWLOC_OBJ_MISC) {
206+
if (loutput->show_only.type == HWLOC_OBJ_TYPE_NONE || hwloc_obj_type_is_memory(loutput->show_only.type) || loutput->show_only.type == HWLOC_OBJ_MISC) {
204207
for(child = l->memory_first_child; child; child = child->next_sibling)
205208
output_only (loutput, child);
206209
}
207210
/* there can be only I/O or Misc below I/O children */
208-
if (hwloc_obj_type_is_io(loutput->show_only) || loutput->show_only == HWLOC_OBJ_MISC) {
211+
if (loutput->show_only.type == HWLOC_OBJ_TYPE_NONE || hwloc_obj_type_is_io(loutput->show_only.type) || loutput->show_only.type == HWLOC_OBJ_MISC) {
209212
for_each_io_child(child, l)
210213
output_only (loutput, child);
211214
}
212215
/* there can be only Misc below Misc children */
213-
if (loutput->show_only == HWLOC_OBJ_MISC) {
216+
if (loutput->show_only.type == HWLOC_OBJ_TYPE_NONE || loutput->show_only.type == HWLOC_OBJ_MISC) {
214217
/* Misc can only contain other Misc, no need to recurse otherwise */
215218
for_each_misc_child(child, l)
216219
output_only (loutput, child);
@@ -505,27 +508,31 @@ output_console(struct lstopo_output *loutput, const char *filename)
505508
* if verbose_mode > 1, print both.
506509
*/
507510

508-
if (loutput->show_only != HWLOC_OBJ_TYPE_NONE) {
509-
if (verbose_mode > 1)
510-
fprintf(output, "Only showing %s objects\n", hwloc_obj_type_string(loutput->show_only));
511+
if (loutput->show_only.depth != HWLOC_TYPE_DEPTH_UNKNOWN) {
512+
if (verbose_mode > 1) {
513+
if (loutput->show_only.type != HWLOC_OBJ_TYPE_NONE)
514+
fprintf(output, "Only showing some %s objects\n", hwloc_obj_type_string(loutput->show_only.type));
515+
else
516+
fprintf(output, "Only showing some objects at depth %d\n", loutput->show_only.depth);
517+
}
511518
output_only (loutput, hwloc_get_root_obj(topology));
512519
} else if (verbose_mode >= 1) {
513520
output_topology (loutput, hwloc_get_root_obj(topology), NULL, 0);
514521
fprintf(output, "\n");
515522
}
516523

517-
if ((verbose_mode > 1 || !verbose_mode) && loutput->show_only == HWLOC_OBJ_TYPE_NONE) {
524+
if ((verbose_mode > 1 || !verbose_mode) && loutput->show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
518525
hwloc_lstopo_show_summary(output, topology);
519526
}
520527

521-
if (verbose_mode > 1 && loutput->show_only == HWLOC_OBJ_TYPE_NONE) {
528+
if (verbose_mode > 1 && loutput->show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
522529
output_distances(loutput);
523530
output_memattrs(loutput);
524531
output_cpukinds(loutput);
525532
output_windows_processor_groups(loutput, verbose_mode > 2);
526533
}
527534

528-
if (verbose_mode > 1 && loutput->show_only == HWLOC_OBJ_TYPE_NONE) {
535+
if (verbose_mode > 1 && loutput->show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
529536
hwloc_const_bitmap_t complete = hwloc_topology_get_complete_cpuset(topology);
530537
hwloc_const_bitmap_t topo = hwloc_topology_get_topology_cpuset(topology);
531538
hwloc_const_bitmap_t allowed = hwloc_topology_get_allowed_cpuset(topology);

utils/lstopo/lstopo.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ main (int argc, char *argv[])
896896
hwloc_bitmap_t allow_cpuset = NULL, allow_nodeset = NULL;
897897
char * callname;
898898
char * input = NULL;
899+
const char *show_only_string = NULL;
899900
struct hwloc_utils_input_format_s input_format = HWLOC_UTILS_INPUT_FORMAT_DEFAULT;
900901
enum output_format output_format = LSTOPO_OUTPUT_DEFAULT;
901902
struct lstopo_type_filter type_filter[HWLOC_OBJ_TYPE_MAX];
@@ -959,7 +960,6 @@ main (int argc, char *argv[])
959960
loutput.show_memattrs_only = 0;
960961
loutput.show_cpukinds_only = 0;
961962
loutput.show_windows_processor_groups_only = 0;
962-
loutput.show_only = HWLOC_OBJ_TYPE_NONE;
963963
loutput.show_cpuset = 0;
964964
loutput.show_taskset = 0;
965965
loutput.transform_distances = -1;
@@ -1080,8 +1080,7 @@ main (int argc, char *argv[])
10801080
} else if (!strcmp (argv[0], "--only")) {
10811081
if (argc < 2)
10821082
goto out_usagefailure;
1083-
if (hwloc_type_sscanf(argv[1], &loutput.show_only, NULL, 0) < 0)
1084-
fprintf(stderr, "Unsupported type `%s' passed to --only, ignoring.\n", argv[1]);
1083+
show_only_string = argv[1];
10851084
opt = 1;
10861085
}
10871086
else if (!strcmp (argv[0], "--filter")) {
@@ -1621,7 +1620,7 @@ main (int argc, char *argv[])
16211620
/* if the output format wasn't enforced, think a bit about what the user probably want */
16221621
if (output_format == LSTOPO_OUTPUT_DEFAULT) {
16231622
if (loutput.show_cpuset
1624-
|| loutput.show_only != HWLOC_OBJ_TYPE_NONE
1623+
|| show_only_string
16251624
|| loutput.show_distances_only
16261625
|| loutput.show_memattrs_only
16271626
|| loutput.show_cpukinds_only
@@ -1949,6 +1948,16 @@ main (int argc, char *argv[])
19491948
lstopo_add_collapse_attributes(topology);
19501949
}
19511950

1951+
loutput.show_only.depth = HWLOC_TYPE_DEPTH_UNKNOWN; /* disable this feature by default */
1952+
if (show_only_string) {
1953+
err = hwloc_calc_parse_level(NULL, topology, show_only_string, strlen(show_only_string), &loutput.show_only);
1954+
if (err < 0 && loutput.show_only.depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
1955+
fprintf(stderr, "level %s passed to --only is unavailable.\n", show_only_string);
1956+
goto out_with_topology;
1957+
}
1958+
/* multiple depth is ok */
1959+
}
1960+
19521961
/******************
19531962
* Output for real
19541963
*/

utils/lstopo/lstopo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "private/autogen/config.h"
1414
#include "hwloc.h"
1515
#include "misc.h"
16+
#include "hwloc-calc.h"
1617

1718
enum lstopo_drawing_e {
1819
LSTOPO_DRAWING_PREPARE,
@@ -100,7 +101,7 @@ struct lstopo_output {
100101
int show_memattrs_only;
101102
int show_cpukinds_only;
102103
int show_windows_processor_groups_only;
103-
hwloc_obj_type_t show_only;
104+
struct hwloc_calc_level show_only;
104105
int show_cpuset;
105106
int show_taskset;
106107
int transform_distances;

0 commit comments

Comments
 (0)