Skip to content

Commit

Permalink
obj_attr_snprintf: switch to KiB/MiB/GiB/TiB
Browse files Browse the repository at this point in the history
Only the displayed unit changes from KB/MB/... to KiB/MiB/...
Values were already divided by 1024 instead of 1000.

Fixes #520

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Dec 13, 2022
1 parent f2f4f06 commit 7d2aa6a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -24,6 +24,7 @@ Version 3.0.0
using object attributes to disambiguate multiple levels with same type.
- hwloc_type_sscanf_as_depth() is deprecated in favor of
hwloc_type_sscanf() followed by hwloc_get_type_depth_with_attr().
+ hwloc_obj_attr_snprintf() now displays KiB/MiB/GiB/TiB units for sizes.
+ The verbose attribute of hwloc_obj_type/attr_snprintf() is replaced
by flags, where value 1 keeps the same meaning as in hwloc 2.x.
+ PCI domains are now always 32bits.
Expand Down
9 changes: 5 additions & 4 deletions include/private/private.h
Expand Up @@ -469,14 +469,15 @@ static __hwloc_inline int hwloc_memory_size_snprintf(char *buffer, size_t bufsiz
return snprintf(buffer, bufsize, "%llu%s", ((size>>9)+1)>>1, "KB");
}

/* units 1024 */
if (size < (10ULL<<20)) {
return snprintf(buffer, bufsize, "%llu%s", ((size>>9)+1)>>1, "KB");
return snprintf(buffer, bufsize, "%llu%s", ((size>>9)+1)>>1, "KiB");
} else if (size < (10ULL<<30)) {
return snprintf(buffer, bufsize, "%llu%s", ((size>>19)+1)>>1, "MB");
return snprintf(buffer, bufsize, "%llu%s", ((size>>19)+1)>>1, "MiB");
} else if (size < (10ULL<<40)) {
return snprintf(buffer, bufsize, "%llu%s", ((size>>29)+1)>>1, "GB");
return snprintf(buffer, bufsize, "%llu%s", ((size>>29)+1)>>1, "GiB");
} else {
return snprintf(buffer, bufsize, "%llu%s", ((size>>39)+1)>>1, "TB");
return snprintf(buffer, bufsize, "%llu%s", ((size>>39)+1)>>1, "TiB");
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/hwloc/linux/4em64t-2c2t-ignore-reorder.output
@@ -1,5 +1,5 @@
Machine (3958MB total)
NUMANode P#0 (3958MB)
Machine (3958MiB total)
NUMANode P#0 (3958MiB)
PU P#0
PU P#1
PU P#2
Expand Down
24 changes: 12 additions & 12 deletions tests/hwloc/xml/16em64t-4s2c2t.console.output
@@ -1,30 +1,30 @@
Machine
NUMANode L#0 (P#0)
Package L#0 + L3 L#0 (4096KB)
L2 L#0 (1024KB) + L1d L#0 (16KB) + Core L#0
Package L#0 + L3 L#0 (4096KiB)
L2 L#0 (1024KiB) + L1d L#0 (16KiB) + Core L#0
PU L#0 (P#0)
PU L#1 (P#8)
L2 L#1 (1024KB) + L1d L#1 (16KB) + Core L#1
L2 L#1 (1024KiB) + L1d L#1 (16KiB) + Core L#1
PU L#2 (P#4)
PU L#3 (P#12)
Package L#1 + L3 L#1 (4096KB)
L2 L#2 (1024KB) + L1d L#2 (16KB) + Core L#2
Package L#1 + L3 L#1 (4096KiB)
L2 L#2 (1024KiB) + L1d L#2 (16KiB) + Core L#2
PU L#4 (P#1)
PU L#5 (P#9)
L2 L#3 (1024KB) + L1d L#3 (16KB) + Core L#3
L2 L#3 (1024KiB) + L1d L#3 (16KiB) + Core L#3
PU L#6 (P#5)
PU L#7 (P#13)
Package L#2 + L3 L#2 (4096KB)
L2 L#4 (1024KB) + L1d L#4 (16KB) + Core L#4
Package L#2 + L3 L#2 (4096KiB)
L2 L#4 (1024KiB) + L1d L#4 (16KiB) + Core L#4
PU L#8 (P#2)
PU L#9 (P#10)
L2 L#5 (1024KB) + L1d L#5 (16KB) + Core L#5
L2 L#5 (1024KiB) + L1d L#5 (16KiB) + Core L#5
PU L#10 (P#6)
PU L#11 (P#14)
Package L#3 + L3 L#3 (4096KB)
L2 L#6 (1024KB) + L1d L#6 (16KB) + Core L#6
Package L#3 + L3 L#3 (4096KiB)
L2 L#6 (1024KiB) + L1d L#6 (16KiB) + Core L#6
PU L#12 (P#3)
PU L#13 (P#11)
L2 L#7 (1024KB) + L1d L#7 (16KB) + Core L#7
L2 L#7 (1024KiB) + L1d L#7 (16KiB) + Core L#7
PU L#14 (P#7)
PU L#15 (P#15)
48 changes: 24 additions & 24 deletions utils/lstopo/test-lstopo.output
@@ -1,37 +1,37 @@
** Default output...
Machine (2048MB total) + Package L#0
Machine (2048MiB total) + Package L#0
Core L#0
NUMANode L#0 (P#0 1024MB)
L2 L#0 (4096KB)
NUMANode L#0 (P#0 1024MiB)
L2 L#0 (4096KiB)
PU L#0 (P#0)
PU L#1 (P#1)
L2 L#1 (4096KB)
L2 L#1 (4096KiB)
PU L#2 (P#2)
PU L#3 (P#3)
Core L#1
NUMANode L#1 (P#1 1024MB)
L2 L#2 (4096KB)
NUMANode L#1 (P#1 1024MiB)
L2 L#2 (4096KiB)
PU L#4 (P#4)
PU L#5 (P#5)
L2 L#3 (4096KB)
L2 L#3 (4096KiB)
PU L#6 (P#6)
PU L#7 (P#7)
** OS-index output merged...
Machine (2048MB total)
Machine (2048MiB total)
Core P#0
NUMANode P#0 (1024MB)
L2 (4096KB)
NUMANode P#0 (1024MiB)
L2 (4096KiB)
PU P#0
PU P#1
L2 (4096KB)
L2 (4096KiB)
PU P#2
PU P#3
Core P#1
NUMANode P#1 (1024MB)
L2 (4096KB)
NUMANode P#1 (1024MiB)
L2 (4096KiB)
PU P#4
PU P#5
L2 (4096KB)
L2 (4096KiB)
PU P#6
PU P#7
** Logical-index verbose output...
Expand Down Expand Up @@ -117,38 +117,38 @@ Package:1 Core:2 [NUMANode(memory=1073741824)] L2Cache:2(size=4194304) PU:2
<support name="custom.exported_support"/>
</topology>
** Restrict flag cpuless...
Machine (1024MB total)
NUMANode L#0 (P#1 1024MB)
Machine (1024MiB total)
NUMANode L#0 (P#1 1024MiB)
PU L#0 (P#4)
PU L#1 (P#5)
PU L#2 (P#6)
PU L#3 (P#7)
** Restrict flag t$,memless...
Machine (2048MB total)
Machine (2048MiB total)
Group0 L#0
NUMANode L#0 (P#0 1024MB)
NUMANode L#0 (P#0 1024MiB)
PU L#0 (P#0)
PU L#1 (P#1)
PU L#2 (P#2)
PU L#3 (P#3)
Group0 L#1
NUMANode L#1 (P#1 1024MB)
NUMANode L#1 (P#1 1024MiB)
PU L#4 (P#4)
PU L#5 (P#5)
PU L#6 (P#6)
PU L#7 (P#7)
** Restrict flag none...
Machine (4096MB total)
Machine (4096MiB total)
Group0 L#0
NUMANode L#0 (P#0 1024MB)
NUMANode L#0 (P#0 1024MiB)
PU L#0 (P#0)
PU L#1 (P#1)
Group0 L#1
NUMANode L#1 (P#3 1024MB)
NUMANode L#1 (P#3 1024MiB)
Group0 L#2
NUMANode L#2 (P#2 1024MB)
NUMANode L#2 (P#2 1024MiB)
Group0 L#3
NUMANode L#3 (P#1 1024MB)
NUMANode L#3 (P#1 1024MiB)
** Export synthetic flag extended,attrs,v1...
Group:4 NUMANode:1 PU:4
** Export XML flag v1...
Expand Down

0 comments on commit 7d2aa6a

Please sign in to comment.