Source-Changes-HG archive

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

[src/trunk]: src extend the ddb "show kernhist" command. the synopsis is now:



details:   https://anonhg.NetBSD.org/src/rev/de0491f27ac1
branches:  trunk
changeset: 363839:de0491f27ac1
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Aug 13 03:20:19 2018 +0000

description:
extend the ddb "show kernhist" command.  the synopsis is now:

     show kernhist[/i] [addr[,count]]

the i modifier means display info instead of entries, and the count
restricts to the last count entries.

the count option is only supported for specified histories.  it
could be extended but requires more logic than the single history,
as multiple histories are merged during display.

diffstat:

 share/man/man4/ddb.4    |  18 +++++++++++++--
 sys/ddb/db_command.c    |   6 ++--
 sys/kern/kern_history.c |  53 +++++++++++++++++++++++++++++++++++++-----------
 sys/sys/kernhist.h      |   6 ++--
 4 files changed, 62 insertions(+), 21 deletions(-)

diffs (213 lines):

diff -r 5eca45094f3b -r de0491f27ac1 share/man/man4/ddb.4
--- a/share/man/man4/ddb.4      Sun Aug 12 22:05:29 2018 +0000
+++ b/share/man/man4/ddb.4      Mon Aug 13 03:20:19 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ddb.4,v 1.182 2018/07/30 06:18:25 ryo Exp $
+.\"    $NetBSD: ddb.4,v 1.183 2018/08/13 03:20:19 mrg Exp $
 .\"
 .\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -56,7 +56,7 @@
 .\" any improvements or extensions that they make and grant Carnegie Mellon
 .\" the rights to redistribute these changes.
 .\"
-.Dd July 30, 2018
+.Dd August 12, 2018
 .Dt DDB 4
 .Os
 .Sh NAME
@@ -771,9 +771,21 @@
 .El
 .It Ic show uvmexp
 Print a selection of UVM counters and statistics.
-.It Ic show kernhist Oo Ar addr Oc
+.It Ic show kernhist Ns Oo Cm /i Oc Oo Ar addr Ns Oo , Ns Ar count Oc Oc
 Dumps all the kernel histories if no address is specified, or the history
 at the address.
+If
+.Cm /i
+is specified, display information about the named history or all histories,
+instead of history entries.
+If
+.Ar count
+is specified, only the last
+.Ar count
+entries will be displayed.
+Currently the
+.Ar count
+handling is only performed if a single history is requested.
 This command is available only if a kernel is compiled with one or more
 of the kernel history options
 .Cd KERNHIST ,
diff -r 5eca45094f3b -r de0491f27ac1 sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Sun Aug 12 22:05:29 2018 +0000
+++ b/sys/ddb/db_command.c      Mon Aug 13 03:20:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.155 2018/08/12 22:05:29 mrg Exp $     */
+/*     $NetBSD: db_command.c,v 1.156 2018/08/13 03:20:19 mrg Exp $     */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.155 2018/08/12 22:05:29 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.156 2018/08/13 03:20:19 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -1232,7 +1232,7 @@
     db_expr_t count, const char *modif)
 {
 
-       kernhist_print((void *)(uintptr_t)addr, db_printf);
+       kernhist_print((void *)(uintptr_t)addr, count, modif, db_printf);
 }
 #endif
 
diff -r 5eca45094f3b -r de0491f27ac1 sys/kern/kern_history.c
--- a/sys/kern/kern_history.c   Sun Aug 12 22:05:29 2018 +0000
+++ b/sys/kern/kern_history.c   Mon Aug 13 03:20:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_history.c,v 1.16 2017/11/03 22:45:14 pgoyette Exp $        */
+/*     $NetBSD: kern_history.c,v 1.17 2018/08/13 03:20:19 mrg Exp $     */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.16 2017/11/03 22:45:14 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.17 2018/08/13 03:20:19 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kernhist.h"
@@ -92,12 +92,22 @@
  * prototypes
  */
 
