From c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699e Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 28 Mar 2013 15:08:49 -0600 Subject: [PATCH] Fix usr/sys/ctx/majf/minf for -USR1 usage Let the threads themselves update their stats. Signed-off-by: Jens Axboe --- backend.c | 24 ++++++++++++++++++++++++ fio.h | 2 ++ stat.c | 10 +++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/backend.c b/backend.c index ae4216db..fcb74dcb 100644 --- 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; } +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. @@ -433,6 +442,8 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes) break; } + check_update_rusage(td); + 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); + check_update_rusage(td); if (runtime_exceeded(td, &td->tv_cache)) { __update_tv_cache(td); @@ -597,6 +609,8 @@ sync_done: break; } + check_update_rusage(td); + 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; + check_update_rusage(td); + 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); @@ -1379,6 +1397,9 @@ err: 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; } @@ -1627,6 +1648,9 @@ static void run_threads(void) 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. diff --git a/fio.h b/fio.h index 621ed606..a1b2a931 100644 --- a/fio.h +++ b/fio.h @@ -354,6 +354,8 @@ struct thread_data { uint64_t stat_io_blocks[DDIR_RWDIR_CNT]; struct timeval iops_sample_time; + volatile int update_rusage; + struct fio_mutex *rusage_sem; struct rusage ru_start; struct rusage ru_end; diff --git a/stat.c b/stat.c index fe09a296..59f37184 100644 --- a/stat.c +++ b/stat.c @@ -1386,13 +1386,21 @@ static void *__show_running_run_stats(void *arg) if (td_trim(td) && td->io_bytes[DDIR_TRIM]) td->ts.runtime[DDIR_TRIM] += rt[i]; - update_rusage_stat(td); + td->update_rusage = 1; td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ]; td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE]; td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM]; td->ts.total_run_time = mtime_since(&td->epoch, &tv); } + for_each_td(td, i) { + if (td->rusage_sem) { + td->update_rusage = 1; + fio_mutex_down(td->rusage_sem); + } + td->update_rusage = 0; + } + show_run_stats(); for_each_td(td, i) { -- 2.25.1