gettime: include min/max cycle counts for CPU clock
authorJens Axboe <axboe@fb.com>
Tue, 6 Jan 2015 16:36:25 +0000 (09:36 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 6 Jan 2015 16:36:25 +0000 (09:36 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
gettime.c

index 5ceb809de3ae9247a5cc7d3e2557b062541fc73f..72968c55c86c80e37cb2d320dc3a2a8b7159e8c6 100644 (file)
--- a/gettime.c
+++ b/gettime.c
@@ -254,7 +254,7 @@ static unsigned long get_cycles_per_usec(void)
 static int calibrate_cpu_clock(void)
 {
        double delta, mean, S;
-       uint64_t avg, cycles[NR_TIME_ITERS];
+       uint64_t minc, maxc, avg, cycles[NR_TIME_ITERS];
        int i, samples;
 
        cycles[0] = get_cycles_per_usec();
@@ -277,10 +277,14 @@ static int calibrate_cpu_clock(void)
 
        S = sqrt(S / (NR_TIME_ITERS - 1.0));
 
-       samples = avg = 0;
+       minc = -1ULL;
+       maxc = samples = avg = 0;
        for (i = 0; i < NR_TIME_ITERS; i++) {
                double this = cycles[i];
 
+               minc = min(cycles[i], minc);
+               maxc = max(cycles[i], maxc);
+
                if ((fmax(this, mean) - fmin(this, mean)) > S)
                        continue;
                samples++;
@@ -296,8 +300,12 @@ static int calibrate_cpu_clock(void)
 
        avg /= samples;
        avg = (avg + 5) / 10;
+       minc /= 10;
+       maxc /= 10;
        dprint(FD_TIME, "avg: %llu\n", (unsigned long long) avg);
-       dprint(FD_TIME, "mean=%f, S=%f\n", mean, S);
+       dprint(FD_TIME, "min=%llu, max=%llu, mean=%f, S=%f\n",
+                       (unsigned long long) minc,
+                       (unsigned long long) maxc, mean, S);
 
        cycles_per_usec = avg;
        inv_cycles_per_usec = 16777216UL / cycles_per_usec;