2 * fio - the flexible io tester
4 * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
5 * Copyright (C) 2006 Jens Axboe <axboe@kernel.dk>
7 * The license below covers all files distributed with fio unless otherwise
8 * noted in the file itself.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 unsigned long page_mask;
42 unsigned long page_size;
44 (char *) (((unsigned long) (buf) + page_mask) & ~page_mask)
47 int thread_number = 0;
53 static struct fio_mutex *startup_mutex;
54 static volatile int fio_abort;
55 static int exit_value;
57 struct io_log *agg_io_log[2];
59 #define TERMINATE_ALL (-1)
60 #define JOB_START_TIMEOUT (5 * 1000)
62 static inline void td_set_runstate(struct thread_data *td, int runstate)
64 if (td->runstate == runstate)
67 dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", td->pid, td->runstate,
69 td->runstate = runstate;
72 static void terminate_threads(int group_id)
74 struct thread_data *td;
78 if (group_id == TERMINATE_ALL || groupid == td->groupid) {
79 dprint(FD_PROCESS, "setting terminate on %d\n",
82 td->o.start_delay = 0;
85 * if the thread is running, just let it exit
87 if (td->runstate < TD_RUNNING)
88 kill(td->pid, SIGQUIT);
90 struct ioengine_ops *ops = td->io_ops;
92 if (ops && (ops->flags & FIO_SIGQUIT))
93 kill(td->pid, SIGQUIT);
99 static void sig_handler(int sig)
104 disk_util_timer_arm();
105 print_thread_status();
108 printf("\nfio: terminating on signal %d\n", sig);
110 terminate_threads(TERMINATE_ALL);
116 * Check if we are above the minimum rate given.
118 static int check_min_rate(struct thread_data *td, struct timeval *now)
120 unsigned long long bytes = 0;
121 unsigned long iops = 0;
126 * No minimum rate set, always ok
128 if (!td->o.ratemin && !td->o.rate_iops_min)
132 * allow a 2 second settle period in the beginning
134 if (mtime_since(&td->start, now) < 2000)
138 iops += td->io_blocks[DDIR_READ];
139 bytes += td->this_io_bytes[DDIR_READ];
142 iops += td->io_blocks[DDIR_WRITE];
143 bytes += td->this_io_bytes[DDIR_WRITE];
147 * if rate blocks is set, sample is running
149 if (td->rate_bytes || td->rate_blocks) {
150 spent = mtime_since(&td->lastrate, now);
151 if (spent < td->o.ratecycle)
156 * check bandwidth specified rate
158 if (bytes < td->rate_bytes) {
159 log_err("%s: min rate %u not met\n", td->o.name,
163 rate = (bytes - td->rate_bytes) / spent;
164 if (rate < td->o.ratemin ||
165 bytes < td->rate_bytes) {
166 log_err("%s: min rate %u not met, got"
167 " %luKiB/sec\n", td->o.name,
168 td->o.ratemin, rate);
174 * checks iops specified rate
176 if (iops < td->o.rate_iops) {
177 log_err("%s: min iops rate %u not met\n",
178 td->o.name, td->o.rate_iops);
181 rate = (iops - td->rate_blocks) / spent;
182 if (rate < td->o.rate_iops_min ||
183 iops < td->rate_blocks) {
184 log_err("%s: min iops rate %u not met,"
185 " got %lu\n", td->o.name,
193 td->rate_bytes = bytes;
194 td->rate_blocks = iops;
195 memcpy(&td->lastrate, now, sizeof(*now));
199 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
203 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
210 * When job exits, we can cancel the in-flight IO if we are using async
211 * io. Attempt to do so.
213 static void cleanup_pending_aio(struct thread_data *td)
215 struct list_head *entry, *n;
220 * get immediately available events, if any
222 r = io_u_queued_complete(td, 0);
227 * now cancel remaining active events
229 if (td->io_ops->cancel) {
230 list_for_each_safe(entry, n, &td->io_u_busylist) {
231 io_u = list_entry(entry, struct io_u, list);
234 * if the io_u isn't in flight, then that generally
235 * means someone leaked an io_u. complain but fix
236 * it up, so we don't stall here.
238 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
239 log_err("fio: non-busy IO on busy list\n");
242 r = td->io_ops->cancel(td, io_u);
250 r = io_u_queued_complete(td, td->cur_depth);
254 * Helper to handle the final sync of a file. Works just like the normal
255 * io path, just does everything sync.
257 static int fio_io_sync(struct thread_data *td, struct fio_file *f)
259 struct io_u *io_u = __get_io_u(td);
265 io_u->ddir = DDIR_SYNC;
268 if (td_io_prep(td, io_u)) {
274 ret = td_io_queue(td, io_u);
276 td_verror(td, io_u->error, "td_io_queue");
279 } else if (ret == FIO_Q_QUEUED) {
280 if (io_u_queued_complete(td, 1) < 0)
282 } else if (ret == FIO_Q_COMPLETED) {
284 td_verror(td, io_u->error, "td_io_queue");
288 if (io_u_sync_complete(td, io_u) < 0)
290 } else if (ret == FIO_Q_BUSY) {
291 if (td_io_commit(td))
300 * The main verify engine. Runs over the writes we previously submitted,
301 * reads the blocks back in, and checks the crc/md5 of the data.
303 static void do_verify(struct thread_data *td)
311 * sync io first and invalidate cache, to make sure we really
314 for_each_file(td, f, i) {
315 if (!(f->flags & FIO_FILE_OPEN))
317 if (fio_io_sync(td, f))
319 if (file_invalidate_cache(td, f))
326 td_set_runstate(td, TD_VERIFYING);
329 while (!td->terminate) {
332 io_u = __get_io_u(td);
336 if (runtime_exceeded(td, &io_u->start_time)) {
342 if (get_next_verify(td, io_u)) {
347 if (td_io_prep(td, io_u)) {
352 io_u->end_io = verify_io_u;
354 ret = td_io_queue(td, io_u);
356 case FIO_Q_COMPLETED:
359 else if (io_u->resid) {
360 int bytes = io_u->xfer_buflen - io_u->resid;
361 struct fio_file *f = io_u->file;
367 td_verror(td, ENODATA, "full resid");
372 io_u->xfer_buflen = io_u->resid;
373 io_u->xfer_buf += bytes;
374 io_u->offset += bytes;
376 td->ts.short_io_u[io_u->ddir]++;
378 if (io_u->offset == f->real_file_size)
381 requeue_io_u(td, &io_u);
384 ret = io_u_sync_complete(td, io_u);
392 requeue_io_u(td, &io_u);
393 ret2 = td_io_commit(td);
399 td_verror(td, -ret, "td_io_queue");
403 if (ret < 0 || td->error)
407 * if we can queue more, do so. but check if there are
408 * completed io_u's first.
411 if (queue_full(td) || ret == FIO_Q_BUSY) {
414 if (td->cur_depth > td->o.iodepth_low)
415 min_events = td->cur_depth - td->o.iodepth_low;
419 * Reap required number of io units, if any, and do the
420 * verification on them through the callback handler
422 if (io_u_queued_complete(td, min_events) < 0)
427 min_events = td->cur_depth;
430 ret = io_u_queued_complete(td, min_events);
432 cleanup_pending_aio(td);
434 td_set_runstate(td, TD_RUNNING);
438 * Main IO worker function. It retrieves io_u's to process and queues
439 * and reaps them, checking for rate and errors along the way.
441 static void do_io(struct thread_data *td)
448 td_set_runstate(td, TD_RUNNING);
450 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
451 struct timeval comp_time;
464 memcpy(&s, &io_u->start_time, sizeof(s));
466 if (runtime_exceeded(td, &s)) {
473 * Add verification end_io handler, if asked to verify
474 * a previously written file.
476 if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ) {
477 io_u->end_io = verify_io_u;
478 td_set_runstate(td, TD_VERIFYING);
480 td_set_runstate(td, TD_RUNNING);
482 ret = td_io_queue(td, io_u);
484 case FIO_Q_COMPLETED:
487 else if (io_u->resid) {
488 int bytes = io_u->xfer_buflen - io_u->resid;
489 struct fio_file *f = io_u->file;
495 td_verror(td, ENODATA, "full resid");
500 io_u->xfer_buflen = io_u->resid;
501 io_u->xfer_buf += bytes;
502 io_u->offset += bytes;
504 td->ts.short_io_u[io_u->ddir]++;
506 if (io_u->offset == f->real_file_size)
509 requeue_io_u(td, &io_u);
512 fio_gettime(&comp_time, NULL);
513 bytes_done = io_u_sync_complete(td, io_u);
520 * if the engine doesn't have a commit hook,
521 * the io_u is really queued. if it does have such
522 * a hook, it has to call io_u_queued() itself.
524 if (td->io_ops->commit == NULL)
525 io_u_queued(td, io_u);
528 requeue_io_u(td, &io_u);
529 ret2 = td_io_commit(td);
539 if (ret < 0 || td->error)
543 * See if we need to complete some commands
545 if (ret == FIO_Q_QUEUED || ret == FIO_Q_BUSY) {
547 if (queue_full(td) || ret == FIO_Q_BUSY) {
550 if (td->cur_depth > td->o.iodepth_low)
551 min_evts = td->cur_depth
555 fio_gettime(&comp_time, NULL);
556 bytes_done = io_u_queued_complete(td, min_evts);
565 * the rate is batched for now, it should work for batches
566 * of completions except the very first one which may look
569 usec = utime_since(&s, &comp_time);
571 rate_throttle(td, usec, bytes_done);
573 if (check_min_rate(td, &comp_time)) {
574 if (exitall_on_terminate)
575 terminate_threads(td->groupid);
576 td_verror(td, ENODATA, "check_min_rate");
580 if (td->o.thinktime) {
581 unsigned long long b;
583 b = td->io_blocks[0] + td->io_blocks[1];
584 if (!(b % td->o.thinktime_blocks)) {
587 if (td->o.thinktime_spin)
588 __usec_sleep(td->o.thinktime_spin);
590 left = td->o.thinktime - td->o.thinktime_spin;
592 usec_sleep(td, left);
597 if (td->o.fill_device && td->error == ENOSPC) {
606 ret = io_u_queued_complete(td, i);
608 if (should_fsync(td) && td->o.end_fsync) {
609 td_set_runstate(td, TD_FSYNCING);
611 for_each_file(td, f, i) {
612 if (!(f->flags & FIO_FILE_OPEN))
618 cleanup_pending_aio(td);
621 * stop job if we failed doing any IO
623 if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
627 static void cleanup_io_u(struct thread_data *td)
629 struct list_head *entry, *n;
632 list_for_each_safe(entry, n, &td->io_u_freelist) {
633 io_u = list_entry(entry, struct io_u, list);
635 list_del(&io_u->list);
643 * "randomly" fill the buffer contents
645 static void fill_io_buf(struct thread_data *td, struct io_u *io_u, int max_bs)
647 long *ptr = io_u->buf;
649 if (!td->o.zero_buffers) {
650 while ((void *) ptr - io_u->buf < max_bs) {
651 *ptr = rand() * GOLDEN_RATIO_PRIME;
655 memset(ptr, 0, max_bs);
658 static int init_io_u(struct thread_data *td)
665 max_units = td->o.iodepth;
666 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
667 td->orig_buffer_size = (unsigned long long) max_bs
668 * (unsigned long long) max_units;
670 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
673 bs = td->orig_buffer_size + td->o.hugepage_size - 1;
674 td->orig_buffer_size = bs & ~(td->o.hugepage_size - 1);
677 if (td->orig_buffer_size != (size_t) td->orig_buffer_size) {
678 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
682 if (allocate_io_mem(td))
686 p = ALIGN(td->orig_buffer);
690 for (i = 0; i < max_units; i++) {
693 io_u = malloc(sizeof(*io_u));
694 memset(io_u, 0, sizeof(*io_u));
695 INIT_LIST_HEAD(&io_u->list);
697 if (!(td->io_ops->flags & FIO_NOIO)) {
698 io_u->buf = p + max_bs * i;
701 fill_io_buf(td, io_u, max_bs);
705 io_u->flags = IO_U_F_FREE;
706 list_add(&io_u->list, &td->io_u_freelist);
714 static int switch_ioscheduler(struct thread_data *td)
716 char tmp[256], tmp2[128];
720 if (td->io_ops->flags & FIO_DISKLESSIO)
723 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
725 f = fopen(tmp, "r+");
727 if (errno == ENOENT) {
728 log_err("fio: os or kernel doesn't support IO scheduler"
732 td_verror(td, errno, "fopen iosched");
739 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
740 if (ferror(f) || ret != 1) {
741 td_verror(td, errno, "fwrite");
749 * Read back and check that the selected scheduler is now the default.
751 ret = fread(tmp, 1, sizeof(tmp), f);
752 if (ferror(f) || ret < 0) {
753 td_verror(td, errno, "fread");
758 sprintf(tmp2, "[%s]", td->o.ioscheduler);
759 if (!strstr(tmp, tmp2)) {
760 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
761 td_verror(td, EINVAL, "iosched_switch");
770 static int keep_running(struct thread_data *td)
772 unsigned long long io_done;
776 if (td->o.time_based)
783 io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]
785 if (io_done < td->o.size)
791 static int clear_io_state(struct thread_data *td)
797 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
798 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
802 td->rw_end_set[0] = td->rw_end_set[1] = 0;
804 td->last_was_sync = 0;
807 * reset file done count if we are to start over
809 if (td->o.time_based || td->o.loops)
810 td->nr_done_files = 0;
815 for_each_file(td, f, i) {
816 f->flags &= ~FIO_FILE_DONE;
817 ret = td_io_open_file(td, f);
826 * Entry point for the thread based jobs. The process based jobs end up
827 * here as well, after a little setup.
829 static void *thread_main(void *data)
831 unsigned long long runtime[2], elapsed;
832 struct thread_data *td = data;
835 if (!td->o.use_thread)
840 dprint(FD_PROCESS, "jobs pid=%d started\n", td->pid);
842 INIT_LIST_HEAD(&td->io_u_freelist);
843 INIT_LIST_HEAD(&td->io_u_busylist);
844 INIT_LIST_HEAD(&td->io_u_requeues);
845 INIT_LIST_HEAD(&td->io_log_list);
846 INIT_LIST_HEAD(&td->io_hist_list);
847 td->io_hist_tree = RB_ROOT;
849 td_set_runstate(td, TD_INITIALIZED);
850 fio_mutex_up(startup_mutex);
851 fio_mutex_down(td->mutex);
854 * the ->mutex mutex is now no longer used, close it to avoid
855 * eating a file descriptor
857 fio_mutex_remove(td->mutex);
860 * May alter parameters that init_io_u() will use, so we need to
869 if (td->o.cpumask_set && fio_setaffinity(td) == -1) {
870 td_verror(td, errno, "cpu_set_affinity");
874 if (td->ioprio_set) {
875 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
876 td_verror(td, errno, "ioprio_set");
881 if (nice(td->o.nice) == -1) {
882 td_verror(td, errno, "nice");
886 if (td->o.ioscheduler && switch_ioscheduler(td))
889 if (!td->o.create_serialize && setup_files(td))
898 if (init_random_map(td))
901 if (td->o.exec_prerun) {
902 if (system(td->o.exec_prerun) < 0)
906 fio_gettime(&td->epoch, NULL);
907 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
908 getrusage(RUSAGE_SELF, &td->ts.ru_start);
910 runtime[0] = runtime[1] = 0;
912 while (keep_running(td)) {
913 fio_gettime(&td->start, NULL);
914 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
917 memcpy(&td->lastrate, &td->ts.stat_sample_time,
918 sizeof(td->lastrate));
920 if (clear_state && clear_io_state(td))
923 prune_io_piece_log(td);
929 if (td_read(td) && td->io_bytes[DDIR_READ]) {
930 if (td->rw_end_set[DDIR_READ])
931 elapsed = utime_since(&td->start,
932 &td->rw_end[DDIR_READ]);
934 elapsed = utime_since_now(&td->start);
936 runtime[DDIR_READ] += elapsed;
938 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
939 if (td->rw_end_set[DDIR_WRITE])
940 elapsed = utime_since(&td->start,
941 &td->rw_end[DDIR_WRITE]);
943 elapsed = utime_since_now(&td->start);
945 runtime[DDIR_WRITE] += elapsed;
948 if (td->error || td->terminate)
951 if (!td->o.do_verify ||
952 td->o.verify == VERIFY_NONE ||
953 (td->io_ops->flags & FIO_UNIDIR))
956 if (clear_io_state(td))
959 fio_gettime(&td->start, NULL);
963 runtime[DDIR_READ] += utime_since_now(&td->start);
965 if (td->error || td->terminate)
969 update_rusage_stat(td);
970 td->ts.runtime[0] = (runtime[0] + 999) / 1000;
971 td->ts.runtime[1] = (runtime[1] + 999) / 1000;
972 td->ts.total_run_time = mtime_since_now(&td->epoch);
973 td->ts.io_bytes[0] = td->io_bytes[0];
974 td->ts.io_bytes[1] = td->io_bytes[1];
977 finish_log(td, td->ts.bw_log, "bw");
979 finish_log(td, td->ts.slat_log, "slat");
981 finish_log(td, td->ts.clat_log, "clat");
982 if (td->o.exec_postrun) {
983 if (system(td->o.exec_postrun) < 0)
984 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
987 if (exitall_on_terminate)
988 terminate_threads(td->groupid);
992 printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error,
994 close_and_free_files(td);
999 * do this very late, it will log file closing as well
1001 if (td->o.write_iolog_file)
1002 write_iolog_close(td);
1004 options_mem_free(td);
1005 td_set_runstate(td, TD_EXITED);
1006 return (void *) (unsigned long) td->error;
1010 * We cannot pass the td data into a forked process, so attach the td and
1011 * pass it to the thread worker.
1013 static int fork_main(int shmid, int offset)
1015 struct thread_data *td;
1018 data = shmat(shmid, NULL, 0);
1019 if (data == (void *) -1) {
1026 td = data + offset * sizeof(struct thread_data);
1027 ret = thread_main(td);
1029 return (int) (unsigned long) ret;
1033 * Run over the job map and reap the threads that have exited, if any.
1035 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
1037 struct thread_data *td;
1038 int i, cputhreads, realthreads, pending, status, ret;
1041 * reap exited threads (TD_EXITED -> TD_REAPED)
1043 realthreads = pending = cputhreads = 0;
1044 for_each_td(td, i) {
1048 * ->io_ops is NULL for a thread that has closed its
1051 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
1060 if (td->runstate == TD_REAPED)
1062 if (td->o.use_thread) {
1063 if (td->runstate == TD_EXITED) {
1064 td_set_runstate(td, TD_REAPED);
1071 if (td->runstate == TD_EXITED)
1075 * check if someone quit or got killed in an unusual way
1077 ret = waitpid(td->pid, &status, flags);
1079 if (errno == ECHILD) {
1080 log_err("fio: pid=%d disappeared %d\n", td->pid,
1082 td_set_runstate(td, TD_REAPED);
1086 } else if (ret == td->pid) {
1087 if (WIFSIGNALED(status)) {
1088 int sig = WTERMSIG(status);
1091 log_err("fio: pid=%d, got signal=%d\n",
1093 td_set_runstate(td, TD_REAPED);
1096 if (WIFEXITED(status)) {
1097 if (WEXITSTATUS(status) && !td->error)
1098 td->error = WEXITSTATUS(status);
1100 td_set_runstate(td, TD_REAPED);
1106 * thread is not dead, continue
1111 if (td->o.use_thread) {
1114 dprint(FD_PROCESS, "joining tread %d\n", td->pid);
1115 if (pthread_join(td->thread, (void *) &ret)) {
1116 dprint(FD_PROCESS, "join failed %ld\n", ret);
1117 perror("pthread_join");
1122 (*m_rate) -= td->o.ratemin;
1123 (*t_rate) -= td->o.rate;
1130 if (*nr_running == cputhreads && !pending && realthreads)
1131 terminate_threads(TERMINATE_ALL);
1135 * Main function for kicking off and reaping jobs, as needed.
1137 static void run_threads(void)
1139 struct thread_data *td;
1140 unsigned long spent;
1141 int i, todo, nr_running, m_rate, t_rate, nr_started;
1143 if (fio_pin_memory())
1146 if (!terse_output) {
1147 printf("Starting ");
1149 printf("%d thread%s", nr_thread,
1150 nr_thread > 1 ? "s" : "");
1154 printf("%d process%s", nr_process,
1155 nr_process > 1 ? "es" : "");
1161 signal(SIGINT, sig_handler);
1162 signal(SIGALRM, sig_handler);
1164 todo = thread_number;
1167 m_rate = t_rate = 0;
1169 for_each_td(td, i) {
1170 print_status_init(td->thread_number - 1);
1172 if (!td->o.create_serialize) {
1178 * do file setup here so it happens sequentially,
1179 * we don't want X number of threads getting their
1180 * client data interspersed on disk
1182 if (setup_files(td)) {
1185 log_err("fio: pid=%d, err=%d/%s\n", td->pid,
1186 td->error, td->verror);
1187 td_set_runstate(td, TD_REAPED);
1194 * for sharing to work, each job must always open
1195 * its own files. so close them, if we opened them
1198 for_each_file(td, f, i)
1199 td_io_close_file(td, f);
1208 struct thread_data *map[MAX_JOBS];
1209 struct timeval this_start;
1210 int this_jobs = 0, left;
1213 * create threads (TD_NOT_CREATED -> TD_CREATED)
1215 for_each_td(td, i) {
1216 if (td->runstate != TD_NOT_CREATED)
1220 * never got a chance to start, killed by other
1221 * thread for some reason
1223 if (td->terminate) {
1228 if (td->o.start_delay) {
1229 spent = mtime_since_genesis();
1231 if (td->o.start_delay * 1000 > spent)
1235 if (td->o.stonewall && (nr_started || nr_running))
1239 * Set state to created. Thread will transition
1240 * to TD_INITIALIZED when it's done setting up.
1242 td_set_runstate(td, TD_CREATED);
1243 map[this_jobs++] = td;
1246 if (td->o.use_thread) {
1247 dprint(FD_PROCESS, "will pthread_create\n");
1248 if (pthread_create(&td->thread, NULL,
1250 perror("thread_create");
1255 dprint(FD_PROCESS, "will fork\n");
1257 int ret = fork_main(shm_id, i);
1262 fio_mutex_down(startup_mutex);
1266 * Wait for the started threads to transition to
1269 fio_gettime(&this_start, NULL);
1271 while (left && !fio_abort) {
1272 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1277 for (i = 0; i < this_jobs; i++) {
1281 if (td->runstate == TD_INITIALIZED) {
1284 } else if (td->runstate >= TD_EXITED) {
1288 nr_running++; /* work-around... */
1294 log_err("fio: %d jobs failed to start\n", left);
1295 for (i = 0; i < this_jobs; i++) {
1299 kill(td->pid, SIGTERM);
1305 * start created threads (TD_INITIALIZED -> TD_RUNNING).
1307 for_each_td(td, i) {
1308 if (td->runstate != TD_INITIALIZED)
1311 td_set_runstate(td, TD_RUNNING);
1314 m_rate += td->o.ratemin;
1315 t_rate += td->o.rate;
1317 fio_mutex_up(td->mutex);
1320 reap_threads(&nr_running, &t_rate, &m_rate);
1326 while (nr_running) {
1327 reap_threads(&nr_running, &t_rate, &m_rate);
1335 int main(int argc, char *argv[])
1342 * We need locale for number printing, if it isn't set then just
1343 * go with the US format.
1345 if (!getenv("LC_NUMERIC"))
1346 setlocale(LC_NUMERIC, "en_US");
1348 if (parse_options(argc, argv))
1354 ps = sysconf(_SC_PAGESIZE);
1356 log_err("Failed to get page size\n");
1364 setup_log(&agg_io_log[DDIR_READ]);
1365 setup_log(&agg_io_log[DDIR_WRITE]);
1368 startup_mutex = fio_mutex_init(0);
1372 disk_util_timer_arm();
1379 __finish_log(agg_io_log[DDIR_READ], "agg-read_bw.log");
1380 __finish_log(agg_io_log[DDIR_WRITE],
1381 "agg-write_bw.log");
1385 fio_mutex_remove(startup_mutex);