From fda2cfacd5ebe1212fade95e6286f7e7ec8919f9 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 23 Oct 2014 23:04:37 -0600 Subject: [PATCH] stat: avoid hang with race in stat thread exit and rusage update Signed-off-by: Jens Axboe --- backend.c | 15 +++++++++++---- stat.c | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend.c b/backend.c index 4437d196..90d998dc 100644 --- a/backend.c +++ b/backend.c @@ -1564,13 +1564,17 @@ err: if (o->write_iolog_file) write_iolog_close(td); - fio_mutex_remove(td->rusage_sem); - td->rusage_sem = NULL; - fio_mutex_remove(td->mutex); td->mutex = NULL; td_set_runstate(td, TD_EXITED); + + /* + * Do this last after setting our runstate to exited, so we + * know that the stat thread is signaled. + */ + check_update_rusage(td); + return (void *) (uintptr_t) td->error; } @@ -2097,8 +2101,11 @@ int fio_backend(void) } } - for_each_td(td, i) + for_each_td(td, i) { fio_options_free(td); + fio_mutex_remove(td->rusage_sem); + td->rusage_sem = NULL; + } free_disk_util(); cgroup_kill(cgroup_list); diff --git a/stat.c b/stat.c index a5fd50b9..3aae76df 100644 --- a/stat.c +++ b/stat.c @@ -1451,6 +1451,8 @@ static void __show_running_run_stats(void) } for_each_td(td, i) { + if (td->runstate >= TD_EXITED) + continue; if (td->rusage_sem) { td->update_rusage = 1; fio_mutex_down(td->rusage_sem); -- 2.25.1