From 34572e28f8cf45ba4e2601797f2aa4a114601fb2 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 20 Oct 2006 09:33:18 +0200 Subject: [PATCH] [PATCH] Add for_each_td() Similar to for_each_file(), just iterates over each td we know about. Signed-off-by: Jens Axboe --- eta.c | 7 +++---- fio.c | 23 ++++++++--------------- fio.h | 4 +++- stat.c | 7 ++----- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/eta.c b/eta.c index 0eca3be0..b3d4434e 100644 --- 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; + struct thread_data *td; 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; - 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++; @@ -206,7 +205,7 @@ void print_thread_status(void) 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]; diff --git a/fio.c b/fio.c index 9a1da292..624c9598 100644 --- a/fio.c +++ b/fio.c @@ -56,11 +56,10 @@ static volatile int startup_sem; static void terminate_threads(int group_id) { + struct thread_data *td; 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; @@ -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) { + struct thread_data *td; 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 @@ -1194,9 +1193,7 @@ static void run_threads(void) 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); @@ -1225,9 +1222,7 @@ static void run_threads(void) /* * 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; @@ -1316,9 +1311,7 @@ static void run_threads(void) /* * 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; diff --git a/fio.h b/fio.h index eed49503..67c2ec21 100644 --- a/fio.h +++ b/fio.h @@ -539,7 +539,9 @@ extern void close_ioengine(struct thread_data *); */ #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) \ - 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 diff --git a/stat.c b/stat.c index 4ba8f193..718a8ab2 100644 --- a/stat.c +++ b/stat.c @@ -446,11 +446,9 @@ void show_run_stats(void) 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; - td = &threads[i]; - 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"); - for (i = 0; i < thread_number; i++) { - td = &threads[i]; + for_each_td(td, i) { rs = &runstats[td->groupid]; if (terse_output) -- 2.25.1