git: dd(1): Rework the time interval calculation

Aaron LI aly at crater.dragonflybsd.org
Thu Feb 14 08:37:58 PST 2019


commit fc98fc71ea79f0e384f90814cb1a90c4e578bd9a
Author: Aaron LI <aly at aaronly.me>
Date:   Thu Feb 14 21:38:21 2019 +0800

    dd(1): Rework the time interval calculation
    
    dd(1) uses gettimeofday(2) to compute the throughput statistics.
    However, gettimeofday returns the system clock, which may jump forward
    or back, especially if NTP is in use.  If the time jumps backwards, then
    dd will see negative elapsed time, round it up to 1usec, and print an
    absurdly fast transfer rate.
    
    The solution is to use clock_gettime(2) with CLOCK_MONOTONIC as the
    clock_id.  That clock advances steadily, regardless of changes to the
    system clock.
    
    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.
    
    Obtained-from: FreeBSD (revisions 265472,265698)

Summary of changes:
 bin/dd/dd.c     |  7 +++----
 bin/dd/dd.h     |  4 +++-
 bin/dd/extern.h |  1 +
 bin/dd/misc.c   | 29 +++++++++++++++++++++++------
 4 files changed, 30 insertions(+), 11 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/fc98fc71ea79f0e384f90814cb1a90c4e578bd9a


-- 
DragonFly BSD source repository


More information about the Commits mailing list