[PATCH] fio: fixes for quit-on-rate-error and status dumps
authorJens Axboe <axboe@suse.de>
Wed, 19 Oct 2005 13:22:27 +0000 (15:22 +0200)
committerJens Axboe <axboe@suse.de>
Wed, 19 Oct 2005 13:22:27 +0000 (15:22 +0200)
fio.c

diff --git a/fio.c b/fio.c
index 6f462186cf978827112b3353d703c02e08dcf6b7..579173ad03a94929bc8b560af996bfceaa31f434 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -174,12 +174,12 @@ static struct thread_data *threads;
 
 static sem_t startup_sem;
 
-static volatile int do_quit;
-
 static void sig_handler(int sig)
 {
        int i;
 
+       printf("got signal %d\n", sig);
+
        for (i = 0; i < thread_number; i++) {
                struct thread_data *td = &threads[i];
 
@@ -189,8 +189,14 @@ static void sig_handler(int sig)
 
 static void terminate_threads(void)
 {
-       do_quit = 1;
-       sig_handler(0);
+       int i;
+
+       for (i = 0; i < thread_number; i++) {
+               struct thread_data *td = &threads[i];
+
+               td->terminate = 1;
+               td->start_delay = 0;
+       }
 }
 
 static int init_random_state(struct thread_data *td)
@@ -560,6 +566,9 @@ static void show_thread_status(struct thread_data *td)
        int prio, prio_class;
        unsigned long bw = 0;
 
+       if (!td->io_blocks && !td->error)
+               return;
+
        if (td->runtime)
                bw = (td->io_blocks * td->bs) / td->runtime;
 
@@ -995,21 +1004,26 @@ static int parse_options(int argc, char *argv[])
        return i;
 }
 
-static int reap_threads(void)
+static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 {
-       int i, reaped = 0;
+       int i;
 
        for (i = 0; i < thread_number; i++) {
                struct thread_data *td = &threads[i];
 
-               if (td->runstate == TD_EXITED) {
-                       td->runstate = TD_REAPED;
-                       waitpid(td->pid, NULL, 0);
-                       reaped++;
-               }
-       }
+               if (td->runstate != TD_EXITED)
+                       continue;
 
-       return reaped;
+               td->runstate = TD_REAPED;
+               waitpid(td->pid, NULL, 0);
+               (*nr_running)--;
+               (*m_rate) -= td->ratemin;
+               (*t_rate) -= td->rate;
+               printf("Threads now running: %d", *nr_running);
+               if (*m_rate || *t_rate)
+                       printf(", rate %d/%dKiB/sec", *t_rate, *m_rate);
+               printf("\n");
+       }
 }
 
 static void run_threads(char *argv[])
@@ -1017,7 +1031,7 @@ static void run_threads(char *argv[])
        struct timeval genesis, now;
        struct thread_data *td;
        unsigned long spent;
-       int i, todo, nr_running;
+       int i, todo, nr_running, m_rate, t_rate;
 
        gettimeofday(&genesis, NULL);
 
@@ -1031,14 +1045,24 @@ static void run_threads(char *argv[])
 
        todo = thread_number;
        nr_running = 0;
+       m_rate = t_rate = 0;
 
-       while (todo && !do_quit) {
+       while (todo) {
                for (i = 0; i < thread_number; i++) {
                        td = &threads[i];
 
                        if (td->runstate != TD_NOT_CREATED)
                                continue;
 
+                       /*
+                        * never got a chance to start, killed by other
+                        * thread for some reason
+                        */
+                       if (td->terminate) {
+                               todo--;
+                               continue;
+                       }
+
                        if (td->start_delay) {
                                gettimeofday(&now, NULL);
                                spent = mtime_since(&genesis, &now);
@@ -1065,19 +1089,25 @@ static void run_threads(char *argv[])
                        if (td->runstate == TD_CREATED) {
                                td->runstate = TD_STARTED;
                                nr_running++;
+                               m_rate += td->ratemin;
+                               t_rate += td->rate;
                                sem_post(&td->mutex);
-                               printf("%d threads now running\n", nr_running);
+
+                               printf("Threads now running: %d", nr_running);
+                               if (m_rate || t_rate)
+                                       printf(", rate %d/%dKiB/sec", t_rate, m_rate);
+                               printf("\n");
                        }
                }
 
-               nr_running -= reap_threads();
+               reap_threads(&nr_running, &t_rate, &m_rate);
 
                if (todo)
                        usleep(100000);
        }
 
        while (nr_running) {
-               nr_running -= reap_threads();
+               reap_threads(&nr_running, &t_rate, &m_rate);
                usleep(10000);
        }
 }