DragonFlyBSD/src fc98fc7bin/dd misc.c dd.c

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)
DeltaFile
+23-6bin/dd/misc.c
+3-4bin/dd/dd.c
+3-1bin/dd/dd.h
+1-0bin/dd/extern.h
+30-114 files

UnifiedSplitRaw