From e25888c9e4d1dcda8ff607f51207ca49cf89e15a Mon Sep 17 00:00:00 2001 From: Brice Goglin Date: Tue, 4 Jun 2024 15:13:27 +0200 Subject: [PATCH] utils: add --cpuset-output-format when we had --taskset hwloc-bind/calc/distrib and lstopo now support: --cpuset-output-format hwloc (default) --cpuset-output-format taskset (supersedes --taskset) --cpuset-output-format list (new) Or --cof for shorter Refs #667 Signed-off-by: Brice Goglin --- contrib/completion/bash/hwloc | 20 ++++++++++++--- doc/hwloc.doxy | 5 ++-- utils/hwloc/hwloc-bind.1in | 13 +++++++--- utils/hwloc/hwloc-bind.c | 36 ++++++++++++++++----------- utils/hwloc/hwloc-calc.1in | 13 +++++++--- utils/hwloc/hwloc-calc.c | 28 +++++++++++++++------ utils/hwloc/hwloc-distrib.1in | 10 +++++--- utils/hwloc/hwloc-distrib.c | 27 ++++++++++++++------ utils/hwloc/misc.h | 32 ++++++++++++++++++++++++ utils/hwloc/test-hwloc-calc.output | 7 ++++-- utils/hwloc/test-hwloc-calc.sh.in | 13 ++++++---- utils/hwloc/test-hwloc-distrib.output | 10 ++++---- utils/hwloc/test-hwloc-distrib.sh.in | 6 ++--- utils/lstopo/lstopo-no-graphics.1in | 13 +++++++--- utils/lstopo/lstopo-text.c | 7 ++---- utils/lstopo/lstopo.c | 24 +++++++++++++++--- utils/lstopo/lstopo.h | 4 +-- utils/lstopo/test-lstopo.sh.in | 4 +-- 18 files changed, 193 insertions(+), 79 deletions(-) diff --git a/contrib/completion/bash/hwloc b/contrib/completion/bash/hwloc index 7658c5084e..03cf0ca8b1 100644 --- a/contrib/completion/bash/hwloc +++ b/contrib/completion/bash/hwloc @@ -32,7 +32,7 @@ _lstopo() { --windows-processor-groups -c --cpuset -C --cpuset-only - --taskset + --cpuset-output-format --cof --filter --ignore --no-caches --no-useless-caches @@ -147,6 +147,9 @@ _lstopo() { --distances-transform) COMPREPLY=( `compgen -W "links merge-switch-ports transitive-closure" -- "$cur"` ) ;; + --cpuset-output-format | --cof) + COMPREPLY=( "hwloc" "list" taskset" ) + ;; esac fi } @@ -251,7 +254,7 @@ _hwloc_bind(){ --nodeset --pid --tid - --taskset + --cpuset-output-format --cof --restrict --restrict-flags --disallowed --whole-system @@ -289,6 +292,9 @@ _hwloc_bind(){ --best-memattr) COMPREPLY=( "" "" ) ;; + --cpuset-output-format | --cof) + COMPREPLY=( "hwloc" "list" taskset" ) + ;; esac fi } @@ -315,7 +321,7 @@ _hwloc_calc(){ --no --nodeset-output --oo --object-output --sep - --taskset + --cpuset-output-format --cof --single --restrict --restrict-flags @@ -366,6 +372,9 @@ _hwloc_calc(){ --cpukind) COMPREPLY=( "=" "" "" ) ;; + --cpuset-output-format | --cof) + COMPREPLY=( "hwloc" "list" taskset" ) + ;; esac fi } @@ -451,7 +460,7 @@ _hwloc_distrib(){ --input -i --input-format --if --single - --taskset + --cpuset-output-format --cof -v --verbose --version -h --help @@ -478,6 +487,9 @@ _hwloc_distrib(){ --restrict-flags) COMPREPLY=( "" "" ) ;; + --cpuset-output-format | --cof) + COMPREPLY=( "hwloc" "list" taskset" ) + ;; esac fi } diff --git a/doc/hwloc.doxy b/doc/hwloc.doxy index 9bf4252869..ede9be6337 100644 --- a/doc/hwloc.doxy +++ b/doc/hwloc.doxy @@ -3058,8 +3058,9 @@ enabled for the current topology. See for instance hwloc_bitmap_taskset_snprintf() in \ref hwlocality_bitmap(). - Most hwloc command-line tools also support the \--taskset - option to manipulate taskset-specific strings. + Most hwloc command-line tools also support the option + \--cpuset-output-format taskset + to manipulate taskset-specific strings. diff --git a/utils/hwloc/hwloc-bind.1in b/utils/hwloc/hwloc-bind.1in index c8094d6728..40becd7481 100644 --- a/utils/hwloc/hwloc-bind.1in +++ b/utils/hwloc/hwloc-bind.1in @@ -213,11 +213,16 @@ This option does not apply to the output, see \fB\-\-get\fR above. Interpret input locations with logical indexes instead of physical/OS indexes (default). This option does not apply to the output, see \fB\-\-get\fR above. .TP -\fB\-\-taskset\fR -Display CPU set strings in the format recognized by the taskset command-line -program instead of hwloc-specific CPU set string format. +\fB\-\-cpuset\-output\-format\fR \fB\-\-cof\fR +Change the format of CPUset or nodeset strings displayed by \fB\-\-get\fR, \fB\-e\fR, etc. +By default, the hwloc-specific format is used. +If \fIlist\fR is given, the output is a comma-separated of numbers or ranges, +e.g. 2,4-5,8 . +If \fItaskset\fR is given, the output is compatible with the taskset program +(replaces the former \fB--taskset\fR option). + This option has no impact on the format of input CPU set strings, -both formats are always accepted. +both hwloc and taskset formats are always accepted. .TP \fB\-f\fR \fB\-\-force\fR Launch the executable even if binding failed. diff --git a/utils/hwloc/hwloc-bind.c b/utils/hwloc/hwloc-bind.c index df0c16596b..edba278e0f 100644 --- a/utils/hwloc/hwloc-bind.c +++ b/utils/hwloc/hwloc-bind.c @@ -58,7 +58,9 @@ void usage(const char *name, FILE *where) #ifdef HWLOC_LINUX_SYS fprintf(where, " --tid Operate on thread \n"); #endif - fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n"); + fprintf(where, " --cpuset-output-format \n" + " --cof \n" + " Change the format of cpuset outputs\n"); fprintf(where, "Miscellaneous options:\n"); fprintf(where, " -f --force Launch the command even if binding failed\n"); fprintf(where, " -q --quiet Hide non-fatal error messages\n"); @@ -85,7 +87,7 @@ int main(int argc, char *argv[]) int no_smt = -1; int only_hbm = -1; int logical = 1; - int taskset = 0; + enum hwloc_utils_cpuset_format_e cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_HWLOC; unsigned cpubind_flags = 0; hwloc_membind_policy_t membind_policy = HWLOC_MEMBIND_BIND; int got_mempolicy = 0; @@ -270,8 +272,21 @@ int main(int argc, char *argv[]) logical = 0; goto next; } + if (!strcmp(argv[0], "--cpuset-output-format") || !strcmp(argv[0], "--cof")) { + if (argc < 2) { + usage (callname, stderr); + exit(EXIT_FAILURE); + } + cpuset_output_format = hwloc_utils_parse_cpuset_format(argv[1]); + if (HWLOC_UTILS_CPUSET_FORMAT_UNKNOWN == cpuset_output_format) { + fprintf(stderr, "Unrecognized %s argument %s\n", argv[0], argv[1]); + exit(EXIT_FAILURE); + } + opt = 1; + goto next; + } if (!strcmp(argv[0], "--taskset")) { - taskset = 1; + cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_TASKSET; goto next; } if (!strcmp (argv[0], "-e") || !strncmp (argv[0], "--get-last-cpu-location", 10)) { @@ -417,16 +432,10 @@ int main(int argc, char *argv[]) if (use_nodeset) { hwloc_bitmap_t nset = hwloc_bitmap_alloc(); hwloc_cpuset_to_nodeset(topology, cpubind_set, nset); - if (taskset) - hwloc_bitmap_taskset_asprintf(&s, nset); - else - hwloc_bitmap_asprintf(&s, nset); + hwloc_utils_cpuset_format_asprintf(&s, nset, cpuset_output_format); hwloc_bitmap_free(nset); } else { - if (taskset) - hwloc_bitmap_taskset_asprintf(&s, cpubind_set); - else - hwloc_bitmap_asprintf(&s, cpubind_set); + hwloc_utils_cpuset_format_asprintf(&s, cpubind_set, cpuset_output_format); } } else { @@ -446,10 +455,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "hwloc_get_membind failed (errno %d %s)\n", errno, errmsg); return EXIT_FAILURE; } - if (taskset) - hwloc_bitmap_taskset_asprintf(&s, membind_set); - else - hwloc_bitmap_asprintf(&s, membind_set); + hwloc_utils_cpuset_format_asprintf(&s, membind_set, cpuset_output_format); switch (policy) { case HWLOC_MEMBIND_FIRSTTOUCH: policystr = "firsttouch"; break; case HWLOC_MEMBIND_BIND: policystr = "bind"; break; diff --git a/utils/hwloc/hwloc-calc.1in b/utils/hwloc/hwloc-calc.1in index 815d6865f1..16d4de7d27 100644 --- a/utils/hwloc/hwloc-calc.1in +++ b/utils/hwloc/hwloc-calc.1in @@ -282,11 +282,16 @@ while a comma is used to separate indexes \fB\-\-single\fR Singlify the output to a single CPU. .TP -\fB\-\-taskset\fR -Display CPU set strings in the format recognized by the taskset command-line -program instead of hwloc-specific CPU set string format. +\fB\-\-cpuset\-output\-format\fR \fB\-\-cof\fR +Change the format of displayed CPU set strings. +By default, the hwloc-specific format is used. +If \fIlist\fR is given, the output is a comma-separated of numbers or ranges, +e.g. 2,4-5,8 . +If \fItaskset\fR is given, the output is compatible with the taskset program +(replaces the former \fB--taskset\fR option). + This option has no impact on the format of input CPU set strings, -both formats are always accepted. +both hwloc and taskset formats are always accepted. .TP \fB\-q\fR \fB\-\-quiet\fR Hide non-fatal error messages. diff --git a/utils/hwloc/hwloc-calc.c b/utils/hwloc/hwloc-calc.c index d7c005f583..7fe7d83c07 100644 --- a/utils/hwloc/hwloc-calc.c +++ b/utils/hwloc/hwloc-calc.c @@ -57,7 +57,9 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where) fprintf(where, " --no --nodeset-output Manipulate nodesets instead of cpusets for outputs\n"); fprintf(where, " --oo --object-output Report objects instead of object indexes\n"); fprintf(where, " --sep Use separator in the output\n"); - fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n"); + fprintf(where, " --cpuset-output-format \n" + " --cof \n" + " Change the format of cpuset outputs\n"); fprintf(where, " --single Singlify the output to a single CPU\n"); fprintf(where, "Miscellaneous options:\n"); fprintf(where, " -q --quiet Hide non-fatal error messages\n"); @@ -83,7 +85,7 @@ static unsigned long best_node_flags = 0; static int showobjs = 0; static int no_smt = -1; static int singlify = 0; -static int taskset = 0; +static enum hwloc_utils_cpuset_format_e cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_HWLOC; static hwloc_bitmap_t cpukind_cpuset = NULL; static int @@ -276,10 +278,7 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set } else { char *string = NULL; - if (taskset) - hwloc_bitmap_taskset_asprintf(&string, set); - else - hwloc_bitmap_asprintf(&string, set); + hwloc_utils_cpuset_format_asprintf(&string, set, cpuset_output_format); printf("%s\n", string); free(string); } @@ -593,10 +592,23 @@ int main(int argc, char *argv[]) singlify = 1; goto next; } - if (!strcmp(argv[0], "--taskset")) { - taskset = 1; + if (!strcmp(argv[0], "--cpuset-output-format") || !strcmp(argv[0], "--cof")) { + if (argc < 2) { + usage (callname, stderr); + exit(EXIT_FAILURE); + } + cpuset_output_format = hwloc_utils_parse_cpuset_format(argv[1]); + if (HWLOC_UTILS_CPUSET_FORMAT_UNKNOWN == cpuset_output_format) { + fprintf(stderr, "Unrecognized %s argument %s\n", argv[0], argv[1]); + exit(EXIT_FAILURE); + } + opt = 1; goto next; } + if (!strcmp(argv[0], "--taskset")) { + cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_TASKSET; + goto next; + } fprintf (stderr, "Unrecognized option: %s\n", argv[0]); usage(callname, stderr); diff --git a/utils/hwloc/hwloc-distrib.1in b/utils/hwloc/hwloc-distrib.1in index adad97e94b..5c3709aa28 100644 --- a/utils/hwloc/hwloc-distrib.1in +++ b/utils/hwloc/hwloc-distrib.1in @@ -21,9 +21,13 @@ hwloc-distrib \- Build a number of cpu masks distributed on the system \fB\-\-single\fR Singlify each output to a single CPU. .TP -\fB\-\-taskset\fR -Show CPU set strings in the format recognized by the taskset command-line -program instead of hwloc-specific CPU set string format. +\fB\-\-cpuset\-output\-format\fR \fB\-\-cof\fR +Change the format of displayed CPU set strings. +By default, the hwloc-specific format is used. +If \fIlist\fR is given, the output is a comma-separated of numbers or ranges, +e.g. 2,4-5,8 . +If \fItaskset\fR is given, the output is compatible with the taskset program +(replaces the former \fB--taskset\fR option). .TP \fB\-v\fR \fB\-\-verbose\fR Verbose messages. diff --git a/utils/hwloc/hwloc-distrib.c b/utils/hwloc/hwloc-distrib.c index 5d031cceef..080c820a37 100644 --- a/utils/hwloc/hwloc-distrib.c +++ b/utils/hwloc/hwloc-distrib.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2022 Inria. All rights reserved. + * Copyright © 2009-2024 Inria. All rights reserved. * Copyright © 2009-2010 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * Copyright © 2023 Université de Reims Champagne-Ardenne. All rights reserved. @@ -33,6 +33,9 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where) fprintf(where, "Formatting options:\n"); fprintf(where, " --single Singlify each output to a single CPU\n"); fprintf(where, " --taskset Show taskset-specific cpuset strings\n"); + fprintf(where, " --cpuset-output-format \n" + " --cof \n" + " Change the format of cpuset outputs\n"); fprintf(where, "Miscellaneous options:\n"); fprintf(where, " -v --verbose Show verbose messages\n"); fprintf(where, " --version Report version and exit\n"); @@ -45,7 +48,7 @@ int main(int argc, char *argv[]) char *callname; char *input = NULL; struct hwloc_utils_input_format_s input_format = HWLOC_UTILS_INPUT_FORMAT_DEFAULT; - int taskset = 0; + enum hwloc_utils_cpuset_format_e cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_HWLOC; int singlify = 0; int verbose = 0; char *restrictstring = NULL; @@ -91,8 +94,21 @@ int main(int argc, char *argv[]) singlify = 1; goto next; } + if (!strcmp(argv[0], "--cpuset-output-format") || !strcmp(argv[0], "--cof")) { + if (argc < 2) { + usage (callname, stderr); + exit(EXIT_FAILURE); + } + cpuset_output_format = hwloc_utils_parse_cpuset_format(argv[1]); + if (HWLOC_UTILS_CPUSET_FORMAT_UNKNOWN == cpuset_output_format) { + fprintf(stderr, "Unrecognized %s argument %s\n", argv[0], argv[1]); + exit(EXIT_FAILURE); + } + opt = 1; + goto next; + } if (!strcmp(argv[0], "--taskset")) { - taskset = 1; + cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_TASKSET; goto next; } if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose")) { @@ -291,10 +307,7 @@ int main(int argc, char *argv[]) hwloc_bitmap_singlify(cpuset[i]); } } - if (taskset) - hwloc_bitmap_taskset_asprintf(&str, cpuset[i]); - else - hwloc_bitmap_asprintf(&str, cpuset[i]); + hwloc_utils_cpuset_format_asprintf(&str, cpuset[i], cpuset_output_format); printf("%s\n", str); free(str); hwloc_bitmap_free(cpuset[i]); diff --git a/utils/hwloc/misc.h b/utils/hwloc/misc.h index 4c7a0a7068..8aa0badcb8 100644 --- a/utils/hwloc/misc.h +++ b/utils/hwloc/misc.h @@ -932,6 +932,38 @@ hwloc_utils_get_best_node_in_array_by_memattr(hwloc_topology_t topology, hwloc_m return -1; } +enum hwloc_utils_cpuset_format_e { + HWLOC_UTILS_CPUSET_FORMAT_UNKNOWN, + HWLOC_UTILS_CPUSET_FORMAT_HWLOC, + HWLOC_UTILS_CPUSET_FORMAT_TASKSET, + HWLOC_UTILS_CPUSET_FORMAT_LIST +}; + +static __hwloc_inline enum hwloc_utils_cpuset_format_e +hwloc_utils_parse_cpuset_format(const char *string) +{ + if (!strcmp(string, "hwloc")) + return HWLOC_UTILS_CPUSET_FORMAT_HWLOC; + else if (!strcmp(string, "list")) + return HWLOC_UTILS_CPUSET_FORMAT_LIST; + else if (!strcmp(string, "taskset")) + return HWLOC_UTILS_CPUSET_FORMAT_TASKSET; + else + return HWLOC_UTILS_CPUSET_FORMAT_UNKNOWN; +} + +static __hwloc_inline int +hwloc_utils_cpuset_format_asprintf(char **string, hwloc_const_bitmap_t set, + enum hwloc_utils_cpuset_format_e cpuset_output_format) +{ + switch (cpuset_output_format) { + case HWLOC_UTILS_CPUSET_FORMAT_HWLOC: return hwloc_bitmap_asprintf(string, set); + case HWLOC_UTILS_CPUSET_FORMAT_TASKSET: return hwloc_bitmap_taskset_asprintf(string, set); + case HWLOC_UTILS_CPUSET_FORMAT_LIST: return hwloc_bitmap_list_asprintf(string, set); + default: abort(); + } +} + static __hwloc_inline unsigned long hwloc_utils_parse_restrict_flags(char * str){ struct hwloc_utils_parsing_flag possible_flags[] = { diff --git a/utils/hwloc/test-hwloc-calc.output b/utils/hwloc/test-hwloc-calc.output index 385869dc97..4f4f884321 100644 --- a/utils/hwloc/test-hwloc-calc.output +++ b/utils/hwloc/test-hwloc-calc.output @@ -1,7 +1,10 @@ -# root +# root --cpuset-output-format hwloc 0xffffffff,0xffffffff -# all --taskset +# all --cof list +0-63 + +# all --cpuset-output-format taskset 0xffffffffffffffff # hex diff --git a/utils/hwloc/test-hwloc-calc.sh.in b/utils/hwloc/test-hwloc-calc.sh.in index 2f3965f828..db4a1a2dad 100644 --- a/utils/hwloc/test-hwloc-calc.sh.in +++ b/utils/hwloc/test-hwloc-calc.sh.in @@ -37,11 +37,14 @@ file="$tmp/test-hwloc-calc.output" set -e ( - echo "# root" - $calc --if synthetic --input "node:4 core:4 pu:4" root + echo "# root --cpuset-output-format hwloc" + $calc --if synthetic --input "node:4 core:4 pu:4" root --cpuset-output-format hwloc echo - echo "# all --taskset" - $calc --if synthetic --input "node:4 core:4 pu:4" all --taskset + echo "# all --cof list" + $calc --if synthetic --input "node:4 core:4 pu:4" all --cof list + echo + echo "# all --cpuset-output-format taskset" + $calc --if synthetic --input "node:4 core:4 pu:4" all --cpuset-output-format taskset echo echo "# hex" @@ -296,7 +299,7 @@ EOF EOF echo echo "# Reading infinite cpusets from stdin and exporting to taskset" - cat << EOF | $calc --if synthetic --input "node:4 core:4 pu:4" --taskset + cat << EOF | $calc --if synthetic --input "node:4 core:4 pu:4" --cpuset-output-format taskset 0xf...f 0xf...f,abcd00 0xf...f,abcd,ef00 diff --git a/utils/hwloc/test-hwloc-distrib.output b/utils/hwloc/test-hwloc-distrib.output index c064942c01..b2dcd3f99e 100644 --- a/utils/hwloc/test-hwloc-distrib.output +++ b/utils/hwloc/test-hwloc-distrib.output @@ -2,11 +2,11 @@ 0x0000000f 0x000000f0 -# 4 sets out of 2 2 2 -0x00000003 -0x0000000c -0x00000030 -0x000000c0 +# 4 sets out of 2 2 2, as lists +0-1 +2-3 +4-5 +6-7 # 8 sets out of 2 2 2 0x00000001 diff --git a/utils/hwloc/test-hwloc-distrib.sh.in b/utils/hwloc/test-hwloc-distrib.sh.in index a42a174646..b343d39741 100644 --- a/utils/hwloc/test-hwloc-distrib.sh.in +++ b/utils/hwloc/test-hwloc-distrib.sh.in @@ -3,7 +3,7 @@ # # Copyright © 2009 CNRS -# Copyright © 2009-2020 Inria. All rights reserved. +# Copyright © 2009-2024 Inria. All rights reserved. # Copyright © 2009 Université Bordeaux # Copyright © 2014 Cisco Systems, Inc. All rights reserved. # See COPYING in top-level directory. @@ -38,8 +38,8 @@ set -e echo "# 2 sets out of 2 2 2" $distrib --if synthetic --input "2 2 2" 2 echo - echo "# 4 sets out of 2 2 2" - $distrib --if synthetic --input "2 2 2" 4 + echo "# 4 sets out of 2 2 2, as lists" + $distrib --if synthetic --input "2 2 2" --cof list 4 echo echo "# 8 sets out of 2 2 2" $distrib --if synthetic --input "2 2 2" 8 diff --git a/utils/lstopo/lstopo-no-graphics.1in b/utils/lstopo/lstopo-no-graphics.1in index 679082c899..4c46893798 100644 --- a/utils/lstopo/lstopo-no-graphics.1in +++ b/utils/lstopo/lstopo-no-graphics.1in @@ -1,5 +1,5 @@ .\" -*- nroff -*- -.\" Copyright © 2009-2023 Inria. All rights reserved. +.\" Copyright © 2009-2024 Inria. All rights reserved. .\" Copyright © 2009-2010 Université of Bordeaux .\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved. .\" Copyright © 2020 Hewlett Packard Enterprise. All rights reserved. @@ -155,9 +155,14 @@ Display the cpuset of each object. Only display the cpuset of each object; do not display anything else about the object. .TP -\fB\-\-taskset\fR -Show CPU set strings in the format recognized by the taskset command-line -program instead of hwloc-specific CPU set string format. +\fB\-\-cpuset\-output\-format\fR \fB\-\-cof\fR +Change the format of displayed CPU set strings. +By default, the hwloc-specific format is used. +If \fIlist\fR is given, the output is a comma-separated of numbers or ranges, +e.g. 2,4-5,8 . +If \fItaskset\fR is given, output cpusets are compatible with the taskset program +(replaces the former \fB--taskset\fR option). + This option should be combined with \fB\-\-cpuset\fR or \fB\-\-cpuset\-only\fR, otherwise it will imply \fB\-\-cpuset\fR. .TP diff --git a/utils/lstopo/lstopo-text.c b/utils/lstopo/lstopo-text.c index 53111fa331..482a606de8 100644 --- a/utils/lstopo/lstopo-text.c +++ b/utils/lstopo/lstopo-text.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2023 Inria. All rights reserved. + * Copyright © 2009-2024 Inria. All rights reserved. * Copyright © 2009-2012 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -118,10 +118,7 @@ output_console_obj (struct lstopo_output *loutput, hwloc_obj_t l, int collapse) fprintf(output, " cpuset="); if (loutput->show_cpuset) { char *cpusetstr; - if (loutput->show_taskset) - hwloc_bitmap_taskset_asprintf(&cpusetstr, l->cpuset); - else - hwloc_bitmap_asprintf(&cpusetstr, l->cpuset); + hwloc_utils_cpuset_format_asprintf(&cpusetstr, l->cpuset, loutput->cpuset_output_format); fprintf(output, "%s", cpusetstr); free(cpusetstr); } diff --git a/utils/lstopo/lstopo.c b/utils/lstopo/lstopo.c index 67f0bae019..98986cd473 100644 --- a/utils/lstopo/lstopo.c +++ b/utils/lstopo/lstopo.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2023 Inria. All rights reserved. + * Copyright © 2009-2024 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. @@ -575,7 +575,9 @@ void usage(const char *name, FILE *where) #endif fprintf (where, " -c --cpuset Show the cpuset of each object\n"); fprintf (where, " -C --cpuset-only Only show the cpuset of each object\n"); - fprintf (where, " --taskset Show taskset-specific cpuset strings\n"); + fprintf (where, " --cpuset-output-format \n" + " --cof \n" + " Change the format of cpuset outputs\n"); fprintf (where, "Object filtering options:\n"); fprintf (where, " --filter : Filter objects of the given type, or all.\n"); fprintf (where, " may be `all' (keep all), `none' (remove all), `structure' or `important'\n"); @@ -961,7 +963,7 @@ main (int argc, char *argv[]) loutput.show_cpukinds_only = 0; loutput.show_windows_processor_groups_only = 0; loutput.show_cpuset = 0; - loutput.show_taskset = 0; + loutput.cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_HWLOC; loutput.transform_distances = -1; loutput.obj_snprintf_flags = HWLOC_OBJ_SNPRINTF_FLAG_SHORT_NAMES; @@ -1073,8 +1075,22 @@ main (int argc, char *argv[]) loutput.show_cpuset = 1; else if (!strcmp (argv[0], "-C") || !strcmp (argv[0], "--cpuset-only")) loutput.show_cpuset = 2; + else if (!strcmp(argv[0], "--cpuset-output-format") || !strcmp(argv[0], "--cof")) { + if (argc < 2) { + usage (callname, stderr); + exit(EXIT_FAILURE); + } + loutput.cpuset_output_format = hwloc_utils_parse_cpuset_format(argv[1]); + if (HWLOC_UTILS_CPUSET_FORMAT_UNKNOWN == loutput.cpuset_output_format) { + fprintf(stderr, "Unrecognized %s argument %s\n", argv[0], argv[1]); + goto out_usagefailure; + } + if (!loutput.show_cpuset) + loutput.show_cpuset = 1; + opt = 1; + } else if (!strcmp (argv[0], "--taskset")) { - loutput.show_taskset = 1; + loutput.cpuset_output_format = HWLOC_UTILS_CPUSET_FORMAT_TASKSET; if (!loutput.show_cpuset) loutput.show_cpuset = 1; } else if (!strcmp (argv[0], "--only")) { diff --git a/utils/lstopo/lstopo.h b/utils/lstopo/lstopo.h index c77c640bde..c5a0aade21 100644 --- a/utils/lstopo/lstopo.h +++ b/utils/lstopo/lstopo.h @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2023 Inria. All rights reserved. + * Copyright © 2009-2024 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. @@ -103,7 +103,7 @@ struct lstopo_output { int show_windows_processor_groups_only; struct hwloc_calc_level show_only; int show_cpuset; - int show_taskset; + enum hwloc_utils_cpuset_format_e cpuset_output_format; int transform_distances; unsigned long obj_snprintf_flags; diff --git a/utils/lstopo/test-lstopo.sh.in b/utils/lstopo/test-lstopo.sh.in index 2770e28f33..e168eb8134 100644 --- a/utils/lstopo/test-lstopo.sh.in +++ b/utils/lstopo/test-lstopo.sh.in @@ -3,7 +3,7 @@ # # Copyright © 2009 CNRS -# Copyright © 2009-2023 Inria. All rights reserved. +# Copyright © 2009-2024 Inria. All rights reserved. # Copyright © 2009, 2011 Université Bordeaux # Copyright © 2020 Hewlett Packard Enterprise. All rights reserved. # See COPYING in top-level directory. @@ -51,7 +51,7 @@ $ls -v > $tmp/test.console_verbose echo "** Verbose with cpusets in $tmp/test.cpuset_verbose ..." $ls -c -v > $tmp/test.cpuset_verbose echo "** Verbose with taskset sets in $tmp/test.taskset ..." -$ls --taskset -v > $tmp/test.taskset +$ls --cpuset-output-format taskset -v > $tmp/test.taskset echo "** Merged topology in $tmp/test.merge ..." $ls --merge > $tmp/test.merge