From 40ef7f6404e3f5a32d4452a54e7c177ab4e9f100 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 3 Nov 2005 21:21:37 +0100 Subject: [PATCH] [PATCH] fio: improve state setting and printing --- fio.c | 101 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/fio.c b/fio.c index 1ad2235..4e2300b 100644 --- a/fio.c +++ b/fio.c @@ -228,6 +228,7 @@ struct thread_data { char *orig_buffer; volatile int terminate; volatile int runstate; + volatile int old_runstate; unsigned int ddir; unsigned int ioprio; unsigned int sequential; @@ -400,10 +401,10 @@ static inline unsigned long msec_now(struct timeval *s) static unsigned long long get_next_offset(struct thread_data *td) { unsigned long long kb; - long r; + double r; if (!td->sequential) { - lrand48_r(&td->random_state, &r); + drand48_r(&td->random_state, &r); kb = (1+(double) (td->kb-1) * r / (RAND_MAX+1.0)); } else kb = td->last_kb; @@ -414,12 +415,12 @@ static unsigned long long get_next_offset(struct thread_data *td) static unsigned int get_next_buflen(struct thread_data *td) { unsigned int buflen; - long r; + double r; if (td->min_bs == td->max_bs) buflen = td->min_bs; else { - lrand48_r(&td->bsrange_state, &r); + drand48_r(&td->bsrange_state, &r); buflen = (1 + (double) (td->max_bs - 1) * r / (RAND_MAX + 1.0)); buflen = (buflen + td->min_bs - 1) & ~(td->min_bs - 1); } @@ -574,13 +575,17 @@ static inline int runtime_exceeded(struct thread_data *td, struct timeval *t) static void fill_random_bytes(struct thread_data *td, unsigned char *p, unsigned int len) { + double r; int todo; - long r; while (len) { - lrand48_r(&td->verify_state, &r); + drand48_r(&td->verify_state, &r); - todo = sizeof(long); + /* + * lrand48_r seems to be broken and only fill the bottom + * 32-bits, even on 64-bit archs with 64-bit longs + */ + todo = sizeof(r); if (todo > len) todo = len; @@ -719,13 +724,20 @@ static struct io_u *get_io_u(struct thread_data *td) return io_u; } +static inline void td_set_runstate(struct thread_data *td, int runstate) +{ + td->old_runstate = td->runstate; + td->runstate = runstate; +} + static int do_sync_verify(struct thread_data *td) { + struct timeval t; struct io_u *io_u = NULL; loff_t off = 0; int back, ret; - td->runstate = TD_VERIFYING; + td_set_runstate(td, TD_VERIFYING); io_u = __get_io_u(td); @@ -734,10 +746,23 @@ static int do_sync_verify(struct thread_data *td) goto out; } + if (!td->odirect) { + unsigned long size = td->kb << 10; + + if (fadvise(td->fd, 0, size, POSIX_FADV_DONTNEED) < 0) { + td->error = errno; + goto out; + } + } + do { if (td->terminate) break; - + + gettimeofday(&t, NULL); + if (runtime_exceeded(td, &t)) + break; + io_u->offset = off; io_u->buflen = td->max_bs; @@ -767,7 +792,7 @@ static int do_sync_verify(struct thread_data *td) } while (1); out: - td->runstate = TD_RUNNING; + td_set_runstate(td, TD_RUNNING); put_io_u(td, io_u); return td->error == 0; @@ -1377,7 +1402,7 @@ err: sem_post(&startup_sem); sem_wait(&td->mutex); } - td->runstate = TD_EXITED; + td_set_runstate(td, TD_EXITED); shmdt(data); return NULL; } @@ -1948,6 +1973,38 @@ static void print_thread_status(struct thread_data *td, int nr_running, fflush(stdout); } +static void check_str_update(struct thread_data *td, int n, int t, int m) +{ + char c = run_str[td->thread_number - 1]; + + if (td->runstate == td->old_runstate) + return; + + switch (td->runstate) { + case TD_REAPED: + c = '_'; + break; + case TD_RUNNING: + c = '+'; + break; + case TD_VERIFYING: + c = 'V'; + break; + case TD_CREATED: + c = 'C'; + break; + case TD_NOT_CREATED: + c = 'P'; + break; + default: + printf("state %d\n", td->runstate); + } + + run_str[td->thread_number - 1] = c; + print_thread_status(td, n, t, m); + td->old_runstate = td->runstate; +} + static void reap_threads(int *nr_running, int *t_rate, int *m_rate) { int i; @@ -1958,20 +2015,20 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) for (i = 0; i < thread_number; i++) { struct thread_data *td = &threads[i]; + check_str_update(td, *nr_running, *t_rate, *m_rate); + if (td->runstate != TD_EXITED) continue; - td->runstate = TD_REAPED; - run_str[td->thread_number - 1] = '_'; + td_set_runstate(td, TD_REAPED); waitpid(td->pid, NULL, 0); (*nr_running)--; (*m_rate) -= td->ratemin; (*t_rate) -= td->rate; + check_str_update(td, *nr_running, *t_rate, *m_rate); if (td->terminate) continue; - - print_thread_status(td, *nr_running, *t_rate, *m_rate); } } @@ -2003,7 +2060,7 @@ static void run_threads(char *argv[]) * client data interspersed on disk */ if (setup_file(td)) { - td->runstate = TD_REAPED; + td_set_runstate(td, TD_REAPED); todo--; } } @@ -2036,8 +2093,8 @@ static void run_threads(char *argv[]) continue; } - td->runstate = TD_CREATED; - run_str[td->thread_number - 1] = 'C'; + td_set_runstate(td, TD_CREATED); + check_str_update(td, nr_running, t_rate, m_rate); sem_init(&startup_sem, 1, 1); todo--; @@ -2058,14 +2115,12 @@ static void run_threads(char *argv[]) if (td->runstate != TD_CREATED) continue; - td->runstate = TD_RUNNING; - run_str[td->thread_number - 1] = '+'; + td_set_runstate(td, TD_RUNNING); nr_running++; m_rate += td->ratemin; t_rate += td->rate; + check_str_update(td, nr_running, t_rate, m_rate); sem_post(&td->mutex); - - print_thread_status(td, nr_running, t_rate, m_rate); } for (i = 0; i < thread_number; i++) { @@ -2078,7 +2133,7 @@ static void run_threads(char *argv[]) else continue; - print_thread_status(td, nr_running, t_rate, m_rate); + check_str_update(td, nr_running, t_rate, m_rate); } reap_threads(&nr_running, &t_rate, &m_rate); -- 2.25.1