From: Jens Axboe Date: Fri, 24 Oct 2014 05:16:50 +0000 (-0600) Subject: Consolidate disk util, eta, and status check thread X-Git-Tag: fio-2.1.14~37 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=5ddc670712a9e7d11f915bcbaff388ddfb7471d1;ds=sidebyside Consolidate disk util, eta, and status check thread We don't need two, we can just have one do everything. Signed-off-by: Jens Axboe --- diff --git a/backend.c b/backend.c index 90d998dc..941a3ead 100644 --- a/backend.c +++ b/backend.c @@ -55,9 +55,10 @@ #include "err.h" #include "lib/tp.h" -static pthread_t disk_util_thread; -static pthread_cond_t du_cond; -static pthread_mutex_t du_lock; +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; @@ -75,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) @@ -1976,23 +1977,23 @@ static void run_threads(void) update_io_ticks(); } -static void wait_for_disk_thread_exit(void) +static void wait_for_helper_thread_exit(void) { void *ret; disk_util_start_exit(); - pthread_cond_signal(&du_cond); - pthread_join(disk_util_thread, &ret); + pthread_cond_signal(&helper_cond); + pthread_join(helper_thread, &ret); } static void free_disk_util(void) { disk_util_prune_entries(); - pthread_cond_destroy(&du_cond); + pthread_cond_destroy(&helper_cond); } -static void *disk_thread_main(void *data) +static void *helper_thread_main(void *data) { int ret = 0; @@ -2012,12 +2013,15 @@ static void *disk_thread_main(void *data) ts.tv_sec++; } - ret = pthread_cond_timedwait(&du_cond, &du_lock, &ts); - if (ret != ETIMEDOUT) - break; + 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(); } @@ -2025,18 +2029,18 @@ static void *disk_thread_main(void *data) return NULL; } -static int create_disk_util_thread(void) +static int create_helper_thread(void) { int ret; setup_disk_util(); - pthread_cond_init(&du_cond, NULL); - pthread_mutex_init(&du_lock, NULL); + 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) { - log_err("Can't create disk util thread: %s\n", strerror(ret)); + log_err("Can't create helper thread: %s\n", strerror(ret)); return 1; } @@ -2076,16 +2080,14 @@ int fio_backend(void) set_genesis_time(); stat_init(); - create_disk_util_thread(); - create_status_interval_thread(); + create_helper_thread(); cgroup_list = smalloc(sizeof(*cgroup_list)); INIT_FLIST_HEAD(cgroup_list); run_threads(); - wait_for_disk_thread_exit(); - wait_for_status_interval_thread_exit(); + wait_for_helper_thread_exit(); if (!fio_abort) { __show_run_stats(); diff --git a/diskutil.c b/diskutil.c index c5c5ea6c..51da8a08 100644 --- a/diskutil.c +++ b/diskutil.c @@ -117,7 +117,7 @@ int update_io_ticks(void) fio_mutex_down(disk_util_mutex); - if (!disk_util_exit) { + if (!helper_exit) { flist_for_each(entry, &disk_list) { du = flist_entry(entry, struct disk_util, list); update_io_tick_disk(du); diff --git a/diskutil.h b/diskutil.h index f621113e..6b1ed6b0 100644 --- a/diskutil.h +++ b/diskutil.h @@ -3,7 +3,7 @@ #include "json.h" #define FIO_DU_NAME_SZ 64 -extern volatile int disk_util_exit; +extern volatile int helper_exit; struct disk_util_stats { uint32_t ios[2]; @@ -125,12 +125,12 @@ static inline void print_disk_util(struct disk_util_stat *du, static inline int update_io_ticks(void) { - return disk_util_exit; + return helper_exit; } #endif static inline void disk_util_start_exit(void) { - disk_util_exit = 1; + helper_exit = 1; } #endif diff --git a/fio.h b/fio.h index f981739e..f453d92a 100644 --- a/fio.h +++ b/fio.h @@ -403,6 +403,8 @@ extern int nr_clients; extern int log_syslog; extern int status_interval; extern const char fio_version_string[]; +extern int helper_do_stat; +extern pthread_cond_t helper_cond; extern struct thread_data *threads; diff --git a/stat.c b/stat.c index 3aae76df..84d9eefd 100644 --- a/stat.c +++ b/stat.c @@ -1422,7 +1422,7 @@ void show_run_stats(void) fio_mutex_up(stat_mutex); } -static void __show_running_run_stats(void) +void __show_running_run_stats(void) { struct thread_data *td; unsigned long long *rt; @@ -1892,52 +1892,11 @@ void stat_exit(void) fio_mutex_remove(stat_mutex); } -static pthread_t si_thread; -static pthread_cond_t si_cond; -static pthread_mutex_t si_lock; -static int si_thread_exit; - /* * Called from signal handler. Wake up status thread. */ void show_running_run_stats(void) { - pthread_cond_signal(&si_cond); -} - -static void *si_thread_main(void *unused) -{ - while (!si_thread_exit) { - pthread_cond_wait(&si_cond, &si_lock); - if (si_thread_exit) - break; - - __show_running_run_stats(); - } - - return NULL; -} - -void create_status_interval_thread(void) -{ - int ret; - - pthread_cond_init(&si_cond, NULL); - pthread_mutex_init(&si_lock, NULL); - - ret = pthread_create(&si_thread, NULL, si_thread_main, NULL); - if (ret) { - log_err("Can't create status thread: %s\n", strerror(ret)); - return; - } -} - -void wait_for_status_interval_thread_exit(void) -{ - void *ret; - - si_thread_exit = 1; - pthread_cond_signal(&si_cond); - pthread_join(si_thread, &ret); - pthread_cond_destroy(&si_cond); + helper_do_stat = 1; + pthread_cond_signal(&helper_cond); } diff --git a/stat.h b/stat.h index 2c68edcc..32ea2269 100644 --- a/stat.h +++ b/stat.h @@ -221,6 +221,7 @@ extern int calc_thread_status(struct jobs_eta *je, int force); extern void display_thread_status(struct jobs_eta *je); extern void show_run_stats(void); extern void __show_run_stats(void); +extern void __show_running_run_stats(void); extern void show_running_run_stats(void); extern void check_for_running_stats(void); extern void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr); @@ -234,8 +235,6 @@ extern void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat); extern void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat); extern void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist); extern void reset_io_stats(struct thread_data *); -extern void create_status_interval_thread(void); -extern void wait_for_status_interval_thread_exit(void); static inline int usec_to_msec(unsigned long *min, unsigned long *max, double *mean, double *dev)