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;
52 unsigned long done_secs = 0;
54 static struct fio_mutex *startup_mutex;
55 static volatile int fio_abort;
56 static int exit_value;
58 struct io_log *agg_io_log[2];
60 #define TERMINATE_ALL (-1)
61 #define JOB_START_TIMEOUT (5 * 1000)
63 static inline void td_set_runstate(struct thread_data *td, int runstate)
65 if (td->runstate == runstate)
68 dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", td->pid, td->runstate,
70 td->runstate = runstate;
73 static void terminate_threads(int group_id)
75 struct thread_data *td;
78 dprint(FD_PROCESS, "terminate group_id=%d\n", group_id);
81 if (group_id == TERMINATE_ALL || groupid == td->groupid) {
82 dprint(FD_PROCESS, "setting terminate on %s/%d\n",
85 td->o.start_delay = 0;
88 * if the thread is running, just let it exit
90 if (td->runstate < TD_RUNNING)
91 kill(td->pid, SIGQUIT);
93 struct ioengine_ops *ops = td->io_ops;
95 if (ops && (ops->flags & FIO_SIGQUIT))
96 kill(td->pid, SIGQUIT);
102 static void sig_handler(int sig)
110 disk_util_timer_arm();
111 print_thread_status();
114 printf("\nfio: terminating on signal %d\n", sig);
116 terminate_threads(TERMINATE_ALL);
122 * Check if we are above the minimum rate given.
124 static int check_min_rate(struct thread_data *td, struct timeval *now)
126 unsigned long long bytes = 0;
127 unsigned long iops = 0;
132 * No minimum rate set, always ok
134 if (!td->o.ratemin && !td->o.rate_iops_min)
138 * allow a 2 second settle period in the beginning
140 if (mtime_since(&td->start, now) < 2000)
144 iops += td->io_blocks[DDIR_READ];
145 bytes += td->this_io_bytes[DDIR_READ];
148 iops += td->io_blocks[DDIR_WRITE];
149 bytes += td->this_io_bytes[DDIR_WRITE];
153 * if rate blocks is set, sample is running
155 if (td->rate_bytes || td->rate_blocks) {
156 spent = mtime_since(&td->lastrate, now);
157 if (spent < td->o.ratecycle)
162 * check bandwidth specified rate
164 if (bytes < td->rate_bytes) {
165 log_err("%s: min rate %u not met\n", td->o.name,
169 rate = (bytes - td->rate_bytes) / spent;
170 if (rate < td->o.ratemin ||
171 bytes < td->rate_bytes) {
172 log_err("%s: min rate %u not met, got"
173 " %luKiB/sec\n", td->o.name,
174 td->o.ratemin, rate);
180 * checks iops specified rate
182 if (iops < td->o.rate_iops) {
183 log_err("%s: min iops rate %u not met\n",
184 td->o.name, td->o.rate_iops);
187 rate = (iops - td->rate_blocks) / spent;
188 if (rate < td->o.rate_iops_min ||
189 iops < td->rate_blocks) {
190 log_err("%s: min iops rate %u not met,"
191 " got %lu\n", td->o.name,
199 td->rate_bytes = bytes;
200 td->rate_blocks = iops;
201 memcpy(&td->lastrate, now, sizeof(*now));
205 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
209 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
216 * When job exits, we can cancel the in-flight IO if we are using async
217 * io. Attempt to do so.
219 static void cleanup_pending_aio(struct thread_data *td)
221 struct list_head *entry, *n;
226 * get immediately available events, if any
228 r = io_u_queued_complete(td, 0);
233 * now cancel remaining active events
235 if (td->io_ops->cancel) {
236 list_for_each_safe(entry, n, &td->io_u_busylist) {
237 io_u = list_entry(entry, struct io_u, list);
240 * if the io_u isn't in flight, then that generally
241 * means someone leaked an io_u. complain but fix
242 * it up, so we don't stall here.
244 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
245 log_err("fio: non-busy IO on busy list\n");
248 r = td->io_ops->cancel(td, io_u);
256 r = io_u_queued_complete(td, td->cur_depth);
260 * Helper to handle the final sync of a file. Works just like the normal
261 * io path, just does everything sync.
263 static int fio_io_sync(struct thread_data *td, struct fio_file *f)
265 struct io_u *io_u = __get_io_u(td);
271 io_u->ddir = DDIR_SYNC;
274 if (td_io_prep(td, io_u)) {
280 ret = td_io_queue(td, io_u);
282 td_verror(td, io_u->error, "td_io_queue");
285 } else if (ret == FIO_Q_QUEUED) {
286 if (io_u_queued_complete(td, 1) < 0)
288 } else if (ret == FIO_Q_COMPLETED) {
290 td_verror(td, io_u->error, "td_io_queue");
294 if (io_u_sync_complete(td, io_u) < 0)
296 } else if (ret == FIO_Q_BUSY) {
297 if (td_io_commit(td))
306 * The main verify engine. Runs over the writes we previously submitted,
307 * reads the blocks back in, and checks the crc/md5 of the data.
309 static void do_verify(struct thread_data *td)
317 * sync io first and invalidate cache, to make sure we really
320 for_each_file(td, f, i) {
321 if (!(f->flags & FIO_FILE_OPEN))
323 if (fio_io_sync(td, f))
325 if (file_invalidate_cache(td, f))
332 td_set_runstate(td, TD_VERIFYING);
335 while (!td->terminate) {
338 io_u = __get_io_u(td);
342 if (runtime_exceeded(td, &io_u->start_time)) {
348 if (get_next_verify(td, io_u)) {
353 if (td_io_prep(td, io_u)) {
358 io_u->end_io = verify_io_u;
360 ret = td_io_queue(td, io_u);
362 case FIO_Q_COMPLETED:
365 else if (io_u->resid) {
366 int bytes = io_u->xfer_buflen - io_u->resid;
367 struct fio_file *f = io_u->file;
373 td_verror(td, ENODATA, "full resid");
378 io_u->xfer_buflen = io_u->resid;
379 io_u->xfer_buf += bytes;
380 io_u->offset += bytes;
382 td->ts.short_io_u[io_u->ddir]++;
384 if (io_u->offset == f->real_file_size)
387 requeue_io_u(td, &io_u);
390 ret = io_u_sync_complete(td, io_u);
398 requeue_io_u(td, &io_u);
399 ret2 = td_io_commit(td);
405 td_verror(td, -ret, "td_io_queue");
409 if (ret < 0 || td->error)
413 * if we can queue more, do so. but check if there are
414 * completed io_u's first.
417 if (queue_full(td) || ret == FIO_Q_BUSY) {
418 if (td->cur_depth >= td->o.iodepth_low)
419 min_events = td->cur_depth - td->o.iodepth_low;
425 * Reap required number of io units, if any, and do the
426 * verification on them through the callback handler
428 if (io_u_queued_complete(td, min_events) < 0)
433 min_events = td->cur_depth;
436 ret = io_u_queued_complete(td, min_events);
438 cleanup_pending_aio(td);
440 td_set_runstate(td, TD_RUNNING);
444 * Main IO worker function. It retrieves io_u's to process and queues
445 * and reaps them, checking for rate and errors along the way.
447 static void do_io(struct thread_data *td)
454 td_set_runstate(td, TD_RUNNING);
456 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
457 struct timeval comp_time;
470 memcpy(&s, &io_u->start_time, sizeof(s));
472 if (runtime_exceeded(td, &s)) {
479 * Add verification end_io handler, if asked to verify
480 * a previously written file.
482 if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ) {
483 io_u->end_io = verify_io_u;
484 td_set_runstate(td, TD_VERIFYING);
486 td_set_runstate(td, TD_RUNNING);
488 ret = td_io_queue(td, io_u);
490 case FIO_Q_COMPLETED:
493 else if (io_u->resid) {
494 int bytes = io_u->xfer_buflen - io_u->resid;
495 struct fio_file *f = io_u->file;
501 td_verror(td, ENODATA, "full resid");
506 io_u->xfer_buflen = io_u->resid;
507 io_u->xfer_buf += bytes;
508 io_u->offset += bytes;
510 td->ts.short_io_u[io_u->ddir]++;
512 if (io_u->offset == f->real_file_size)
515 requeue_io_u(td, &io_u);
518 fio_gettime(&comp_time, NULL);
519 bytes_done = io_u_sync_complete(td, io_u);
526 * if the engine doesn't have a commit hook,
527 * the io_u is really queued. if it does have such
528 * a hook, it has to call io_u_queued() itself.
530 if (td->io_ops->commit == NULL)
531 io_u_queued(td, io_u);
534 requeue_io_u(td, &io_u);
535 ret2 = td_io_commit(td);
545 if (ret < 0 || td->error)
549 * See if we need to complete some commands
551 if (queue_full(td) || ret == FIO_Q_BUSY) {
553 if (td->cur_depth >= td->o.iodepth_low)
554 min_evts = td->cur_depth - td->o.iodepth_low;
557 fio_gettime(&comp_time, NULL);
558 bytes_done = io_u_queued_complete(td, min_evts);
567 * the rate is batched for now, it should work for batches
568 * of completions except the very first one which may look
571 usec = utime_since(&s, &comp_time);
573 rate_throttle(td, usec, bytes_done);
575 if (check_min_rate(td, &comp_time)) {
576 if (exitall_on_terminate)
577 terminate_threads(td->groupid);
578 td_verror(td, ENODATA, "check_min_rate");
582 if (td->o.thinktime) {
583 unsigned long long b;
585 b = td->io_blocks[0] + td->io_blocks[1];
586 if (!(b % td->o.thinktime_blocks)) {
589 if (td->o.thinktime_spin)
590 __usec_sleep(td->o.thinktime_spin);
592 left = td->o.thinktime - td->o.thinktime_spin;
594 usec_sleep(td, left);
599 if (td->o.fill_device && td->error == ENOSPC) {
608 ret = io_u_queued_complete(td, i);
610 if (should_fsync(td) && td->o.end_fsync) {
611 td_set_runstate(td, TD_FSYNCING);
613 for_each_file(td, f, i) {
614 if (!(f->flags & FIO_FILE_OPEN))
620 cleanup_pending_aio(td);
623 * stop job if we failed doing any IO
625 if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
629 static void cleanup_io_u(struct thread_data *td)
631 struct list_head *entry, *n;
634 list_for_each_safe(entry, n, &td->io_u_freelist) {
635 io_u = list_entry(entry, struct io_u, list);
637 list_del(&io_u->list);
644 static int init_io_u(struct thread_data *td)
651 max_units = td->o.iodepth;
652 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
653 td->orig_buffer_size = (unsigned long long) max_bs
654 * (unsigned long long) max_units;
656 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
659 bs = td->orig_buffer_size + td->o.hugepage_size - 1;
660 td->orig_buffer_size = bs & ~(td->o.hugepage_size - 1);
663 if (td->orig_buffer_size != (size_t) td->orig_buffer_size) {
664 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
668 if (allocate_io_mem(td))
672 p = ALIGN(td->orig_buffer);
676 for (i = 0; i < max_units; i++) {
679 io_u = malloc(sizeof(*io_u));
680 memset(io_u, 0, sizeof(*io_u));
681 INIT_LIST_HEAD(&io_u->list);
683 if (!(td->io_ops->flags & FIO_NOIO)) {
684 io_u->buf = p + max_bs * i;
686 if (td_write(td) && !td->o.refill_buffers)
687 io_u_fill_buffer(td, io_u, max_bs);
691 io_u->flags = IO_U_F_FREE;
692 list_add(&io_u->list, &td->io_u_freelist);
700 static int switch_ioscheduler(struct thread_data *td)
702 char tmp[256], tmp2[128];
706 if (td->io_ops->flags & FIO_DISKLESSIO)
709 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
711 f = fopen(tmp, "r+");
713 if (errno == ENOENT) {
714 log_err("fio: os or kernel doesn't support IO scheduler"
718 td_verror(td, errno, "fopen iosched");
725 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
726 if (ferror(f) || ret != 1) {
727 td_verror(td, errno, "fwrite");
735 * Read back and check that the selected scheduler is now the default.
737 ret = fread(tmp, 1, sizeof(tmp), f);
738 if (ferror(f) || ret < 0) {
739 td_verror(td, errno, "fread");
744 sprintf(tmp2, "[%s]", td->o.ioscheduler);
745 if (!strstr(tmp, tmp2)) {
746 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
747 td_verror(td, EINVAL, "iosched_switch");
756 static int keep_running(struct thread_data *td)
758 unsigned long long io_done;
762 if (td->o.time_based)
769 io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]
771 if (io_done < td->o.size)
777 static int clear_io_state(struct thread_data *td)
783 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
784 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
788 td->rw_end_set[0] = td->rw_end_set[1] = 0;
790 td->last_was_sync = 0;
793 * reset file done count if we are to start over
795 if (td->o.time_based || td->o.loops)
796 td->nr_done_files = 0;
801 for_each_file(td, f, i) {
802 f->flags &= ~FIO_FILE_DONE;
803 ret = td_io_open_file(td, f);
812 * Entry point for the thread based jobs. The process based jobs end up
813 * here as well, after a little setup.
815 static void *thread_main(void *data)
817 unsigned long long runtime[2], elapsed;
818 struct thread_data *td = data;
821 if (!td->o.use_thread)
826 dprint(FD_PROCESS, "jobs pid=%d started\n", td->pid);
828 INIT_LIST_HEAD(&td->io_u_freelist);
829 INIT_LIST_HEAD(&td->io_u_busylist);
830 INIT_LIST_HEAD(&td->io_u_requeues);
831 INIT_LIST_HEAD(&td->io_log_list);
832 INIT_LIST_HEAD(&td->io_hist_list);
833 td->io_hist_tree = RB_ROOT;
835 td_set_runstate(td, TD_INITIALIZED);
836 fio_mutex_up(startup_mutex);
837 fio_mutex_down(td->mutex);
840 * the ->mutex mutex is now no longer used, close it to avoid
841 * eating a file descriptor
843 fio_mutex_remove(td->mutex);
846 * May alter parameters that init_io_u() will use, so we need to
855 if (td->o.cpumask_set && fio_setaffinity(td) == -1) {
856 td_verror(td, errno, "cpu_set_affinity");
860 if (td->ioprio_set) {
861 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
862 td_verror(td, errno, "ioprio_set");
867 if (nice(td->o.nice) == -1) {
868 td_verror(td, errno, "nice");
872 if (td->o.ioscheduler && switch_ioscheduler(td))
875 if (!td->o.create_serialize && setup_files(td))
884 if (init_random_map(td))
887 if (td->o.exec_prerun) {
888 if (system(td->o.exec_prerun) < 0)
892 fio_gettime(&td->epoch, NULL);
893 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
894 getrusage(RUSAGE_SELF, &td->ts.ru_start);
896 runtime[0] = runtime[1] = 0;
898 while (keep_running(td)) {
899 fio_gettime(&td->start, NULL);
900 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
903 memcpy(&td->lastrate, &td->ts.stat_sample_time,
904 sizeof(td->lastrate));
906 if (clear_state && clear_io_state(td))
909 prune_io_piece_log(td);
915 if (td_read(td) && td->io_bytes[DDIR_READ]) {
916 if (td->rw_end_set[DDIR_READ])
917 elapsed = utime_since(&td->start,
918 &td->rw_end[DDIR_READ]);
920 elapsed = utime_since_now(&td->start);
922 runtime[DDIR_READ] += elapsed;
924 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
925 if (td->rw_end_set[DDIR_WRITE])
926 elapsed = utime_since(&td->start,
927 &td->rw_end[DDIR_WRITE]);
929 elapsed = utime_since_now(&td->start);
931 runtime[DDIR_WRITE] += elapsed;
934 if (td->error || td->terminate)
937 if (!td->o.do_verify ||
938 td->o.verify == VERIFY_NONE ||
939 (td->io_ops->flags & FIO_UNIDIR))
942 if (clear_io_state(td))
945 fio_gettime(&td->start, NULL);
949 runtime[DDIR_READ] += utime_since_now(&td->start);
951 if (td->error || td->terminate)
955 update_rusage_stat(td);
956 td->ts.runtime[0] = (runtime[0] + 999) / 1000;
957 td->ts.runtime[1] = (runtime[1] + 999) / 1000;
958 td->ts.total_run_time = mtime_since_now(&td->epoch);
959 td->ts.io_bytes[0] = td->io_bytes[0];
960 td->ts.io_bytes[1] = td->io_bytes[1];
963 finish_log(td, td->ts.bw_log, "bw");
965 finish_log(td, td->ts.slat_log, "slat");
967 finish_log(td, td->ts.clat_log, "clat");
968 if (td->o.exec_postrun) {
969 if (system(td->o.exec_postrun) < 0)
970 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
973 if (exitall_on_terminate)
974 terminate_threads(td->groupid);
978 printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error,
980 close_and_free_files(td);
985 * do this very late, it will log file closing as well
987 if (td->o.write_iolog_file)
988 write_iolog_close(td);
990 options_mem_free(td);
991 td_set_runstate(td, TD_EXITED);
992 return (void *) (unsigned long) td->error;
996 * We cannot pass the td data into a forked process, so attach the td and
997 * pass it to the thread worker.
999 static int fork_main(int shmid, int offset)
1001 struct thread_data *td;
1004 data = shmat(shmid, NULL, 0);
1005 if (data == (void *) -1) {
1012 td = data + offset * sizeof(struct thread_data);
1013 ret = thread_main(td);
1015 return (int) (unsigned long) ret;
1019 * Run over the job map and reap the threads that have exited, if any.
1021 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
1023 struct thread_data *td;
1024 int i, cputhreads, realthreads, pending, status, ret;
1027 * reap exited threads (TD_EXITED -> TD_REAPED)
1029 realthreads = pending = cputhreads = 0;
1030 for_each_td(td, i) {
1034 * ->io_ops is NULL for a thread that has closed its
1037 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
1046 if (td->runstate == TD_REAPED)
1048 if (td->o.use_thread) {
1049 if (td->runstate == TD_EXITED) {
1050 td_set_runstate(td, TD_REAPED);
1057 if (td->runstate == TD_EXITED)
1061 * check if someone quit or got killed in an unusual way
1063 ret = waitpid(td->pid, &status, flags);
1065 if (errno == ECHILD) {
1066 log_err("fio: pid=%d disappeared %d\n", td->pid,
1068 td_set_runstate(td, TD_REAPED);
1072 } else if (ret == td->pid) {
1073 if (WIFSIGNALED(status)) {
1074 int sig = WTERMSIG(status);
1077 log_err("fio: pid=%d, got signal=%d\n",
1079 td_set_runstate(td, TD_REAPED);
1082 if (WIFEXITED(status)) {
1083 if (WEXITSTATUS(status) && !td->error)
1084 td->error = WEXITSTATUS(status);
1086 td_set_runstate(td, TD_REAPED);
1092 * thread is not dead, continue
1098 (*m_rate) -= td->o.ratemin;
1099 (*t_rate) -= td->o.rate;
1106 done_secs += mtime_since_now(&td->epoch) / 1000;
1109 if (*nr_running == cputhreads && !pending && realthreads)
1110 terminate_threads(TERMINATE_ALL);
1114 * Main function for kicking off and reaping jobs, as needed.
1116 static void run_threads(void)
1118 struct thread_data *td;
1119 unsigned long spent;
1120 int i, todo, nr_running, m_rate, t_rate, nr_started;
1122 if (fio_pin_memory())
1125 if (!terse_output) {
1126 printf("Starting ");
1128 printf("%d thread%s", nr_thread,
1129 nr_thread > 1 ? "s" : "");
1133 printf("%d process%s", nr_process,
1134 nr_process > 1 ? "es" : "");
1140 signal(SIGINT, sig_handler);
1141 signal(SIGALRM, sig_handler);
1143 todo = thread_number;
1146 m_rate = t_rate = 0;
1148 for_each_td(td, i) {
1149 print_status_init(td->thread_number - 1);
1151 if (!td->o.create_serialize) {
1157 * do file setup here so it happens sequentially,
1158 * we don't want X number of threads getting their
1159 * client data interspersed on disk
1161 if (setup_files(td)) {
1164 log_err("fio: pid=%d, err=%d/%s\n", td->pid,
1165 td->error, td->verror);
1166 td_set_runstate(td, TD_REAPED);
1173 * for sharing to work, each job must always open
1174 * its own files. so close them, if we opened them
1177 for_each_file(td, f, i)
1178 td_io_close_file(td, f);
1187 struct thread_data *map[MAX_JOBS];
1188 struct timeval this_start;
1189 int this_jobs = 0, left;
1192 * create threads (TD_NOT_CREATED -> TD_CREATED)
1194 for_each_td(td, i) {
1195 if (td->runstate != TD_NOT_CREATED)
1199 * never got a chance to start, killed by other
1200 * thread for some reason
1202 if (td->terminate) {
1207 if (td->o.start_delay) {
1208 spent = mtime_since_genesis();
1210 if (td->o.start_delay * 1000 > spent)
1214 if (td->o.stonewall && (nr_started || nr_running)) {
1215 dprint(FD_PROCESS, "%s: stonewall wait\n",
1221 * Set state to created. Thread will transition
1222 * to TD_INITIALIZED when it's done setting up.
1224 td_set_runstate(td, TD_CREATED);
1225 map[this_jobs++] = td;
1228 if (td->o.use_thread) {
1229 dprint(FD_PROCESS, "will pthread_create\n");
1230 if (pthread_create(&td->thread, NULL,
1232 perror("pthread_create");
1236 if (pthread_detach(td->thread) < 0)
1237 perror("pthread_detach");
1240 dprint(FD_PROCESS, "will fork\n");
1243 int ret = fork_main(shm_id, i);
1246 } else if (i == fio_debug_jobno)
1247 *fio_debug_jobp = pid;
1249 fio_mutex_down(startup_mutex);
1253 * Wait for the started threads to transition to
1256 fio_gettime(&this_start, NULL);
1258 while (left && !fio_abort) {
1259 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1264 for (i = 0; i < this_jobs; i++) {
1268 if (td->runstate == TD_INITIALIZED) {
1271 } else if (td->runstate >= TD_EXITED) {
1275 nr_running++; /* work-around... */
1281 log_err("fio: %d jobs failed to start\n", left);
1282 for (i = 0; i < this_jobs; i++) {
1286 kill(td->pid, SIGTERM);
1292 * start created threads (TD_INITIALIZED -> TD_RUNNING).
1294 for_each_td(td, i) {
1295 if (td->runstate != TD_INITIALIZED)
1298 td_set_runstate(td, TD_RUNNING);
1301 m_rate += td->o.ratemin;
1302 t_rate += td->o.rate;
1304 fio_mutex_up(td->mutex);
1307 reap_threads(&nr_running, &t_rate, &m_rate);
1313 while (nr_running) {
1314 reap_threads(&nr_running, &t_rate, &m_rate);
1322 int main(int argc, char *argv[])
1329 * We need locale for number printing, if it isn't set then just
1330 * go with the US format.
1332 if (!getenv("LC_NUMERIC"))
1333 setlocale(LC_NUMERIC, "en_US");
1335 if (parse_options(argc, argv))
1341 ps = sysconf(_SC_PAGESIZE);
1343 log_err("Failed to get page size\n");
1351 setup_log(&agg_io_log[DDIR_READ]);
1352 setup_log(&agg_io_log[DDIR_WRITE]);
1355 startup_mutex = fio_mutex_init(0);
1359 disk_util_timer_arm();
1366 __finish_log(agg_io_log[DDIR_READ], "agg-read_bw.log");
1367 __finish_log(agg_io_log[DDIR_WRITE],
1368 "agg-write_bw.log");
1372 fio_mutex_remove(startup_mutex);