Consolidate disk util, eta, and status check thread
authorJens Axboe <axboe@fb.com>
Fri, 24 Oct 2014 05:16:50 +0000 (23:16 -0600)
committerJens Axboe <axboe@fb.com>
Fri, 24 Oct 2014 05:16:50 +0000 (23:16 -0600)
We don't need two, we can just have one do everything.

Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
diskutil.c
diskutil.h
fio.h
stat.c
stat.h

index 90d998dc18653630d7a6d6979085901166a7f52d..941a3ead9b63acfc07170f04d9a83f02c072d30b 100644 (file)
--- a/backend.c
+++ b/backend.c
 #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();
index c5c5ea6ca91b05ab38fcdb69bbf0f3b9b4dc52cd..51da8a089d5dc173cb1f2718c47e9adf6564f9fc 100644 (file)
@@ -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);
index f621113e4b1a43c7bd80f1a872651dde794b5ffc..6b1ed6b0a8e96a3a84519b3016e8e78974b6abcd 100644 (file)
@@ -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 f981739e8fc261285056da4bdc65a50bc8757fdb..f453d92a98d4e088744ac9e06f73382a4c4bea07 100644 (file)
--- 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 3aae76df431e7d9acdb56ec31a2b8a172da195a1..84d9eefd842e76ca6a1d96a482ad3fd2a4c251a7 100644 (file)
--- 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 2c68edcc4513fc40bd7f0e9f37daa5a8dd3d6d98..32ea22694e75e173db8df7252e10288150c577f1 100644 (file)
--- 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)