X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=backend.c;h=d19d870f8143d985882841af68a0a94c056f7e35;hp=30f78b72f9d15acdca6c04930a8e26db53fa2d5e;hb=4a995ddae8b12d20efc2367ad4e1c9b159f96eed;hpb=ebea21332ee7d7d12f17cbe9718611bcec558210 diff --git a/backend.c b/backend.c index 30f78b72..d19d870f 100644 --- a/backend.c +++ b/backend.c @@ -55,8 +55,11 @@ #include "err.h" #include "lib/tp.h" -static pthread_t disk_util_thread; -static struct fio_mutex *disk_thread_mutex; +static pthread_t helper_thread; +static pthread_mutex_t helper_lock; +pthread_cond_t helper_cond; +int helper_do_stat = 0; + static struct fio_mutex *startup_mutex; static struct flist_head *cgroup_list; static char *cgroup_mnt; @@ -73,7 +76,7 @@ unsigned int stat_number = 0; int shm_id = 0; int temp_stall_ts; unsigned long done_secs = 0; -volatile int disk_util_exit = 0; +volatile int helper_exit = 0; #define PAGE_ALIGN(buf) \ (char *) (((uintptr_t) (buf) + page_mask) & ~page_mask) @@ -87,7 +90,7 @@ static void sig_int(int sig) fio_server_got_signal(sig); else { log_info("\nfio: terminating on signal %d\n", sig); - fflush(stdout); + log_info_flush(); exit_value = 128; } @@ -1562,13 +1565,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; } @@ -1763,7 +1770,7 @@ static void run_threads(void) nr_process > 1 ? "es" : ""); } log_info("\n"); - fflush(stdout); + log_info_flush(); } todo = thread_number; @@ -1970,57 +1977,70 @@ static void run_threads(void) update_io_ticks(); } -void wait_for_disk_thread_exit(void) +static void wait_for_helper_thread_exit(void) { - fio_mutex_down(disk_thread_mutex); + void *ret; + + helper_exit = 1; + pthread_cond_signal(&helper_cond); + pthread_join(helper_thread, &ret); } static void free_disk_util(void) { - disk_util_start_exit(); - wait_for_disk_thread_exit(); disk_util_prune_entries(); + + pthread_cond_destroy(&helper_cond); } -static void *disk_thread_main(void *data) +static void *helper_thread_main(void *data) { int ret = 0; fio_mutex_up(startup_mutex); - while (threads && !ret) { - usleep(DISK_UTIL_MSEC * 1000); - if (!threads) - break; + while (!ret) { + uint64_t sec = DISK_UTIL_MSEC / 1000; + uint64_t nsec = (DISK_UTIL_MSEC % 1000) * 1000000; + struct timespec ts; + struct timeval tv; + + gettimeofday(&tv, NULL); + ts.tv_sec = tv.tv_sec + sec; + ts.tv_nsec = (tv.tv_usec * 1000) + nsec; + if (ts.tv_nsec > 1000000000ULL) { + ts.tv_nsec -= 1000000000ULL; + ts.tv_sec++; + } + + pthread_cond_timedwait(&helper_cond, &helper_lock, &ts); + ret = update_io_ticks(); + if (helper_do_stat) { + helper_do_stat = 0; + __show_running_run_stats(); + } + if (!is_backend) print_thread_status(); } - fio_mutex_up(disk_thread_mutex); return NULL; } -static int create_disk_util_thread(void) +static int create_helper_thread(void) { int ret; setup_disk_util(); - disk_thread_mutex = fio_mutex_init(FIO_MUTEX_LOCKED); + pthread_cond_init(&helper_cond, NULL); + pthread_mutex_init(&helper_lock, NULL); - ret = pthread_create(&disk_util_thread, NULL, disk_thread_main, NULL); + ret = pthread_create(&helper_thread, NULL, helper_thread_main, NULL); if (ret) { - fio_mutex_remove(disk_thread_mutex); - log_err("Can't create disk util thread: %s\n", strerror(ret)); - return 1; - } - - ret = pthread_detach(disk_util_thread); - if (ret) { - fio_mutex_remove(disk_thread_mutex); - log_err("Can't detatch disk util thread: %s\n", strerror(ret)); + log_err("Can't create helper thread: %s\n", strerror(ret)); return 1; } @@ -2060,15 +2080,17 @@ int fio_backend(void) set_genesis_time(); stat_init(); - create_disk_util_thread(); + create_helper_thread(); cgroup_list = smalloc(sizeof(*cgroup_list)); INIT_FLIST_HEAD(cgroup_list); run_threads(); + wait_for_helper_thread_exit(); + if (!fio_abort) { - show_run_stats(); + __show_run_stats(); if (write_bw_log) { int i; @@ -2081,8 +2103,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); @@ -2090,7 +2115,6 @@ int fio_backend(void) sfree(cgroup_mnt); fio_mutex_remove(startup_mutex); - fio_mutex_remove(disk_thread_mutex); stat_exit(); return exit_value; }