-void kernhist_dump(struct kern_history *,
+void kernhist_dump(struct kern_history *, size_t count,
     void (*)(const char *, ...) __printflike(1, 2));
+static void kernhist_info(struct kern_history *,
+    void (*)(const char *, ...));
 void kernhist_dumpmask(uint32_t);
-static void kernhist_dump_histories(struct kern_history *[],
+static void kernhist_dump_histories(struct kern_history *[], size_t count,
     void (*)(const char *, ...) __printflike(1, 2));
 
+/* display info about one kernhist */
+static void
+kernhist_info(struct kern_history *l, void (*pr)(const char *, ...))
+{
+
+       pr("kernhist '%s': at %p total %u next free %u\n",
+           l->name, l, l->n, l->f);
+}
 
 /*
  * call this from ddb
@@ -105,11 +115,17 @@
  * expects the system to be quiesced, no locking
  */
 void
-kernhist_dump(struct kern_history *l, void (*pr)(const char *, ...))
+kernhist_dump(struct kern_history *l, size_t count,
+    void (*pr)(const char *, ...))
 {
        int lcv;
 
        lcv = l->f;
+       if (count > l->n)
+               pr("%s: count %zu > size %u\n", __func__, count, l->n);
+       else if (count)
+               lcv = (lcv - count) % l->n;
+
        do {
                if (l->e[lcv].fmt)
                        kernhist_entry_print(&l->e[lcv], pr);
@@ -118,10 +134,11 @@
 }
 
 /*
- * print a merged list of kern_history structures
+ * print a merged list of kern_history structures.  count is unused so far.
  */
 static void
-kernhist_dump_histories(struct kern_history *hists[], void (*pr)(const char *, ...))
+kernhist_dump_histories(struct kern_history *hists[], size_t count,
+    void (*pr)(const char *, ...))
 {
        struct bintime  bt;
        int     cur[MAXHISTS];
@@ -178,6 +195,7 @@
 
                /* print and move to the next entry */
                kernhist_entry_print(&hists[hi]->e[cur[hi]], pr);
+
                cur[hi] = (cur[hi] + 1) % (hists[hi]->n);
                if (cur[hi] == hists[hi]->f)
                        cur[hi] = -1;
@@ -227,14 +245,15 @@
 
        hists[i] = NULL;
 
-       kernhist_dump_histories(hists, printf);
+       kernhist_dump_histories(hists, 0, printf);
 }
 
 /*
- * kernhist_print: ddb hook to print kern history
+ * kernhist_print: ddb hook to print kern history.
  */
 void
-kernhist_print(void *addr, void (*pr)(const char *, ...) __printflike(1,2))
+kernhist_print(void *addr, size_t count, const char *modif,
+    void (*pr)(const char *, ...) __printflike(1,2))
 {
        struct kern_history *h;
 
@@ -264,9 +283,19 @@
 #endif
                hists[i] = NULL;
 
-               kernhist_dump_histories(hists, pr);
+               if (*modif == 'i') {
+                       int lcv;
+
+                       for (lcv = 0; hists[lcv]; lcv++)
+                               kernhist_info(hists[lcv], pr);
+               } else {
+                       kernhist_dump_histories(hists, count, pr);
+               }
        } else {
-               kernhist_dump(h, pr);
+               if (*modif == 'i')
+                       kernhist_info(h, pr);
+               else
+                       kernhist_dump(h, count, pr);
        }
 }
 
diff -r 5eca45094f3b -r de0491f27ac1 sys/sys/kernhist.h
--- a/sys/sys/kernhist.h        Sun Aug 12 22:05:29 2018 +0000
+++ b/sys/sys/kernhist.h        Mon Aug 13 03:20:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernhist.h,v 1.23 2018/04/19 21:19:07 christos Exp $   */
+/*     $NetBSD: kernhist.h,v 1.24 2018/08/13 03:20:19 mrg Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -270,8 +270,8 @@
 }
 
 #if defined(DDB)
-void   kernhist_dump(struct kern_history *, void (*)(const char *, ...) __printflike(1, 2));
-void   kernhist_print(void *, void (*)(const char *, ...) __printflike(1, 2));
+void   kernhist_dump(struct kern_history *, size_t, void (*)(const char *, ...) __printflike(1, 2));
+void   kernhist_print(void *, size_t, const char *, void (*)(const char *, ...) __printflike(1, 2));
 #endif /* DDB */
 
 void sysctl_kernhist_init(void);



Home | Main Index | Thread Index | Old Index