Author: jhb
Date: Sat Oct  1 22:12:33 2016
New Revision: 306565
URL: https://svnweb.freebsd.org/changeset/base/306565

Log:
  Use timercmp() and timersub() in kdump.
  
  Previously, kdump used the kernel-only timervalsub() macro which required
  defining _KERNEL when including <sys/time.h>.  Now, kdump uses the existing
  userland API.  The timercmp() usage to check for a backwards timestamp is
  also clearer and simpler than the previous code which checked the result of
  the subtraction for a negative value.
  
  While here, take advantage of the 3-arg timersub() to store the subtraction
  results in a tempory timeval instead of overwriting the timestamp in the
  ktrace record and then having to restore it.

Modified:
  head/usr.bin/kdump/kdump.c

Modified: head/usr.bin/kdump/kdump.c
==============================================================================
--- head/usr.bin/kdump/kdump.c  Sat Oct  1 22:08:07 2016        (r306564)
+++ head/usr.bin/kdump/kdump.c  Sat Oct  1 22:12:33 2016        (r306565)
@@ -45,9 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/capsicum.h>
 #include <sys/errno.h>
-#define _KERNEL
 #include <sys/time.h>
-#undef _KERNEL
 #include <sys/uio.h>
 #include <sys/ktrace.h>
 #include <sys/ioctl.h>
@@ -637,27 +635,23 @@ dumpheader(struct ktr_header *kth)
                if (timestamp & TIMESTAMP_ELAPSED) {
                        if (prevtime_e.tv_sec == 0)
                                prevtime_e = kth->ktr_time;
-                       timevalsub(&kth->ktr_time, &prevtime_e);
-                       printf("%jd.%06ld ", (intmax_t)kth->ktr_time.tv_sec,
-                           kth->ktr_time.tv_usec);
-                       timevaladd(&kth->ktr_time, &prevtime_e);
+                       timersub(&kth->ktr_time, &prevtime_e, &temp);
+                       printf("%jd.%06ld ", (intmax_t)temp.tv_sec,
+                           temp.tv_usec);
                }
                if (timestamp & TIMESTAMP_RELATIVE) {
                        if (prevtime.tv_sec == 0)
                                prevtime = kth->ktr_time;
-                       temp = kth->ktr_time;
-                       timevalsub(&kth->ktr_time, &prevtime);
-                       if ((intmax_t)kth->ktr_time.tv_sec < 0) {
-                               kth->ktr_time = prevtime;
-                               prevtime = temp;
-                               timevalsub(&kth->ktr_time, &prevtime);
+                       if (timercmp(&kth->ktr_time, &prevtime, <)) {
+                               timersub(&prevtime, &kth->ktr_time, &temp);
                                sign = "-";
                        } else {
-                               prevtime = temp;
+                               timersub(&kth->ktr_time, &prevtime, &temp);
                                sign = "";
                        }
-                       printf("%s%jd.%06ld ", sign, 
(intmax_t)kth->ktr_time.tv_sec,
-                           kth->ktr_time.tv_usec);
+                       prevtime = kth->ktr_time;
+                       printf("%s%jd.%06ld ", sign, (intmax_t)temp.tv_sec,
+                           temp.tv_usec);
                }
        }
        printf("%s  ", type);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to