Refactor for_each_td() to catch inappropriate td ptr reuse
[fio.git] / eta.c
diff --git a/eta.c b/eta.c
index 6017ca3102eb3b5795915a676e1140728b72579c..b392b83c2a44b4904b103b740eb51ace22fe9392 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -381,8 +381,7 @@ bool eta_time_within_slack(unsigned int time)
  */
 bool calc_thread_status(struct jobs_eta *je, int force)
 {
-       struct thread_data *td;
-       int i, unified_rw_rep;
+       int unified_rw_rep;
        uint64_t rate_time, disp_time, bw_avg_time, *eta_secs;
        unsigned long long io_bytes[DDIR_RWDIR_CNT] = {};
        unsigned long long io_iops[DDIR_RWDIR_CNT] = {};
@@ -416,7 +415,7 @@ bool calc_thread_status(struct jobs_eta *je, int force)
 
        bw_avg_time = ULONG_MAX;
        unified_rw_rep = 0;
-       for_each_td(td, i) {
+       for_each_td(td) {
                unified_rw_rep += td->o.unified_rw_rep;
                if (is_power_of_2(td->o.kb_base))
                        je->is_pow2 = 1;
@@ -458,9 +457,9 @@ bool calc_thread_status(struct jobs_eta *je, int force)
                        je->nr_pending++;
 
                if (je->elapsed_sec >= 3)
-                       eta_secs[i] = thread_eta(td);
+                       eta_secs[__td_index] = thread_eta(td);
                else
-                       eta_secs[i] = INT_MAX;
+                       eta_secs[__td_index] = INT_MAX;
 
                check_str_update(td);
 
@@ -477,26 +476,26 @@ bool calc_thread_status(struct jobs_eta *je, int force)
                                }
                        }
                }
-       }
+       } end_for_each();
 
        if (exitall_on_terminate) {
                je->eta_sec = INT_MAX;
-               for_each_td(td, i) {
-                       if (eta_secs[i] < je->eta_sec)
-                               je->eta_sec = eta_secs[i];
-               }
+               for_each_td_index() {
+                       if (eta_secs[__td_index] < je->eta_sec)
+                               je->eta_sec = eta_secs[__td_index];
+               } end_for_each();
        } else {
                unsigned long eta_stone = 0;
 
                je->eta_sec = 0;
-               for_each_td(td, i) {
+               for_each_td(td) {
                        if ((td->runstate == TD_NOT_CREATED) && td->o.stonewall)
-                               eta_stone += eta_secs[i];
+                               eta_stone += eta_secs[__td_index];
                        else {
-                               if (eta_secs[i] > je->eta_sec)
-                                       je->eta_sec = eta_secs[i];
+                               if (eta_secs[__td_index] > je->eta_sec)
+                                       je->eta_sec = eta_secs[__td_index];
                        }
-               }
+               } end_for_each();
                je->eta_sec += eta_stone;
        }
 
@@ -505,7 +504,7 @@ bool calc_thread_status(struct jobs_eta *je, int force)
        fio_gettime(&now, NULL);
        rate_time = mtime_since(&rate_prev_time, &now);
 
-       if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
+       if (write_bw_log && rate_time > bw_avg_time /* && !in_ramp_time(td) fixme: td isn't valid here */) {
                calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes,
                                je->rate);
                memcpy(&rate_prev_time, &now, sizeof(now));