X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=backend.c;h=1dcdcf049026db4f1ae33d04284ade793b76d77f;hp=65a3e184a6d77d7d5439f23c9a4c17813a405326;hb=92330695e64a42fd5dc54a6970a4b8122d3cd80e;hpb=36870c47801ca85d1a98c7ec47950b0aa360f865 diff --git a/backend.c b/backend.c index 65a3e184..1dcdcf04 100644 --- a/backend.c +++ b/backend.c @@ -363,6 +363,20 @@ static inline int runtime_exceeded(struct thread_data *td, struct timeval *t) return 0; } +/* + * We need to update the runtime consistently in ms, but keep a running + * tally of the current elapsed time in microseconds for sub millisecond + * updates. + */ +static inline void update_runtime(struct thread_data *td, + unsigned long long *elapsed_us, + const enum fio_ddir ddir) +{ + td->ts.runtime[ddir] -= (elapsed_us[ddir] + 999) / 1000; + elapsed_us[ddir] += utime_since_now(&td->start); + td->ts.runtime[ddir] += (elapsed_us[ddir] + 999) / 1000; +} + static int break_on_this_error(struct thread_data *td, enum fio_ddir ddir, int *retptr) { @@ -428,7 +442,7 @@ static int wait_for_completions(struct thread_data *td, struct timeval *time) * if the queue is full, we MUST reap at least 1 event */ min_evts = min(td->o.iodepth_batch_complete, td->cur_depth); - if (full && !min_evts) + if ((full && !min_evts) || !td->o.iodepth_batch_complete) min_evts = 1; if (time && (__should_check_rate(td, DDIR_READ) || @@ -1306,7 +1320,7 @@ static void io_workqueue_fn(struct thread_data *td, struct io_u *io_u) */ static void *thread_main(void *data) { - unsigned long long elapsed; + unsigned long long elapsed_us[DDIR_RWDIR_CNT] = { 0, }; struct thread_data *td = data; struct thread_options *o = &td->o; pthread_condattr_t attr; @@ -1544,18 +1558,12 @@ static void *thread_main(void *data) check_update_rusage(td); fio_mutex_down(stat_mutex); - if (td_read(td) && td->io_bytes[DDIR_READ]) { - elapsed = mtime_since_now(&td->start); - td->ts.runtime[DDIR_READ] += elapsed; - } - if (td_write(td) && td->io_bytes[DDIR_WRITE]) { - elapsed = mtime_since_now(&td->start); - td->ts.runtime[DDIR_WRITE] += elapsed; - } - if (td_trim(td) && td->io_bytes[DDIR_TRIM]) { - elapsed = mtime_since_now(&td->start); - td->ts.runtime[DDIR_TRIM] += elapsed; - } + if (td_read(td) && td->io_bytes[DDIR_READ]) + update_runtime(td, elapsed_us, DDIR_READ); + if (td_write(td) && td->io_bytes[DDIR_WRITE]) + update_runtime(td, elapsed_us, DDIR_WRITE); + if (td_trim(td) && td->io_bytes[DDIR_TRIM]) + update_runtime(td, elapsed_us, DDIR_TRIM); fio_gettime(&td->start, NULL); fio_mutex_up(stat_mutex); @@ -1579,7 +1587,7 @@ static void *thread_main(void *data) check_update_rusage(td); fio_mutex_down(stat_mutex); - td->ts.runtime[DDIR_READ] += mtime_since_now(&td->start); + update_runtime(td, elapsed_us, DDIR_READ); fio_gettime(&td->start, NULL); fio_mutex_up(stat_mutex);