Merge branch 'master' into gfio
[fio.git] / backend.c
index 600f5ce2c7662cc0356055d1f1c0a9a56f42c54d..022122a2d9914ca78a6406075e41e3c58b58242a 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -406,6 +406,15 @@ static int break_on_this_error(struct thread_data *td, enum fio_ddir ddir,
        return 0;
 }
 
        return 0;
 }
 
+static void check_update_rusage(struct thread_data *td)
+{
+       if (td->update_rusage) {
+               td->update_rusage = 0;
+               update_rusage_stat(td);
+               fio_mutex_up(td->rusage_sem);
+       }
+}
+
 /*
  * The main verify engine. Runs over the writes we previously submitted,
  * reads the blocks back in, and checks the crc/md5 of the data.
 /*
  * The main verify engine. Runs over the writes we previously submitted,
  * reads the blocks back in, and checks the crc/md5 of the data.
@@ -433,6 +442,8 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes)
                        break;
        }
 
                        break;
        }
 
+       check_update_rusage(td);
+
        if (td->error)
                return;
 
        if (td->error)
                return;
 
@@ -444,6 +455,7 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes)
                int ret2, full;
 
                update_tv_cache(td);
                int ret2, full;
 
                update_tv_cache(td);
+               check_update_rusage(td);
 
                if (runtime_exceeded(td, &td->tv_cache)) {
                        __update_tv_cache(td);
 
                if (runtime_exceeded(td, &td->tv_cache)) {
                        __update_tv_cache(td);
@@ -597,6 +609,8 @@ sync_done:
                        break;
        }
 
                        break;
        }
 
+       check_update_rusage(td);
+
        if (!td->error) {
                min_events = td->cur_depth;
 
        if (!td->error) {
                min_events = td->cur_depth;
 
@@ -652,6 +666,8 @@ static uint64_t do_io(struct thread_data *td)
                int ret2, full;
                enum fio_ddir ddir;
 
                int ret2, full;
                enum fio_ddir ddir;
 
+               check_update_rusage(td);
+
                if (td->terminate || td->done)
                        break;
 
                if (td->terminate || td->done)
                        break;
 
@@ -816,6 +832,8 @@ sync_done:
                }
        }
 
                }
        }
 
+       check_update_rusage(td);
+
        if (td->trim_entries)
                log_err("fio: %d trim entries leaked?\n", td->trim_entries);
 
        if (td->trim_entries)
                log_err("fio: %d trim entries leaked?\n", td->trim_entries);
 
@@ -884,8 +902,7 @@ static int init_io_u(struct thread_data *td)
        char *p;
 
        max_units = td->o.iodepth;
        char *p;
 
        max_units = td->o.iodepth;
-       max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
-       max_bs = max(td->o.max_bs[DDIR_TRIM], max_bs);
+       max_bs = td_max_bs(td);
        min_write = td->o.min_bs[DDIR_WRITE];
        td->orig_buffer_size = (unsigned long long) max_bs
                                        * (unsigned long long) max_units;
        min_write = td->o.min_bs[DDIR_WRITE];
        td->orig_buffer_size = (unsigned long long) max_bs
                                        * (unsigned long long) max_units;
@@ -1042,7 +1059,7 @@ static int keep_running(struct thread_data *td)
                 * are done.
                 */
                diff = td->o.size - ddir_rw_sum(td->io_bytes);
                 * are done.
                 */
                diff = td->o.size - ddir_rw_sum(td->io_bytes);
-               if (diff < td->o.rw_min_bs)
+               if (diff < td_max_bs(td))
                        return 0;
 
                return 1;
                        return 0;
 
                return 1;
@@ -1392,6 +1409,9 @@ err:
        if (td->o.write_iolog_file)
                write_iolog_close(td);
 
        if (td->o.write_iolog_file)
                write_iolog_close(td);
 
+       fio_mutex_remove(td->rusage_sem);
+       td->rusage_sem = NULL;
+
        td_set_runstate(td, TD_EXITED);
        return (void *) (uintptr_t) td->error;
 }
        td_set_runstate(td, TD_EXITED);
        return (void *) (uintptr_t) td->error;
 }
@@ -1645,6 +1665,9 @@ static void run_threads(void)
 
                        init_disk_util(td);
 
 
                        init_disk_util(td);
 
+                       td->rusage_sem = fio_mutex_init(FIO_MUTEX_LOCKED);
+                       td->update_rusage = 0;
+
                        /*
                         * Set state to created. Thread will transition
                         * to TD_INITIALIZED when it's done setting up.
                        /*
                         * Set state to created. Thread will transition
                         * to TD_INITIALIZED when it's done setting up.