From owner-svn-src-stable@FreeBSD.ORG Fri Apr 19 03:55:55 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 71F9959F; Fri, 19 Apr 2013 03:55:55 +0000 (UTC) (envelope-from ken@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 4867378A; Fri, 19 Apr 2013 03:55:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3J3tsPJ035800; Fri, 19 Apr 2013 03:55:54 GMT (envelope-from ken@svn.freebsd.org) Received: (from ken@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3J3tsMb035799; Fri, 19 Apr 2013 03:55:54 GMT (envelope-from ken@svn.freebsd.org) Message-Id: <201304190355.r3J3tsMb035799@svn.freebsd.org> From: "Kenneth D. Merry" Date: Fri, 19 Apr 2013 03:55:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r249632 - stable/9/usr.bin/ctlstat X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Apr 2013 03:55:55 -0000 Author: ken Date: Fri Apr 19 03:55:54 2013 New Revision: 249632 URL: http://svnweb.freebsd.org/changeset/base/249632 Log: MFC r249334 and r249384: ------------------------------------------------------------------------ r249334 | ken | 2013-04-10 10:01:45 -0600 (Wed, 10 Apr 2013) | 11 lines Fix a time calculation error in ctlstat_standard(). ctlstat.c: When converting a timeval to a floating point number in ctlstat_standard(), cast the nanoseconds calculation to a long double, so we don't lose precision. Without the cast, we wind up with a time in whole seconds only. Sponsored by: Spectra Logic ------------------------------------------------------------------------ r249384 | ken | 2013-04-11 15:18:04 -0600 (Thu, 11 Apr 2013) | 17 lines Fix bugs in the elapsed time calculation in ctlstat_standard() pointed out by bde: - Casting to long double isn't needed. - The division isn't needed, multiplication can be used. "When 1 nanosecond is in a floating point literal, the whole expression is automatically promoted correctly." - non-KNF indentation (1 tab) for the newly split line - different non-KNF indentation (5 spaces) for the previously split line - exessive parentheses around the division operation - bogus blank line which splits up the etime initialization - general verboseness from the above. Submitted by: bde Sponsored by: Spectra Logic Modified: stable/9/usr.bin/ctlstat/ctlstat.c Directory Properties: stable/9/usr.bin/ctlstat/ (props changed) Modified: stable/9/usr.bin/ctlstat/ctlstat.c ============================================================================== --- stable/9/usr.bin/ctlstat/ctlstat.c Fri Apr 19 00:30:52 2013 (r249631) +++ stable/9/usr.bin/ctlstat/ctlstat.c Fri Apr 19 03:55:54 2013 (r249632) @@ -404,7 +404,7 @@ ctlstat_json(struct ctlstat_context *ctx static void ctlstat_standard(struct ctlstat_context *ctx) { - long double cur_secs, prev_secs, etime; + long double etime; uint64_t delta_jiffies, delta_idle; uint32_t port; long double cpu_percentage; @@ -416,11 +416,8 @@ ctlstat_standard(struct ctlstat_context if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0)) errx(1, "error returned from getcpu()"); - cur_secs = ctx->cur_time.tv_sec + (ctx->cur_time.tv_nsec / 1000000000); - prev_secs = ctx->prev_time.tv_sec + - (ctx->prev_time.tv_nsec / 1000000000); - - etime = cur_secs - prev_secs; + etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec + + (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; if (F_CPU(ctx)) { ctx->prev_total_jiffies = ctx->cur_total_jiffies;