|
Jeff Moyer |
2c91dc |
From e8b5b191a55b7be671abf2c6d5d10db6edd8c1fb Mon Sep 17 00:00:00 2001
|
|
Jeff Moyer |
2c91dc |
From: Dan Williams <dan.j.williams@intel.com>
|
|
Jeff Moyer |
2c91dc |
Date: Thu, 28 Apr 2022 15:10:16 -0700
|
|
Jeff Moyer |
2c91dc |
Subject: [PATCH 157/217] util: Pretty print terabytes
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
CXL capacities are such that gigabytes are too small of a unit for
|
|
Jeff Moyer |
2c91dc |
displaying capacities. Add terabyte support to the display_size()
|
|
Jeff Moyer |
2c91dc |
helper.
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
Link: https://lore.kernel.org/r/165118381648.1676208.1686584406206186723.stgit@dwillia2-desk3.amr.corp.intel.com
|
|
Jeff Moyer |
2c91dc |
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
|
|
Jeff Moyer |
2c91dc |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
Jeff Moyer |
2c91dc |
---
|
|
Jeff Moyer |
2c91dc |
util/json.c | 15 +++++++++++++--
|
|
Jeff Moyer |
2c91dc |
1 file changed, 13 insertions(+), 2 deletions(-)
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
diff --git a/util/json.c b/util/json.c
|
|
Jeff Moyer |
2c91dc |
index ebdf8d9..1d5c6bc 100644
|
|
Jeff Moyer |
2c91dc |
--- a/util/json.c
|
|
Jeff Moyer |
2c91dc |
+++ b/util/json.c
|
|
Jeff Moyer |
2c91dc |
@@ -37,11 +37,16 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
c = snprintf(buf, sizeof(buf), "\"%ld.%02ld MiB",
|
|
Jeff Moyer |
2c91dc |
cMiB/100 , cMiB % 100);
|
|
Jeff Moyer |
2c91dc |
- } else {
|
|
Jeff Moyer |
2c91dc |
+ } else if (bytes < 2*SZ_1T) {
|
|
Jeff Moyer |
2c91dc |
long cGiB = (bytes * 200LL / SZ_1G+1) /2;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
c = snprintf(buf, sizeof(buf), "\"%ld.%02ld GiB",
|
|
Jeff Moyer |
2c91dc |
cGiB/100 , cGiB % 100);
|
|
Jeff Moyer |
2c91dc |
+ } else {
|
|
Jeff Moyer |
2c91dc |
+ long cTiB = (bytes * 200LL / SZ_1T+1) /2;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ c = snprintf(buf, sizeof(buf), "\"%ld.%02ld TiB",
|
|
Jeff Moyer |
2c91dc |
+ cTiB/100 , cTiB % 100);
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
/* JEDEC */
|
|
Jeff Moyer |
2c91dc |
@@ -50,12 +55,18 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld MB)\"",
|
|
Jeff Moyer |
2c91dc |
cMB/100, cMB % 100);
|
|
Jeff Moyer |
2c91dc |
- } else {
|
|
Jeff Moyer |
2c91dc |
+ } else if (bytes < 2*SZ_1T) {
|
|
Jeff Moyer |
2c91dc |
long cGB = (bytes / (1000000000LL/200LL) + 1) / 2;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld GB)\"",
|
|
Jeff Moyer |
2c91dc |
cGB/100 , cGB % 100);
|
|
Jeff Moyer |
2c91dc |
+ } else {
|
|
Jeff Moyer |
2c91dc |
+ long cTB = (bytes / (1000000000000LL/200LL) + 1) / 2;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld TB)\"",
|
|
Jeff Moyer |
2c91dc |
+ cTB/100 , cTB % 100);
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
return printbuf_memappend(pbuf, buf, strlen(buf));
|
|
Jeff Moyer |
2c91dc |
--
|
|
Jeff Moyer |
2c91dc |
2.27.0
|
|
Jeff Moyer |
2c91dc |
|