Skip to content

Commit d0672c5

Browse files
bgoglinndenoyelle
authored andcommitted
utils/calc+bind: add --no-smt to keep a single PU per core
Signed-off-by: Brice Goglin <[email protected]>
1 parent 2a6c598 commit d0672c5

File tree

7 files changed

+65
-3
lines changed

7 files changed

+65
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Version 2.1.0
9393
See dynamic_SVG_example.html for an example.
9494
+ Add --nodeset options to hwloc-calc for converting between cpusets and
9595
nodesets.
96+
+ Add --no-smt to hwloc-bind and hwloc-calc to ignore multiple
97+
PU in SMT cores.
9698
+ hwloc-annotate may annotate multiple locations at once.
9799
+ Add a HTML/JS version of hwloc-ps. See contrib/hwloc-ps.www/README.
98100
+ Add bash completions.

utils/hwloc/hwloc-bind.1in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" -*- nroff -*-
2-
.\" Copyright © 2009-2018 Inria. All rights reserved.
2+
.\" Copyright © 2009-2019 Inria. All rights reserved.
33
.\" Copyright © 2010 Université of Bordeaux
44
.\" Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
55
.\" See COPYING in top-level directory.
@@ -97,6 +97,9 @@ No location may be given since no binding is performed.
9797
\fB\-\-single\fR
9898
Bind on a single CPU to prevent migration.
9999
.TP
100+
\fB\-\-no\-smt\fR
101+
Only keep a single PU per core before binding.
102+
.TP
100103
\fB\-\-strict\fR
101104
Require strict binding.
102105
.TP

utils/hwloc/hwloc-bind.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void usage(const char *name, FILE *where)
5050
#endif
5151
fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n");
5252
fprintf(where, "Input topology options:\n");
53+
fprintf(where, " --no-smt Only keep a single PU per core\n");
5354
fprintf(where, " --restrict <set> Restrict the topology to processors listed in <set>\n");
5455
fprintf(where, " --disallowed Include objects disallowed by administrative limitations\n");
5556
fprintf(where, " --hbm Only consider high bandwidth memory nodes\n");
@@ -76,6 +77,7 @@ int main(int argc, char *argv[])
7677
int force = 0;
7778
int single = 0;
7879
int verbose = 0;
80+
int no_smt = 0;
7981
int only_hbm = -1;
8082
int logical = 1;
8183
int taskset = 0;
@@ -142,6 +144,10 @@ int main(int argc, char *argv[])
142144
single = 1;
143145
goto next;
144146
}
147+
if (!strcmp(argv[0], "--no-smt")) {
148+
no_smt = 1;
149+
goto next;
150+
}
145151
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--force")) {
146152
force = 1;
147153
goto next;
@@ -448,6 +454,11 @@ int main(int argc, char *argv[])
448454
fprintf(stderr, "--mempolicy ignored unless memory binding is also requested with --membind.\n");
449455
}
450456

