gettime: don't attempt to fixup what looks like a backwards clock
authorJens Axboe <axboe@fb.com>
Tue, 16 Dec 2014 22:13:45 +0000 (15:13 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 16 Dec 2014 22:13:45 +0000 (15:13 -0700)
It could just be a wrap. The code is buggy, kill it, we'll deal
with the wrap later.

Signed-off-by: Jens Axboe <axboe@fb.com>
gettime.c

index 6a7e35f87249905c044165bfe1869f4ac0605e99..8e53f83fd3b22e368f104d683c776e8aeb6868d1 100644 (file)
--- a/gettime.c
+++ b/gettime.c
@@ -20,9 +20,8 @@ static unsigned long inv_cycles_per_usec;
 int tsc_reliable = 0;
 
 struct tv_valid {
 int tsc_reliable = 0;
 
 struct tv_valid {
-       struct timeval last_tv;
        uint64_t last_cycles;
        uint64_t last_cycles;
-       int last_tv_valid;
+       uint64_t last_tv_valid;
 };
 #ifdef CONFIG_TLS_THREAD
 static __thread struct tv_valid static_tv_valid;
 };
 #ifdef CONFIG_TLS_THREAD
 static __thread struct tv_valid static_tv_valid;
@@ -136,7 +135,7 @@ static int fill_clock_gettime(struct timespec *ts)
 }
 #endif
 
 }
 #endif
 
-static void *__fio_gettime(struct timeval *tp)
+static void __fio_gettime(struct timeval *tp)
 {
        struct tv_valid *tv;
 
 {
        struct tv_valid *tv;
 
@@ -171,12 +170,11 @@ static void *__fio_gettime(struct timeval *tp)
                uint64_t usecs, t;
 
                t = get_cpu_clock();
                uint64_t usecs, t;
 
                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)
-                       tv->last_cycles = t;
+               if (t < tv->last_cycles && tv->last_tv_valid)
+                       log_err("fio: CPU clock going back in time\n");
 
 
+               tv->last_cycles = t;
+               tv->last_tv_valid = 1;
 #ifdef ARCH_CPU_CLOCK_CYCLES_PER_USEC
                usecs = t / ARCH_CPU_CLOCK_CYCLES_PER_USEC;
 #else
 #ifdef ARCH_CPU_CLOCK_CYCLES_PER_USEC
                usecs = t / ARCH_CPU_CLOCK_CYCLES_PER_USEC;
 #else
@@ -191,8 +189,6 @@ static void *__fio_gettime(struct timeval *tp)
                log_err("fio: invalid clock source %d\n", fio_clock_source);
                break;
        }
                log_err("fio: invalid clock source %d\n", fio_clock_source);
                break;
        }
-
-       return tv;
 }
 
 #ifdef FIO_DEBUG_TIME
 }
 
 #ifdef FIO_DEBUG_TIME
@@ -201,8 +197,6 @@ void fio_gettime(struct timeval *tp, void *caller)
 void fio_gettime(struct timeval *tp, void fio_unused *caller)
 #endif
 {
 void fio_gettime(struct timeval *tp, void fio_unused *caller)
 #endif
 {
-       struct tv_valid *tv;
-
 #ifdef FIO_DEBUG_TIME
        if (!caller)
                caller = __builtin_return_address(0);
 #ifdef FIO_DEBUG_TIME
        if (!caller)
                caller = __builtin_return_address(0);
@@ -214,23 +208,7 @@ void fio_gettime(struct timeval *tp, void fio_unused *caller)
                return;
        }
 
                return;
        }
 
-       tv = __fio_gettime(tp);
-
-       /*
-        * If Linux is using the tsc clock on non-synced processors,
-        * sometimes time can appear to drift backwards. Fix that up.
-        */
-       if (tv) {
-               if (tv->last_tv_valid) {
-                       if (tp->tv_sec < tv->last_tv.tv_sec)
-                               tp->tv_sec = tv->last_tv.tv_sec;
-                       else if (tv->last_tv.tv_sec == tp->tv_sec &&
-                                tp->tv_usec < tv->last_tv.tv_usec)
-                               tp->tv_usec = tv->last_tv.tv_usec;
-               }
-               tv->last_tv_valid = 1;
-               memcpy(&tv->last_tv, tp, sizeof(*tp));
-       }
+       __fio_gettime(tp);
 }
 
 #if defined(ARCH_HAVE_CPU_CLOCK) && !defined(ARCH_CPU_CLOCK_CYCLES_PER_USEC)
 }
 
 #if defined(ARCH_HAVE_CPU_CLOCK) && !defined(ARCH_CPU_CLOCK_CYCLES_PER_USEC)
@@ -336,8 +314,10 @@ void fio_local_clock_init(int is_thread)
        struct tv_valid *t;
 
        t = calloc(1, sizeof(*t));
        struct tv_valid *t;
 
        t = calloc(1, sizeof(*t));
-       if (pthread_setspecific(tv_tls_key, t))
+       if (pthread_setspecific(tv_tls_key, t)) {
                log_err("fio: can't set TLS key\n");
                log_err("fio: can't set TLS key\n");
+               assert(0);
+       }
 }
 
 static void kill_tv_tls_key(void *data)
 }
 
 static void kill_tv_tls_key(void *data)