[PATCH] Fixup rate usec cycle calculation for small values
authorJens Axboe <jens.axboe@oracle.com>
Sat, 13 Jan 2007 11:29:13 +0000 (12:29 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 13 Jan 2007 11:29:13 +0000 (12:29 +0100)
If someone set rate to 2KiB/sec or something low in that range,
we would integer divide by zero. Do calculation in reads per msec
instead of full seconds and fix the zero division.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
log.c

diff --git a/log.c b/log.c
index f61215eae73e2b63e3868e713f99bf95eddeb240..a4f4c7801d0fa92671bd4b67ee8798b7f0f88924 100644 (file)
--- a/log.c
+++ b/log.c
@@ -185,7 +185,8 @@ int init_iolog(struct thread_data *td)
 
 int setup_rate(struct thread_data *td)
 {
-       int nr_reads_per_sec;
+       unsigned long long rate;
+       int nr_reads_per_msec;
 
        if (!td->rate)
                return 0;
@@ -195,8 +196,14 @@ int setup_rate(struct thread_data *td)
                return -1;
        }
 
-       nr_reads_per_sec = (td->rate * 1024) / td->min_bs[DDIR_READ];
-       td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
+       rate = td->rate;
+       nr_reads_per_msec = (rate * 1024 * 1000) / td->min_bs[DDIR_READ];
+       if (!nr_reads_per_msec) {
+               log_err("rate lower than supported\n");
+               return -1;
+       }
+
+       td->rate_usec_cycle = 1000000000ULL / nr_reads_per_msec;
        td->rate_pending_usleep = 0;
        return 0;
 }