qemu-io-cmds: use clock_gettime for benchmarking
commit50290c002c045280f8defad911901e16bfb52884
authorAlex Bennée <alex.bennee@linaro.org>
Wed, 29 May 2019 16:16:32 +0000 (29 17:16 +0100)
committerAlex Bennée <alex.bennee@linaro.org>
Wed, 12 Jun 2019 16:53:22 +0000 (12 17:53 +0100)
treec432853313b60bfe43c5fe6db27756d847ccd1bf
parent9b109f566adff4d394806b046b395363e523bd80
qemu-io-cmds: use clock_gettime for benchmarking

The previous use of gettimeofday() ran into undefined behaviour when
we ended up doing a div 0 for a very short operation. This is because
gettimeofday only works at the microsecond level as well as being
prone to discontinuous jumps in system time. Using clock_gettime with
CLOCK_MONOTONIC gives greater precision and alleviates some of the
potential problems with time jumping around.

We could use CLOCK_MONOTONIC_RAW to avoid being tripped up by NTP and
adjtime but that is Linux specific so I decided it would do for now.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
qemu-io-cmds.c