Skip to content

Commit 4d9a984

Browse files
committed
utils/annotate: accept memory/cache size as GiB/KiB and handle GB/kB correctly
Refs #519 Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
1 parent 0bbbad5 commit 4d9a984

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

utils/hwloc/hwloc-annotate.1in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" -*- nroff -*-
2-
.\" Copyright © 2013-2021 Inria. All rights reserved.
2+
.\" Copyright © 2013-2022 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
@@ -87,7 +87,8 @@ If an empty string is given, the subtype is removed.
8787
.TP
8888
.B size <size>
8989
Specifies the size of a cache or NUMA node.
90-
The value may be suffixed with \fBkB\fR, \fBMB\fR, \fBGB\fR or \fBTB\fR.
90+
The value may be suffixed with \fBkB\fR, \fBKiB\fR, \fBMB\fR, \fBMiB\fR,
91+
\fBGB\fR, \fBGiB\fR, etc.
9192
.TP
9293
.B misc <name>
9394
Specifies a new Misc object name.

utils/hwloc/hwloc-annotate.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2012-2021 Inria. All rights reserved.
2+
* Copyright © 2012-2022 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -601,12 +601,20 @@ int main(int argc, char *argv[])
601601
sizevalue = strtoull(argv[1], &end, 0);
602602
if (end) {
603603
if (!strcasecmp(end, "kB"))
604+
sizevalue *= 1024ULL;
605+
else if (!strcasecmp(end, "kiB"))
604606
sizevalue <<= 10;
605607
else if (!strcasecmp(end, "MB"))
608+
sizevalue *= 1024ULL*1024ULL;
609+
else if (!strcasecmp(end, "MiB"))
606610
sizevalue <<= 20;
607-
if (!strcasecmp(end, "GB"))
611+
else if (!strcasecmp(end, "GB"))
612+
sizevalue *= 1024ULL*1024ULL*1024ULL;
613+
else if (!strcasecmp(end, "GiB"))
608614
sizevalue <<= 30;
609-
if (!strcasecmp(end, "TB"))
615+
else if (!strcasecmp(end, "TB"))
616+
sizevalue *= 1024ULL*1024ULL*1024ULL*1024ULL;
617+
else if (!strcasecmp(end, "TiB"))
610618
sizevalue <<= 40;
611619
}
612620

0 commit comments

Comments
 (0)