From: Jens Axboe Date: Wed, 17 Dec 2014 02:43:55 +0000 (-0700) Subject: gettime: improve gettimeofday() offload support X-Git-Tag: fio-2.2.0~8 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=27325ed5a4f770b681c6847352c547d51dbdeb62 gettime: improve gettimeofday() offload support Signed-off-by: Jens Axboe --- 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