Merge branch 'io-threads'
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index 34e3792fd8f1d5ca8bbcf2f13c74a4320012ca4c..d143d36c0c60ed1d5d6c1bca6b1aa27bd86c9212 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1369,7 +1369,7 @@ void __show_run_stats(void)
        struct group_run_stats *runstats, *rs;
        struct thread_data *td;
        struct thread_stat *threadstats, *ts;
-       int i, j, nr_ts, last_ts, idx;
+       int i, j, k, nr_ts, last_ts, idx;
        int kb_base_warned = 0;
        int unit_base_warned = 0;
        struct json_object *root = NULL;
@@ -1481,8 +1481,8 @@ void __show_run_stats(void)
                ts->latency_window = td->o.latency_window;
 
                ts->nr_block_infos = td->ts.nr_block_infos;
-               for (i = 0; i < ts->nr_block_infos; i++)
-                       ts->block_infos[i] = td->ts.block_infos[i];
+               for (k = 0; k < ts->nr_block_infos; k++)
+                       ts->block_infos[k] = td->ts.block_infos[k];
 
                sum_thread_stats(ts, &td->ts, idx);
        }
@@ -2009,6 +2009,8 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
        if (spent < td->o.bw_avg_time)
                return;
 
+       td_io_u_lock(td);
+
        /*
         * Compute both read and write rates for the interval.
         */
@@ -2033,6 +2035,7 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
        }
 
        fio_gettime(&td->bw_sample_time, NULL);
+       td_io_u_unlock(td);
 }
 
 void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
@@ -2048,6 +2051,8 @@ void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs
        if (spent < td->o.iops_avg_time)
                return;
 
+       td_io_u_lock(td);
+
        /*
         * Compute both read and write rates for the interval.
         */
@@ -2072,6 +2077,7 @@ void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs
        }
 
        fio_gettime(&td->iops_sample_time, NULL);
+       td_io_u_unlock(td);
 }
 
 void stat_init(void)