Skip to content

Commit 6acac76

Browse files
committed
utils/annotate: add the "cpukind#N" fake location to tweak cpukind infos
And document that we may also call hwloc-annotate multiple times with same cpukind parameters but different info names and values. Signed-off-by: Brice Goglin <[email protected]>
1 parent d07e4ac commit 6acac76

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

utils/hwloc/hwloc-annotate.1in

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" -*- nroff -*-
2-
.\" Copyright © 2013-2022 Inria. All rights reserved.
2+
.\" Copyright © 2013-2023 Inria. All rights reserved.
33
.\" See COPYING in top-level directory.
44
.TH HWLOC-ANNOTATE "1" "%HWLOC_DATE%" "%PACKAGE_VERSION%" "%PACKAGE_NAME%"
55
.SH NAME
@@ -80,6 +80,8 @@ This is specified by the \fImode\fR:
8080
.B info <name> <value>
8181
Specifies a new string info attribute whose name is \fIname\fR and
8282
value is \fIvalue\fR.
83+
If \fBlocation\fR is \fIcpukind#<N>\fR, operate on the info attributes
84+
of the N-th cpukind.
8385
.TP
8486
.B subtype <subtype>
8587
Specifies that the subtype attribute of the object should now be \fIsubtype\fR.
@@ -132,6 +134,10 @@ ranking of kinds. It should be -1 if unknown.
132134
If \fIinfoname\fR and \fIinfovalue\fR are given and non-empty,
133135
they are added as info attributes to this kind of CPU.
134136

137+
More info attributes may be added by applying this operating
138+
multiple times. See also the \fBinfo\fR operation above for ways
139+
to tweak info attributes using the \fIcpukind#<N>\fR location.
140+
135141
See the function hwloc_cpukinds_register() for details.
136142

137143
.TP
@@ -218,6 +224,10 @@ Only add to all Core objects:
218224

219225
$ hwloc-annotate input.xml output.xml Core:all info infoname infovalue
220226

227+
Remove all info attributes from the first cpukind:
228+
229+
$ hwloc-annotate --ci input.xml output.xml -- cpukind#0 -- none
230+
+
221231
Add a Misc object named "foobar" under the root object of the topology
222232
and modify the input XML directly:
223233

utils/hwloc/hwloc-annotate.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,22 @@ int main(int argc, char *argv[])
786786

787787
for(i=0; i<nr_locations; i++) {
788788
char *location = locations[i];
789-
if (!strcmp(location, "all")) {
789+
if (!strncmp(location, "cpukind#", 8) && (infoname || clearinfos)) {
790+
struct hwloc_infos_s *infos;
791+
int num;
792+
if (location[8] < '0' || location[8] > '9') {
793+
fprintf(stderr, "Failed to recognize number after cpukind# in location %s\n", location);
794+
goto out_with_topology;
795+
}
796+
num = atoi(location+8);
797+
err = hwloc_cpukinds_get_info(topology, num, NULL, NULL, &infos, 0);
798+
if (err < 0) {
799+
fprintf(stderr, "Failed to find cpukind#%d\n", num);
800+
goto out_with_topology;
801+
} else {
802+
apply_infos(infos);
803+
}
804+
} else if (!strcmp(location, "all")) {
790805
apply_recursive(topology, hwloc_get_root_obj(topology));
791806
} else if (!strcmp(location, "root")) {
792807
apply(topology, hwloc_get_root_obj(topology));

utils/hwloc/test-hwloc-annotate.output

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
<cpukind cpuset="0x00000008" forced_efficiency="7">
171171
<info name="foo" value="bar"/>
172172
<info name="foo2" value="bar3"/>
173+
<info name="foo3" value="bar4"/>
174+
<info name="foo4" value="bar5"/>
173175
</cpukind>
174176
<cpukind cpuset="0x00000001" forced_efficiency="4">
175177
<info name="foo2" value="bar2"/>

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

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

44
#
5-
# Copyright © 2009-2021 Inria. All rights reserved.
5+
# Copyright © 2009-2023 Inria. All rights reserved.
66
# Copyright © 2014 Cisco Systems, Inc. All rights reserved.
77
# See COPYING in top-level directory.
88
#
@@ -67,6 +67,8 @@ $annotate $file $file -- dummy -- cpukind 0x5 -1 0
6767
$annotate $file $file -- dummy -- cpukind 0xa -1 0 foo bar
6868
$annotate $file $file -- dummy -- cpukind 0x3 4 0 foo2 bar2
6969
$annotate $file $file -- dummy -- cpukind 0xc 7 0 foo2 bar3
70+
$annotate $file $file -- dummy -- cpukind 0x8 7 0 foo3 bar4
71+
$annotate $file $file -- cpukind#1 -- info foo4 bar5
7072
cat > $distances << EOF
7173
name=mynewdistances
7274
5

0 commit comments

Comments
 (0)