Skip to content

Commit

Permalink
utils: add support for --restrict nodeset=<nodeset>
Browse files Browse the repository at this point in the history
This was already support in lstopo --allow

Signed-off-by: Valentin Hoyet <valentin.hoyet@inria.fr>
Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
Valentin Hoyet authored and bgoglin committed Apr 27, 2020
1 parent d01d10d commit ebb6dbf
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 20 deletions.
3 changes: 3 additions & 0 deletions utils/hwloc/hwloc-bind.1in
Expand Up @@ -130,6 +130,9 @@ both formats are always accepted.
\fB\-\-restrict\fR <cpuset>
Restrict the topology to the given cpuset.
.TP
\fB\-\-restrict\fR nodeset=<nodeset>
Restrict the topology to the given nodeset, unless --restrict-flags specifies something different.
.TP
\fB\-\-disallowed\fR
Include objects disallowed by administrative limitations.
.TP
Expand Down
15 changes: 11 additions & 4 deletions utils/hwloc/hwloc-bind.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2019 Inria. All rights reserved.
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2010, 2012 Université Bordeaux
* Copyright © 2009-2018 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -51,7 +51,8 @@ void usage(const char *name, FILE *where)
fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n");
fprintf(where, "Input topology options:\n");
fprintf(where, " --no-smt Only keep a single PU per core\n");
fprintf(where, " --restrict <set> Restrict the topology to processors listed in <set>\n");
fprintf(where, " --restrict [nodeset=]<bitmap>\n");
fprintf(where, " Restrict the topology to some processors or NUMA nodes.\n");
fprintf(where, " --disallowed Include objects disallowed by administrative limitations\n");
fprintf(where, " --hbm Only consider high bandwidth memory nodes\n");
fprintf(where, " --no-hbm Ignore high-bandwidth memory nodes\n");
Expand All @@ -74,6 +75,7 @@ int main(int argc, char *argv[])
int use_nodeset = 0;
int get_last_cpu_location = 0;
unsigned long flags = 0;
unsigned long restrict_flags = 0;
int force = 0;
int single = 0;
int verbose = 0;
Expand Down Expand Up @@ -261,9 +263,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
restrictset = hwloc_bitmap_alloc();
hwloc_bitmap_sscanf(restrictset, argv[1]);
if(strncmp(argv[1], "nodeset=", 8)) {
hwloc_bitmap_sscanf(restrictset, argv[1]);
} else {
hwloc_bitmap_sscanf(restrictset, argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
ENSURE_LOADED();
err = hwloc_topology_restrict (topology, restrictset, 0);
err = hwloc_topology_restrict (topology, restrictset, restrict_flags);
if (err) {
perror("Restricting the topology");
/* FALLTHRU */
Expand Down
3 changes: 3 additions & 0 deletions utils/hwloc/hwloc-calc.1in
Expand Up @@ -118,6 +118,9 @@ both formats are always accepted.
\fB\-\-restrict\fR <cpuset>
Restrict the topology to the given cpuset.
.TP
\fB\-\-restrict\fR nodeset=<nodeset>
Restrict the topology to the given nodeset, unless --restrict-flags specifies something different.
.TP
\fB\-\-disallowed\fR
Include objects disallowed by administrative limitations.
.TP
Expand Down
14 changes: 10 additions & 4 deletions utils/hwloc/hwloc-calc.c
Expand Up @@ -47,7 +47,8 @@ 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, " --no-smt Only keep a single PU per core\n");
fprintf(where, " --restrict <cpuset> Restrict the topology to processors listed in <cpuset>\n");
fprintf(where, " --restrict [nodeset=]<bitmap>\n");
fprintf(where, " Restrict the topology to some processors or NUMA nodes.\n");
fprintf(where, " --disallowed Include objects disallowed by administrative limitations\n");
hwloc_utils_input_format_usage(where, 10);
fprintf(where, "Miscellaneous options:\n");
Expand Down Expand Up @@ -231,6 +232,7 @@ int main(int argc, char *argv[])
hwloc_topology_t topology;
int loaded = 0;
unsigned long flags = 0;
unsigned long restrict_flags = 0;
char *input = NULL;
enum hwloc_utils_input_format input_format = HWLOC_UTILS_INPUT_DEFAULT;
int depth = 0;
Expand Down Expand Up @@ -317,9 +319,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
restrictset = hwloc_bitmap_alloc();
hwloc_bitmap_sscanf(restrictset, argv[1]);
if(strncmp(argv[1], "nodeset=", 8)) {
hwloc_bitmap_sscanf(restrictset, argv[1]);
} else {
hwloc_bitmap_sscanf(restrictset, argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
ENSURE_LOADED();
err = hwloc_topology_restrict (topology, restrictset, 0);
err = hwloc_topology_restrict (topology, restrictset, restrict_flags);
if (err) {
perror("Restricting the topology");
/* FALLTHRU */
Expand Down Expand Up @@ -519,7 +526,6 @@ int main(int argc, char *argv[])
#define HWLOC_CALC_LINE_LEN 64
size_t len = HWLOC_CALC_LINE_LEN;
char * line = malloc(len);

while (1) {
char *current, *tmpline;

Expand Down
5 changes: 4 additions & 1 deletion utils/hwloc/hwloc-distrib.1in
@@ -1,5 +1,5 @@
.\" -*- nroff -*-
.\" Copyright © 2010-2018 Inria. All rights reserved.
.\" Copyright © 2010-2020 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%"
Expand Down Expand Up @@ -82,6 +82,9 @@ and singlify CPU sets by keeping the last bit (instead of the first bit).
\fB\-\-restrict\fR <cpuset>
Restrict the topology to the given cpuset.
.TP
\fB\-\-restrict\fR nodeset=<nodeset>
Restrict the topology to the given nodeset, unless --restrict-flags specifies something different.
.TP
\fB\-\-disallowed\fR
Include objects disallowed by administrative limitations.
.TP
Expand Down
15 changes: 11 additions & 4 deletions utils/hwloc/hwloc-distrib.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2019 Inria. All rights reserved.
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2010 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand All @@ -24,7 +24,8 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where)
fprintf(where, " --at <type> Distribute among objects of the given type\n");
fprintf(where, " --reverse Distribute by starting from last objects\n");
fprintf(where, "Input topology options:\n");
fprintf(where, " --restrict <set> Restrict the topology to processors listed in <set>\n");
fprintf(where, " --restrict [nodeset=]<bitmap>\n");
fprintf(where, " Restrict the topology to some processors or NUMA nodes.\n");
fprintf(where, " --disallowed Include objects disallowed by administrative limitations\n");
hwloc_utils_input_format_usage(where, 0);
fprintf(where, "Formatting options:\n");
Expand All @@ -48,6 +49,7 @@ int main(int argc, char *argv[])
const char *from_type = NULL, *to_type = NULL;
hwloc_topology_t topology;
unsigned long flags = 0;
unsigned long restrict_flags = 0;
unsigned long dflags = 0;
int opt;
int err;
Expand Down Expand Up @@ -155,7 +157,12 @@ int main(int argc, char *argv[])
usage (callname, stdout);
exit(EXIT_FAILURE);
}
restrictstring = strdup(argv[1]);
if(strncmp(argv[1], "nodeset=", 8)) {
restrictstring = strdup(argv[1]);
} else {
restrictstring = strdup(argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
argc--;
argv++;
goto next;
Expand Down Expand Up @@ -216,7 +223,7 @@ int main(int argc, char *argv[])
if (restrictstring) {
hwloc_bitmap_t restrictset = hwloc_bitmap_alloc();
hwloc_bitmap_sscanf(restrictset, restrictstring);
err = hwloc_topology_restrict (topology, restrictset, 0);
err = hwloc_topology_restrict (topology, restrictset, restrict_flags);
if (err) {
perror("Restricting the topology");
/* FALLTHRU */
Expand Down
5 changes: 4 additions & 1 deletion utils/hwloc/hwloc-info.1in
@@ -1,5 +1,5 @@
.\" -*- nroff -*-
.\" Copyright © 2009-2018 Inria. All rights reserved.
.\" Copyright © 2009-2020 Inria. All rights reserved.
.\" Copyright © 2009-2010 Université of Bordeaux
.\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
.\" See COPYING in top-level directory.
Expand Down Expand Up @@ -104,6 +104,9 @@ Include objects disallowed by administrative limitations.
\fB\-\-restrict\fR <cpuset>
Restrict the topology to the given cpuset.
.TP
\fB\-\-restrict\fR nodeset=<nodeset>
Restrict the topology to the given nodeset, unless --restrict-flags specifies something different.
.TP
\fB\-\-restrict\fR binding
Restrict the topology to the current process binding.
This option requires the use of the actual current machine topology
Expand Down
15 changes: 11 additions & 4 deletions utils/hwloc/hwloc-info.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2019 Inria. All rights reserved.
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -44,7 +44,8 @@ void usage(const char *name, FILE *where)
fprintf (where, " --descendants <type> Only display descendants of the given type\n");
fprintf (where, " -n Prefix each line with the index of the considered object\n");
fprintf (where, "Object filtering options:\n");
fprintf (where, " --restrict <cpuset> Restrict the topology to processors listed in <cpuset>\n");
fprintf (where, " --restrict [nodeset=]<bitmap>\n");
fprintf (where, " Restrict the topology to some processors or NUMA nodes.\n");
fprintf (where, " --restrict binding Restrict the topology to the current process binding\n");
fprintf (where, " --filter <type>:<knd> Filter objects of the given type, or all.\n");
fprintf (where, " <knd> may be `all' (keep all), `none' (remove all), `structure' or `important'\n");
Expand Down Expand Up @@ -339,6 +340,7 @@ main (int argc, char *argv[])
hwloc_topology_t topology;
int topodepth;
unsigned long flags = 0;
unsigned long restrict_flags = 0;
char * callname;
char * input = NULL;
enum hwloc_utils_input_format input_format = HWLOC_UTILS_INPUT_DEFAULT;
Expand Down Expand Up @@ -484,7 +486,12 @@ main (int argc, char *argv[])
usage (callname, stderr);
exit(EXIT_FAILURE);
}
restrictstring = strdup(argv[1]);
if(strncmp(argv[1], "nodeset=", 8)) {
restrictstring = strdup(argv[1]);
} else {
restrictstring = strdup(argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
opt = 1;
}

Expand Down Expand Up @@ -588,7 +595,7 @@ main (int argc, char *argv[])
} else {
hwloc_bitmap_sscanf(restrictset, restrictstring);
}
err = hwloc_topology_restrict (topology, restrictset, 0);
err = hwloc_topology_restrict (topology, restrictset, restrict_flags);
if (err) {
perror("Restricting the topology");
/* FALLTHRU */
Expand Down
3 changes: 3 additions & 0 deletions utils/lstopo/lstopo-no-graphics.1in
Expand Up @@ -203,6 +203,9 @@ inside a single physical device) are collapsed.
\fB\-\-restrict\fR <cpuset>
Restrict the topology to the given cpuset.
.TP
\fB\-\-restrict\fR nodeset=<nodeset>
Restrict the topology to the given nodeset, unless --restrict-flags specifies something different.
.TP
\fB\-\-restrict\fR binding
Restrict the topology to the current process binding.
This option requires the use of the actual current machine topology
Expand Down
10 changes: 8 additions & 2 deletions utils/lstopo/lstopo.c
Expand Up @@ -384,7 +384,8 @@ void usage(const char *name, FILE *where)
fprintf (where, " --merge Do not show levels that do not have a hierarchical\n"
" impact\n");
fprintf (where, " --no-collapse Do not collapse identical PCI devices\n");
fprintf (where, " --restrict <cpuset> Restrict the topology to processors listed in <cpuset>\n");
fprintf (where, " --restrict [nodeset=]<bitmap>\n");
fprintf (where, " Restrict the topology to some processors or NUMA nodes.\n");
fprintf (where, " --restrict binding Restrict the topology to the current process binding\n");
fprintf (where, " --restrict-flags <n> Set the flags to be used during restrict\n");
fprintf (where, " --no-io Do not show any I/O device or bridge\n");
Expand Down Expand Up @@ -914,7 +915,12 @@ main (int argc, char *argv[])
else if (!strcmp (argv[0], "--restrict")) {
if (argc < 2)
goto out_usagefailure;
restrictstring = strdup(argv[1]);
if(strncmp(argv[1], "nodeset=", 8)) {
restrictstring = strdup(argv[1]);
} else {
restrictstring = strdup(argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
opt = 1;
}
else if (!strcmp (argv[0], "--restrict-flags")) {
Expand Down

0 comments on commit ebb6dbf

Please sign in to comment.