[PATCH] Add for_each_td()
authorJens Axboe <jens.axboe@oracle.com>
Fri, 20 Oct 2006 07:33:18 +0000 (09:33 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 20 Oct 2006 07:33:18 +0000 (09:33 +0200)
Similar to for_each_file(), just iterates over each td we know about.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
eta.c
fio.c
fio.h
stat.c

diff --git a/eta.c b/eta.c
index 0eca3be0e345ee6c797f1d9f86f1ccbb9f6cd783..b3d4434e126b46b96356db78cfbf289ae8cc0659 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -172,6 +172,7 @@ void print_thread_status(void)
 {
        unsigned long elapsed = mtime_since_genesis() / 1000;
        int i, nr_running, nr_pending, t_rate, m_rate, *eta_secs, eta_sec;
 {
        unsigned long elapsed = mtime_since_genesis() / 1000;
        int i, nr_running, nr_pending, t_rate, m_rate, *eta_secs, eta_sec;
+       struct thread_data *td;
        char eta_str[32];
        double perc = 0.0;
 
        char eta_str[32];
        double perc = 0.0;
 
@@ -182,9 +183,7 @@ void print_thread_status(void)
        memset(eta_secs, 0, thread_number * sizeof(int));
 
        nr_pending = nr_running = t_rate = m_rate = 0;
        memset(eta_secs, 0, thread_number * sizeof(int));
 
        nr_pending = nr_running = t_rate = m_rate = 0;
-       for (i = 0; i < thread_number; i++) {
-               struct thread_data *td = &threads[i];
-
+       for_each_td(td, i) {
                if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING||
                    td->runstate == TD_FSYNCING) {
                        nr_running++;
                if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING||
                    td->runstate == TD_FSYNCING) {
                        nr_running++;
@@ -206,7 +205,7 @@ void print_thread_status(void)
        else
                eta_sec = 0;
 
        else
                eta_sec = 0;
 
-       for (i = 0; i < thread_number; i++) {
+       for_each_td(td, i) {
                if (exitall_on_terminate) {
                        if (eta_secs[i] < eta_sec)
                                eta_sec = eta_secs[i];
                if (exitall_on_terminate) {
                        if (eta_secs[i] < eta_sec)
                                eta_sec = eta_secs[i];
diff --git a/fio.c b/fio.c
index 9a1da292f9d5b5ab580948955f36794f921ecd7a..624c9598cf0a3cd7eb84753a40d609850248b0de 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -56,11 +56,10 @@ static volatile int startup_sem;
 
 static void terminate_threads(int group_id)
 {
 
 static void terminate_threads(int group_id)
 {
+       struct thread_data *td;
        int i;
 
        int i;
 
-       for (i = 0; i < thread_number; i++) {
-               struct thread_data *td = &threads[i];
-
+       for_each_td(td, i) {
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
                        td->terminate = 1;
                        td->start_delay = 0;
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
                        td->terminate = 1;
                        td->start_delay = 0;
@@ -1090,14 +1089,14 @@ static void *fork_main(int shmid, int offset)
  */
 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 {
  */
 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 {
+       struct thread_data *td;
        int i, cputhreads;
 
        /*
         * reap exited threads (TD_EXITED -> TD_REAPED)
         */
        int i, cputhreads;
 
        /*
         * reap exited threads (TD_EXITED -> TD_REAPED)
         */
-       for (i = 0, cputhreads = 0; i < thread_number; i++) {
-               struct thread_data *td = &threads[i];
-
+       cputhreads = 0;
+       for_each_td(td, i) {
                /*
                 * ->io_ops is NULL for a thread that has closed its
                 * io engine
                /*
                 * ->io_ops is NULL for a thread that has closed its
                 * io engine
@@ -1194,9 +1193,7 @@ static void run_threads(void)
        nr_started = 0;
        m_rate = t_rate = 0;
 
        nr_started = 0;
        m_rate = t_rate = 0;
 
-       for (i = 0; i < thread_number; i++) {
-               td = &threads[i];
-
+       for_each_td(td, i) {
                print_status_init(td->thread_number - 1);
 
                init_disk_util(td);
                print_status_init(td->thread_number - 1);
 
                init_disk_util(td);
@@ -1225,9 +1222,7 @@ static void run_threads(void)
                /*
                 * create threads (TD_NOT_CREATED -> TD_CREATED)
                 */
                /*
                 * create threads (TD_NOT_CREATED -> TD_CREATED)
                 */
-               for (i = 0; i < thread_number; i++) {
-                       td = &threads[i];
-
+               for_each_td(td, i) {
                        if (td->runstate != TD_NOT_CREATED)
                                continue;
 
                        if (td->runstate != TD_NOT_CREATED)
                                continue;
 
@@ -1316,9 +1311,7 @@ static void run_threads(void)
                /*
                 * start created threads (TD_INITIALIZED -> TD_RUNNING).
                 */
                /*
                 * start created threads (TD_INITIALIZED -> TD_RUNNING).
                 */
-               for (i = 0; i < thread_number; i++) {
-                       td = &threads[i];
-
+               for_each_td(td, i) {
                        if (td->runstate != TD_INITIALIZED)
                                continue;
 
                        if (td->runstate != TD_INITIALIZED)
                                continue;
 
diff --git a/fio.h b/fio.h
index eed49503ba1367b57ed413c238fc8412969490cf..67c2ec2179a9d24113e1e86f09e16d7e086b1539 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -539,7 +539,9 @@ extern void close_ioengine(struct thread_data *);
  */
 #define fio_unused     __attribute((__unused__))
 
  */
 #define fio_unused     __attribute((__unused__))
 
+#define for_each_td(td, i)     \
+       for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
 #define for_each_file(td, f, i)        \
 #define for_each_file(td, f, i)        \
-       for ((i) = 0, (f) = &(td)->files[0]; (i) < (int) (td)->nr_files; (i)++, (f) = &(td)->files[(i)])
+       for ((i) = 0, (f) = &(td)->files[0]; (i) < (int) (td)->nr_files; (i)++, (f)++)
 
 #endif
 
 #endif
diff --git a/stat.c b/stat.c
index 4ba8f193967e8ce51d8134ba7e5b42bc908de1a9..718a8ab2acc1ee65618f132c3efabb9dc6ce7aef 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -446,11 +446,9 @@ void show_run_stats(void)
                rs->min_bw[1] = rs->min_run[1] = ~0UL;
        }
 
                rs->min_bw[1] = rs->min_run[1] = ~0UL;
        }
 
-       for (i = 0; i < thread_number; i++) {
+       for_each_td(td, i) {
                unsigned long long rbw, wbw;
 
                unsigned long long rbw, wbw;
 
-               td = &threads[i];
-
                if (td->error) {
                        fprintf(f_out, "%s: %s\n", td->name, td->verror);
                        continue;
                if (td->error) {
                        fprintf(f_out, "%s: %s\n", td->name, td->verror);
                        continue;
@@ -501,8 +499,7 @@ void show_run_stats(void)
        if (!terse_output)
                printf("\n");
 
        if (!terse_output)
                printf("\n");
 
-       for (i = 0; i < thread_number; i++) {
-               td = &threads[i];
+       for_each_td(td, i) {
                rs = &runstats[td->groupid];
 
                if (terse_output)
                rs = &runstats[td->groupid];
 
                if (terse_output)