Skip to content

Commit

Permalink
lstopo: add --os/logical-index-prefix
Browse files Browse the repository at this point in the history
To replace " P#" and " L#" with a custom prefix.

Useful for avoiding "P" and "L" in figures in papers
when we don't want to talk about logical-vs-os indexes.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed May 29, 2022
1 parent b4369ae commit 8223863
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -34,6 +34,8 @@ Version 2.8.0
* Tools
+ lstopo and other tools may now load Linux and x86 cpuid topology files
from a tarball.
+ lstopo may now replace the P# and L# index prefixes with custom strings
thanks to --os-index-prefix and --logical-index-prefix options.
* Misc
+ Add --disable-readme to avoid regenerating the top-level hwloc README
file from the documentation.
Expand Down
9 changes: 7 additions & 2 deletions contrib/completion/bash/hwloc
@@ -1,5 +1,5 @@
#
# Copyright © 2018-2021 Inria. All rights reserved.
# Copyright © 2018-2022 Inria. All rights reserved.
# See COPYING in top-level directory.
#

Expand All @@ -17,7 +17,9 @@ _lstopo() {
local FILTERKINDS=("none" "all" "structure" "important")
local OPTIONS=(-l --logical
-p --physical
--output-format --of
--logical-index-prefix
--os-index-prefix
--output-format --of
-f --force
--only
-v --verbose
Expand Down Expand Up @@ -110,6 +112,9 @@ _lstopo() {
--restrict)
COMPREPLY=( `compgen -W "binding <cpuset>" -- "$cur"` )
;;
--logical-index-prefix | --os-index-prefix)
COMPREPLY=( "<string>" "" )
;;
-i | --input)
_filedir xml
;;
Expand Down
17 changes: 10 additions & 7 deletions utils/lstopo/lstopo-draw.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2013, 2015 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -990,22 +990,22 @@ lstopo_obj_snprintf(struct lstopo_output *loutput, char *text, size_t textlen, h
if (obj->type == HWLOC_OBJ_PU || obj->type == HWLOC_OBJ_NUMANODE) {
/* by default we show logical+physical for PU/NUMA */
idx = obj->logical_index;
indexprefix = " L#";
indexprefix = loutput->logical_index_prefix;
} else if (obj->type == HWLOC_OBJ_PACKAGE || obj->type == HWLOC_OBJ_DIE || obj->type == HWLOC_OBJ_CORE) {
/* logical only for package+core (so that we see easily how many packages/cores there are */
idx = obj->logical_index;
indexprefix = " L#";
indexprefix = loutput->logical_index_prefix;
} else {
/* nothing for others */
idx = HWLOC_UNKNOWN_INDEX;
indexprefix = "";
}
} else if (index_type == LSTOPO_INDEX_TYPE_LOGICAL) {
idx = obj->logical_index;
indexprefix = " L#";
indexprefix = loutput->logical_index_prefix;
} else if (index_type == LSTOPO_INDEX_TYPE_PHYSICAL) {
idx = obj->os_index;
indexprefix = " P#";
indexprefix = loutput->os_index_prefix;
} else {
/* shutup the compiler */
idx = 0;
Expand All @@ -1021,7 +1021,7 @@ lstopo_obj_snprintf(struct lstopo_output *loutput, char *text, size_t textlen, h

if (index_type == LSTOPO_INDEX_TYPE_DEFAULT && obj->type == HWLOC_OBJ_NUMANODE && loutput->show_indexes[obj->type])
/* NUMA have both P# and L# on the same line (PU is split on 2 lines) */
snprintf(index2str, sizeof(index2str), " P#%u", obj->os_index);
snprintf(index2str, sizeof(index2str), "%s%u", loutput->os_index_prefix, obj->os_index);

if (loutput->show_attrs_enabled && loutput->show_attrs[obj->type]) {
attrlen = hwloc_obj_attr_snprintf(attrstr, sizeof(attrstr), obj, " ", 0);
Expand Down Expand Up @@ -1245,7 +1245,10 @@ prepare_text(struct lstopo_output *loutput, hwloc_obj_t obj)

if (HWLOC_OBJ_PU == obj->type && loutput->index_type == LSTOPO_INDEX_TYPE_DEFAULT && loutput->show_indexes[obj->type]) {
/* PU P# is on second line */
snprintf(lud->text[lud->ntext++].text, sizeof(lud->text[0].text), "P#%u", obj->os_index);
snprintf(lud->text[lud->ntext++].text, sizeof(lud->text[0].text),
"%s%u",
loutput->os_index_prefix[0] == ' ' ? loutput->os_index_prefix+1 : loutput->os_index_prefix, /* skip the starting space if any */
obj->os_index);
}

if (loutput->show_attrs_enabled && loutput->show_attrs[obj->type]) {
Expand Down
6 changes: 6 additions & 0 deletions utils/lstopo/lstopo-no-graphics.1in
Expand Up @@ -128,6 +128,12 @@ Display OS/physical indexes of all objects, with prefix "P#".
By default, both logical and physical/OS indexes are displayed for PUs and NUMA nodes,
logical only for cores, dies and packages, and no index for other types.
.TP
\fB\-\-logical\-index\-prefix\fR <prefix>
Replace " L#" with the given prefix for logical indexes.
.TP
\fB\-\-os\-index\-prefix\fR <prefix>
Replace " P#" with the given prefix for physical/OS indexes.
.TP
\fB\-c\fR \fB\-\-cpuset\fR
Display the cpuset of each object.
.TP
Expand Down
15 changes: 9 additions & 6 deletions utils/lstopo/lstopo-text.c
Expand Up @@ -40,10 +40,10 @@ output_console_obj (struct lstopo_output *loutput, hwloc_obj_t l, int collapse)

if (collapse > 1 && l->type == HWLOC_OBJ_PCI_DEVICE) {
strcpy(pidxstr, "P#[collapsed]"); /* shouldn't be used, os_index should be -1 except if importing old XMLs */
snprintf(lidxstr, sizeof(lidxstr), "L#%u-%u", l->logical_index, l->logical_index+collapse-1);
snprintf(lidxstr, sizeof(lidxstr), "%s%u-%u", loutput->logical_index_prefix, l->logical_index, l->logical_index+collapse-1);
} else {
snprintf(pidxstr, sizeof(pidxstr), "P#%u", l->os_index);
snprintf(lidxstr, sizeof(lidxstr), "L#%u", l->logical_index);
snprintf(pidxstr, sizeof(pidxstr), "%s%u", loutput->os_index_prefix, l->os_index);
snprintf(lidxstr, sizeof(lidxstr), "%s%u", loutput->logical_index_prefix, l->logical_index);
}
if (l->type == HWLOC_OBJ_PCI_DEVICE)
lstopo_busid_snprintf(loutput, busidstr, sizeof(busidstr), l, collapse, loutput->need_pci_domain);
Expand All @@ -59,18 +59,21 @@ output_console_obj (struct lstopo_output *loutput, hwloc_obj_t l, int collapse)
if (l->depth != 0 && (verbose_mode >= 2 || (hwloc_obj_type_is_normal(l->type) || hwloc_obj_type_is_memory(l->type)))) {
if (index_type != LSTOPO_INDEX_TYPE_PHYSICAL)
/* print logical index in logical and default case */
fprintf(output, " %s", lidxstr);
fprintf(output, "%s", lidxstr);
else if (index_type == LSTOPO_INDEX_TYPE_PHYSICAL && l->os_index != HWLOC_UNKNOWN_INDEX)
/* print physical index in physical case */
fprintf(output, " %s", pidxstr);
fprintf(output, "%s", pidxstr);
}
if (l->name && (l->type == HWLOC_OBJ_MISC || l->type == HWLOC_OBJ_GROUP))
fprintf(output, " %s", l->name);
if (index_type == LSTOPO_INDEX_TYPE_DEFAULT
&& l->os_index != HWLOC_UNKNOWN_INDEX
&& (verbose_mode >= 2 || l->type == HWLOC_OBJ_PU || l->type == HWLOC_OBJ_NUMANODE))
/* print physical index too if default index */
snprintf(phys, sizeof(phys), "%s", pidxstr);
snprintf(phys, sizeof(phys),
"%s",
pidxstr[0] == ' ' ? pidxstr+1 : pidxstr /* skip the starting space if any */
);
if (l->type == HWLOC_OBJ_PCI_DEVICE && verbose_mode <= 1)
fprintf(output, " %s (%s)",
busidstr, hwloc_pci_class_string(l->attr->pcidev.class_id));
Expand Down
18 changes: 17 additions & 1 deletion utils/lstopo/lstopo.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012, 2015, 2017 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* Copyright © 2020 Hewlett Packard Enterprise. All rights reserved.
Expand Down Expand Up @@ -560,6 +560,8 @@ void usage(const char *name, FILE *where)
fprintf (where, " --top-color <none|#xxyyzz>\n"
" Disable or change task background color for --top\n");
fprintf (where, "Miscellaneous options:\n");
fprintf (where, " --logical-index-prefix <s> --os-index-prefix <s>\n");
fprintf (where, " Use <s> as a prefix for logical or physical/OS indexes\n");
fprintf (where, " --export-xml-flags <n>\n"
" Set flags during the XML topology export\n");
fprintf (where, " --export-synthetic-flags <n>\n"
Expand Down Expand Up @@ -872,6 +874,8 @@ main (int argc, char *argv[])
}
loutput.show_attrs_enabled = 1;
loutput.show_text_enabled = 1;
loutput.os_index_prefix = (char *) " P#";
loutput.logical_index_prefix = (char *) " L#";

loutput.show_binding = 1;
loutput.show_disallowed = 1;
Expand Down Expand Up @@ -1269,6 +1273,18 @@ main (int argc, char *argv[])
fprintf(stderr, "Unsupported color `%s' passed to %s, ignoring.\n", argv[1], argv[0]);
opt = 1;
}
else if (!strcmp(argv[0], "--os-index-prefix")) {
if (argc < 2)
goto out_usagefailure;
loutput.os_index_prefix = argv[1];
opt = 1;
}
else if (!strcmp(argv[0], "--logical-index-prefix")) {
if (argc < 2)
goto out_usagefailure;
loutput.logical_index_prefix = argv[1];
opt = 1;
}
else if (!strncmp (argv[0], "--no-text", 9)
|| !strncmp (argv[0], "--text", 6)
|| !strncmp (argv[0], "--no-index", 10)
Expand Down
4 changes: 3 additions & 1 deletion utils/lstopo/lstopo.h
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2010, 2012, 2015 Université Bordeaux
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
* Copyright © 2020 Hewlett Packard Enterprise. All rights reserved.
Expand Down Expand Up @@ -122,6 +122,8 @@ struct lstopo_output {
int show_disallowed;
int show_process_color;
int show_cpukinds;
char *logical_index_prefix;
char *os_index_prefix;
int factorize_enabled; /* global toggle for interactive keyboard shortcuts */
unsigned factorize_min[HWLOC_OBJ_TYPE_MAX]; /* minimum number of object before factorizing (parent->arity must be strictly higher) */
#define FACTORIZE_MIN_DEFAULT 4
Expand Down

0 comments on commit 8223863

Please sign in to comment.