Module Name:    src
Committed By:   mrg
Date:           Mon Aug 13 03:20:19 UTC 2018

Modified Files:
        src/share/man/man4: ddb.4
        src/sys/ddb: db_command.c
        src/sys/kern: kern_history.c
        src/sys/sys: kernhist.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/share/man/man4/ddb.4
cvs rdiff -u -r1.155 -r1.156 src/sys/ddb/db_command.c
cvs rdiff -u -r1.16 -r1.17 src/sys/kern/kern_history.c
cvs rdiff -u -r1.23 -r1.24 src/sys/sys/kernhist.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/ddb.4
diff -u src/share/man/man4/ddb.4:1.182 src/share/man/man4/ddb.4:1.183
--- src/share/man/man4/ddb.4:1.182	Mon Jul 30 06:18:25 2018
+++ src/share/man/man4/ddb.4	Mon Aug 13 03:20:19 2018
@@ -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 @@ is specified, all sockets are printed.
 .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 ,

Index: src/sys/ddb/db_command.c
diff -u src/sys/ddb/db_command.c:1.155 src/sys/ddb/db_command.c:1.156
--- src/sys/ddb/db_command.c:1.155	Sun Aug 12 22:05:29 2018
+++ src/sys/ddb/db_command.c	Mon Aug 13 03:20:19 2018
@@ -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_kernhist_print_cmd(db_expr_t addr, bo
     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
 

Index: src/sys/kern/kern_history.c
diff -u src/sys/kern/kern_history.c:1.16 src/sys/kern/kern_history.c:1.17
--- src/sys/kern/kern_history.c:1.16	Fri Nov  3 22:45:14 2017
+++ src/sys/kern/kern_history.c	Mon Aug 13 03:20:19 2018
@@ -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 @@ static int sysctl_kernhist_helper(SYSCTL
  * 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 @@ static void kernhist_dump_histories(stru
  * 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 @@ kernhist_dump(struct kern_history *l, vo
 }
 
 /*
- * 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 @@ restart:
 
 		/* 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 @@ kernhist_dumpmask(uint32_t bitmask)	/* X
 
 	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 @@ kernhist_print(void *addr, void (*pr)(co
 #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);
 	}
 }
 

Index: src/sys/sys/kernhist.h
diff -u src/sys/sys/kernhist.h:1.23 src/sys/sys/kernhist.h:1.24
--- src/sys/sys/kernhist.h:1.23	Thu Apr 19 21:19:07 2018
+++ src/sys/sys/kernhist.h	Mon Aug 13 03:20:19 2018
@@ -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 @@ kernhist_entry_print(const struct kern_h
 }
 
 #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);

Reply via email to