Add gtod_cpu option for pinning gettimeofday() to a single CPU
Similar to what real life products sometimes do, offload gettimeofday()
calls to a single CPU and have that update the current time into a shared
memory location. This option pins a specific CPU for that job, and excludes
it from participating in any of the IO jobs.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/gettime.c b/gettime.c
index 80eeaf1..b1431f3 100644
--- a/gettime.c
+++ b/gettime.c
@@ -6,6 +6,7 @@
#include <sys/time.h>
#include "fio.h"
+#include "smalloc.h"
#include "hash.h"
@@ -13,6 +14,10 @@
static struct timeval last_tv;
static int last_tv_valid;
+static struct timeval *fio_tv;
+int fio_gtod_offload = 0;
+int fio_gtod_cpu = -1;
+
#ifdef FIO_DEBUG_TIME
#define HASH_BITS 8
@@ -116,7 +121,10 @@
gtod_log_caller(caller);
#endif
- if (!clock_gettime_works) {
+ if (fio_tv) {
+ memcpy(tp, fio_tv, sizeof(*tp));
+ return;
+ } else if (!clock_gettime_works) {
gtod:
gettimeofday(tp, NULL);
} else {
@@ -145,3 +153,14 @@
last_tv_valid = 1;
memcpy(&last_tv, tp, sizeof(*tp));
}
+
+void fio_gtod_init(void)
+{
+ fio_tv = smalloc(sizeof(struct timeval));
+ assert(fio_tv);
+}
+
+void fio_gtod_update(void)
+{
+ gettimeofday(fio_tv, NULL);
+}