gettime: improve gettimeofday() offload support
[fio.git] / gettime.h
index f0ad20c8a2927437cc49eb2a4adf9fb28f4b247f..f5412286e3bad41dd32111f8885d647af20fad75 100644 (file)
--- a/gettime.h
+++ b/gettime.h
@@ -1,6 +1,8 @@
 #ifndef FIO_GETTIME_H
 #define FIO_GETTIME_H
 
+#include "arch/arch.h"
+
 /*
  * Clock sources
  */
@@ -20,4 +22,20 @@ extern void fio_local_clock_init(int);
 
 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