Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-10]: src/sbin/nvmectl Pull up following revision(s) (requested by...



details:   https://anonhg.NetBSD.org/src/rev/1367f5ced312
branches:  netbsd-10
changeset: 373828:1367f5ced312
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Mar 05 14:37:14 2023 +0000

description:
Pull up following revision(s) (requested by mlelstv in ticket #112):

        sbin/nvmectl/nvmectl.h: revision 1.10
        sbin/nvmectl/logpage.c: revision 1.11
        sbin/nvmectl/util.c: revision 1.3

Data units read/written are counted in 1000s of 512 bytes.

Convert to human-readable value.

diffstat:

 sbin/nvmectl/logpage.c |  10 ++++----
 sbin/nvmectl/nvmectl.h |   3 +-
 sbin/nvmectl/util.c    |  57 +++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 59 insertions(+), 11 deletions(-)

diffs (143 lines):

diff -r c7b7c8c14291 -r 1367f5ced312 sbin/nvmectl/logpage.c
--- a/sbin/nvmectl/logpage.c    Sun Mar 05 14:34:59 2023 +0000
+++ b/sbin/nvmectl/logpage.c    Sun Mar 05 14:37:14 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: logpage.c,v 1.10 2022/07/31 13:49:23 mlelstv Exp $     */
+/*     $NetBSD: logpage.c,v 1.10.2.1 2023/03/05 14:37:14 martin Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: logpage.c,v 1.10 2022/07/31 13:49:23 mlelstv Exp $");
+__RCSID("$NetBSD: logpage.c,v 1.10.2.1 2023/03/05 14:37:14 martin Exp $");
 #if 0
 __FBSDID("$FreeBSD: head/sbin/nvmecontrol/logpage.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
@@ -263,9 +263,9 @@
        printf("Percentage used:                %u\n",
            health->percentage_used);
 
-       print_bignum("Data units (512 byte) read:", health->data_units_read, "");
-       print_bignum("Data units (512 byte) written:", health->data_units_written,
-           "");
+       print_bignum1("Data units read:", health->data_units_read, "", "B", 512000);
+       print_bignum1("Data units written:", health->data_units_written,
+           "", "B", 512000);
        print_bignum("Host read commands:", health->host_read_commands, "");
        print_bignum("Host write commands:", health->host_write_commands, "");
        print_bignum("Controller busy time (minutes):", health->controller_busy_time,
diff -r c7b7c8c14291 -r 1367f5ced312 sbin/nvmectl/nvmectl.h
--- a/sbin/nvmectl/nvmectl.h    Sun Mar 05 14:34:59 2023 +0000
+++ b/sbin/nvmectl/nvmectl.h    Sun Mar 05 14:37:14 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmectl.h,v 1.9 2020/09/27 18:17:35 jdolecek Exp $     */
+/*     $NetBSD: nvmectl.h,v 1.9.6.1 2023/03/05 14:37:14 martin Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -109,6 +109,7 @@
 /* Utility Routines */
 void nvme_strvis(uint8_t *, int, const uint8_t *, int);
 void print_bignum(const char *, uint64_t v[2], const char *);
+void print_bignum1(const char *, uint64_t v[2], const char *, const char *, long);
 uint64_t le48dec(const void *);
 
 #endif /* __NVMECTL_H__ */
diff -r c7b7c8c14291 -r 1367f5ced312 sbin/nvmectl/util.c
--- a/sbin/nvmectl/util.c       Sun Mar 05 14:34:59 2023 +0000
+++ b/sbin/nvmectl/util.c       Sun Mar 05 14:37:14 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.2 2018/04/18 10:11:44 nonaka Exp $  */
+/*     $NetBSD: util.c,v 1.2.16.1 2023/03/05 14:37:14 martin Exp $     */
 
 /*-
  * Copyright (c) 2017 Netflix, Inc
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.2 2018/04/18 10:11:44 nonaka Exp $");
+__RCSID("$NetBSD: util.c,v 1.2.16.1 2023/03/05 14:37:14 martin Exp $");
 #if 0
 __FBSDID("$FreeBSD: head/sbin/nvmecontrol/util.c 320423 2017-06-27 20:24:25Z imp $");
 #endif
@@ -84,10 +84,47 @@
 #define        METRIX_PREFIX_BUFSIZ    17
 #define        NO_METRIX_PREFIX_BUFSIZ 42
 
+static void
+unit_string(BIGNUM *bn, const char *unit, long scale, char *out, size_t len)
+{
+       size_t ulen = strlen(unit);
+       uint8_t tmp[4];
+       BN_CTX *ctx;
+       BIGNUM *sn;
+
+       if (6 + ulen + 3 >= len)
+               return;
+
+       if (scale > 1) {
+               ctx = BN_CTX_new();
+               if (ctx == NULL)
+                       return;
+
+               tmp[0] = (scale >> 24) & 0xff;
+               tmp[1] = (scale >> 16) & 0xff;
+               tmp[2] = (scale >>  8) & 0xff;
+               tmp[3] = scale & 0xff;
+
+               sn = BN_bin2bn(tmp, sizeof(tmp), NULL);
+               if (sn != NULL) {
+                       BN_mul(bn, bn, sn, ctx);
+                       BN_free(sn);
+               }       
+
+               BN_CTX_free(ctx);
+       }
+
+       strncpy(out, " (", len);
+       humanize_bignum(out+2, 6 + ulen, bn, unit, HN_AUTOSCALE, HN_DECIMAL);
+       strncat(out, ")", len);
+}
+
 void
-print_bignum(const char *title, uint64_t v[2], const char *suffix)
+print_bignum1(const char *title, uint64_t v[2], const char *suffix,
+    const char *unit, long scale)
 {
        char buf[64];
+       char buf2[64];
        uint8_t tmp[16];
        uint64_t h, l;
 
@@ -119,15 +156,25 @@
 #endif
 
        buf[0] = '\0';
+       buf2[0] = '\0';
+
        BIGNUM *bn = BN_bin2bn(tmp, sizeof(tmp), NULL);
        if (bn != NULL) {
                humanize_bignum(buf, METRIX_PREFIX_BUFSIZ + strlen(suffix),
-                   bn, suffix, HN_AUTOSCALE, HN_DECIMAL);
+                   bn, suffix, HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE);
+               if (unit)
+                       unit_string(bn, unit, scale, buf2, sizeof(buf2));
                BN_free(bn);
        }
        if (buf[0] == '\0')
                snprintf(buf, sizeof(buf), "0x%016" PRIx64 "%016" PRIx64, h, l);
-       printf("%-31s %s\n", title, buf);
+       printf("%-31s %s%s\n", title, buf, buf2);
+}
+
+void
+print_bignum(const char *title, uint64_t v[2], const char *suffix)
+{
+       print_bignum1(title, v, suffix, NULL, 1);
 }
 
 /* "Missing" from endian.h */



Home | Main Index | Thread Index | Old Index