Your observation that gettimeofday
switches to kernel mode is incorrect for Linux on a few popular architectures due to the use of vsyscalls. Clearly using gettimeofday
here is not a bad option. You should however consider using a monotonic clock, see man 3 clock_gettime
. Note that clock_gettime
is not yet converted to vsyscall for as many architectures as gettimeofday
.
Beyond this option you may be able to set the SO_TIMESTAMP
socket option and obtain precise timestamps via recvmsg
.