From ca4525b556680256149ead3746b566103e043d8e Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Wed, 26 May 2010 12:32:36 -0400 Subject: [PATCH] Replace gettimeofday() with clock_gettime(CLOCK_MONOTONIC,...) Contributed by Nils Carlson. --- include/ust/clock.h | 16 ++++++++++------ libust/Makefile.am | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/ust/clock.h b/include/ust/clock.h index d4b6a9d..cb8a663 100644 --- a/include/ust/clock.h +++ b/include/ust/clock.h @@ -18,6 +18,7 @@ #ifndef UST_CLOCK_H #define UST_CLOCK_H +#include #include #include @@ -34,6 +35,9 @@ For merging traces with the kernel, a time source compatible with that of the kernel is necessary. + Instead of gettimeofday(), we are now using clock_gettime for better + precision and monotonicity. + */ #define TRACE_CLOCK_GENERIC @@ -41,13 +45,13 @@ static __inline__ u64 trace_clock_read64(void) { - struct timeval tv; + struct timespec ts; u64 retval; - gettimeofday(&tv, NULL); - retval = tv.tv_sec; - retval *= 1000000; - retval += tv.tv_usec; + clock_gettime(CLOCK_MONOTONIC, &ts); + retval = ts.tv_sec; + retval *= 1000000000; + retval += ts.tv_nsec; return retval; } @@ -104,7 +108,7 @@ static __inline__ u64 trace_clock_read64(void) static __inline__ u64 trace_clock_frequency(void) { - return 1000000LL; + return 1000000000LL; } static __inline__ u32 trace_clock_freq_scale(void) diff --git a/libust/Makefile.am b/libust/Makefile.am index 2de5857..e357ad1 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -27,6 +27,7 @@ libust_la_LDFLAGS = -no-undefined -version-info 0:0:0 libust_la_LIBADD = \ -lpthread \ + -lrt \ $(top_builddir)/snprintf/libustsnprintf.la \ $(top_builddir)/libustcomm/libustcomm.la -- 2.34.1