Module Name:    src
Committed By:   pgoyette
Date:           Thu Jan  5 03:40:33 UTC 2017

Modified Files:
        src/sys/kern: kern_history.c
        src/sys/sys: kernhist.h param.h

Log Message:
By popular demand, update kernhist to use bintime(9) as the basis for
its timestamps.

As this changes storage structures for data passed between kernel and
userland, welcome to 7.99.55!

XXX Output routines still use microsecond resolution when printf()ing.

XXX Possible future feature would be addition of option to use
XXX getbintime(9) for less time-critical histories.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/kern/kern_history.c
cvs rdiff -u -r1.16 -r1.17 src/sys/sys/kernhist.h
cvs rdiff -u -r1.521 -r1.522 src/sys/sys/param.h

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

Modified files:

Index: src/sys/kern/kern_history.c
diff -u src/sys/kern/kern_history.c:1.10 src/sys/kern/kern_history.c:1.11
--- src/sys/kern/kern_history.c:1.10	Wed Jan  4 01:05:58 2017
+++ src/sys/kern/kern_history.c	Thu Jan  5 03:40:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_history.c,v 1.10 2017/01/04 01:05:58 pgoyette Exp $	 */
+/*	$NetBSD: kern_history.c,v 1.11 2017/01/05 03:40:33 pgoyette 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.10 2017/01/04 01:05:58 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.11 2017/01/05 03:40:33 pgoyette Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kernhist.h"
@@ -120,7 +120,7 @@ kernhist_dump(struct kern_history *l, vo
 static void
 kernhist_dump_histories(struct kern_history *hists[], void (*pr)(const char *, ...))
 {
-	struct timeval  tv;
+	struct bintime	bt;
 	int	cur[MAXHISTS];
 	int	lcv, hi;
 
@@ -136,7 +136,7 @@ kernhist_dump_histories(struct kern_hist
 	 */
 	for (;;) {
 		hi = -1;
-		tv.tv_sec = tv.tv_usec = 0;
+		bt.sec = 0; bt.frac = 0;
 
 		/* loop over each history */
 		for (lcv = 0; hists[lcv]; lcv++) {
@@ -159,12 +159,12 @@ restart:
 
 			/*
 			 * if the time hasn't been set yet, or this entry is
-			 * earlier than the current tv, set the time and history
+			 * earlier than the current bt, set the time and history
 			 * index.
 			 */
-			if (tv.tv_sec == 0 ||
-			    timercmp(&hists[lcv]->e[cur[lcv]].tv, &tv, <)) {
-				tv = hists[lcv]->e[cur[lcv]].tv;
+			if (bt.sec == 0 ||
+			    bintimecmp(&hists[lcv]->e[cur[lcv]].bt, &bt, <)) {
+				bt = hists[lcv]->e[cur[lcv]].bt;
 				hi = lcv;
 			}
 		}
@@ -466,8 +466,7 @@ sysctl_kernhist_helper(SYSCTLFN_ARGS)
 			out_evt->she_fmtoffset = 0;
 			continue;
 		}
-		out_evt->she_time_sec = in_evt->tv.tv_sec;
-		out_evt->she_time_usec = in_evt->tv.tv_usec;
+		out_evt->she_bintime = in_evt->bt;
 		out_evt->she_callnumber = in_evt->call;
 		out_evt->she_cpunum = in_evt->cpunum;
 		out_evt->she_values[0] = in_evt->v[0];

Index: src/sys/sys/kernhist.h
diff -u src/sys/sys/kernhist.h:1.16 src/sys/sys/kernhist.h:1.17
--- src/sys/sys/kernhist.h:1.16	Wed Jan  4 01:52:13 2017
+++ src/sys/sys/kernhist.h	Thu Jan  5 03:40:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kernhist.h,v 1.16 2017/01/04 01:52:13 pgoyette Exp $	*/
+/*	$NetBSD: kernhist.h,v 1.17 2017/01/05 03:40:33 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -46,7 +46,7 @@
  */
 
 struct kern_history_ent {
-	struct timeval tv; 		/* time stamp */
+	struct bintime bt; 		/* time stamp */
 	int cpunum;
 	const char *fmt;		/* printf format */
 	size_t fmtlen;			/* length of printf format */
@@ -80,8 +80,7 @@ struct sysctl_history_list_entry {
 
 /* info for a single history event */
 struct sysctl_history_event {
-	uint64_t	she_time_sec;
-	uint64_t	she_time_usec;
+	struct bintime	she_bintime;
 	uint64_t	she_callnumber;
 	uint64_t	she_values[4];
 	uint32_t	she_cpunum;
@@ -213,7 +212,7 @@ do { \
 	} while (atomic_cas_uint(&(NAME).f, _i_, _j_) != _i_); \
 	struct kern_history_ent * const _e_ = &(NAME).e[_i_]; \
 	if (__predict_true(!cold)) \
-		microtime(&_e_->tv); \
+		bintime(&_e_->bt); \
 	_e_->cpunum = cpu_number(); \
 	_e_->fmt = (FMT); \
 	_e_->fmtlen = strlen(FMT); \
@@ -257,7 +256,10 @@ do { \
 static inline void
 kernhist_entry_print(const struct kern_history_ent *e, void (*pr)(const char *, ...) __printflike(1, 2))
 {
-	pr("%06" PRIu64 ".%06d ", e->tv.tv_sec, e->tv.tv_usec);
+	struct timeval tv;
+
+	bintime2timeval(&e->bt, &tv);
+	pr("%06" PRIu64 ".%06d ", tv.tv_sec, tv.tv_usec);
 	pr("%s#%ld@%d: ", e->fn, e->call, e->cpunum);
 	pr(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
 	pr("\n");

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.521 src/sys/sys/param.h:1.522
--- src/sys/sys/param.h:1.521	Mon Jan  2 10:33:28 2017
+++ src/sys/sys/param.h	Thu Jan  5 03:40:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.521 2017/01/02 10:33:28 hannken Exp $	*/
+/*	$NetBSD: param.h,v 1.522 2017/01/05 03:40:33 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	799005400	/* NetBSD 7.99.54 */
+#define	__NetBSD_Version__	799005500	/* NetBSD 7.99.55 */
 
 #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
     (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)

Reply via email to