From owner-svn-src-all@freebsd.org Mon Jan 9 23:43:43 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C99BCA80E9; Mon, 9 Jan 2017 23:43:43 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4A7D41D9E; Mon, 9 Jan 2017 23:43:43 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v09Nhgd3053915; Mon, 9 Jan 2017 23:43:42 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v09NhgEP053914; Mon, 9 Jan 2017 23:43:42 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201701092343.v09NhgEP053914@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Mon, 9 Jan 2017 23:43:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r311839 - stable/11/usr.bin/kdump X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jan 2017 23:43:43 -0000 Author: jhb Date: Mon Jan 9 23:43:42 2017 New Revision: 311839 URL: https://svnweb.freebsd.org/changeset/base/311839 Log: MFC 306565,306566: Use timercmp() and timersub() in kdump. 306565: Use timercmp() and timersub() in kdump. Previously, kdump used the kernel-only timervalsub() macro which required defining _KERNEL when including . 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. 306566: Don't declare the 'temp' timeval as static. Modified: stable/11/usr.bin/kdump/kdump.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/kdump/kdump.c ============================================================================== --- stable/11/usr.bin/kdump/kdump.c Mon Jan 9 23:42:02 2017 (r311838) +++ stable/11/usr.bin/kdump/kdump.c Mon Jan 9 23:43:42 2017 (r311839) @@ -45,9 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#define _KERNEL #include -#undef _KERNEL #include #include #include @@ -564,7 +562,8 @@ void dumpheader(struct ktr_header *kth) { static char unknown[64]; - static struct timeval prevtime, prevtime_e, temp; + static struct timeval prevtime, prevtime_e; + struct timeval temp; const char *type; const char *sign; @@ -637,27 +636,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);