summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-12-16 19:43:55 -0700
committerJens Axboe <axboe@fb.com>2014-12-16 19:43:55 -0700
commit27325ed5a4f770b681c6847352c547d51dbdeb62 (patch)
treeffccb7f296309b844f1d52b456dd722315ef9924
parent02dcf81c05b90bf50c062545a4b1158bca75950b (diff)
downloadfio-27325ed5a4f770b681c6847352c547d51dbdeb62.tar.gz
fio-27325ed5a4f770b681c6847352c547d51dbdeb62.tar.bz2
gettime: improve gettimeofday() offload support
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--gettime-thread.c11
-rw-r--r--gettime.c4
-rw-r--r--gettime.h18
3 files changed, 28 insertions, 5 deletions
diff --git a/gettime-thread.c b/gettime-thread.c
index 3d49034a..72cc4d8a 100644
--- a/gettime-thread.c
+++ b/gettime-thread.c
@@ -20,8 +20,15 @@ void fio_gtod_init(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)
diff --git a/gettime.c b/gettime.c
index 87abca0f..e2746711 100644
--- 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
- if (fio_unlikely(fio_tv)) {
- memcpy(tp, fio_tv, sizeof(*tp));
+ if (fio_unlikely(fio_gettime_offload(tp)))
return;
- }
__fio_gettime(tp);
}
diff --git a/gettime.h b/gettime.h
index f0ad20c8..f5412286 100644
--- 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