Skip to content

Commit

Permalink
utils/calc+bind: add --no-smt to keep a single PU per core
Browse files Browse the repository at this point in the history
Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Aug 6, 2019
1 parent 9c84686 commit d7c395a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -93,6 +93,8 @@ Version 2.1.0
See dynamic_SVG_example.html for an example.
+ Add --nodeset options to hwloc-calc for converting between cpusets and
nodesets.
+ Add --no-smt to hwloc-bind and hwloc-calc to ignore multiple
PU in SMT cores.
+ hwloc-annotate may annotate multiple locations at once.
+ Add a HTML/JS version of hwloc-ps. See contrib/hwloc-ps.www/README.
+ Add bash completions.
Expand Down
5 changes: 4 additions & 1 deletion utils/hwloc/hwloc-bind.1in
@@ -1,5 +1,5 @@
.\" -*- nroff -*-
.\" Copyright © 2009-2018 Inria. All rights reserved.
.\" Copyright © 2009-2019 Inria. All rights reserved.
.\" Copyright © 2010 Université of Bordeaux
.\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
.\" See COPYING in top-level directory.
Expand Down Expand Up @@ -97,6 +97,9 @@ No location may be given since no binding is performed.
\fB\-\-single\fR
Bind on a single CPU to prevent migration.
.TP
\fB\-\-no\-smt\fR
Only keep a single PU per core before binding.
.TP
\fB\-\-strict\fR
Require strict binding.
.TP
Expand Down
28 changes: 28 additions & 0 deletions utils/hwloc/hwloc-bind.c
Expand Up @@ -50,6 +50,7 @@ void usage(const char *name, FILE *where)
#endif
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, " --disallowed Include objects disallowed by administrative limitations\n");
fprintf(where, " --hbm Only consider high bandwidth memory nodes\n");
Expand All @@ -76,6 +77,7 @@ int main(int argc, char *argv[])
int force = 0;
int single = 0;
int verbose = 0;
int no_smt = 0;
int only_hbm = -1;
int logical = 1;
int taskset = 0;
Expand Down Expand Up @@ -142,6 +144,10 @@ int main(int argc, char *argv[])
single = 1;
goto next;
}
if (!strcmp(argv[0], "--no-smt")) {
no_smt = 1;
goto next;
}
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--force")) {
force = 1;
goto next;
Expand Down Expand Up @@ -448,6 +454,11 @@ int main(int argc, char *argv[])
fprintf(stderr, "--mempolicy ignored unless memory binding is also requested with --membind.\n");
}

if (!got_cpubind && no_smt) {
hwloc_bitmap_copy(cpubind_set, hwloc_topology_get_topology_cpuset(topology));
got_cpubind = 1;
}

if (got_cpubind) {
if (hwloc_bitmap_iszero(cpubind_set)) {
if (verbose >= 0)
Expand All @@ -466,6 +477,23 @@ int main(int argc, char *argv[])
fprintf(stderr, "Conflicting CPU and memory binding requested, adding HWLOC_CPUBIND_NOMEMBIND flag.\n");
cpubind_flags |= HWLOC_CPUBIND_NOMEMBIND;
}
if (no_smt) {
if (hwloc_get_type_depth(topology, HWLOC_OBJ_CORE) == HWLOC_TYPE_DEPTH_UNKNOWN) {
fprintf(stderr, "Topology has no Core object, ignoring --no-smt\n");
} else {
hwloc_obj_t core = NULL;
while ((core = hwloc_get_next_obj_covering_cpuset_by_type(topology, cpubind_set, HWLOC_OBJ_CORE, core)) != NULL) {
int firstpu = hwloc_bitmap_first(core->cpuset);
int hadpu = hwloc_bitmap_isset(cpubind_set, firstpu);
assert(firstpu >= 0);
/* remove the entire core */
hwloc_bitmap_andnot(cpubind_set, cpubind_set, core->cpuset);
/* put back its first PU if it was there */
if (hadpu)
hwloc_bitmap_set(cpubind_set, firstpu);
}
}
}
if (single)
hwloc_bitmap_singlify(cpubind_set);
if (pid_number > 0)
Expand Down
5 changes: 4 additions & 1 deletion utils/hwloc/hwloc-calc.1in
@@ -1,5 +1,5 @@
.\" -*- nroff -*-
.\" Copyright © 2010-2018 Inria. All rights reserved.
.\" Copyright © 2010-2019 Inria. All rights reserved.
.\" Copyright © 2009 Cisco Systems, Inc. All rights reserved.
.\" See COPYING in top-level directory.
.TH HWLOC-CALC "1" "%HWLOC_DATE%" "%PACKAGE_VERSION%" "%PACKAGE_NAME%"
Expand Down Expand Up @@ -93,6 +93,9 @@ while a comma is used to separate indexes
\fB\-\-single\fR
Singlify the output to a single CPU.
.TP
\fB\-\-no\-smt\fR
Only keep a single PU per core in the input locations.
.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.
Expand Down
24 changes: 24 additions & 0 deletions utils/hwloc/hwloc-calc.c
Expand Up @@ -46,6 +46,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where)
fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n");
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, " --disallowed Include objects disallowed by administrative limitations\n");
hwloc_utils_input_format_usage(where, 10);
Expand All @@ -65,6 +66,7 @@ static int intersectdepth = -1;
static int hiernblevels = 0;
static int *hierdepth = NULL;
static int showobjs = 0;
static int no_smt = 0;
static int singlify = 0;
static int taskset = 0;