457+
if (!got_cpubind && no_smt) {
458+
hwloc_bitmap_copy(cpubind_set, hwloc_topology_get_topology_cpuset(topology));
459+
got_cpubind = 1;
460+
}
461+
451462
if (got_cpubind) {
452463
if (hwloc_bitmap_iszero(cpubind_set)) {
453464
if (verbose >= 0)
@@ -466,6 +477,23 @@ int main(int argc, char *argv[])
466477
fprintf(stderr, "Conflicting CPU and memory binding requested, adding HWLOC_CPUBIND_NOMEMBIND flag.\n");
467478
cpubind_flags |= HWLOC_CPUBIND_NOMEMBIND;
468479
}
480+
if (no_smt) {
481+
if (hwloc_get_type_depth(topology, HWLOC_OBJ_CORE) == HWLOC_TYPE_DEPTH_UNKNOWN) {
482+
fprintf(stderr, "Topology has no Core object, ignoring --no-smt\n");
483+
} else {
484+
hwloc_obj_t core = NULL;
485+
while ((core = hwloc_get_next_obj_covering_cpuset_by_type(topology, cpubind_set, HWLOC_OBJ_CORE, core)) != NULL) {
486+
int firstpu = hwloc_bitmap_first(core->cpuset);
487+
int hadpu = hwloc_bitmap_isset(cpubind_set, firstpu);
488+
assert(firstpu >= 0);
489+
/* remove the entire core */
490+
hwloc_bitmap_andnot(cpubind_set, cpubind_set, core->cpuset);
491+
/* put back its first PU if it was there */
492+
if (hadpu)
493+
hwloc_bitmap_set(cpubind_set, firstpu);
494+
}
495+
}
496+
}
469497
if (single)
470498
hwloc_bitmap_singlify(cpubind_set);
471499
if (pid_number > 0)

utils/hwloc/hwloc-calc.1in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" -*- nroff -*-
2-
.\" Copyright © 2010-2018 Inria. All rights reserved.
2+
.\" Copyright © 2010-2019 Inria. All rights reserved.
33
.\" Copyright © 2009 Cisco Systems, Inc. All rights reserved.
44
.\" See COPYING in top-level directory.
55
.TH HWLOC-CALC "1" "%HWLOC_DATE%" "%PACKAGE_VERSION%" "%PACKAGE_NAME%"
@@ -93,6 +93,9 @@ while a comma is used to separate indexes
9393
\fB\-\-single\fR
9494
Singlify the output to a single CPU.
9595
.TP
96+
\fB\-\-no\-smt\fR
97+
Only keep a single PU per core in the input locations.
98+
.TP
9699
\fB\-\-taskset\fR
97100
Display CPU set strings in the format recognized by the taskset command-line
98101
program instead of hwloc-specific CPU set string format.

utils/hwloc/hwloc-calc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where)
4646
fprintf(where, " --taskset Use taskset-specific format when displaying cpuset strings\n");
4747
fprintf(where, " --single Singlify the output to a single CPU\n");
4848
fprintf(where, "Input topology options:\n");
49+
fprintf(where, " --no-smt Only keep a single PU per core\n");
4950
fprintf(where, " --restrict <cpuset> Restrict the topology to processors listed in <cpuset>\n");
5051
fprintf(where, " --disallowed Include objects disallowed by administrative limitations\n");
5152
hwloc_utils_input_format_usage(where, 10);
@@ -65,6 +66,7 @@ static int intersectdepth = -1;
6566
static int hiernblevels = 0;
6667
static int *hierdepth = NULL;
6768
static int showobjs = 0;
69+
static int no_smt = 0;
6870
static int singlify = 0;
6971
static int taskset = 0;
7072

@@ -101,6 +103,24 @@ hwloc_calc_hierarch_output(hwloc_topology_t topology, const char *prefix, const
101103
static int
102104
hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set)
103105
{
106+
if (no_smt) {
107+
if (hwloc_get_type_depth(topology, HWLOC_OBJ_CORE) == HWLOC_TYPE_DEPTH_UNKNOWN) {
108+
fprintf(stderr, "Topology has no Core object, ignoring --no-smt\n");
109+
} else {
110+
hwloc_obj_t core = NULL;
111+
while ((core = hwloc_get_next_obj_covering_cpuset_by_type(topology, set, HWLOC_OBJ_CORE, core)) != NULL) {
112+
int firstpu = hwloc_bitmap_first(core->cpuset);
113+
int hadpu = hwloc_bitmap_isset(set, firstpu);
114+
assert(firstpu >= 0);
115+
/* remove the entire core */
116+
hwloc_bitmap_andnot(set, set, core->cpuset);
117+
/* put back its first PU if it was there */
118+
if (hadpu)
119+
hwloc_bitmap_set(set, firstpu);
120+
}
121+
}
122+
}
123+
104124
if (singlify)
105125
hwloc_bitmap_singlify(set);
106126

@@ -267,6 +287,10 @@ int main(int argc, char *argv[])
267287
usage(callname, stdout);
268288
return EXIT_SUCCESS;
269289
}
290+
if (!strcmp (argv[0], "--no-smt")) {
291+
no_smt = 1;
292+
goto next;
293+
}
270294
if (!strcmp (argv[0], "--restrict")) {
271295
hwloc_bitmap_t restrictset;
272296
if (argc < 2) {

utils/hwloc/test-hwloc-calc.output

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
0xffffffffffffffff
33

44
0x0000000f
5+
0x11111111,0x0
56
0x00000f0c
67
0x0000800a
78

utils/hwloc/test-hwloc-calc.sh.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

0 commit comments

Comments
 (0)