Add ddir_rw_sum()
authorJens Axboe <axboe@kernel.dk>
Fri, 14 Sep 2012 06:59:20 +0000 (08:59 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 14 Sep 2012 06:59:20 +0000 (08:59 +0200)
We sum up the three data direction primitives a lot, this is
more readable.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
eta.c
io_ddir.h

index f6d1983..9b0d791 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -717,8 +717,7 @@ sync_done:
 
                if (ret < 0)
                        break;
-               if (!(bytes_done[DDIR_READ] + bytes_done[DDIR_WRITE]
-                               + bytes_done[DDIR_TRIM]))
+               if (!ddir_rw_sum(bytes_done))
                        continue;
 
                if (!in_ramp_time(td) && should_check_rate(td, bytes_done)) {
@@ -733,8 +732,7 @@ sync_done:
                if (td->o.thinktime) {
                        unsigned long long b;
 
-                       b = td->io_blocks[DDIR_READ] + td->io_blocks[DDIR_WRITE] +
-                               td->io_blocks[DDIR_TRIM];
+                       b = ddir_rw_sum(td->io_blocks);
                        if (!(b % td->o.thinktime_blocks)) {
                                int left;
 
@@ -780,8 +778,7 @@ sync_done:
        /*
         * stop job if we failed doing any IO
         */
-       if ((td->this_io_bytes[DDIR_READ] + td->this_io_bytes[DDIR_WRITE] +
-                       td->this_io_bytes[DDIR_TRIM]) == 0)
+       if (!ddir_rw_sum(td->this_io_bytes))
                td->done = 1;
 }
 
@@ -936,8 +933,6 @@ static int switch_ioscheduler(struct thread_data *td)
 
 static int keep_running(struct thread_data *td)
 {
-       unsigned long long io_done;
-
        if (td->done)
                return 0;
        if (td->o.time_based)
@@ -947,9 +942,7 @@ static int keep_running(struct thread_data *td)
                return 1;
        }
 
-       io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE] +
-                       td->io_bytes[DDIR_TRIM] + td->io_skip_bytes;
-       if (io_done < td->o.size)
+       if (ddir_rw_sum(td->io_bytes) < td->o.size)
                return 1;
 
        return 0;
@@ -1356,10 +1349,8 @@ static void reap_threads(unsigned int *nr_running, unsigned int *t_rate,
                continue;
 reaped:
                (*nr_running)--;
-               (*m_rate) -= (td->o.ratemin[DDIR_READ] + td->o.ratemin[DDIR_WRITE] +
-                       td->o.ratemin[DDIR_TRIM]);
-               (*t_rate) -= (td->o.rate[DDIR_READ] + td->o.rate[DDIR_WRITE] +
-                       td->o.rate[DDIR_TRIM]);
+               (*m_rate) -= ddir_rw_sum(td->o.ratemin);
+               (*t_rate) -= ddir_rw_sum(td->o.rate);
                if (!td->pid)
                        pending--;
 
@@ -1581,10 +1572,8 @@ static void run_threads(void)
                                td_set_runstate(td, TD_RUNNING);
                        nr_running++;
                        nr_started--;
-                       m_rate += td->o.ratemin[DDIR_READ] +
-                               td->o.ratemin[DDIR_WRITE] + td->o.ratemin[DDIR_TRIM];
-                       t_rate += td->o.rate[DDIR_READ] +
-                               td->o.rate[DDIR_WRITE] + td->o.rate[DDIR_TRIM];
+                       m_rate += ddir_rw_sum(td->o.ratemin);
+                       t_rate += ddir_rw_sum(td->o.rate);
                        todo--;
                        fio_mutex_up(td->mutex);
                }
diff --git a/eta.c b/eta.c
index e2a5a29..1caee49 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -155,8 +155,7 @@ static int thread_eta(struct thread_data *td)
        if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
                double perc, perc_t;
 
-               bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE] +
-                       td->io_bytes[DDIR_TRIM];
+               bytes_done = ddir_rw_sum(td->io_bytes);
                perc = (double) bytes_done / (double) bytes_total;
                if (perc > 1.0)
                        perc = 1.0;
@@ -177,6 +176,7 @@ static int thread_eta(struct thread_data *td)
                        || td->runstate == TD_RAMP
                        || td->runstate == TD_PRE_READING) {
                int t_eta = 0, r_eta = 0;
+               unsigned long long rate_bytes;
 
                /*
                 * We can only guess - assume it'll run the full timeout
@@ -195,11 +195,9 @@ static int thread_eta(struct thread_data *td)
                                        t_eta -= ramp_left;
                        }
                }
-               if (td->o.rate[DDIR_READ] || td->o.rate[DDIR_WRITE] ||
-                   td->o.rate[DDIR_TRIM]) {
-                       r_eta = (bytes_total / 1024) /
-                               (td->o.rate[DDIR_READ] + td->o.rate[DDIR_WRITE] +
-                               td->o.rate[DDIR_TRIM]);
+               rate_bytes = ddir_rw_sum(td->o.rate);
+               if (rate_bytes) {
+                       r_eta = (bytes_total / 1024) / rate_bytes;
                        r_eta += td->o.start_delay;
                }
 
@@ -273,11 +271,9 @@ int calc_thread_status(struct jobs_eta *je, int force)
                        return 0;
        }
 
-       if (!rate_io_bytes[DDIR_READ] && !rate_io_bytes[DDIR_WRITE] &&
-                       !rate_io_bytes[DDIR_TRIM])
+       if (!ddir_rw_sum(rate_io_bytes))
                fill_start_time(&rate_prev_time);
-       if (!disp_io_bytes[DDIR_READ] && !disp_io_bytes[DDIR_WRITE] &&
-                       !disp_io_bytes[DDIR_TRIM])
+       if (!ddir_rw_sum(disp_io_bytes))
                fill_start_time(&disp_prev_time);
 
        eta_secs = malloc(thread_number * sizeof(unsigned long));
index fa3b143..df5abbb 100644 (file)
--- a/io_ddir.h
+++ b/io_ddir.h
@@ -45,4 +45,7 @@ static inline int ddir_rw(enum fio_ddir ddir)
 
 #define ddir_trim(ddir) ((ddir) == DDIR_TRIM)
 
+#define ddir_rw_sum(arr)       \
+       ((arr)[DDIR_READ] + (arr)[DDIR_WRITE] + (arr)[DDIR_TRIM])
+
 #endif