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;
57 static struct itimerval itimer;
59 struct io_log *agg_io_log[2];
61 #define TERMINATE_ALL (-1)
62 #define JOB_START_TIMEOUT (5 * 1000)
64 static inline void td_set_runstate(struct thread_data *td, int runstate)
66 if (td->runstate == runstate)
69 dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", (int) td->pid,
70 td->runstate, runstate);
71 td->runstate = runstate;
74 static void terminate_threads(int group_id)
76 struct thread_data *td;
79 dprint(FD_PROCESS, "terminate group_id=%d\n", group_id);
82 if (group_id == TERMINATE_ALL || groupid == td->groupid) {
83 dprint(FD_PROCESS, "setting terminate on %s/%d\n",
84 td->o.name, (int) td->pid);
86 td->o.start_delay = 0;
89 * if the thread is running, just let it exit
91 if (td->runstate < TD_RUNNING)
92 kill(td->pid, SIGQUIT);
94 struct ioengine_ops *ops = td->io_ops;
96 if (ops && (ops->flags & FIO_SIGQUIT))
97 kill(td->pid, SIGQUIT);
103 static void status_timer_arm(void)
105 itimer.it_value.tv_sec = 0;
106 itimer.it_value.tv_usec = DISK_UTIL_MSEC * 1000;
107 setitimer(ITIMER_REAL, &itimer, NULL);
110 static void sig_alrm(int sig)
114 print_thread_status();
119 static void sig_int(int sig)
122 printf("\nfio: terminating on signal %d\n", sig);
124 terminate_threads(TERMINATE_ALL);
129 * We need to rearm on BSD/solaris. Switch this to sigaction in the future...
131 static void set_sig_handlers(void)
133 struct sigaction act;
135 memset(&act, 0, sizeof(act));
136 act.sa_handler = sig_alrm;
137 act.sa_flags = SA_RESTART;
138 sigaction(SIGALRM, &act, NULL);
140 memset(&act, 0, sizeof(act));
141 act.sa_handler = sig_int;
142 act.sa_flags = SA_RESTART;
143 sigaction(SIGINT, &act, NULL);
147 * Check if we are above the minimum rate given.
149 static int check_min_rate(struct thread_data *td, struct timeval *now)
151 unsigned long long bytes = 0;
152 unsigned long iops = 0;
157 * No minimum rate set, always ok
159 if (!td->o.ratemin && !td->o.rate_iops_min)
163 * allow a 2 second settle period in the beginning
165 if (mtime_since(&td->start, now) < 2000)
169 iops += td->io_blocks[DDIR_READ];
170 bytes += td->this_io_bytes[DDIR_READ];
173 iops += td->io_blocks[DDIR_WRITE];
174 bytes += td->this_io_bytes[DDIR_WRITE];
178 * if rate blocks is set, sample is running
180 if (td->rate_bytes || td->rate_blocks) {
181 spent = mtime_since(&td->lastrate, now);
182 if (spent < td->o.ratecycle)
187 * check bandwidth specified rate
189 if (bytes < td->rate_bytes) {
190 log_err("%s: min rate %u not met\n", td->o.name,
194 rate = (bytes - td->rate_bytes) / spent;
195 if (rate < td->o.ratemin ||
196 bytes < td->rate_bytes) {
197 log_err("%s: min rate %u not met, got"
198 " %luKiB/sec\n", td->o.name,
199 td->o.ratemin, rate);
205 * checks iops specified rate
207 if (iops < td->o.rate_iops) {
208 log_err("%s: min iops rate %u not met\n",
209 td->o.name, td->o.rate_iops);
212 rate = (iops - td->rate_blocks) / spent;
213 if (rate < td->o.rate_iops_min ||
214 iops < td->rate_blocks) {
215 log_err("%s: min iops rate %u not met,"
216 " got %lu\n", td->o.name,
224 td->rate_bytes = bytes;
225 td->rate_blocks = iops;
226 memcpy(&td->lastrate, now, sizeof(*now));
230 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
234 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
241 * When job exits, we can cancel the in-flight IO if we are using async
242 * io. Attempt to do so.
244 static void cleanup_pending_aio(struct thread_data *td)
246 struct flist_head *entry, *n;
251 * get immediately available events, if any
253 r = io_u_queued_complete(td, 0);
258 * now cancel remaining active events
260 if (td->io_ops->cancel) {
261 flist_for_each_safe(entry, n, &td->io_u_busylist) {
262 io_u = flist_entry(entry, struct io_u, list);
265 * if the io_u isn't in flight, then that generally
266 * means someone leaked an io_u. complain but fix
267 * it up, so we don't stall here.
269 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
270 log_err("fio: non-busy IO on busy list\n");
273 r = td->io_ops->cancel(td, io_u);
281 r = io_u_queued_complete(td, td->cur_depth);
285 * Helper to handle the final sync of a file. Works just like the normal
286 * io path, just does everything sync.
288 static int fio_io_sync(struct thread_data *td, struct fio_file *f)
290 struct io_u *io_u = __get_io_u(td);
296 io_u->ddir = DDIR_SYNC;
299 if (td_io_prep(td, io_u)) {
305 ret = td_io_queue(td, io_u);
307 td_verror(td, io_u->error, "td_io_queue");
310 } else if (ret == FIO_Q_QUEUED) {
311 if (io_u_queued_complete(td, 1) < 0)
313 } else if (ret == FIO_Q_COMPLETED) {
315 td_verror(td, io_u->error, "td_io_queue");
319 if (io_u_sync_complete(td, io_u) < 0)
321 } else if (ret == FIO_Q_BUSY) {
322 if (td_io_commit(td))
331 * The main verify engine. Runs over the writes we previously submitted,
332 * reads the blocks back in, and checks the crc/md5 of the data.
334 static void do_verify(struct thread_data *td)
342 * sync io first and invalidate cache, to make sure we really
345 for_each_file(td, f, i) {
346 if (!(f->flags & FIO_FILE_OPEN))
348 if (fio_io_sync(td, f))
350 if (file_invalidate_cache(td, f))
357 td_set_runstate(td, TD_VERIFYING);
360 while (!td->terminate) {
363 io_u = __get_io_u(td);
367 if (runtime_exceeded(td, &io_u->start_time)) {
373 if (get_next_verify(td, io_u)) {
378 if (td_io_prep(td, io_u)) {
383 io_u->end_io = verify_io_u;
385 ret = td_io_queue(td, io_u);
387 case FIO_Q_COMPLETED:
390 else if (io_u->resid) {
391 int bytes = io_u->xfer_buflen - io_u->resid;
392 struct fio_file *f = io_u->file;
398 td_verror(td, EIO, "full resid");
403 io_u->xfer_buflen = io_u->resid;
404 io_u->xfer_buf += bytes;
405 io_u->offset += bytes;
407 td->ts.short_io_u[io_u->ddir]++;
409 if (io_u->offset == f->real_file_size)
412 requeue_io_u(td, &io_u);
415 ret = io_u_sync_complete(td, io_u);
423 requeue_io_u(td, &io_u);
424 ret2 = td_io_commit(td);
430 td_verror(td, -ret, "td_io_queue");
434 if (ret < 0 || td->error)
438 * if we can queue more, do so. but check if there are
439 * completed io_u's first.
442 if (queue_full(td) || ret == FIO_Q_BUSY) {
443 if (td->cur_depth >= td->o.iodepth_low)
444 min_events = td->cur_depth - td->o.iodepth_low;
450 * Reap required number of io units, if any, and do the
451 * verification on them through the callback handler
453 if (io_u_queued_complete(td, min_events) < 0)
458 min_events = td->cur_depth;
461 ret = io_u_queued_complete(td, min_events);
463 cleanup_pending_aio(td);
465 td_set_runstate(td, TD_RUNNING);
469 * Main IO worker function. It retrieves io_u's to process and queues
470 * and reaps them, checking for rate and errors along the way.
472 static void do_io(struct thread_data *td)
479 td_set_runstate(td, TD_RUNNING);
481 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
482 struct timeval comp_time;
495 memcpy(&s, &io_u->start_time, sizeof(s));
497 if (runtime_exceeded(td, &s)) {
504 * Add verification end_io handler, if asked to verify
505 * a previously written file.
507 if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ) {
508 io_u->end_io = verify_io_u;
509 td_set_runstate(td, TD_VERIFYING);
511 td_set_runstate(td, TD_RUNNING);
513 ret = td_io_queue(td, io_u);
515 case FIO_Q_COMPLETED:
518 else if (io_u->resid) {
519 int bytes = io_u->xfer_buflen - io_u->resid;
520 struct fio_file *f = io_u->file;
526 td_verror(td, EIO, "full resid");
531 io_u->xfer_buflen = io_u->resid;
532 io_u->xfer_buf += bytes;
533 io_u->offset += bytes;
535 td->ts.short_io_u[io_u->ddir]++;
537 if (io_u->offset == f->real_file_size)
540 requeue_io_u(td, &io_u);
543 fio_gettime(&comp_time, NULL);
544 bytes_done = io_u_sync_complete(td, io_u);
551 * if the engine doesn't have a commit hook,
552 * the io_u is really queued. if it does have such
553 * a hook, it has to call io_u_queued() itself.
555 if (td->io_ops->commit == NULL)
556 io_u_queued(td, io_u);
559 requeue_io_u(td, &io_u);
560 ret2 = td_io_commit(td);
570 if (ret < 0 || td->error)
574 * See if we need to complete some commands
576 if (queue_full(td) || ret == FIO_Q_BUSY) {
578 if (td->cur_depth >= td->o.iodepth_low)
579 min_evts = td->cur_depth - td->o.iodepth_low;
582 fio_gettime(&comp_time, NULL);
583 bytes_done = io_u_queued_complete(td, min_evts);
592 * the rate is batched for now, it should work for batches
593 * of completions except the very first one which may look
596 usec = utime_since(&s, &comp_time);
598 rate_throttle(td, usec, bytes_done);
600 if (check_min_rate(td, &comp_time)) {
601 if (exitall_on_terminate)
602 terminate_threads(td->groupid);
603 td_verror(td, EIO, "check_min_rate");
607 if (td->o.thinktime) {
608 unsigned long long b;
610 b = td->io_blocks[0] + td->io_blocks[1];
611 if (!(b % td->o.thinktime_blocks)) {
614 if (td->o.thinktime_spin)
615 __usec_sleep(td->o.thinktime_spin);
617 left = td->o.thinktime - td->o.thinktime_spin;
619 usec_sleep(td, left);
624 if (td->o.fill_device && td->error == ENOSPC) {
633 ret = io_u_queued_complete(td, i);
635 if (should_fsync(td) && td->o.end_fsync) {
636 td_set_runstate(td, TD_FSYNCING);
638 for_each_file(td, f, i) {
639 if (!(f->flags & FIO_FILE_OPEN))
645 cleanup_pending_aio(td);
648 * stop job if we failed doing any IO
650 if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
654 static void cleanup_io_u(struct thread_data *td)
656 struct flist_head *entry, *n;
659 flist_for_each_safe(entry, n, &td->io_u_freelist) {
660 io_u = flist_entry(entry, struct io_u, list);
662 flist_del(&io_u->list);
669 static int init_io_u(struct thread_data *td)
676 max_units = td->o.iodepth;
677 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
678 td->orig_buffer_size = (unsigned long long) max_bs
679 * (unsigned long long) max_units;
681 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
684 bs = td->orig_buffer_size + td->o.hugepage_size - 1;
685 td->orig_buffer_size = bs & ~(td->o.hugepage_size - 1);
688 if (td->orig_buffer_size != (size_t) td->orig_buffer_size) {
689 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
693 if (allocate_io_mem(td))
697 p = ALIGN(td->orig_buffer);
701 for (i = 0; i < max_units; i++) {
704 io_u = malloc(sizeof(*io_u));
705 memset(io_u, 0, sizeof(*io_u));
706 INIT_FLIST_HEAD(&io_u->list);
708 if (!(td->io_ops->flags & FIO_NOIO)) {
709 io_u->buf = p + max_bs * i;
711 if (td_write(td) && !td->o.refill_buffers)
712 io_u_fill_buffer(td, io_u, max_bs);
716 io_u->flags = IO_U_F_FREE;
717 flist_add(&io_u->list, &td->io_u_freelist);
725 static int switch_ioscheduler(struct thread_data *td)
727 char tmp[256], tmp2[128];
731 if (td->io_ops->flags & FIO_DISKLESSIO)
734 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
736 f = fopen(tmp, "r+");
738 if (errno == ENOENT) {
739 log_err("fio: os or kernel doesn't support IO scheduler"
743 td_verror(td, errno, "fopen iosched");
750 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
751 if (ferror(f) || ret != 1) {
752 td_verror(td, errno, "fwrite");
760 * Read back and check that the selected scheduler is now the default.
762 ret = fread(tmp, 1, sizeof(tmp), f);
763 if (ferror(f) || ret < 0) {
764 td_verror(td, errno, "fread");
769 sprintf(tmp2, "[%s]", td->o.ioscheduler);
770 if (!strstr(tmp, tmp2)) {
771 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
772 td_verror(td, EINVAL, "iosched_switch");
781 static int keep_running(struct thread_data *td)
783 unsigned long long io_done;
787 if (td->o.time_based)
794 io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]
796 if (io_done < td->o.size)
802 static int clear_io_state(struct thread_data *td)
808 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
809 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
813 td->rw_end_set[0] = td->rw_end_set[1] = 0;
815 td->last_was_sync = 0;
818 * reset file done count if we are to start over
820 if (td->o.time_based || td->o.loops)
821 td->nr_done_files = 0;
826 for_each_file(td, f, i) {
827 f->flags &= ~FIO_FILE_DONE;
828 ret = td_io_open_file(td, f);
837 * Entry point for the thread based jobs. The process based jobs end up
838 * here as well, after a little setup.
840 static void *thread_main(void *data)
842 unsigned long long runtime[2], elapsed;
843 struct thread_data *td = data;
846 if (!td->o.use_thread)
851 dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
853 INIT_FLIST_HEAD(&td->io_u_freelist);
854 INIT_FLIST_HEAD(&td->io_u_busylist);
855 INIT_FLIST_HEAD(&td->io_u_requeues);
856 INIT_FLIST_HEAD(&td->io_log_list);
857 INIT_FLIST_HEAD(&td->io_hist_list);
858 td->io_hist_tree = RB_ROOT;
860 td_set_runstate(td, TD_INITIALIZED);
861 fio_mutex_up(startup_mutex);
862 fio_mutex_down(td->mutex);
865 * the ->mutex mutex is now no longer used, close it to avoid
866 * eating a file descriptor
868 fio_mutex_remove(td->mutex);
871 * May alter parameters that init_io_u() will use, so we need to
880 if (td->o.cpumask_set && fio_setaffinity(td) == -1) {
881 td_verror(td, errno, "cpu_set_affinity");
885 if (td->ioprio_set) {
886 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
887 td_verror(td, errno, "ioprio_set");
892 if (nice(td->o.nice) == -1) {
893 td_verror(td, errno, "nice");
897 if (td->o.ioscheduler && switch_ioscheduler(td))
900 if (!td->o.create_serialize && setup_files(td))
909 if (init_random_map(td))
912 if (td->o.exec_prerun) {
913 if (system(td->o.exec_prerun) < 0)
917 fio_gettime(&td->epoch, NULL);
918 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
919 getrusage(RUSAGE_SELF, &td->ts.ru_start);
921 runtime[0] = runtime[1] = 0;
923 while (keep_running(td)) {
924 fio_gettime(&td->start, NULL);
925 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
928 memcpy(&td->lastrate, &td->ts.stat_sample_time,
929 sizeof(td->lastrate));
931 if (clear_state && clear_io_state(td))
934 prune_io_piece_log(td);
940 if (td_read(td) && td->io_bytes[DDIR_READ]) {
941 if (td->rw_end_set[DDIR_READ])
942 elapsed = utime_since(&td->start,
943 &td->rw_end[DDIR_READ]);
945 elapsed = utime_since_now(&td->start);
947 runtime[DDIR_READ] += elapsed;
949 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
950 if (td->rw_end_set[DDIR_WRITE])
951 elapsed = utime_since(&td->start,
952 &td->rw_end[DDIR_WRITE]);
954 elapsed = utime_since_now(&td->start);
956 runtime[DDIR_WRITE] += elapsed;
959 if (td->error || td->terminate)
962 if (!td->o.do_verify ||
963 td->o.verify == VERIFY_NONE ||
964 (td->io_ops->flags & FIO_UNIDIR))
967 if (clear_io_state(td))
970 fio_gettime(&td->start, NULL);
974 runtime[DDIR_READ] += utime_since_now(&td->start);
976 if (td->error || td->terminate)
980 update_rusage_stat(td);
981 td->ts.runtime[0] = (runtime[0] + 999) / 1000;
982 td->ts.runtime[1] = (runtime[1] + 999) / 1000;
983 td->ts.total_run_time = mtime_since_now(&td->epoch);
984 td->ts.io_bytes[0] = td->io_bytes[0];
985 td->ts.io_bytes[1] = td->io_bytes[1];
988 finish_log(td, td->ts.bw_log, "bw");
990 finish_log(td, td->ts.slat_log, "slat");
992 finish_log(td, td->ts.clat_log, "clat");
993 if (td->o.exec_postrun) {
994 if (system(td->o.exec_postrun) < 0)
995 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
998 if (exitall_on_terminate)
999 terminate_threads(td->groupid);
1003 printf("fio: pid=%d, err=%d/%s\n", (int) td->pid, td->error,
1005 close_and_free_files(td);
1010 * do this very late, it will log file closing as well
1012 if (td->o.write_iolog_file)
1013 write_iolog_close(td);
1015 options_mem_free(td);
1016 td_set_runstate(td, TD_EXITED);
1017 return (void *) (unsigned long) td->error;
1021 * We cannot pass the td data into a forked process, so attach the td and
1022 * pass it to the thread worker.
1024 static int fork_main(int shmid, int offset)
1026 struct thread_data *td;
1029 data = shmat(shmid, NULL, 0);
1030 if (data == (void *) -1) {
1037 td = data + offset * sizeof(struct thread_data);
1038 ret = thread_main(td);
1040 return (int) (unsigned long) ret;
1044 * Run over the job map and reap the threads that have exited, if any.
1046 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
1048 struct thread_data *td;
1049 int i, cputhreads, realthreads, pending, status, ret;
1052 * reap exited threads (TD_EXITED -> TD_REAPED)
1054 realthreads = pending = cputhreads = 0;
1055 for_each_td(td, i) {
1059 * ->io_ops is NULL for a thread that has closed its
1062 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
1071 if (td->runstate == TD_REAPED)
1073 if (td->o.use_thread) {
1074 if (td->runstate == TD_EXITED) {
1075 td_set_runstate(td, TD_REAPED);
1082 if (td->runstate == TD_EXITED)
1086 * check if someone quit or got killed in an unusual way
1088 ret = waitpid(td->pid, &status, flags);
1090 if (errno == ECHILD) {
1091 log_err("fio: pid=%d disappeared %d\n",
1092 (int) td->pid, td->runstate);
1093 td_set_runstate(td, TD_REAPED);
1097 } else if (ret == td->pid) {
1098 if (WIFSIGNALED(status)) {
1099 int sig = WTERMSIG(status);
1102 log_err("fio: pid=%d, got signal=%d\n",
1103 (int) td->pid, sig);
1104 td_set_runstate(td, TD_REAPED);
1107 if (WIFEXITED(status)) {
1108 if (WEXITSTATUS(status) && !td->error)
1109 td->error = WEXITSTATUS(status);
1111 td_set_runstate(td, TD_REAPED);
1117 * thread is not dead, continue
1123 (*m_rate) -= td->o.ratemin;
1124 (*t_rate) -= td->o.rate;
1131 done_secs += mtime_since_now(&td->epoch) / 1000;
1134 if (*nr_running == cputhreads && !pending && realthreads)
1135 terminate_threads(TERMINATE_ALL);
1139 * Main function for kicking off and reaping jobs, as needed.
1141 static void run_threads(void)
1143 struct thread_data *td;
1144 unsigned long spent;
1145 int i, todo, nr_running, m_rate, t_rate, nr_started;
1147 if (fio_pin_memory())
1150 if (!terse_output) {
1151 printf("Starting ");
1153 printf("%d thread%s", nr_thread,
1154 nr_thread > 1 ? "s" : "");
1158 printf("%d process%s", nr_process,
1159 nr_process > 1 ? "es" : "");
1167 todo = thread_number;
1170 m_rate = t_rate = 0;
1172 for_each_td(td, i) {
1173 print_status_init(td->thread_number - 1);
1175 if (!td->o.create_serialize) {
1181 * do file setup here so it happens sequentially,
1182 * we don't want X number of threads getting their
1183 * client data interspersed on disk
1185 if (setup_files(td)) {
1188 log_err("fio: pid=%d, err=%d/%s\n",
1189 (int) td->pid, td->error, td->verror);
1190 td_set_runstate(td, TD_REAPED);
1197 * for sharing to work, each job must always open
1198 * its own files. so close them, if we opened them
1201 for_each_file(td, f, i)
1202 td_io_close_file(td, f);
1211 struct thread_data *map[MAX_JOBS];
1212 struct timeval this_start;
1213 int this_jobs = 0, left;
1216 * create threads (TD_NOT_CREATED -> TD_CREATED)
1218 for_each_td(td, i) {
1219 if (td->runstate != TD_NOT_CREATED)
1223 * never got a chance to start, killed by other
1224 * thread for some reason
1226 if (td->terminate) {
1231 if (td->o.start_delay) {
1232 spent = mtime_since_genesis();
1234 if (td->o.start_delay * 1000 > spent)
1238 if (td->o.stonewall && (nr_started || nr_running)) {
1239 dprint(FD_PROCESS, "%s: stonewall wait\n",
1245 * Set state to created. Thread will transition
1246 * to TD_INITIALIZED when it's done setting up.
1248 td_set_runstate(td, TD_CREATED);
1249 map[this_jobs++] = td;
1252 if (td->o.use_thread) {
1253 dprint(FD_PROCESS, "will pthread_create\n");
1254 if (pthread_create(&td->thread, NULL,
1256 perror("pthread_create");
1260 if (pthread_detach(td->thread) < 0)
1261 perror("pthread_detach");
1264 dprint(FD_PROCESS, "will fork\n");
1267 int ret = fork_main(shm_id, i);
1270 } else if (i == fio_debug_jobno)
1271 *fio_debug_jobp = pid;
1273 fio_mutex_down(startup_mutex);
1277 * Wait for the started threads to transition to
1280 fio_gettime(&this_start, NULL);
1282 while (left && !fio_abort) {
1283 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1288 for (i = 0; i < this_jobs; i++) {
1292 if (td->runstate == TD_INITIALIZED) {
1295 } else if (td->runstate >= TD_EXITED) {
1299 nr_running++; /* work-around... */
1305 log_err("fio: %d jobs failed to start\n", left);
1306 for (i = 0; i < this_jobs; i++) {
1310 kill(td->pid, SIGTERM);
1316 * start created threads (TD_INITIALIZED -> TD_RUNNING).
1318 for_each_td(td, i) {
1319 if (td->runstate != TD_INITIALIZED)
1322 td_set_runstate(td, TD_RUNNING);
1325 m_rate += td->o.ratemin;
1326 t_rate += td->o.rate;
1328 fio_mutex_up(td->mutex);
1331 reap_threads(&nr_running, &t_rate, &m_rate);
1337 while (nr_running) {
1338 reap_threads(&nr_running, &t_rate, &m_rate);
1346 int main(int argc, char *argv[])
1353 * We need locale for number printing, if it isn't set then just
1354 * go with the US format.
1356 if (!getenv("LC_NUMERIC"))
1357 setlocale(LC_NUMERIC, "en_US");
1359 if (parse_options(argc, argv))
1365 ps = sysconf(_SC_PAGESIZE);
1367 log_err("Failed to get page size\n");
1375 setup_log(&agg_io_log[DDIR_READ]);
1376 setup_log(&agg_io_log[DDIR_WRITE]);
1379 startup_mutex = fio_mutex_init(0);
1390 __finish_log(agg_io_log[DDIR_READ], "agg-read_bw.log");
1391 __finish_log(agg_io_log[DDIR_WRITE],
1392 "agg-write_bw.log");
1396 fio_mutex_remove(startup_mutex);