Replace gettimeofday() with clock_gettime(CLOCK_MONOTONIC,...)
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 26 May 2010 16:32:36 +0000 (12:32 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 26 May 2010 16:32:36 +0000 (12:32 -0400)
Contributed by Nils Carlson.

include/ust/clock.h
libust/Makefile.am

index d4b6a9ddc1e2768a219beed14d0c6336b4d58b13..cb8a663ceb229f75ab19cc69db8df4390084f8ea 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef UST_CLOCK_H
 #define UST_CLOCK_H
 
+#include <time.h>
 #include <sys/time.h>
 #include <ust/kcompat/kcompat.h>
 
@@ -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
 
 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)
index 2de58574f0acb7fc7f6d14c423990748f6ce5b60..e357ad16496e0f719a0618a776423e77768860d7 100644 (file)
@@ -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
 
This page took 0.025358 seconds and 4 git commands to generate.