iolog: prevent early entry from skewing entire logging run
authorJens Axboe <axboe@fb.com>
Wed, 3 Aug 2016 15:11:56 +0000 (09:11 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 3 Aug 2016 15:11:56 +0000 (09:11 -0600)
If we go out of ramp time, our wakeup trigger could cause us to enter
too early in add_log_sample(). If that happens, the time diff could be
negative (so huge unsigned). Since we carry that forward, we end up
logging every entry and not just over the average window.

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

diff --git a/stat.c b/stat.c
index 7a35117a6f1998faae15cae2c1e3b660205470b7..d6787b7f10973c9c3797b724736ee5fcab158706 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -2139,7 +2139,9 @@ static long add_log_sample(struct thread_data *td, struct io_log *iolog,
         * need to do.
         */
        this_window = elapsed - iolog->avg_last;
-       if (this_window < iolog->avg_msec) {
+       if (elapsed < iolog->avg_last)
+               return iolog->avg_last - elapsed;
+       else if (this_window < iolog->avg_msec) {
                int diff = iolog->avg_msec - this_window;
 
                if (inline_log(iolog) || diff > LOG_MSEC_SLACK)