Fix usr/sys/ctx/majf/minf for -USR1 usage
authorJens Axboe <axboe@kernel.dk>
Thu, 28 Mar 2013 21:08:49 +0000 (15:08 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 28 Mar 2013 21:08:49 +0000 (15:08 -0600)
Let the threads themselves update their stats.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
fio.h
stat.c

index ae4216db26c69b8fc23d1494a9f648965b882948..fcb74dcbcfc3d39b7916c3c1f2f8fcb43127e889 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -406,6 +406,15 @@ static int break_on_this_error(struct thread_data *td, enum fio_ddir ddir,
        return 0;
 }
 
        return 0;
 }
 
+static void check_update_rusage(struct thread_data *td)
+{
+       if (td->update_rusage) {
+               td->update_rusage = 0;
+               update_rusage_stat(td);
+               fio_mutex_up(td->rusage_sem);
+       }
+}
+
 /*
  * The main verify engine. Runs over the writes we previously submitted,
  * reads the blocks back in, and checks the crc/md5 of the data.
 /*
  * The main verify engine. Runs over the writes we previously submitted,
  * reads the blocks back in, and checks the crc/md5 of the data.
@@ -433,6 +442,8 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes)
                        break;
        }
 
                        break;
        }
 
+       check_update_rusage(td);
+
        if (td->error)
                return;
 
        if (td->error)
                return;
 
@@ -444,6 +455,7 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes)
                int ret2, full;
 
                update_tv_cache(td);
                int ret2, full;
 
                update_tv_cache(td);
+               check_update_rusage(td);
 
                if (runtime_exceeded(td, &td->tv_cache)) {
                        __update_tv_cache(td);
 
                if (runtime_exceeded(td, &td->tv_cache)) {
                        __update_tv_cache(td);
@@ -597,6 +609,8 @@ sync_done:
                        break;
        }
 
                        break;
        }
 
+       check_update_rusage(td);
+
        if (!td->error) {
                min_events = td->cur_depth;
 
        if (!td->error) {
                min_events = td->cur_depth;
 
@@ -652,6 +666,8 @@ static uint64_t do_io(struct thread_data *td)
                int ret2, full;
                enum fio_ddir ddir;
 
                int ret2, full;
                enum fio_ddir ddir;
 
+               check_update_rusage(td);
+
                if (td->terminate || td->done)
                        break;
 
                if (td->terminate || td->done)
                        break;
 
@@ -816,6 +832,8 @@ sync_done:
                }
        }
 
                }
        }
 
+       check_update_rusage(td);
+
        if (td->trim_entries)
                log_err("fio: %d trim entries leaked?\n", td->trim_entries);
 
        if (td->trim_entries)
                log_err("fio: %d trim entries leaked?\n", td->trim_entries);
 
@@ -1379,6 +1397,9 @@ err:
        if (td->o.write_iolog_file)
                write_iolog_close(td);
 
        if (td->o.write_iolog_file)
                write_iolog_close(td);
 
+       fio_mutex_remove(td->rusage_sem);
+       td->rusage_sem = NULL;
+
        td_set_runstate(td, TD_EXITED);
        return (void *) (uintptr_t) td->error;
 }
        td_set_runstate(td, TD_EXITED);
        return (void *) (uintptr_t) td->error;
 }
@@ -1627,6 +1648,9 @@ static void run_threads(void)
 
                        init_disk_util(td);
 
 
                        init_disk_util(td);
 
+                       td->rusage_sem = fio_mutex_init(FIO_MUTEX_LOCKED);
+                       td->update_rusage = 0;
+
                        /*
                         * Set state to created. Thread will transition
                         * to TD_INITIALIZED when it's done setting up.
                        /*
                         * Set state to created. Thread will transition
                         * to TD_INITIALIZED when it's done setting up.
diff --git a/fio.h b/fio.h
index 621ed606c0065279a7fc91dd1623aa329321dda9..a1b2a931e616179847928c8d145935b956d6432e 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -354,6 +354,8 @@ struct thread_data {
        uint64_t stat_io_blocks[DDIR_RWDIR_CNT];
        struct timeval iops_sample_time;
 
        uint64_t stat_io_blocks[DDIR_RWDIR_CNT];
        struct timeval iops_sample_time;
 
+       volatile int update_rusage;
+       struct fio_mutex *rusage_sem;
        struct rusage ru_start;
        struct rusage ru_end;
 
        struct rusage ru_start;
        struct rusage ru_end;
 
diff --git a/stat.c b/stat.c
index fe09a2968e6b4cfea853ef526640fd46eee58faa..59f37184117ba3ac0c225ae6b33ddc3607b83efe 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1386,13 +1386,21 @@ static void *__show_running_run_stats(void *arg)
                if (td_trim(td) && td->io_bytes[DDIR_TRIM])
                        td->ts.runtime[DDIR_TRIM] += rt[i];
 
                if (td_trim(td) && td->io_bytes[DDIR_TRIM])
                        td->ts.runtime[DDIR_TRIM] += rt[i];
 
-               update_rusage_stat(td);
+               td->update_rusage = 1;
                td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
                td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
                td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
                td->ts.total_run_time = mtime_since(&td->epoch, &tv);
        }
 
                td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
                td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
                td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
                td->ts.total_run_time = mtime_since(&td->epoch, &tv);
        }
 
+       for_each_td(td, i) {
+               if (td->rusage_sem) {
+                       td->update_rusage = 1;
+                       fio_mutex_down(td->rusage_sem);
+               }
+               td->update_rusage = 0;
+       }
+
        show_run_stats();
 
        for_each_td(td, i) {
        show_run_stats();
 
        for_each_td(td, i) {