[PATCH] Time and seek optimizations

We did too many gettimeofday() calls, this patch cuts the number by
40%. Use clock_gettime() MONOTONIC instead, it is faster on my system
at least.

This patch also optimizes calling lseek() only when necessary for the
sync io engine.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/stat.c b/stat.c
index 0ccf37e..e6da421 100644
--- a/stat.c
+++ b/stat.c
@@ -60,7 +60,7 @@
 	dus->io_ticks += (__dus.io_ticks - ldus->io_ticks);
 	dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue);
 
-	gettimeofday(&t, NULL);
+	fio_gettime(&t, NULL);
 	du->msec += mtime_since(&du->time, &t);
 	memcpy(&du->time, &t, sizeof(t));
 	memcpy(ldus, &__dus, sizeof(__dus));
@@ -102,7 +102,7 @@
 	du->name = strdup(basename(path));
 	du->dev = dev;
 
-	gettimeofday(&du->time, NULL);
+	fio_gettime(&du->time, NULL);
 	get_io_ticks(du, &du->last_dus);
 
 	list_add_tail(&du->list, &disk_list);
@@ -574,9 +574,9 @@
 		add_log_sample(td, td->slat_log, msec, ddir);
 }
 
-void add_bw_sample(struct thread_data *td, int ddir)
+void add_bw_sample(struct thread_data *td, int ddir, struct timeval *t)
 {
-	unsigned long spent = mtime_since_now(&td->stat_sample_time[ddir]);
+	unsigned long spent = mtime_since(&td->stat_sample_time[ddir], t);
 	unsigned long rate;
 
 	if (spent < td->bw_avg_time)
@@ -588,7 +588,7 @@
 	if (td->bw_log)
 		add_log_sample(td, td->bw_log, rate, ddir);
 
-	gettimeofday(&td->stat_sample_time[ddir], NULL);
+	fio_gettime(&td->stat_sample_time[ddir], NULL);
 	td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
 }