rate: fix bad math
authorJens Axboe <axboe@kernel.dk>
Fri, 8 Dec 2017 18:59:38 +0000 (11:59 -0700)
committerJens Axboe <axboe@kernel.dk>
Fri, 8 Dec 2017 18:59:38 +0000 (11:59 -0700)
To figure out how much data we missed when doing a thinktime sleep,
we're currently dividing by the time slept. This is wrong, it should
be multiplied by the time slept and divided by 1000000 to go from
usec to a second base.

Additionally, don't ever subtract more than a block of data, and
adjust down depending on sleep.

Fixes: 1aa39b0c ("rate: ensure IO issue restarts right after sleep")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c

index 5304ddc0ae1df0245405d2f6136c1b45755473d2..e248117f20624846dbfac614abe7204ca3259807 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -898,8 +898,15 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir)
         * start issuing immediately after the sleep.
         */
        if (total && td->rate_bps[ddir] && td->o.rate_ign_think) {
-               td->rate_io_issue_bytes[ddir] += (td->rate_bps[ddir] * 1000000) / total;
-               td->rate_io_issue_bytes[ddir] -= td->o.min_bs[ddir];
+               uint64_t missed = (td->rate_bps[ddir] * total) / 1000000ULL;
+               uint64_t over;
+
+               if (total >= 1000000)
+                       over = td->o.min_bs[ddir];
+               else
+                       over = (td->o.min_bs[ddir] * total) / 1000000ULL;
+
+               td->rate_io_issue_bytes[ddir] += (missed - over);
        }
 }