From owner-svn-src-all@FreeBSD.ORG Thu May 8 19:10:05 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AE1B4CFC; Thu, 8 May 2014 19:10:05 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 9B639824; Thu, 8 May 2014 19:10:05 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s48JA5aw055384; Thu, 8 May 2014 19:10:05 GMT (envelope-from asomers@svn.freebsd.org) Received: (from asomers@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s48JA5Us055372; Thu, 8 May 2014 19:10:05 GMT (envelope-from asomers@svn.freebsd.org) Message-Id: <201405081910.s48JA5Us055372@svn.freebsd.org> From: Alan Somers Date: Thu, 8 May 2014 19:10:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r265698 - head/bin/dd X-SVN-Group: head 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.18 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: Thu, 08 May 2014 19:10:05 -0000 Author: asomers Date: Thu May 8 19:10:04 2014 New Revision: 265698 URL: http://svnweb.freebsd.org/changeset/base/265698 Log: Incorporate feedback from bde and jilles regarding r265472 to dd(1). * Don't use sysexits.h. Just exit 1 on error and 0 otherwise. * Don't sacrifice precision by converting the output of clock_gettime() to a double and then comparing the results. Instead, subtract the values of the two clock_gettime() calls, then convert to double. * Don't use CLOCK_MONOTONIC_PRECISE. It's an unportable synonym for CLOCK_MONOTONIC. * Use more appropriate names for some local variables. * In the summary message, round elapsed time to the nearest microsecond. Reported by: bde, jilles MFC after: 3 days X-MFC-With: 265472 Modified: head/bin/dd/dd.c head/bin/dd/dd.h head/bin/dd/misc.c Modified: head/bin/dd/dd.c ============================================================================== --- head/bin/dd/dd.c Thu May 8 19:08:07 2014 (r265697) +++ head/bin/dd/dd.c Thu May 8 19:10:04 2014 (r265698) @@ -61,7 +61,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -126,7 +125,6 @@ static void setup(void) { u_int cnt; - struct timespec tv; if (in.name == NULL) { in.name = "stdin"; @@ -245,9 +243,8 @@ setup(void) ctab = casetab; } - if (clock_gettime(CLOCK_MONOTONIC_PRECISE, &tv)) - err(EX_OSERR, "clock_gettime"); - st.start = tv.tv_sec + tv.tv_nsec * 1.0e-9; + if (clock_gettime(CLOCK_MONOTONIC, &st.start)) + err(1, "clock_gettime"); } static void Modified: head/bin/dd/dd.h ============================================================================== --- head/bin/dd/dd.h Thu May 8 19:08:07 2014 (r265697) +++ head/bin/dd/dd.h Thu May 8 19:10:04 2014 (r265698) @@ -64,7 +64,7 @@ typedef struct { uintmax_t trunc; /* # of truncated records */ uintmax_t swab; /* # of odd-length swab blocks */ uintmax_t bytes; /* # of bytes written */ - double start; /* start time of dd */ + struct timespec start; /* start time of dd */ } STAT; /* Flags (in ddflags). */ Modified: head/bin/dd/misc.c ============================================================================== --- head/bin/dd/misc.c Thu May 8 19:08:07 2014 (r265697) +++ head/bin/dd/misc.c Thu May 8 19:10:04 2014 (r265698) @@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -58,18 +57,19 @@ __FBSDID("$FreeBSD$"); void summary(void) { - struct timespec tv, tv_res; + struct timespec end, ts_res; double secs, res; if (ddflags & C_NOINFO) return; - if (clock_gettime(CLOCK_MONOTONIC_PRECISE, &tv)) - err(EX_OSERR, "clock_gettime"); - if (clock_getres(CLOCK_MONOTONIC_PRECISE, &tv_res)) - err(EX_OSERR, "clock_getres"); - secs = tv.tv_sec + tv.tv_nsec * 1.0e-9 - st.start; - res = tv_res.tv_sec + tv_res.tv_nsec * 1.0e-9; + if (clock_gettime(CLOCK_MONOTONIC, &end)) + err(1, "clock_gettime"); + if (clock_getres(CLOCK_MONOTONIC, &ts_res)) + err(1, "clock_getres"); + secs = (end.tv_sec - st.start.tv_sec) + \ + (end.tv_nsec - st.start.tv_nsec) * 1e-9; + res = ts_res.tv_sec + ts_res.tv_nsec * 1e-9; if (secs < res) secs = res; (void)fprintf(stderr, @@ -83,7 +83,7 @@ summary(void) st.trunc, (st.trunc == 1) ? "block" : "blocks"); if (!(ddflags & C_NOXFER)) { (void)fprintf(stderr, - "%ju bytes transferred in %.9f secs (%.0f bytes/sec)\n", + "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n", st.bytes, secs, st.bytes / secs); } need_summary = 0;