Skip to content
Snippets Groups Projects
  • Alex Bennée's avatar
    50290c00
    qemu-io-cmds: use clock_gettime for benchmarking · 50290c00
    Alex Bennée authored
    
    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: default avatarAlex Bennée <alex.bennee@linaro.org>
    50290c00
    History
    qemu-io-cmds: use clock_gettime for benchmarking
    Alex Bennée authored
    
    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: default avatarAlex Bennée <alex.bennee@linaro.org>