summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2012-12-20 15:17:57 +0100
committerJens Axboe <axboe@kernel.dk>2012-12-20 15:17:57 +0100
commit9ff1c070210a697c599abd1019737d79cd3351e6 (patch)
treefe9946e2cefb78544c7f21eb75659ed10dcda274
parent79b199dfb3ae06fc91381e323f21114c73b7b39c (diff)
downloadfio-9ff1c070210a697c599abd1019737d79cd3351e6.tar.gz
fio-9ff1c070210a697c599abd1019737d79cd3351e6.tar.bz2
Use clock_gettime() for CPU clock calibration
gettimeofday() has very poor resolution on some platforms. So use clock_gettime() instead. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--gettime.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/gettime.c b/gettime.c
index 248f1469..035d275d 100644
--- a/gettime.c
+++ b/gettime.c
@@ -120,6 +120,15 @@ static void fio_init gtod_init(void)
#endif /* FIO_DEBUG_TIME */
+static int fill_clock_gettime(struct timespec *ts)
+{
+#ifdef FIO_HAVE_CLOCK_MONOTONIC
+ return clock_gettime(CLOCK_MONOTONIC, ts);
+#else
+ return clock_gettime(CLOCK_REALTIME, ts);
+#endif
+}
+
#ifdef FIO_DEBUG_TIME
void fio_gettime(struct timeval *tp, void *caller)
#else
@@ -148,11 +157,7 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
case CS_CGETTIME: {
struct timespec ts;
-#ifdef FIO_HAVE_CLOCK_MONOTONIC
- if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
-#else
- if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
-#endif
+ if (fill_clock_gettime(&ts) < 0) {
log_err("fio: clock_gettime fails\n");
assert(0);
}
@@ -203,15 +208,22 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
#ifdef ARCH_HAVE_CPU_CLOCK
static unsigned long get_cycles_per_usec(void)
{
+ struct timespec ts;
struct timeval s, e;
unsigned long long c_s, c_e;
- gettimeofday(&s, NULL);
+ fill_clock_gettime(&ts);
+ s.tv_sec = ts.tv_sec;
+ s.tv_usec = ts.tv_nsec / 1000;
+
c_s = get_cpu_clock();
do {
unsigned long long elapsed;
- gettimeofday(&e, NULL);
+ fill_clock_gettime(&ts);
+ e.tv_sec = ts.tv_sec;
+ e.tv_usec = ts.tv_nsec / 1000;
+
elapsed = utime_since(&s, &e);
if (elapsed >= 1280) {
c_e = get_cpu_clock();