Fix initialization of lastrate when using ratemin
authorJosh Carter <public@joshcarter.com>
Tue, 22 Nov 2011 08:35:29 +0000 (09:35 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 22 Nov 2011 08:35:29 +0000 (09:35 +0100)
fio was copying td->bw_sample_time (single timeval) into td->lastrate
(array of two timevals) using the latter's size. Thus is would get one
timeval worth of good data plus who-knows-what for the second timeval.
I'm pretty sure the intent of this code was to copy bw_sample_time
into both members of lastrate.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fio.c

diff --git a/fio.c b/fio.c
index 8702086..ce29c26 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1248,9 +1248,12 @@ static void *thread_main(void *data)
                memcpy(&td->iops_sample_time, &td->start, sizeof(td->start));
                memcpy(&td->tv_cache, &td->start, sizeof(td->start));
 
-               if (td->o.ratemin[0] || td->o.ratemin[1])
-                       memcpy(&td->lastrate, &td->bw_sample_time,
-                                                       sizeof(td->lastrate));
+               if (td->o.ratemin[0] || td->o.ratemin[1]) {
+                       memcpy(&td->lastrate[0], &td->bw_sample_time,
+                                               sizeof(td->bw_sample_time));
+                       memcpy(&td->lastrate[1], &td->bw_sample_time,
+                                               sizeof(td->bw_sample_time));
+               }
 
                if (clear_state)
                        clear_io_state(td);