From 358d19cc02027fb4ab323cc9d76add64c2f4011c Mon Sep 17 00:00:00 2001 From: Brice Goglin Date: Tue, 15 Oct 2013 11:13:40 +0200 Subject: [PATCH] tools: Add --whole-system and --restrict for uniformity Add --whole-system to hwloc-bind, hwloc-calc, hwloc-distances and hwloc-distrib, and add --restrict to hwloc-bind for uniformity among tools. Based on http://www.open-mpi.org/community/lists/hwloc-users/2013/10/0908.php --- NEWS | 3 +++ utils/hwloc-bind.1in | 8 +++++++- utils/hwloc-bind.c | 37 +++++++++++++++++++++++++++++++++++-- utils/hwloc-calc.1in | 3 +++ utils/hwloc-calc.c | 32 ++++++++++++++++++++++---------- utils/hwloc-distances.1in | 5 ++++- utils/hwloc-distances.c | 7 +++++++ utils/hwloc-distrib.1in | 5 ++++- utils/hwloc-distrib.c | 9 ++++++++- 9 files changed, 93 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 4b919d8a..6086d7cf 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,9 @@ Version 1.8.0 discussing the idea. + hwloc-calc and friends have a more robust parsing of locations given on the command-line and they report useful error messages about it. + + Add --whole-system to hwloc-bind, hwloc-calc, hwloc-distances and + hwloc-distrib, and add --restrict to hwloc-bind for uniformity among + tools. * Misc + Calling hwloc_topology_load() or hwloc_topology_set_*() on an already loaded topology now returns an error. diff --git a/utils/hwloc-bind.1in b/utils/hwloc-bind.1in index 101574f6..1d85f6f0 100644 --- a/utils/hwloc-bind.1in +++ b/utils/hwloc-bind.1in @@ -1,5 +1,5 @@ .\" -*- nroff -*- -.\" Copyright © 2009-2012 Inria. All rights reserved. +.\" Copyright © 2009-2013 Inria. All rights reserved. .\" Copyright © 2010 Université of Bordeaux .\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved. .\" See COPYING in top-level directory. @@ -76,6 +76,12 @@ program instead of hwloc-specific CPU set string format. This option has no impact on the format of input CPU set strings, both formats are always accepted. .TP +\fB\-\-restrict\fR +Restrict the topology to the given cpuset. +.TP +\fB\-\-whole\-system\fR +Do not consider administration limitations. +.TP \fB\-f\fR \fB\-\-force\fR Launch the executable even if binding failed. .TP diff --git a/utils/hwloc-bind.c b/utils/hwloc-bind.c index a03a0aca..ed773b17 100644 --- a/utils/hwloc-bind.c +++ b/utils/hwloc-bind.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2012 Inria. All rights reserved. + * Copyright © 2009-2013 Inria. All rights reserved. * Copyright © 2009-2010, 2012 Université Bordeaux 1 * Copyright © 2009 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -37,6 +37,10 @@ void usage(const char *name, FILE *where) " Retrieve the last processors where the current process ran\n"); fprintf(where, " --pid Operate on process \n"); fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n"); + fprintf(where, "Input topology options:\n"); + fprintf(where, " --restrict Restrict the topology to processors listed in \n"); + fprintf(where, " --whole-system Do not consider administration limitations\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"); fprintf(where, " -v --verbose Show verbose messages\n"); @@ -52,6 +56,7 @@ int main(int argc, char *argv[]) int working_on_cpubind = 1; /* membind if 0 */ int get_binding = 0; int get_last_cpu_location = 0; + unsigned long flags = HWLOC_TOPOLOGY_FLAG_WHOLE_IO|HWLOC_TOPOLOGY_FLAG_ICACHES; int force = 0; int single = 0; int verbose = 0; @@ -70,7 +75,7 @@ int main(int argc, char *argv[]) membind_set = hwloc_bitmap_alloc(); hwloc_topology_init(&topology); - hwloc_topology_set_flags(topology, HWLOC_TOPOLOGY_FLAG_WHOLE_IO|HWLOC_TOPOLOGY_FLAG_ICACHES); + hwloc_topology_set_flags(topology, flags); hwloc_topology_load(topology); depth = hwloc_topology_get_depth(topology); @@ -176,6 +181,34 @@ int main(int argc, char *argv[]) opt = 1; goto next; } + else if (!strcmp (argv[0], "--whole-system")) { + flags |= HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM; + hwloc_topology_destroy(topology); + hwloc_topology_init(&topology); + hwloc_topology_set_flags(topology, flags); + hwloc_topology_load(topology); + depth = hwloc_topology_get_depth(topology); + goto next; + } + else if (!strcmp (argv[0], "--restrict")) { + hwloc_bitmap_t restrictset; + int err; + if (argc < 2) { + usage (callname, stdout); + exit(EXIT_FAILURE); + } + restrictset = hwloc_bitmap_alloc(); + hwloc_bitmap_sscanf(restrictset, argv[1]); + err = hwloc_topology_restrict (topology, restrictset, 0); + if (err) { + perror("Restricting the topology"); + /* fallthrough */ + } + hwloc_bitmap_free(restrictset); + argc--; + argv++; + goto next; + } fprintf (stderr, "Unrecognized option: %s\n", argv[0]); usage("hwloc-bind", stderr); diff --git a/utils/hwloc-calc.1in b/utils/hwloc-calc.1in index f137cbb3..8a6302d1 100644 --- a/utils/hwloc-calc.1in +++ b/utils/hwloc-calc.1in @@ -93,6 +93,9 @@ both formats are always accepted. \fB\-\-restrict\fR Restrict the topology to the given cpuset. .TP +\fB\-\-whole\-system\fR +Do not consider administration limitations. +.TP \fB\-i\fR , \fB\-\-input\fR Read topology from XML file (instead of discovering the topology on the local machine). If is "\-", the standard input diff --git a/utils/hwloc-calc.c b/utils/hwloc-calc.c index c13695ef..0d91a27a 100644 --- a/utils/hwloc-calc.c +++ b/utils/hwloc-calc.c @@ -45,6 +45,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where) fprintf(where, " --single Singlify the output to a single CPU\n"); fprintf(where, "Input topology options:\n"); fprintf(where, " --restrict Restrict the topology to processors listed in \n"); + fprintf(where, " --whole-system Do not consider administration limitations\n"); hwloc_utils_input_format_usage(where, 10); fprintf(where, "Miscellaneous options:\n"); fprintf(where, " -q --quiet Hide non-fatal error messages\n"); @@ -235,6 +236,11 @@ int main(int argc, char *argv[]) verbose--; goto next; } + if (!strcmp (argv[0], "--whole-system")) { + flags |= HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM; + input_changed = 1; + goto next; + } if (!strcmp(argv[0], "--help")) { usage(callname, stdout); return EXIT_SUCCESS; @@ -394,14 +400,17 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (input_changed && input) { - /* only update the input when actually using it */ + if (input_changed) { + /* flags or input was changed */ hwloc_topology_destroy(topology); hwloc_topology_init(&topology); hwloc_topology_set_flags(topology, flags); - err = hwloc_utils_enable_input_format(topology, input, input_format, verbose, callname); - if (err) - return err; + if (input) { + /* only update the input when actually using it */ + err = hwloc_utils_enable_input_format(topology, input, input_format, verbose, callname); + if (err) + return err; + } hwloc_topology_load(topology); depth = hwloc_topology_get_depth(topology); input_changed = 0; @@ -436,14 +445,17 @@ int main(int argc, char *argv[]) size_t len = HWLOC_CALC_LINE_LEN; char * line = malloc(len); - if (input_changed && input) { - /* only update the input when actually using it */ + if (input_changed) { + /* flags or input was changed */ hwloc_topology_destroy(topology); hwloc_topology_init(&topology); hwloc_topology_set_flags(topology, flags); - err = hwloc_utils_enable_input_format(topology, input, input_format, verbose, callname); - if (err) - return err; + if (input) { + /* only update the input when actually using it */ + err = hwloc_utils_enable_input_format(topology, input, input_format, verbose, callname); + if (err) + return err; + } hwloc_topology_load(topology); depth = hwloc_topology_get_depth(topology); input_changed = 0; diff --git a/utils/hwloc-distances.1in b/utils/hwloc-distances.1in index 7e3535ae..70f0eda4 100644 --- a/utils/hwloc-distances.1in +++ b/utils/hwloc-distances.1in @@ -1,5 +1,5 @@ .\" -*- nroff -*- -.\" Copyright © 2012 Inria. All rights reserved. +.\" Copyright © 2012-2013 Inria. All rights reserved. .\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved. .\" See COPYING in top-level directory. .TH HWLOC-DISTANCES "1" "#HWLOC_DATE#" "#PACKAGE_VERSION#" "#PACKAGE_NAME#" @@ -49,6 +49,9 @@ and \fBsynthetic\fR. \fB\-\-restrict\fR Restrict the topology to the given cpuset. .TP +\fB\-\-whole\-system\fR +Do not consider administration limitations. +.TP \fB\-v\fR \fB\-\-verbose\fR Verbose messages. .TP diff --git a/utils/hwloc-distances.c b/utils/hwloc-distances.c index b38e0ba4..9330e9e3 100644 --- a/utils/hwloc-distances.c +++ b/utils/hwloc-distances.c @@ -22,6 +22,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where) fprintf(where, " -p --physical Display physical object indexes\n"); fprintf(where, "Input topology options:\n"); fprintf(where, " --restrict Restrict the topology to processors listed in \n"); + fprintf(where, " --whole-system Do not consider administration limitations\n"); hwloc_utils_input_format_usage(where, 0); fprintf(where, "Miscellaneous options:\n"); fprintf(where, " -v --verbose Show verbose messages\n"); @@ -35,6 +36,7 @@ int main(int argc, char *argv[]) enum hwloc_utils_input_format input_format = HWLOC_UTILS_INPUT_DEFAULT; char *restrictstring = NULL; hwloc_topology_t topology; + unsigned long flags = 0; unsigned i, depth; int logical = 1; int verbose = 0; @@ -76,6 +78,10 @@ int main(int argc, char *argv[]) logical = 0; goto next; } + if (!strcmp (argv[0], "--whole-system")) { + flags |= HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM; + goto next; + } if (hwloc_utils_lookup_input_option(argv, argc, &opt, &input, &input_format, callname)) { @@ -113,6 +119,7 @@ int main(int argc, char *argv[]) if (err) return err; } + hwloc_topology_set_flags(topology, flags); hwloc_topology_load(topology); if (restrictstring) { diff --git a/utils/hwloc-distrib.1in b/utils/hwloc-distrib.1in index 8e4a8203..be79db25 100644 --- a/utils/hwloc-distrib.1in +++ b/utils/hwloc-distrib.1in @@ -1,5 +1,5 @@ .\" -*- nroff -*- -.\" Copyright © 2010-2012 Inria. All rights reserved. +.\" Copyright © 2010-2013 Inria. All rights reserved. .\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved. .\" See COPYING in top-level directory. .TH HWLOC-DISTRIB "1" "#HWLOC_DATE#" "#PACKAGE_VERSION#" "#PACKAGE_NAME#" @@ -71,6 +71,9 @@ both \fB\-\-from\fR and \fB\-\-to\fR at the same time. \fB\-\-restrict\fR Restrict the topology to the given cpuset. .TP +\fB\-\-whole\-system\fR +Do not consider administration limitations. +.TP \fB\-\-version\fR Report version and exit. . diff --git a/utils/hwloc-distrib.c b/utils/hwloc-distrib.c index bda82c7c..b04c15be 100644 --- a/utils/hwloc-distrib.c +++ b/utils/hwloc-distrib.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2012 Inria. All rights reserved. + * Copyright © 2009-2013 Inria. All rights reserved. * Copyright © 2009-2010 Université Bordeaux 1 * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -25,6 +25,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where) fprintf(where, " --at Distribute among objects of the given type\n"); fprintf(where, "Input topology options:\n"); fprintf(where, " --restrict Restrict the topology to processors listed in \n"); + fprintf(where, " --whole-system Do not consider administration limitations\n"); hwloc_utils_input_format_usage(where, 0); fprintf(where, "Formatting options:\n"); fprintf(where, " --single Singlify each output to a single CPU\n"); @@ -46,6 +47,7 @@ int main(int argc, char *argv[]) char *restrictstring = NULL; hwloc_obj_type_t from_type = (hwloc_obj_type_t) -1, to_type = (hwloc_obj_type_t) -1; hwloc_topology_t topology; + unsigned long flags = 0; int opt; int err; @@ -80,6 +82,10 @@ int main(int argc, char *argv[]) verbose = 1; goto next; } + if (!strcmp (argv[0], "--whole-system")) { + flags |= HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM; + goto next; + } if (!strcmp(argv[0], "--help")) { usage(callname, stdout); return EXIT_SUCCESS; @@ -194,6 +200,7 @@ int main(int argc, char *argv[]) if (err) return err; } + hwloc_topology_set_flags(topology, flags); hwloc_topology_load(topology); if (restrictstring) { -- 2.39.5