From ffc3b12c071d0fcedcda14fe0bfc3b877e6edc52 Mon Sep 17 00:00:00 2001 From: "Kenneth D. Merry" Date: Wed, 10 Apr 2013 16:01:45 +0000 Subject: [PATCH] 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 MFC after: 3 days --- usr.bin/ctlstat/ctlstat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr.bin/ctlstat/ctlstat.c b/usr.bin/ctlstat/ctlstat.c index 1462ab9679c2..ff67bf6ad6a5 100644 --- a/usr.bin/ctlstat/ctlstat.c +++ b/usr.bin/ctlstat/ctlstat.c @@ -416,9 +416,10 @@ ctlstat_standard(struct ctlstat_context *ctx) { 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); + cur_secs = ctx->cur_time.tv_sec + + ((long double)ctx->cur_time.tv_nsec / 1000000000); prev_secs = ctx->prev_time.tv_sec + - (ctx->prev_time.tv_nsec / 1000000000); + ((long double)ctx->prev_time.tv_nsec / 1000000000); etime = cur_secs - prev_secs;