Update ramp_time
authorJens Axboe <jens.axboe@oracle.com>
Thu, 11 Sep 2008 08:17:26 +0000 (10:17 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 11 Sep 2008 08:17:26 +0000 (10:17 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
HOWTO
eta.c
fio.c
fio.h
io_u.c
time.c

diff --git a/HOWTO b/HOWTO
index 634a599..5e5b212 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -580,7 +580,10 @@ time_based If set, fio will run for the duration of the runtime
 ramp_time=time If set, fio will run the specified workload for this amount
                of time before logging any performance numbers. Useful for
                letting performance settle before logging results, thus
-               minimizing the runtime required for stable results.
+               minimizing the runtime required for stable results. Note
+               that the ramp_time is considered lead in time for a job,
+               thus it will increase the total runtime if a special timeout
+               or runtime is specified.
 
 invalidate=bool        Invalidate the buffer/page cache parts for this file prior
                to starting io. Defaults to true.
diff --git a/eta.c b/eta.c
index 47e9e33..1c809ee 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -23,6 +23,9 @@ static void check_str_update(struct thread_data *td)
        case TD_EXITED:
                c = 'E';
                break;
+       case TD_RAMP:
+               c = '/';
+               break;
        case TD_RUNNING:
                if (td_rw(td)) {
                        if (td_random(td))
@@ -94,10 +97,13 @@ static void eta_to_str(char *str, unsigned long eta_sec)
 /*
  * Best effort calculation of the estimated pending runtime of a job.
  */
-static int thread_eta(struct thread_data *td, unsigned long elapsed)
+static int thread_eta(struct thread_data *td)
 {
        unsigned long long bytes_total, bytes_done;
        unsigned long eta_sec = 0;
+       unsigned long elapsed;
+
+       elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
 
        bytes_total = td->total_io_size;
 
@@ -138,15 +144,26 @@ static int thread_eta(struct thread_data *td, unsigned long elapsed)
                    eta_sec > (td->o.timeout + done_secs - elapsed))
                        eta_sec = td->o.timeout + done_secs - elapsed;
        } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
-                       || td->runstate == TD_INITIALIZED) {
+                       || td->runstate == TD_INITIALIZED
+                       || td->runstate == TD_RAMP) {
                int t_eta = 0, r_eta = 0;
 
                /*
                 * We can only guess - assume it'll run the full timeout
                 * if given, otherwise assume it'll run at the specified rate.
                 */
-               if (td->o.timeout)
+               if (td->o.timeout) {
                        t_eta = td->o.timeout + td->o.start_delay;
+
+                       if (in_ramp_time(td)) {
+                               unsigned long ramp_left;
+
+                               ramp_left = mtime_since_now(&td->start);
+                               ramp_left = (ramp_left + 999) / 1000;
+                               if (ramp_left <= t_eta)
+                                       t_eta -= ramp_left;
+                       }
+               }
                if (td->o.rate) {
                        r_eta = (bytes_total / 1024) / td->o.rate;
                        r_eta += td->o.start_delay;
@@ -185,8 +202,8 @@ static void calc_rate(unsigned long mtime, unsigned long long *io_bytes,
  */
 void print_thread_status(void)
 {
-       unsigned long elapsed = mtime_since_genesis() / 1000;
-       int i, nr_running, nr_pending, t_rate, m_rate;
+       unsigned long elapsed = (mtime_since_genesis() + 999) / 1000;
+       int i, nr_ramp, nr_running, nr_pending, t_rate, m_rate;
        int t_iops, m_iops, files_open;
        struct thread_data *td;
        char eta_str[128];
@@ -218,6 +235,7 @@ void print_thread_status(void)
 
        io_bytes[0] = io_bytes[1] = 0;
        nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0;
+       nr_ramp = 0;
        bw_avg_time = ULONG_MAX;
        files_open = 0;
        for_each_td(td, i) {
@@ -231,17 +249,23 @@ void print_thread_status(void)
                        t_iops += td->o.rate_iops;
                        m_iops += td->o.rate_iops_min;
                        files_open += td->nr_open_files;
+               } else if (td->runstate == TD_RAMP) {
+                       nr_running++;
+                       nr_ramp++;
                } else if (td->runstate < TD_RUNNING)
                        nr_pending++;
 
                if (elapsed >= 3)
-                       eta_secs[i] = thread_eta(td, elapsed);
+                       eta_secs[i] = thread_eta(td);
                else
                        eta_secs[i] = INT_MAX;
 
                check_str_update(td);
-               io_bytes[0] += td->io_bytes[0];
-               io_bytes[1] += td->io_bytes[1];
+
+               if (td->runstate > TD_RAMP) {
+                       io_bytes[0] += td->io_bytes[0];
+                       io_bytes[1] += td->io_bytes[1];
+               }
        }
 
        if (exitall_on_terminate)
@@ -269,7 +293,7 @@ void print_thread_status(void)
        fio_gettime(&now, NULL);
        rate_time = mtime_since(&rate_prev_time, &now);
 
-       if (write_bw_log && rate_time > bw_avg_time) {
+       if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
                calc_rate(rate_time, io_bytes, rate_io_bytes, rate);
                memcpy(&rate_prev_time, &now, sizeof(now));
                add_agg_sample(rate[DDIR_READ], DDIR_READ);
@@ -295,7 +319,7 @@ void print_thread_status(void)
                char perc_str[32];
                int ll;
 
-               if (!eta_sec && !eta_good)
+               if ((!eta_sec && !eta_good) || nr_ramp == nr_running)
                        strcpy(perc_str, "-.-% done");
                else {
                        eta_good = 1;
diff --git a/fio.c b/fio.c
index 2a09fbe..dbb9ef6 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -61,7 +61,7 @@ struct io_log *agg_io_log[2];
 #define TERMINATE_ALL          (-1)
 #define JOB_START_TIMEOUT      (5 * 1000)
 
-static inline void td_set_runstate(struct thread_data *td, int runstate)
+void td_set_runstate(struct thread_data *td, int runstate)
 {
        if (td->runstate == runstate)
                return;
@@ -495,7 +495,10 @@ static void do_io(struct thread_data *td)
        unsigned int i;
        int ret = 0;
 
-       td_set_runstate(td, TD_RUNNING);
+       if (in_ramp_time(td))
+               td_set_runstate(td, TD_RAMP);
+       else
+               td_set_runstate(td, TD_RUNNING);
 
        while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
                struct timeval comp_time;
@@ -526,7 +529,9 @@ static void do_io(struct thread_data *td)
                if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ) {
                        io_u->end_io = verify_io_u;
                        td_set_runstate(td, TD_VERIFYING);
-               } else
+               } else if (in_ramp_time(td))
+                       td_set_runstate(td, TD_RAMP);
+               else
                        td_set_runstate(td, TD_RUNNING);
 
                ret = td_io_queue(td, io_u);
@@ -619,7 +624,7 @@ sync_done:
                 * of completions except the very first one which may look
                 * a little bursty
                 */
-               if (ramp_time_over(td)) {
+               if (!in_ramp_time(td)) {
                        usec = utime_since(&s, &comp_time);
 
                        rate_throttle(td, usec, bytes_done);
@@ -827,12 +832,8 @@ static int keep_running(struct thread_data *td)
        return 0;
 }
 
-static int clear_io_state(struct thread_data *td)
+static void reset_io_counters(struct thread_data *td)
 {
-       struct fio_file *f;
-       unsigned int i;
-       int ret;
-
        td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
        td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
        td->zone_bytes = 0;
@@ -847,6 +848,34 @@ static int clear_io_state(struct thread_data *td)
         */
        if (td->o.time_based || td->o.loops)
                td->nr_done_files = 0;
+}
+
+void reset_all_stats(struct thread_data *td)
+{
+       struct timeval tv;
+       int i;
+
+       reset_io_counters(td);
+
+       for (i = 0; i < 2; i++) {
+               td->io_bytes[i] = 0;
+               td->io_blocks[i] = 0;
+               td->io_issues[i] = 0;
+               td->ts.total_io_u[i] = 0;
+       }
+       
+       fio_gettime(&tv, NULL);
+       memcpy(&td->epoch, &tv, sizeof(tv));
+       memcpy(&td->start, &tv, sizeof(tv));
+}
+
+static int clear_io_state(struct thread_data *td)
+{
+       struct fio_file *f;
+       unsigned int i;
+       int ret;
+
+       reset_io_counters(td);
 
        close_files(td);
 
@@ -1347,7 +1376,10 @@ static void run_threads(void)
                        if (td->runstate != TD_INITIALIZED)
                                continue;
 
-                       td_set_runstate(td, TD_RUNNING);
+                       if (in_ramp_time(td))
+                               td_set_runstate(td, TD_RAMP);
+                       else
+                               td_set_runstate(td, TD_RUNNING);
                        nr_running++;
                        nr_started--;
                        m_rate += td->o.ratemin;
diff --git a/fio.h b/fio.h
index a0c1109..9131792 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -820,6 +820,7 @@ extern void fill_start_time(struct timeval *);
 extern void fio_gettime(struct timeval *, void *);
 extern void set_genesis_time(void);
 extern int ramp_time_over(struct thread_data *);
+extern int in_ramp_time(struct thread_data *);
 
 /*
  * Init/option functions
@@ -886,6 +887,7 @@ enum {
        TD_NOT_CREATED = 0,
        TD_CREATED,
        TD_INITIALIZED,
+       TD_RAMP,
        TD_RUNNING,
        TD_VERIFYING,
        TD_FSYNCING,
@@ -893,6 +895,8 @@ enum {
        TD_REAPED,
 };
 
+extern void td_set_runstate(struct thread_data *, int);
+
 /*
  * Verify helpers
  */
@@ -927,6 +931,11 @@ extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int
 void io_u_mark_complete(struct thread_data *, unsigned int);
 void io_u_mark_submit(struct thread_data *, unsigned int);
 
+/*
+ * Reset stats after ramp time completes
+ */
+extern void reset_all_stats(struct thread_data *);
+
 /*
  * io engine entry points
  */
diff --git a/io_u.c b/io_u.c
index 17db16b..e7d1efa 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -903,15 +903,13 @@ static void io_completed(struct thread_data *td, struct io_u *io_u,
        if (!io_u->error) {
                unsigned int bytes = io_u->buflen - io_u->resid;
                const enum fio_ddir idx = io_u->ddir;
-               int ret, ramp_done;
+               int ret;
 
-               ramp_done = ramp_time_over(td);
-
-               if (ramp_done) {
-                       td->io_blocks[idx]++;
-                       td->io_bytes[idx] += bytes;
-                       td->this_io_bytes[idx] += bytes;
+               td->io_blocks[idx]++;
+               td->io_bytes[idx] += bytes;
+               td->this_io_bytes[idx] += bytes;
 
+               if (ramp_time_over(td)) {
                        usec = utime_since(&io_u->issue_time, &icd->time);
 
                        add_clat_sample(td, idx, usec);
@@ -924,8 +922,7 @@ static void io_completed(struct thread_data *td, struct io_u *io_u,
                    td->o.verify != VERIFY_NONE)
                        log_io_piece(td, io_u);
 
-               if (ramp_done)
-                       icd->bytes_done[idx] += bytes;
+               icd->bytes_done[idx] += bytes;
 
                if (io_u->end_io) {
                        ret = io_u->end_io(td, io_u);
diff --git a/time.c b/time.c
index 4f1c13a..e84fb01 100644 (file)
--- a/time.c
+++ b/time.c
@@ -164,6 +164,11 @@ unsigned long mtime_since_genesis(void)
        return mtime_since_now(&genesis);
 }
 
+int in_ramp_time(struct thread_data *td)
+{
+       return td->o.ramp_time && !td->ramp_time_over;
+}
+
 int ramp_time_over(struct thread_data *td)
 {
        struct timeval tv;
@@ -174,7 +179,8 @@ int ramp_time_over(struct thread_data *td)
        fio_gettime(&tv, NULL);
        if (mtime_since(&td->epoch, &tv) >= td->o.ramp_time * 1000) {
                td->ramp_time_over = 1;
-               memcpy(&td->start, &tv, sizeof(tv));
+               reset_all_stats(td);
+               td_set_runstate(td, TD_RAMP);
                return 1;
        }