From: Bart Van Assche Date: Wed, 14 May 2008 09:50:08 +0000 (+0000) Subject: VG_(read_millisecond_timer)() is now monotonic, even if set_timeofday() is called... X-Git-Tag: svn/VALGRIND_3_4_0~571 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=37f950c02a45d991215ac654871a7b8413cc4edf;p=thirdparty%2Fvalgrind.git VG_(read_millisecond_timer)() is now monotonic, even if set_timeofday() is called or if ntpd adjusts the clock backwards. On Linux kernels where the clock_gettime() syscall is not supported, VG_(read_millisecond_timer)() falls back to the old behavior. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8072 --- diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c index 3117f96a79..cd3d771214 100644 --- a/coregrind/m_libcproc.c +++ b/coregrind/m_libcproc.c @@ -541,10 +541,21 @@ UInt VG_(read_millisecond_timer) ( void ) now += (ULong)(nsec / 1000); # else - struct vki_timeval tv_now; + struct vki_timespec ts_now; SysRes res; - res = VG_(do_syscall2)(__NR_gettimeofday, (UWord)&tv_now, (UWord)NULL); - now = tv_now.tv_sec * 1000000ULL + tv_now.tv_usec; + res = VG_(do_syscall2)(__NR_clock_gettime, VKI_CLOCK_MONOTONIC, + (UWord)&ts_now); + if (res.isError == 0) + { + now = ts_now.tv_sec * 1000000ULL + ts_now.tv_nsec / 1000; + } + else + { + struct vki_timeval tv_now; + res = VG_(do_syscall2)(__NR_gettimeofday, (UWord)&tv_now, (UWord)NULL); + vg_assert(! res.isError); + now = tv_now.tv_sec * 1000000ULL + tv_now.tv_usec; + } # endif if (base == 0)