stat: avoid hang with race in stat thread exit and rusage update
authorJens Axboe <axboe@fb.com>
Fri, 24 Oct 2014 05:04:37 +0000 (23:04 -0600)
committerJens Axboe <axboe@fb.com>
Fri, 24 Oct 2014 05:04:37 +0000 (23:04 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
stat.c

index 4437d196c0d5cdf2b5a9ce34c1982d353e7ea480..90d998dc18653630d7a6d6979085901166a7f52d 100644 (file)
--- 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 a5fd50b921dbad3279561bf5f471838f67cc87dd..3aae76df431e7d9acdb56ec31a2b8a172da195a1 100644 (file)
--- 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);