Expand Down Expand Up @@ -101,6 +103,24 @@ hwloc_calc_hierarch_output(hwloc_topology_t topology, const char *prefix, const
static int
hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set)
{
if (no_smt) {
if (hwloc_get_type_depth(topology, HWLOC_OBJ_CORE) == HWLOC_TYPE_DEPTH_UNKNOWN) {
fprintf(stderr, "Topology has no Core object, ignoring --no-smt\n");
} else {
hwloc_obj_t core = NULL;
while ((core = hwloc_get_next_obj_covering_cpuset_by_type(topology, set, HWLOC_OBJ_CORE, core)) != NULL) {
int firstpu = hwloc_bitmap_first(core->cpuset);
int hadpu = hwloc_bitmap_isset(set, firstpu);
assert(firstpu >= 0);
/* remove the entire core */
hwloc_bitmap_andnot(set, set, core->cpuset);
/* put back its first PU if it was there */
if (hadpu)
hwloc_bitmap_set(set, firstpu);
}
}
}

if (singlify)
hwloc_bitmap_singlify(set);

Expand Down Expand Up @@ -267,6 +287,10 @@ int main(int argc, char *argv[])
usage(callname, stdout);
return EXIT_SUCCESS;
}
if (!strcmp (argv[0], "--no-smt")) {
no_smt = 1;
goto next;
}
if (!strcmp (argv[0], "--restrict")) {
hwloc_bitmap_t restrictset;
if (argc < 2) {
Expand Down
1 change: 1 addition & 0 deletions utils/hwloc/test-hwloc-calc.output
Expand Up @@ -2,6 +2,7 @@
0xffffffffffffffff

0x0000000f
0x11111111,0x0
0x00000f0c
0x0000800a

Expand Down
3 changes: 2 additions & 1 deletion utils/hwloc/test-hwloc-calc.sh.in
Expand Up @@ -3,7 +3,7 @@

#
# Copyright © 2009 CNRS
# Copyright © 2009-2018 Inria. All rights reserved.
# Copyright © 2009-2019 Inria. All rights reserved.
# Copyright © 2009, 2011 Université Bordeaux
# Copyright © 2014 Cisco Systems, Inc. All rights reserved.
# See COPYING in top-level directory.
Expand Down Expand Up @@ -40,6 +40,7 @@ set -e
$calc --if synthetic --input "node:4 core:4 pu:4" all --taskset
echo
$calc --if synthetic --input "node:4 core:4 pu:4" 0xf
$calc --if synthetic --input "node:4 core:4 pu:4" --no-smt node:2-3
$calc --if synthetic --input "node:4 core:4 pu:4" 0xf ~0x3 0xff0 '^0xf0'
$calc --if synthetic --input "node:4 core:4 pu:4" core:0 pu:15 ~pu:0 '^pu:2'
echo
Expand Down

0 comments on commit d7c395a

Please sign in to comment.