All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: vishal.l.verma@intel.com
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Subject: [ndctl PATCH 03/10] util: Pretty print terabytes
Date: Thu, 28 Apr 2022 15:10:16 -0700	[thread overview]
Message-ID: <165118381648.1676208.1686584406206186723.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <165118380037.1676208.7644295506592461996.stgit@dwillia2-desk3.amr.corp.intel.com>

CXL capacities are such that gigabytes are too small of a unit for
displaying capacities. Add terabyte support to the display_size()
helper.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/json.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/util/json.c b/util/json.c
index ebdf8d9eedd9..1d5c6bc7822e 100644
--- a/util/json.c
+++ b/util/json.c
@@ -37,11 +37,16 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
 
 			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld MiB",
 					cMiB/100 , cMiB % 100);
-		} else {
+		} else if (bytes < 2*SZ_1T) {
 			long cGiB = (bytes * 200LL / SZ_1G+1) /2;
 
 			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld GiB",
 					cGiB/100 , cGiB % 100);
+		} else {
+			long cTiB = (bytes * 200LL / SZ_1T+1) /2;
+
+			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld TiB",
+					cTiB/100 , cTiB % 100);
 		}
 
 		/* JEDEC */
@@ -50,12 +55,18 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
 
 			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld MB)\"",
 					cMB/100, cMB % 100);
-		} else {
+		} else if (bytes < 2*SZ_1T) {
 			long cGB  = (bytes / (1000000000LL/200LL) + 1) / 2;
 
 			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld GB)\"",
 					cGB/100 , cGB % 100);
+		} else {
+			long cTB  = (bytes / (1000000000000LL/200LL) + 1) / 2;
+
+			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld TB)\"",
+					cTB/100 , cTB % 100);
 		}
+
 	}
 
 	return printbuf_memappend(pbuf, buf, strlen(buf));


  parent reply	other threads:[~2022-04-28 22:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 22:10 [ndctl PATCH 00/10] CXL topology unit test Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 01/10] build: Move utility helpers to libutil.a Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 02/10] util: Use SZ_ size macros in display size Dan Williams
2022-04-28 22:10 ` Dan Williams [this message]
2022-04-28 22:10 ` [ndctl PATCH 04/10] cxl/port: Fix disable-port man page Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 05/10] cxl/bus: Add bus disable support Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 06/10] cxl/list: Auto-enable 'single' mode for port listings Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 07/10] cxl/memdev: Fix bus_invalidate() crash Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 08/10] cxl/list: Add support for filtering by host identifiers Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 09/10] cxl/port: Relax port identifier validation Dan Williams
2022-04-28 22:10 ` [ndctl PATCH 10/10] cxl/test: Add topology enumeration and hotplug test Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165118381648.1676208.1686584406206186723.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.