2 * fio - the flexible io tester
4 * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include <sys/types.h>
39 #include <semaphore.h>
42 #include <sys/ioctl.h>
43 #include <asm/unistd.h>
44 #include <asm/types.h>
45 #include <asm/bitops.h>
51 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
54 #define MAX_JOBS (1024)
57 * assume we don't have _get either, if _set isn't defined
59 #ifndef __NR_ioprio_set
61 #define __NR_ioprio_set 289
62 #define __NR_ioprio_get 290
63 #elif defined(__powerpc__) || defined(__powerpc64__)
64 #define __NR_ioprio_set 273
65 #define __NR_ioprio_get 274
66 #elif defined(__x86_64__)
67 #define __NR_ioprio_set 251
68 #define __NR_ioprio_get 252
69 #elif defined(__ia64__)
70 #define __NR_ioprio_set 1274
71 #define __NR_ioprio_get 1275
72 #elif defined(__alpha__)
73 #define __NR_ioprio_set 442
74 #define __NR_ioprio_get 443
75 #elif defined(__s390x__) || defined(__s390__)
76 #define __NR_ioprio_set 282
77 #define __NR_ioprio_get 283
79 #error "Unsupported arch"
83 #ifndef __NR_fadvise64
85 #define __NR_fadvise64 250
86 #elif defined(__powerpc__) || defined(__powerpc64__)
87 #define __NR_fadvise64 233
88 #elif defined(__x86_64__)
89 #define __NR_fadvise64 221
90 #elif defined(__ia64__)
91 #define __NR_fadvise64 1234
92 #elif defined(__alpha__)
93 #define __NR_fadvise64 413
94 #elif defined(__s390x__) || defined(__s390__)
95 #define __NR_fadvise64 253
97 #error "Unsupported arch"
101 static int ioprio_set(int which, int who, int ioprio)
103 return syscall(__NR_ioprio_set, which, who, ioprio);
107 * we want fadvise64 really, but it's so tangled... later
109 static int fadvise(int fd, loff_t offset, size_t len, int advice)
112 return syscall(__NR_fadvise64, fd, offset, offset >> 32, len, advice);
114 return posix_fadvise(fd, (off_t) offset, len, advice);
119 IOPRIO_WHO_PROCESS = 1,
124 #define IOPRIO_CLASS_SHIFT 13
128 #define DEF_BS (4096)
129 #define DEF_TIMEOUT (0)
130 #define DEF_RATE_CYCLE (1000)
131 #define DEF_ODIRECT (1)
132 #define DEF_SEQUENTIAL (1)
133 #define DEF_RAND_REPEAT (1)
134 #define DEF_OVERWRITE (0)
135 #define DEF_CREATE (1)
136 #define DEF_INVALIDATE (1)
137 #define DEF_SYNCIO (0)
138 #define DEF_RANDSEED (0xb1899bedUL)
139 #define DEF_BWAVGTIME (500)
140 #define DEF_CREATE_SER (1)
141 #define DEF_CREATE_FSYNC (1)
142 #define DEF_LOOPS (1)
143 #define DEF_VERIFY (0)
145 #define ALIGN(buf) (char *) (((unsigned long) (buf) + MASK) & ~(MASK))
147 static int repeatable = DEF_RAND_REPEAT;
148 static int rate_quit = 1;
149 static int write_lat_log;
150 static int write_bw_log;
151 static int exitall_on_terminate;
153 static int thread_number;
154 static char *ini_file;
156 static int max_jobs = MAX_JOBS;
158 static char run_str[MAX_JOBS + 1];
189 struct timeval start_time;
190 struct timeval issue_time;
194 unsigned long long offset;
196 struct list_head list;
201 unsigned long val_sq;
202 unsigned long max_val;
203 unsigned long min_val;
204 unsigned long samples;
213 unsigned long nr_samples;
214 unsigned long max_samples;
215 struct io_sample *log;
219 struct list_head list;
220 unsigned long long offset;
224 #define FIO_HDR_MAGIC 0xf00baaef
226 struct verify_header {
227 unsigned int fio_magic;
229 char md5_digest[MD5_HASH_WORDS * 4];
232 #define td_read(td) ((td)->ddir == DDIR_READ)
233 #define td_write(td) ((td)->ddir == DDIR_WRITE)
234 #define should_fsync(td) (td_write(td) && !(td)->odirect)
236 #define BLOCKS_PER_MAP (8 * sizeof(long))
237 #define RAND_MAP_IDX(sector) ((sector) / BLOCKS_PER_MAP)
238 #define RAND_MAP_BIT(sector) ((sector) & (BLOCKS_PER_MAP - 1))
247 volatile int terminate;
248 volatile int runstate;
249 volatile int old_runstate;
252 unsigned int sequential;
256 unsigned int odirect;
257 unsigned int thinktime;
258 unsigned int fsync_blocks;
259 unsigned int start_delay;
260 unsigned int timeout;
261 unsigned int use_aio;
262 unsigned int create_file;
263 unsigned int overwrite;
264 unsigned int invalidate_cache;
265 unsigned int bw_avg_time;
266 unsigned int create_serialize;
267 unsigned int create_fsync;
269 unsigned long long file_size;
270 unsigned long long file_offset;
271 unsigned int sync_io;
272 unsigned int mem_type;
276 struct drand48_data bsrange_state;
277 struct drand48_data verify_state;
283 io_context_t aio_ctx;
284 unsigned int aio_depth;
285 struct io_event *aio_events;
287 unsigned int cur_depth;
288 struct list_head io_u_freelist;
289 struct list_head io_u_busylist;
292 unsigned int ratemin;
293 unsigned int ratecycle;
294 unsigned long rate_usec_cycle;
295 long rate_pending_usleep;
296 unsigned long rate_bytes;
297 struct timeval lastrate;
299 unsigned long runtime; /* sec */
300 unsigned long long io_size;
302 unsigned long io_blocks;
303 unsigned long io_bytes;
304 unsigned long this_io_bytes;
305 unsigned long last_bytes;
308 struct drand48_data random_state;
309 unsigned long *file_map;
310 unsigned int num_maps;
313 * bandwidth and latency stats
315 struct io_stat clat_stat; /* completion latency */
316 struct io_stat slat_stat; /* submission latency */
318 struct io_stat bw_stat; /* bandwidth stats */
319 unsigned long stat_io_bytes;
320 struct timeval stat_sample_time;
322 struct io_log *lat_log;
323 struct io_log *bw_log;
325 struct timeval start;
326 struct rusage ru_start;
327 struct rusage ru_end;
329 struct list_head io_hist_list;
332 static struct thread_data *threads;
333 static struct thread_data def_thread;
335 static sem_t startup_sem;
337 static void sig_handler(int sig)
341 for (i = 0; i < thread_number; i++) {
342 struct thread_data *td = &threads[i];
349 static int init_random_state(struct thread_data *td)
352 int fd, num_maps, blocks;
354 fd = open("/dev/random", O_RDONLY);
360 if (read(fd, &seed, sizeof(seed)) < (int) sizeof(seed)) {
368 srand48_r(seed, &td->bsrange_state);
369 srand48_r(seed, &td->verify_state);
377 blocks = (td->io_size + td->min_bs - 1) / td->min_bs;
378 num_maps = blocks / BLOCKS_PER_MAP;
379 td->file_map = malloc(num_maps * sizeof(long));
380 td->num_maps = num_maps;
381 memset(td->file_map, 0, num_maps * sizeof(long));
383 srand48_r(seed, &td->random_state);
387 static unsigned long utime_since(struct timeval *s, struct timeval *e)
391 sec = e->tv_sec - s->tv_sec;
392 usec = e->tv_usec - s->tv_usec;
393 if (sec > 0 && usec < 0) {
398 sec *= (double) 1000000;
403 static unsigned long mtime_since(struct timeval *s, struct timeval *e)
407 sec = e->tv_sec - s->tv_sec;
408 usec = e->tv_usec - s->tv_usec;
409 if (sec > 0 && usec < 0) {
414 sec *= (double) 1000;
415 usec /= (double) 1000;
420 static unsigned long mtime_since_now(struct timeval *s)
424 gettimeofday(&t, NULL);
425 return mtime_since(s, &t);
428 static inline unsigned long msec_now(struct timeval *s)
430 return s->tv_sec * 1000 + s->tv_usec / 1000;
433 static int random_map_free(struct thread_data *td, unsigned long long block)
435 unsigned int idx = RAND_MAP_IDX(block);
436 unsigned int bit = RAND_MAP_BIT(block);
438 return (td->file_map[idx] & (1UL << bit)) == 0;
441 static int get_next_free_block(struct thread_data *td, unsigned long long *b)
447 while ((*b) * td->min_bs < td->io_size) {
448 if (td->file_map[i] != -1UL) {
449 *b += ffz(td->file_map[i]);
453 *b += BLOCKS_PER_MAP;
460 static void mark_random_map(struct thread_data *td, struct io_u *io_u)
462 unsigned long block = io_u->offset / td->min_bs;
463 unsigned int blocks = 0;
465 while (blocks < (io_u->buflen / td->min_bs)) {
468 if (!random_map_free(td, block))
471 idx = RAND_MAP_IDX(block);
472 bit = RAND_MAP_BIT(block);
474 assert(idx < td->num_maps);
476 td->file_map[idx] |= (1UL << bit);
481 if ((blocks * td->min_bs) < io_u->buflen)
482 io_u->buflen = blocks * td->min_bs;
485 static int get_next_offset(struct thread_data *td, unsigned long long *offset)
487 unsigned long long b;
490 if (!td->sequential) {
491 unsigned long max_blocks = td->io_size / td->min_bs;
495 lrand48_r(&td->random_state, &r);
496 b = ((max_blocks - 1) * r / (RAND_MAX+1.0));
498 } while (!random_map_free(td, b) && loops);
501 if (get_next_free_block(td, &b))
505 b = td->last_bytes / td->min_bs;
507 *offset = (b * td->min_bs) + td->file_offset;
511 static unsigned int get_next_buflen(struct thread_data *td)
516 if (td->min_bs == td->max_bs)
519 lrand48_r(&td->bsrange_state, &r);
520 buflen = (1 + (double) (td->max_bs - 1) * r / (RAND_MAX + 1.0));
521 buflen = (buflen + td->min_bs - 1) & ~(td->min_bs - 1);
524 if (buflen > td->io_size - td->this_io_bytes)
525 buflen = td->io_size - td->this_io_bytes;
530 static inline void add_stat_sample(struct thread_data *td, struct io_stat *is,
533 if (val > is->max_val)
535 if (val < is->min_val)
539 is->val_sq += val * val;
543 static void add_log_sample(struct thread_data *td, struct io_log *log,
546 if (log->nr_samples == log->max_samples) {
547 int new_size = sizeof(struct io_sample) * log->max_samples * 2;
549 log->log = realloc(log->log, new_size);
550 log->max_samples <<= 1;
553 log->log[log->nr_samples].val = val;
554 log->log[log->nr_samples].time = mtime_since_now(&td->start);
558 static void add_clat_sample(struct thread_data *td, unsigned long msec)
560 add_stat_sample(td, &td->clat_stat, msec);
563 add_log_sample(td, td->lat_log, msec);
566 static void add_slat_sample(struct thread_data *td, unsigned long msec)
568 add_stat_sample(td, &td->slat_stat, msec);
571 static void add_bw_sample(struct thread_data *td)
573 unsigned long spent = mtime_since_now(&td->stat_sample_time);
576 if (spent < td->bw_avg_time)
579 rate = (td->this_io_bytes - td->stat_io_bytes) / spent;
580 add_stat_sample(td, &td->bw_stat, rate);
583 add_log_sample(td, td->bw_log, rate);
585 gettimeofday(&td->stat_sample_time, NULL);
586 td->stat_io_bytes = td->this_io_bytes;
589 static void usec_sleep(int usec)
591 struct timespec req = { .tv_sec = 0, .tv_nsec = usec * 1000 };
595 rem.tv_sec = rem.tv_nsec = 0;
596 nanosleep(&req, &rem);
600 req.tv_nsec = rem.tv_nsec;
604 static void rate_throttle(struct thread_data *td, unsigned long time_spent,
607 unsigned long usec_cycle;
612 usec_cycle = td->rate_usec_cycle * (bytes / td->min_bs);
614 if (time_spent < usec_cycle) {
615 unsigned long s = usec_cycle - time_spent;
617 td->rate_pending_usleep += s;
618 if (td->rate_pending_usleep >= 100000) {
619 usec_sleep(td->rate_pending_usleep);
620 td->rate_pending_usleep = 0;
623 long overtime = time_spent - usec_cycle;
625 td->rate_pending_usleep -= overtime;
629 static int check_min_rate(struct thread_data *td, struct timeval *now)
635 * allow a 2 second settle period in the beginning
637 if (mtime_since(&td->start, now) < 2000)
641 * if rate blocks is set, sample is running
643 if (td->rate_bytes) {
644 spent = mtime_since(&td->lastrate, now);
645 if (spent < td->ratecycle)
648 rate = (td->this_io_bytes - td->rate_bytes) / spent;
649 if (rate < td->ratemin) {
650 printf("Client%d: min rate %d not met, got %ldKiB/sec\n", td->thread_number, td->ratemin, rate);
657 td->rate_bytes = td->this_io_bytes;
658 memcpy(&td->lastrate, now, sizeof(*now));
662 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
666 if (mtime_since(&td->start, t) >= td->timeout * 1000)
672 static void fill_random_bytes(struct thread_data *td,
673 unsigned char *p, unsigned int len)
679 drand48_r(&td->verify_state, &r);
682 * lrand48_r seems to be broken and only fill the bottom
683 * 32-bits, even on 64-bit archs with 64-bit longs
696 static void hexdump(void *buffer, int len)
698 unsigned char *p = buffer;
701 for (i = 0; i < len; i++)
702 printf("%02x", p[i]);
706 static int verify_io_u(struct io_u *io_u)
708 struct verify_header *hdr = (struct verify_header *) io_u->buf;
709 unsigned char *p = (unsigned char *) io_u->buf;
710 struct md5_ctx md5_ctx;
713 if (hdr->fio_magic != FIO_HDR_MAGIC)
716 memset(&md5_ctx, 0, sizeof(md5_ctx));
718 md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr));
720 ret = memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash));
722 hexdump(hdr->md5_digest, sizeof(hdr->md5_digest));
723 hexdump(md5_ctx.hash, sizeof(md5_ctx.hash));
730 * fill body of io_u->buf with random data and add a header with the
731 * (eg) sha1sum of that data.
733 static void populate_io_u(struct thread_data *td, struct io_u *io_u)
735 struct md5_ctx md5_ctx;
736 struct verify_header hdr;
737 unsigned char *p = (unsigned char *) io_u->buf;
739 hdr.fio_magic = FIO_HDR_MAGIC;
740 hdr.len = io_u->buflen;
742 fill_random_bytes(td, p, io_u->buflen - sizeof(hdr));
744 memset(&md5_ctx, 0, sizeof(md5_ctx));
745 md5_update(&md5_ctx, p, io_u->buflen - sizeof(hdr));
746 memcpy(hdr.md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash));
747 memcpy(io_u->buf, &hdr, sizeof(hdr));
750 static void put_io_u(struct thread_data *td, struct io_u *io_u)
752 list_del(&io_u->list);
753 list_add(&io_u->list, &td->io_u_freelist);
757 #define queue_full(td) (list_empty(&(td)->io_u_freelist))
759 static struct io_u *__get_io_u(struct thread_data *td)
766 io_u = list_entry(td->io_u_freelist.next, struct io_u, list);
767 list_del(&io_u->list);
768 list_add(&io_u->list, &td->io_u_busylist);
773 static struct io_u *get_io_u(struct thread_data *td)
777 io_u = __get_io_u(td);
781 if (get_next_offset(td, &io_u->offset)) {
786 io_u->buflen = get_next_buflen(td);
792 if (io_u->buflen + io_u->offset > td->io_size)
793 io_u->buflen = td->io_size - io_u->offset;
796 mark_random_map(td, io_u);
798 td->last_bytes += io_u->buflen;
801 populate_io_u(td, io_u);
805 io_prep_pread(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
807 io_prep_pwrite(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
810 gettimeofday(&io_u->start_time, NULL);
814 static inline void td_set_runstate(struct thread_data *td, int runstate)
816 td->old_runstate = td->runstate;
817 td->runstate = runstate;
820 static int get_next_verify(struct thread_data *td,
821 unsigned long long *offset, unsigned int *len)
823 struct io_piece *ipo;
825 if (list_empty(&td->io_hist_list))
828 ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
829 list_del(&ipo->list);
831 *offset = ipo->offset;
837 static void prune_io_piece_log(struct thread_data *td)
839 struct io_piece *ipo;
841 while (!list_empty(&td->io_hist_list)) {
842 ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
844 list_del(&ipo->list);
850 * log a succesful write, so we can unwind the log for verify
852 static void log_io_piece(struct thread_data *td, struct io_u *io_u)
854 struct io_piece *ipo = malloc(sizeof(struct io_piece));
855 struct list_head *entry;
857 INIT_LIST_HEAD(&ipo->list);
858 ipo->offset = io_u->offset;
859 ipo->len = io_u->buflen;
862 * for random io where the writes extend the file, it will typically
863 * be laid out with the block scattered as written. it's faster to
864 * read them in in that order again, so don't sort
866 if (td->sequential || !td->overwrite) {
867 list_add_tail(&ipo->list, &td->io_hist_list);
872 * for random io, sort the list so verify will run faster
874 entry = &td->io_hist_list;
875 while ((entry = entry->prev) != &td->io_hist_list) {
876 struct io_piece *__ipo = list_entry(entry, struct io_piece, list);
878 if (__ipo->offset < ipo->offset)
882 list_add(&ipo->list, entry);
885 static void do_sync_verify(struct thread_data *td)
888 struct io_u *io_u = NULL;
891 td_set_runstate(td, TD_VERIFYING);
893 io_u = __get_io_u(td);
896 if (fadvise(td->fd, td->file_offset, td->io_size, POSIX_FADV_DONTNEED) < 0) {
906 gettimeofday(&t, NULL);
907 if (runtime_exceeded(td, &t))
910 if (get_next_verify(td, &io_u->offset, &io_u->buflen))
913 if (td->cur_off != io_u->offset) {
914 if (lseek(td->fd, io_u->offset, SEEK_SET) == -1) {
920 ret = read(td->fd, io_u->buf, io_u->buflen);
921 if (ret < (int) io_u->buflen) {
931 if (verify_io_u(io_u))
934 td->cur_off = io_u->offset + io_u->buflen;
938 td_set_runstate(td, TD_RUNNING);
942 static void do_sync_io(struct thread_data *td)
944 unsigned long msec, usec;
945 struct io_u *io_u = NULL;
948 while (td->this_io_bytes < td->io_size) {
958 if (td->cur_off != io_u->offset) {
959 if (lseek(td->fd, io_u->offset, SEEK_SET) == -1) {
966 ret = read(td->fd, io_u->buf, io_u->buflen);
968 ret = write(td->fd, io_u->buf, io_u->buflen);
970 if (ret < (int) io_u->buflen) {
977 log_io_piece(td, io_u);
980 td->io_bytes += io_u->buflen;
981 td->this_io_bytes += io_u->buflen;
982 td->cur_off = io_u->offset + io_u->buflen;
984 gettimeofday(&e, NULL);
986 usec = utime_since(&io_u->start_time, &e);
988 rate_throttle(td, usec, io_u->buflen);
990 if (check_min_rate(td, &e)) {
996 add_clat_sample(td, msec);
999 if (runtime_exceeded(td, &e))
1006 usec_sleep(td->thinktime);
1008 if (should_fsync(td) && td->fsync_blocks &&
1009 (td->io_blocks % td->fsync_blocks) == 0)
1016 if (should_fsync(td))
1020 static int io_u_getevents(struct thread_data *td, int min, int max,
1026 r = io_getevents(td->aio_ctx, min, max, td->aio_events, t);
1027 if (r != -EAGAIN && r != -EINTR)
1034 static int io_u_queue(struct thread_data *td, struct io_u *io_u)
1036 struct iocb *iocb = &io_u->iocb;
1040 ret = io_submit(td->aio_ctx, 1, &iocb);
1043 else if (ret == -EAGAIN)
1045 else if (ret == -EINTR)
1054 #define iocb_time(iocb) ((unsigned long) (iocb)->data)
1055 #define ev_to_iou(ev) (struct io_u *) ((unsigned long) (ev)->obj)
1057 static int ios_completed(struct thread_data *td, int nr)
1064 gettimeofday(&e, NULL);
1066 for (i = 0, bytes_done = 0; i < nr; i++) {
1067 io_u = ev_to_iou(td->aio_events + i);
1070 td->io_bytes += io_u->buflen;
1071 td->this_io_bytes += io_u->buflen;
1073 msec = mtime_since(&io_u->issue_time, &e);
1075 add_clat_sample(td, msec);
1079 log_io_piece(td, io_u);
1081 bytes_done += io_u->buflen;
1088 static void cleanup_pending_aio(struct thread_data *td)
1090 struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
1091 struct list_head *entry, *n;
1096 * get immediately available events, if any
1098 r = io_u_getevents(td, 0, td->cur_depth, &ts);
1100 ios_completed(td, r);
1103 * now cancel remaining active events
1105 list_for_each_safe(entry, n, &td->io_u_busylist) {
1106 io_u = list_entry(entry, struct io_u, list);
1108 r = io_cancel(td->aio_ctx, &io_u->iocb, td->aio_events);
1113 if (td->cur_depth) {
1114 r = io_u_getevents(td, td->cur_depth, td->cur_depth, NULL);
1116 ios_completed(td, r);
1120 static int async_do_verify(struct thread_data *td, struct io_u **io_u)
1122 struct io_u *v_io_u = *io_u;
1126 ret = verify_io_u(v_io_u);
1127 put_io_u(td, v_io_u);
1134 static void do_async_verify(struct thread_data *td)
1137 struct io_u *io_u, *v_io_u = NULL;
1140 td_set_runstate(td, TD_VERIFYING);
1146 gettimeofday(&t, NULL);
1147 if (runtime_exceeded(td, &t))
1150 io_u = __get_io_u(td);
1154 if (get_next_verify(td, &io_u->offset, &io_u->buflen)) {
1159 io_prep_pread(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
1160 ret = io_u_queue(td, io_u);
1168 * we have one pending to verify, do that while the next
1169 * we are doing io on the next one
1171 if (async_do_verify(td, &v_io_u))
1174 ret = io_u_getevents(td, 1, 1, NULL);
1181 v_io_u = ev_to_iou(td->aio_events);
1183 td->cur_off = v_io_u->offset + v_io_u->buflen;
1186 * if we can't submit more io, we need to verify now
1188 if (queue_full(td) && async_do_verify(td, &v_io_u))
1193 async_do_verify(td, &v_io_u);
1196 cleanup_pending_aio(td);
1198 td_set_runstate(td, TD_RUNNING);
1201 static void do_async_io(struct thread_data *td)
1203 struct timeval s, e;
1206 while (td->this_io_bytes < td->io_size) {
1207 struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
1208 struct timespec *timeout;
1209 int ret, min_evts = 0;
1211 unsigned int bytes_done;
1216 io_u = get_io_u(td);
1220 memcpy(&s, &io_u->start_time, sizeof(s));
1222 ret = io_u_queue(td, io_u);
1229 gettimeofday(&io_u->issue_time, NULL);
1230 add_slat_sample(td, mtime_since(&io_u->start_time, &io_u->issue_time));
1231 if (td->cur_depth < td->aio_depth) {
1239 ret = io_u_getevents(td, min_evts, td->cur_depth, timeout);
1246 bytes_done = ios_completed(td, ret);
1249 * the rate is batched for now, it should work for batches
1250 * of completions except the very first one which may look
1253 gettimeofday(&e, NULL);
1254 usec = utime_since(&s, &e);
1256 rate_throttle(td, usec, bytes_done);
1258 if (check_min_rate(td, &e)) {
1259 td->error = ENODATA;
1263 if (runtime_exceeded(td, &e))
1267 usec_sleep(td->thinktime);
1269 if (should_fsync(td) && td->fsync_blocks &&
1270 (td->io_blocks % td->fsync_blocks) == 0)
1275 cleanup_pending_aio(td);
1277 if (should_fsync(td))
1281 static void cleanup_aio(struct thread_data *td)
1283 io_destroy(td->aio_ctx);
1286 free(td->aio_events);
1289 static int init_aio(struct thread_data *td)
1291 if (io_queue_init(td->aio_depth, &td->aio_ctx)) {
1296 td->aio_events = malloc(td->aio_depth * sizeof(struct io_event));
1300 static void cleanup_io_u(struct thread_data *td)
1302 struct list_head *entry, *n;
1305 list_for_each_safe(entry, n, &td->io_u_freelist) {
1306 io_u = list_entry(entry, struct io_u, list);
1308 list_del(&io_u->list);
1312 if (td->mem_type == MEM_MALLOC)
1313 free(td->orig_buffer);
1314 else if (td->mem_type == MEM_SHM) {
1315 struct shmid_ds sbuf;
1317 shmdt(td->orig_buffer);
1318 shmctl(td->shm_id, IPC_RMID, &sbuf);
1322 static int init_io_u(struct thread_data *td)
1325 int i, max_units, mem_size;
1331 max_units = td->aio_depth;
1333 mem_size = td->max_bs * max_units + MASK;
1335 if (td->mem_type == MEM_MALLOC)
1336 td->orig_buffer = malloc(mem_size);
1337 else if (td->mem_type == MEM_SHM) {
1338 td->shm_id = shmget(IPC_PRIVATE, mem_size, IPC_CREAT | 0600);
1339 if (td->shm_id < 0) {
1345 td->orig_buffer = shmat(td->shm_id, NULL, 0);
1346 if (td->orig_buffer == (void *) -1) {
1353 INIT_LIST_HEAD(&td->io_u_freelist);
1354 INIT_LIST_HEAD(&td->io_u_busylist);
1355 INIT_LIST_HEAD(&td->io_hist_list);
1357 p = ALIGN(td->orig_buffer);
1358 for (i = 0; i < max_units; i++) {
1359 io_u = malloc(sizeof(*io_u));
1360 memset(io_u, 0, sizeof(*io_u));
1361 INIT_LIST_HEAD(&io_u->list);
1363 io_u->buf = p + td->max_bs * i;
1364 list_add(&io_u->list, &td->io_u_freelist);
1370 static void setup_log(struct io_log **log)
1372 struct io_log *l = malloc(sizeof(*l));
1375 l->max_samples = 1024;
1376 l->log = malloc(l->max_samples * sizeof(struct io_sample));
1380 static void finish_log(struct thread_data *td, struct io_log *log, char *name)
1382 char file_name[128];
1386 sprintf(file_name, "client%d_%s.log", td->thread_number, name);
1387 f = fopen(file_name, "w");
1389 perror("fopen log");
1393 for (i = 0; i < log->nr_samples; i++)
1394 fprintf(f, "%lu, %lu\n", log->log[i].time, log->log[i].val);
1401 static int create_file(struct thread_data *td)
1403 unsigned long long left;
1409 * unless specifically asked for overwrite, let normal io extend it
1411 if (td_write(td) && !td->overwrite)
1414 if (!td->file_size) {
1415 fprintf(stderr, "Need size for create\n");
1420 printf("Client%d: Laying out IO file\n", td->thread_number);
1422 td->fd = open(td->file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1428 if (ftruncate(td->fd, td->file_size) == -1) {
1433 td->io_size = td->file_size;
1434 b = malloc(td->max_bs);
1435 memset(b, 0, td->max_bs);
1437 left = td->file_size;
1443 r = write(td->fd, b, bs);
1445 if (r == (int) bs) {
1458 if (td->create_fsync)
1467 static int file_exists(struct thread_data *td)
1471 if (stat(td->file_name, &st) != -1)
1474 return errno != ENOENT;
1477 static int get_file_size(struct thread_data *td)
1482 if (fstat(td->fd, &st) == -1) {
1488 * if block device, get size via BLKGETSIZE64 ioctl. try that as well
1489 * if this is a link, fall back to st.st_size if it fails
1491 if (S_ISBLK(st.st_mode) || S_ISLNK(st.st_mode)) {
1492 if (ioctl(td->fd, BLKGETSIZE64, &bytes)) {
1493 if (S_ISBLK(st.st_mode)) {
1503 if (td->file_size > bytes)
1504 bytes = td->file_size;
1507 td->file_size = 1024 * 1024 * 1024;
1509 bytes = td->file_size;
1512 if (td->file_offset > bytes) {
1513 fprintf(stderr, "Client%d: offset larger than length\n", td->thread_number);
1517 td->io_size = bytes - td->file_offset;
1518 if (td->io_size == 0) {
1519 fprintf(stderr, "Client%d: no io blocks\n", td->thread_number);
1527 static int setup_file(struct thread_data *td)
1531 if (!file_exists(td)) {
1532 if (!td->create_file) {
1536 if (create_file(td))
1544 td->fd = open(td->file_name, flags | O_RDONLY);
1555 td->fd = open(td->file_name, flags | O_CREAT, 0600);
1563 if (get_file_size(td))
1566 if (td_write(td) && ftruncate(td->fd, td->file_size) == -1) {
1571 if (td->invalidate_cache) {
1572 if (fadvise(td->fd, td->file_offset, td->file_size, POSIX_FADV_DONTNEED) < 0) {
1581 static void clear_io_state(struct thread_data *td)
1584 lseek(td->fd, SEEK_SET, 0);
1588 td->stat_io_bytes = 0;
1589 td->this_io_bytes = 0;
1592 memset(td->file_map, 0, td->num_maps * sizeof(long));
1595 static void *thread_main(int shm_id, int offset, char *argv[])
1597 struct thread_data *td;
1603 data = shmat(shm_id, NULL, 0);
1604 if (data == (void *) -1) {
1609 td = data + offset * sizeof(struct thread_data);
1615 if (sched_setaffinity(td->pid, sizeof(td->cpumask), &td->cpumask) == -1) {
1620 sprintf(argv[0], "fio%d", offset);
1622 if (td->use_aio && init_aio(td))
1626 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
1632 sem_post(&startup_sem);
1633 sem_wait(&td->mutex);
1635 if (!td->create_serialize && setup_file(td))
1638 if (init_random_state(td))
1641 gettimeofday(&td->start, NULL);
1643 getrusage(RUSAGE_SELF, &td->ru_start);
1645 while (td->loops--) {
1646 gettimeofday(&td->stat_sample_time, NULL);
1649 memcpy(&td->lastrate, &td->stat_sample_time, sizeof(td->lastrate));
1652 prune_io_piece_log(td);
1670 do_async_verify(td);
1676 td->runtime = mtime_since_now(&td->start);
1677 getrusage(RUSAGE_SELF, &td->ru_end);
1681 finish_log(td, td->bw_log, "bw");
1683 finish_log(td, td->lat_log, "lat");
1685 if (exitall_on_terminate)
1697 sem_post(&startup_sem);
1698 sem_wait(&td->mutex);
1700 td_set_runstate(td, TD_EXITED);
1705 static void free_shm(void)
1707 struct shmid_ds sbuf;
1712 shmctl(shm_id, IPC_RMID, &sbuf);
1716 static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
1717 double *mean, double *dev)
1721 if (is->samples == 0)
1727 n = (double) is->samples;
1728 *mean = (double) is->val / n;
1729 *dev = sqrt(((double) is->val_sq - (*mean * *mean) / n) / (n - 1));
1733 static void show_thread_status(struct thread_data *td)
1735 int prio, prio_class;
1736 unsigned long min, max, bw = 0, ctx;
1737 double mean, dev, usr_cpu, sys_cpu;
1739 if (!td->io_bytes && !td->error)
1743 bw = td->io_bytes / td->runtime;
1745 prio = td->ioprio & 0xff;
1746 prio_class = td->ioprio >> IOPRIO_CLASS_SHIFT;
1748 printf("Client%d: err=%2d, io=%6luMiB, bw=%6luKiB/s, runt=%6lumsec\n", td->thread_number, td->error, td->io_bytes >> 20, bw, td->runtime);
1750 if (calc_lat(&td->slat_stat, &min, &max, &mean, &dev))
1751 printf(" slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
1752 if (calc_lat(&td->clat_stat, &min, &max, &mean, &dev))
1753 printf(" clat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
1754 if (calc_lat(&td->bw_stat, &min, &max, &mean, &dev))
1755 printf(" bw (KiB/s) : min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
1760 t = mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime);
1761 usr_cpu = (double) t * 100 / (double) td->runtime;
1763 t = mtime_since(&td->ru_start.ru_stime, &td->ru_end.ru_stime);
1764 sys_cpu = (double) t * 100 / (double) td->runtime;
1770 ctx = td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
1772 printf(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, ctx);
1775 static int setup_rate(struct thread_data *td)
1777 int nr_reads_per_sec;
1782 if (td->rate < td->ratemin) {
1783 fprintf(stderr, "min rate larger than nominal rate\n");
1787 nr_reads_per_sec = (td->rate * 1024) / td->min_bs;
1788 td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
1789 td->rate_pending_usleep = 0;
1793 static struct thread_data *get_new_job(int global)
1795 struct thread_data *td;
1799 if (thread_number >= max_jobs)
1802 td = &threads[thread_number++];
1803 memset(td, 0, sizeof(*td));
1806 td->thread_number = thread_number;
1808 td->ddir = def_thread.ddir;
1809 td->ioprio = def_thread.ioprio;
1810 td->sequential = def_thread.sequential;
1811 td->bs = def_thread.bs;
1812 td->min_bs = def_thread.min_bs;
1813 td->max_bs = def_thread.max_bs;
1814 td->odirect = def_thread.odirect;
1815 td->thinktime = def_thread.thinktime;
1816 td->fsync_blocks = def_thread.fsync_blocks;
1817 td->start_delay = def_thread.start_delay;
1818 td->timeout = def_thread.timeout;
1819 td->use_aio = def_thread.use_aio;
1820 td->create_file = def_thread.create_file;
1821 td->overwrite = def_thread.overwrite;
1822 td->invalidate_cache = def_thread.invalidate_cache;
1823 td->file_size = def_thread.file_size;
1824 td->file_offset = def_thread.file_offset;
1825 td->rate = def_thread.rate;
1826 td->ratemin = def_thread.ratemin;
1827 td->ratecycle = def_thread.ratecycle;
1828 td->aio_depth = def_thread.aio_depth;
1829 td->sync_io = def_thread.sync_io;
1830 td->mem_type = def_thread.mem_type;
1831 td->bw_avg_time = def_thread.bw_avg_time;
1832 td->create_serialize = def_thread.create_serialize;
1833 td->create_fsync = def_thread.create_fsync;
1834 td->loops = def_thread.loops;
1835 td->verify = def_thread.verify;
1836 memcpy(&td->cpumask, &def_thread.cpumask, sizeof(td->cpumask));
1841 static void put_job(struct thread_data *td)
1843 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
1847 static int add_job(struct thread_data *td, const char *filename, int prioclass,
1850 if (td == &def_thread)
1853 strcpy(td->file_name, filename);
1854 sem_init(&td->mutex, 1, 0);
1855 td->ioprio = (prioclass << IOPRIO_CLASS_SHIFT) | prio;
1857 td->clat_stat.min_val = ULONG_MAX;
1858 td->slat_stat.min_val = ULONG_MAX;
1859 td->bw_stat.min_val = ULONG_MAX;
1861 run_str[td->thread_number - 1] = 'P';
1863 if (td->use_aio && !td->aio_depth)
1866 if (td->min_bs == -1U)
1867 td->min_bs = td->bs;
1868 if (td->max_bs == -1U)
1869 td->max_bs = td->bs;
1877 setup_log(&td->lat_log);
1879 setup_log(&td->bw_log);
1881 printf("Client%d: file=%s, rw=%d, prio=%d/%d, seq=%d, odir=%d, bs=%d-%d, rate=%d, aio=%d, aio_depth=%d\n", td->thread_number, filename, td->ddir, prioclass, prio, td->sequential, td->odirect, td->min_bs, td->max_bs, td->rate, td->use_aio, td->aio_depth);
1885 static void fill_cpu_mask(cpu_set_t cpumask, int cpu)
1891 for (i = 0; i < sizeof(int) * 8; i++) {
1893 CPU_SET(i, &cpumask);
1897 unsigned long get_mult(char c)
1908 return 1024 * 1024 * 1024;
1915 * convert string after '=' into decimal value, noting any size suffix
1917 static int str_cnv(char *p, unsigned long long *val)
1922 str = strstr(p, "=");
1929 *val = strtoul(str, NULL, 10);
1930 if (*val == ULONG_MAX && errno == ERANGE)
1933 *val *= get_mult(str[len - 2]);
1937 static int check_strcnv(char *p, char *name, unsigned long long *val)
1939 if (!strstr(p, name))
1942 return str_cnv(p, val);
1945 static int check_str(char *p, char *name, char *option)
1947 char *s = strstr(p, name);
1953 if (strstr(s, option))
1959 static int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
1964 sprintf(str, "%s=%%lu%%c-%%lu%%c", name);
1965 if (sscanf(p, str, s, &s1, e, &s2) == 4) {
1971 sprintf(str, "%s = %%lu%%c-%%lu%%c", name);
1972 if (sscanf(p, str, s, &s1, e, &s2) == 4) {
1978 sprintf(str, "%s=%%lu-%%lu", name);
1979 if (sscanf(p, str, s, e) == 2)
1982 sprintf(str, "%s = %%lu-%%lu", name);
1983 if (sscanf(p, str, s, e) == 2)
1990 static int check_int(char *p, char *name, unsigned int *val)
1994 sprintf(str, "%s=%%d", name);
1995 if (sscanf(p, str, val) == 1)
1998 sprintf(str, "%s = %%d", name);
1999 if (sscanf(p, str, val) == 1)
2005 static int is_empty_or_comment(char *line)
2009 for (i = 0; i < strlen(line); i++) {
2012 if (!isspace(line[i]) && !iscntrl(line[i]))
2019 static int parse_jobs_ini(char *file)
2021 unsigned int prioclass, prio, cpu, global;
2022 unsigned long long ull;
2023 unsigned long ul1, ul2;
2024 struct thread_data *td;
2025 char *string, *name;
2030 f = fopen(file, "r");
2036 string = malloc(4096);
2039 while ((p = fgets(string, 4096, f)) != NULL) {
2040 if (is_empty_or_comment(p))
2042 if (sscanf(p, "[%s]", name) != 1)
2045 global = !strncmp(name, "global", 6);
2047 name[strlen(name) - 1] = '\0';
2049 td = get_new_job(global);
2057 while ((p = fgets(string, 4096, f)) != NULL) {
2058 if (is_empty_or_comment(p))
2062 if (!check_int(p, "rw", &td->ddir)) {
2066 if (!check_int(p, "prio", &prio)) {
2070 if (!check_int(p, "prioclass", &prioclass)) {
2074 if (!check_int(p, "direct", &td->odirect)) {
2078 if (!check_int(p, "rate", &td->rate)) {
2082 if (!check_int(p, "ratemin", &td->ratemin)) {
2086 if (!check_int(p, "ratecycle", &td->ratecycle)) {
2090 if (!check_int(p, "thinktime", &td->thinktime)) {
2094 if (!check_int(p, "cpumask", &cpu)) {
2095 fill_cpu_mask(td->cpumask, cpu);
2099 if (!check_int(p, "fsync", &td->fsync_blocks)) {
2103 if (!check_int(p, "startdelay", &td->start_delay)) {
2107 if (!check_int(p, "timeout", &td->timeout)) {
2111 if (!check_int(p, "invalidate",&td->invalidate_cache)) {
2115 if (!check_int(p, "aio_depth", &td->aio_depth)) {
2119 if (!check_int(p, "sync", &td->sync_io)) {
2123 if (!check_int(p, "bwavgtime", &td->bw_avg_time)) {
2127 if (!check_int(p, "create_serialize", &td->create_serialize)) {
2131 if (!check_int(p, "create_fsync", &td->create_fsync)) {
2135 if (!check_int(p, "loops", &td->loops)) {
2139 if (!check_int(p, "verify", &td->verify)) {
2143 if (!check_range(p, "bsrange", &ul1, &ul2)) {
2145 printf("bad min block size, must be a multiple of 512\n");
2149 printf("bad max block size, must be a multiple of 512\n");
2155 if (!check_strcnv(p, "bs", &ull)) {
2157 printf("bad block size, must be a multiple of 512\n");
2163 if (!check_strcnv(p, "size", &td->file_size)) {
2167 if (!check_strcnv(p, "offset", &td->file_offset)) {
2171 if (!check_str(p, "mem", "malloc")) {
2172 td->mem_type = MEM_MALLOC;
2176 if (!check_str(p, "mem", "shm")) {
2177 td->mem_type = MEM_SHM;
2181 if (!strncmp(p, "sequential", 10)) {
2186 if (!strncmp(p, "random", 6)) {
2191 if (!strncmp(p, "aio", 3)) {
2196 if (!strncmp(p, "create", 6)) {
2197 td->create_file = 1;
2201 if (!strncmp(p, "overwrite", 9)) {
2206 if (!strncmp(p, "exitall", 7)) {
2207 exitall_on_terminate = 1;
2211 printf("Client%d: bad option %s\n",td->thread_number,p);
2215 if (add_job(td, name, prioclass, prio))
2225 static int parse_options(int argc, char *argv[])
2229 for (i = 1; i < argc; i++) {
2230 char *parm = argv[i];
2239 def_thread.sequential = !!atoi(parm);
2243 def_thread.bs = atoi(parm);
2244 def_thread.bs <<= 10;
2245 if (!def_thread.bs) {
2246 printf("bad block size\n");
2247 def_thread.bs = DEF_BS;
2252 def_thread.timeout = atoi(parm);
2256 repeatable = !!atoi(parm);
2260 rate_quit = !!atoi(parm);
2264 def_thread.odirect = !!atoi(parm);
2267 if (i + 1 >= argc) {
2268 printf("-f needs file as arg\n");
2271 ini_file = strdup(argv[i+1]);
2281 printf("bad option %s\n", argv[i]);
2289 static void print_thread_status(struct thread_data *td, int nr_running,
2290 int t_rate, int m_rate)
2292 printf("Threads now running: %d", nr_running);
2293 if (m_rate || t_rate)
2294 printf(", commitrate %d/%dKiB/sec", t_rate, m_rate);
2295 printf(" : [%s]\r", run_str);
2299 static void check_str_update(struct thread_data *td, int n, int t, int m)
2301 char c = run_str[td->thread_number - 1];
2303 if (td->runstate == td->old_runstate)
2306 switch (td->runstate) {
2332 case TD_NOT_CREATED:
2336 printf("state %d\n", td->runstate);
2339 run_str[td->thread_number - 1] = c;
2340 print_thread_status(td, n, t, m);
2341 td->old_runstate = td->runstate;
2344 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
2349 * reap exited threads (TD_EXITED -> TD_REAPED)
2351 for (i = 0; i < thread_number; i++) {
2352 struct thread_data *td = &threads[i];
2354 check_str_update(td, *nr_running, *t_rate, *m_rate);
2356 if (td->runstate != TD_EXITED)
2359 td_set_runstate(td, TD_REAPED);
2360 waitpid(td->pid, NULL, 0);
2362 (*m_rate) -= td->ratemin;
2363 (*t_rate) -= td->rate;
2364 check_str_update(td, *nr_running, *t_rate, *m_rate);
2371 static void run_threads(char *argv[])
2373 struct timeval genesis;
2374 struct thread_data *td;
2375 unsigned long spent;
2376 int i, todo, nr_running, m_rate, t_rate;
2378 printf("Starting %d threads\n", thread_number);
2381 signal(SIGINT, sig_handler);
2383 todo = thread_number;
2385 m_rate = t_rate = 0;
2387 for (i = 0; i < thread_number; i++) {
2390 if (!td->create_serialize)
2394 * do file setup here so it happens sequentially,
2395 * we don't want X number of threads getting their
2396 * client data interspersed on disk
2398 if (setup_file(td)) {
2399 td_set_runstate(td, TD_REAPED);
2404 gettimeofday(&genesis, NULL);
2408 * create threads (TD_NOT_CREATED -> TD_CREATED)
2410 for (i = 0; i < thread_number; i++) {
2413 if (td->runstate != TD_NOT_CREATED)
2417 * never got a chance to start, killed by other
2418 * thread for some reason
2420 if (td->terminate) {
2425 if (td->start_delay) {
2426 spent = mtime_since_now(&genesis);
2428 if (td->start_delay * 1000 > spent)
2432 td_set_runstate(td, TD_CREATED);
2433 check_str_update(td, nr_running, t_rate, m_rate);
2434 sem_init(&startup_sem, 1, 1);
2438 sem_wait(&startup_sem);
2440 thread_main(shm_id, i, argv);
2446 * start created threads (TD_CREATED -> TD_RUNNING)
2448 for (i = 0; i < thread_number; i++) {
2449 struct thread_data *td = &threads[i];
2451 if (td->runstate != TD_CREATED)
2454 td_set_runstate(td, TD_RUNNING);
2456 m_rate += td->ratemin;
2458 check_str_update(td, nr_running, t_rate, m_rate);
2459 sem_post(&td->mutex);
2462 for (i = 0; i < thread_number; i++) {
2463 struct thread_data *td = &threads[i];
2465 if (td->runstate == TD_RUNNING)
2466 run_str[td->thread_number - 1] = '+';
2467 else if (td->runstate == TD_VERIFYING)
2468 run_str[td->thread_number - 1] = 'V';
2472 check_str_update(td, nr_running, t_rate, m_rate);
2475 reap_threads(&nr_running, &t_rate, &m_rate);
2481 while (nr_running) {
2482 reap_threads(&nr_running, &t_rate, &m_rate);
2487 int setup_thread_area(void)
2490 * 1024 is too much on some machines, scale max_jobs if
2491 * we get a failure that looks like too large a shm segment
2494 int s = max_jobs * sizeof(struct thread_data);
2496 shm_id = shmget(0, s, IPC_CREAT | 0600);
2499 if (errno != EINVAL) {
2510 threads = shmat(shm_id, NULL, 0);
2511 if (threads == (void *) -1) {
2520 int main(int argc, char *argv[])
2522 static unsigned long max_run[2], min_run[2];
2523 static unsigned long max_bw[2], min_bw[2];
2524 static unsigned long io_mb[2], agg[2];
2527 if (setup_thread_area())
2530 if (sched_getaffinity(getpid(), sizeof(cpu_set_t), &def_thread.cpumask) == -1) {
2531 perror("sched_getaffinity");
2538 def_thread.ddir = DDIR_READ;
2539 def_thread.bs = DEF_BS;
2540 def_thread.min_bs = -1;
2541 def_thread.max_bs = -1;
2542 def_thread.odirect = DEF_ODIRECT;
2543 def_thread.ratecycle = DEF_RATE_CYCLE;
2544 def_thread.sequential = DEF_SEQUENTIAL;
2545 def_thread.timeout = DEF_TIMEOUT;
2546 def_thread.create_file = DEF_CREATE;
2547 def_thread.overwrite = DEF_OVERWRITE;
2548 def_thread.invalidate_cache = DEF_INVALIDATE;
2549 def_thread.sync_io = DEF_SYNCIO;
2550 def_thread.mem_type = MEM_MALLOC;
2551 def_thread.bw_avg_time = DEF_BWAVGTIME;
2552 def_thread.create_serialize = DEF_CREATE_SER;
2553 def_thread.create_fsync = DEF_CREATE_FSYNC;
2554 def_thread.loops = DEF_LOOPS;
2555 def_thread.verify = DEF_VERIFY;
2557 i = parse_options(argc, argv);
2560 printf("Need job file\n");
2564 if (parse_jobs_ini(ini_file))
2567 if (!thread_number) {
2568 printf("Nothing to do\n");
2574 min_bw[0] = min_run[0] = ~0UL;
2575 min_bw[1] = min_run[1] = ~0UL;
2576 io_mb[0] = io_mb[1] = 0;
2577 agg[0] = agg[1] = 0;
2578 for (i = 0; i < thread_number; i++) {
2579 struct thread_data *td = &threads[i];
2580 unsigned long bw = 0;
2583 if (td->runtime < min_run[td->ddir])
2584 min_run[td->ddir] = td->runtime;
2585 if (td->runtime > max_run[td->ddir])
2586 max_run[td->ddir] = td->runtime;
2589 bw = td->io_bytes / td->runtime;
2590 if (bw < min_bw[td->ddir])
2591 min_bw[td->ddir] = bw;
2592 if (bw > max_bw[td->ddir])
2593 max_bw[td->ddir] = bw;
2595 io_mb[td->ddir] += td->io_bytes >> 20;
2598 show_thread_status(td);
2602 agg[0] = (io_mb[0] * 1024 * 1000) / max_run[0];
2604 agg[1] = (io_mb[1] * 1024 * 1000) / max_run[1];
2606 printf("\nRun status:\n");
2607 if (max_run[DDIR_READ])
2608 printf(" READ: io=%luMiB, aggrb=%lu, minb=%lu, maxb=%lu, mint=%lumsec, maxt=%lumsec\n", io_mb[0], agg[0], min_bw[0], max_bw[0], min_run[0], max_run[0]);
2609 if (max_run[DDIR_WRITE])
2610 printf(" WRITE: io=%luMiB, aggrb=%lu, minb=%lu, maxb=%lu, mint=%lumsec, maxt=%lumsec\n", io_mb[1], agg[1], min_bw[1], max_bw[1], min_run[1], max_run[1]);