All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gettime: minimize integer division
@ 2012-12-20  0:52 Sam Bradshaw
  2012-12-20  8:14 ` Jens Axboe
  0 siblings, 1 reply; 12+ messages in thread
From: Sam Bradshaw @ 2012-12-20  0:52 UTC (permalink / raw)
  To: axboe; +Cc: fio


This patch generally converts a division to a subtraction in fio_gettime().

Shows ~1% better iops with synthetic benchmarking at roughly the same cpu 
time spent in fio_gettime().

Signed-off-by: Sam Bradshaw <sbradshaw@micron.com>

diff --git a/gettime.c b/gettime.c
index 248f146..e2a6241 100644
--- a/gettime.c
+++ b/gettime.c
@@ -163,17 +163,23 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
 		}
 #ifdef ARCH_HAVE_CPU_CLOCK
 	case CS_CPUCLOCK: {
-		unsigned long long usecs, t;
+		unsigned long long usecs, t, delta = 0;

 		t = get_cpu_clock();
 		if (tv && t < tv->last_cycles) {
 			dprint(FD_TIME, "CPU clock going back in time\n");
 			t = tv->last_cycles;
-		} else if (tv)
+		} else if (tv) {
+			if (tv->last_tv_valid)
+				delta = t - tv->last_cycles;
 			tv->last_cycles = t;
+		}

 		usecs = t / cycles_per_usec;
-		tp->tv_sec = usecs / 1000000;
+		if (delta > 1000000)
+			tp->tv_sec = tv->last_tv.tv_sec;
+		else
+			tp->tv_sec = usecs / 1000000;
 		tp->tv_usec = usecs % 1000000;
 		break;
 		}


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-12-23 20:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-20  0:52 [PATCH] gettime: minimize integer division Sam Bradshaw
2012-12-20  8:14 ` Jens Axboe
2012-12-20 17:18   ` Sam Bradshaw
2012-12-20 18:03     ` Jens Axboe
2012-12-20 18:58       ` Sam Bradshaw (sbradshaw)
2012-12-20 19:23       ` Sam Bradshaw
2012-12-21 15:33         ` Jens Axboe
2012-12-21 15:45           ` Jens Axboe
2012-12-21 21:28           ` Sam Bradshaw (sbradshaw)
2012-12-21 21:30             ` Jens Axboe
2012-12-21 21:53               ` Sam Bradshaw (sbradshaw)
2012-12-23 20:49                 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.