gettime: improve gettimeofday() offload support
authorJens Axboe <axboe@fb.com>
Wed, 17 Dec 2014 02:43:55 +0000 (19:43 -0700)
committerJens Axboe <axboe@fb.com>
Wed, 17 Dec 2014 02:43:55 +0000 (19:43 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
gettime-thread.c
gettime.c
gettime.h

index 3d49034a72792fc6cfc590ed545c522de4f7a999..72cc4d8a472783f7e73d7d40f8a8da9f56759a2a 100644 (file)
@@ -20,8 +20,15 @@ void fio_gtod_init(void)
 
 static void fio_gtod_update(void)
 {
 
 static void fio_gtod_update(void)
 {
-       if (fio_tv)
-               gettimeofday(fio_tv, NULL);
+       if (fio_tv) {
+               struct timeval __tv;
+
+               gettimeofday(&__tv, NULL);
+               fio_tv->tv_sec = __tv.tv_sec;
+               write_barrier();
+               fio_tv->tv_usec = __tv.tv_usec;
+               write_barrier();
+       }
 }
 
 static void *gtod_thread_main(void *data)
 }
 
 static void *gtod_thread_main(void *data)
index 87abca0ff883f59c4850f191ae8d744128552bee..e2746711d2e4e2b51b914a98a2c9d30e914beeda 100644 (file)
--- a/gettime.c
+++ b/gettime.c
@@ -207,10 +207,8 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
 
        gtod_log_caller(caller);
 #endif
 
        gtod_log_caller(caller);
 #endif
-       if (fio_unlikely(fio_tv)) {
-               memcpy(tp, fio_tv, sizeof(*tp));
+       if (fio_unlikely(fio_gettime_offload(tp)))
                return;
                return;
-       }
 
        __fio_gettime(tp);
 }
 
        __fio_gettime(tp);
 }
index f0ad20c8a2927437cc49eb2a4adf9fb28f4b247f..f5412286e3bad41dd32111f8885d647af20fad75 100644 (file)
--- a/gettime.h
+++ b/gettime.h
@@ -1,6 +1,8 @@
 #ifndef FIO_GETTIME_H
 #define FIO_GETTIME_H
 
 #ifndef FIO_GETTIME_H
 #define FIO_GETTIME_H
 
+#include "arch/arch.h"
+
 /*
  * Clock sources
  */
 /*
  * Clock sources
  */
@@ -20,4 +22,20 @@ extern void fio_local_clock_init(int);
 
 extern struct timeval *fio_tv;
 
 
 extern struct timeval *fio_tv;
 
+static inline int fio_gettime_offload(struct timeval *tv)
+{
+       size_t last_sec;
+
+       if (!fio_tv)
+               return 0;
+
+       do {
+               read_barrier();
+               last_sec = tv->tv_sec = fio_tv->tv_sec;
+               tv->tv_usec = fio_tv->tv_usec;
+       } while (fio_tv->tv_sec != last_sec);
+
+       return 1;
+}
+
 #endif
 #endif