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);
111 * We need to rearm on BSD/solaris. Switch this to sigaction in the future...
113 static void set_sig_handlers(void (*sighandler)(int))
115 signal(SIGINT, sighandler);
116 signal(SIGALRM, sighandler);
119 static void sig_handler(int sig)
121 set_sig_handlers(sig_handler);
129 print_thread_status();
133 printf("\nfio: terminating on signal %d\n", sig);
135 terminate_threads(TERMINATE_ALL);
141 * Check if we are above the minimum rate given.
143 static int check_min_rate(struct thread_data *td, struct timeval *now)
145 unsigned long long bytes = 0;
146 unsigned long iops = 0;
151 * No minimum rate set, always ok
153 if (!td->o.ratemin && !td->o.rate_iops_min)
157 * allow a 2 second settle period in the beginning
159 if (mtime_since(&td->start, now) < 2000)
163 iops += td->io_blocks[DDIR_READ];
164 bytes += td->this_io_bytes[DDIR_READ];
167 iops += td->io_blocks[DDIR_WRITE];
168 bytes += td->this_io_bytes[DDIR_WRITE];
172 * if rate blocks is set, sample is running
174 if (td->rate_bytes || td->rate_blocks) {
175 spent = mtime_since(&td->lastrate, now);
176 if (spent < td->o.ratecycle)
181 * check bandwidth specified rate
183 if (bytes < td->rate_bytes) {
184 log_err("%s: min rate %u not met\n", td->o.name,
188 rate = (bytes - td->rate_bytes) / spent;
189 if (rate < td->o.ratemin ||
190 bytes < td->rate_bytes) {
191 log_err("%s: min rate %u not met, got"
192 " %luKiB/sec\n", td->o.name,
193 td->o.ratemin, rate);
199 * checks iops specified rate
201 if (iops < td->o.rate_iops) {
202 log_err("%s: min iops rate %u not met\n",
203 td->o.name, td->o.rate_iops);
206 rate = (iops - td->rate_blocks) / spent;
207 if (rate < td->o.rate_iops_min ||
208 iops < td->rate_blocks) {
209 log_err("%s: min iops rate %u not met,"
210 " got %lu\n", td->o.name,
218 td->rate_bytes = bytes;
219 td->rate_blocks = iops;
220 memcpy(&td->lastrate, now, sizeof(*now));
224 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
228 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
235 * When job exits, we can cancel the in-flight IO if we are using async
236 * io. Attempt to do so.
238 static void cleanup_pending_aio(struct thread_data *td)
240 struct list_head *entry, *n;
245 * get immediately available events, if any
247 r = io_u_queued_complete(td, 0);
252 * now cancel remaining active events
254 if (td->io_ops->cancel) {
255 list_for_each_safe(entry, n, &td->io_u_busylist) {
256 io_u = list_entry(entry, struct io_u, list);
259 * if the io_u isn't in flight, then that generally
260 * means someone leaked an io_u. complain but fix
261 * it up, so we don't stall here.
263 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
264 log_err("fio: non-busy IO on busy list\n");
267 r = td->io_ops->cancel(td, io_u);
275 r = io_u_queued_complete(td, td->cur_depth);
279 * Helper to handle the final sync of a file. Works just like the normal
280 * io path, just does everything sync.
282 static int fio_io_sync(struct thread_data *td, struct fio_file *f)
284 struct io_u *io_u = __get_io_u(td);
290 io_u->ddir = DDIR_SYNC;
293 if (td_io_prep(td, io_u)) {
299 ret = td_io_queue(td, io_u);
301 td_verror(td, io_u->error, "td_io_queue");
304 } else if (ret == FIO_Q_QUEUED) {
305 if (io_u_queued_complete(td, 1) < 0)
307 } else if (ret == FIO_Q_COMPLETED) {
309 td_verror(td, io_u->error, "td_io_queue");
313 if (io_u_sync_complete(td, io_u) < 0)
315 } else if (ret == FIO_Q_BUSY) {
316 if (td_io_commit(td))
325 * The main verify engine. Runs over the writes we previously submitted,
326 * reads the blocks back in, and checks the crc/md5 of the data.
328 static void do_verify(struct thread_data *td)
336 * sync io first and invalidate cache, to make sure we really
339 for_each_file(td, f, i) {
340 if (!(f->flags & FIO_FILE_OPEN))
342 if (fio_io_sync(td, f))
344 if (file_invalidate_cache(td, f))
351 td_set_runstate(td, TD_VERIFYING);
354 while (!td->terminate) {
357 io_u = __get_io_u(td);
361 if (runtime_exceeded(td, &io_u->start_time)) {
367 if (get_next_verify(td, io_u)) {
372 if (td_io_prep(td, io_u)) {
377 io_u->end_io = verify_io_u;
379 ret = td_io_queue(td, io_u);
381 case FIO_Q_COMPLETED:
384 else if (io_u->resid) {
385 int bytes = io_u->xfer_buflen - io_u->resid;
386 struct fio_file *f = io_u->file;
392 td_verror(td, ENODATA, "full resid");
397 io_u->xfer_buflen = io_u->resid;
398 io_u->xfer_buf += bytes;
399 io_u->offset += bytes;
401 td->ts.short_io_u[io_u->ddir]++;
403 if (io_u->offset == f->real_file_size)
406 requeue_io_u(td, &io_u);
409 ret = io_u_sync_complete(td, io_u);
417 requeue_io_u(td, &io_u);
418 ret2 = td_io_commit(td);
424 td_verror(td, -ret, "td_io_queue");
428 if (ret < 0 || td->error)
432 * if we can queue more, do so. but check if there are
433 * completed io_u's first.
436 if (queue_full(td) || ret == FIO_Q_BUSY) {
437 if (td->cur_depth >= td->o.iodepth_low)
438 min_events = td->cur_depth - td->o.iodepth_low;
444 * Reap required number of io units, if any, and do the
445 * verification on them through the callback handler
447 if (io_u_queued_complete(td, min_events) < 0)
452 min_events = td->cur_depth;
455 ret = io_u_queued_complete(td, min_events);
457 cleanup_pending_aio(td);
459 td_set_runstate(td, TD_RUNNING);
463 * Main IO worker function. It retrieves io_u's to process and queues
464 * and reaps them, checking for rate and errors along the way.
466 static void do_io(struct thread_data *td)
473 td_set_runstate(td, TD_RUNNING);
475 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
476 struct timeval comp_time;
489 memcpy(&s, &io_u->start_time, sizeof(s));
491 if (runtime_exceeded(td, &s)) {
498 * Add verification end_io handler, if asked to verify
499 * a previously written file.
501 if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ) {
502 io_u->end_io = verify_io_u;
503 td_set_runstate(td, TD_VERIFYING);
505 td_set_runstate(td, TD_RUNNING);
507 ret = td_io_queue(td, io_u);
509 case FIO_Q_COMPLETED:
512 else if (io_u->resid) {
513 int bytes = io_u->xfer_buflen - io_u->resid;
514 struct fio_file *f = io_u->file;
520 td_verror(td, ENODATA, "full resid");
525 io_u->xfer_buflen = io_u->resid;
526 io_u->xfer_buf += bytes;
527 io_u->offset += bytes;
529 td->ts.short_io_u[io_u->ddir]++;
531 if (io_u->offset == f->real_file_size)
534 requeue_io_u(td, &io_u);
537 fio_gettime(&comp_time, NULL);
538 bytes_done = io_u_sync_complete(td, io_u);
545 * if the engine doesn't have a commit hook,
546 * the io_u is really queued. if it does have such
547 * a hook, it has to call io_u_queued() itself.
549 if (td->io_ops->commit == NULL)
550 io_u_queued(td, io_u);
553 requeue_io_u(td, &io_u);
554 ret2 = td_io_commit(td);
564 if (ret < 0 || td->error)
568 * See if we need to complete some commands
570 if (queue_full(td) || ret == FIO_Q_BUSY) {
572 if (td->cur_depth >= td->o.iodepth_low)
573 min_evts = td->cur_depth - td->o.iodepth_low;
576 fio_gettime(&comp_time, NULL);
577 bytes_done = io_u_queued_complete(td, min_evts);
586 * the rate is batched for now, it should work for batches
587 * of completions except the very first one which may look
590 usec = utime_since(&s, &comp_time);
592 rate_throttle(td, usec, bytes_done);
594 if (check_min_rate(td, &comp_time)) {
595 if (exitall_on_terminate)
596 terminate_threads(td->groupid);
597 td_verror(td, ENODATA, "check_min_rate");
601 if (td->o.thinktime) {
602 unsigned long long b;
604 b = td->io_blocks[0] + td->io_blocks[1];
605 if (!(b % td->o.thinktime_blocks)) {
608 if (td->o.thinktime_spin)
609 __usec_sleep(td->o.thinktime_spin);
611 left = td->o.thinktime - td->o.thinktime_spin;
613 usec_sleep(td, left);
618 if (td->o.fill_device && td->error == ENOSPC) {
627 ret = io_u_queued_complete(td, i);
629 if (should_fsync(td) && td->o.end_fsync) {
630 td_set_runstate(td, TD_FSYNCING);
632 for_each_file(td, f, i) {
633 if (!(f->flags & FIO_FILE_OPEN))
639 cleanup_pending_aio(td);
642 * stop job if we failed doing any IO
644 if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
648 static void cleanup_io_u(struct thread_data *td)
650 struct list_head *entry, *n;
653 list_for_each_safe(entry, n, &td->io_u_freelist) {
654 io_u = list_entry(entry, struct io_u, list);
656 list_del(&io_u->list);
663 static int init_io_u(struct thread_data *td)
670 max_units = td->o.iodepth;
671 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
672 td->orig_buffer_size = (unsigned long long) max_bs
673 * (unsigned long long) max_units;
675 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
678 bs = td->orig_buffer_size + td->o.hugepage_size - 1;
679 td->orig_buffer_size = bs & ~(td->o.hugepage_size - 1);
682 if (td->orig_buffer_size != (size_t) td->orig_buffer_size) {
683 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
687 if (allocate_io_mem(td))
691 p = ALIGN(td->orig_buffer);
695 for (i = 0; i < max_units; i++) {
698 io_u = malloc(sizeof(*io_u));
699 memset(io_u, 0, sizeof(*io_u));
700 INIT_LIST_HEAD(&io_u->list);
702 if (!(td->io_ops->flags & FIO_NOIO)) {
703 io_u->buf = p + max_bs * i;
705 if (td_write(td) && !td->o.refill_buffers)
706 io_u_fill_buffer(td, io_u, max_bs);
710 io_u->flags = IO_U_F_FREE;
711 list_add(&io_u->list, &td->io_u_freelist);
719 static int switch_ioscheduler(struct thread_data *td)
721 char tmp[256], tmp2[128];
725 if (td->io_ops->flags & FIO_DISKLESSIO)
728 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
730 f = fopen(tmp, "r+");
732 if (errno == ENOENT) {
733 log_err("fio: os or kernel doesn't support IO scheduler"
737 td_verror(td, errno, "fopen iosched");
744 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
745 if (ferror(f) || ret != 1) {
746 td_verror(td, errno, "fwrite");
754 * Read back and check that the selected scheduler is now the default.
756 ret = fread(tmp, 1, sizeof(tmp), f);
757 if (ferror(f) || ret < 0) {
758 td_verror(td, errno, "fread");
763 sprintf(tmp2, "[%s]", td->o.ioscheduler);
764 if (!strstr(tmp, tmp2)) {
765 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
766 td_verror(td, EINVAL, "iosched_switch");
775 static int keep_running(struct thread_data *td)
777 unsigned long long io_done;
781 if (td->o.time_based)
788 io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]
790 if (io_done < td->o.size)
796 static int clear_io_state(struct thread_data *td)
802 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
803 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
807 td->rw_end_set[0] = td->rw_end_set[1] = 0;
809 td->last_was_sync = 0;
812 * reset file done count if we are to start over
814 if (td->o.time_based || td->o.loops)
815 td->nr_done_files = 0;
820 for_each_file(td, f, i) {
821 f->flags &= ~FIO_FILE_DONE;
822 ret = td_io_open_file(td, f);
831 * Entry point for the thread based jobs. The process based jobs end up
832 * here as well, after a little setup.
834 static void *thread_main(void *data)
836 unsigned long long runtime[2], elapsed;
837 struct thread_data *td = data;
840 if (!td->o.use_thread)
845 dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
847 INIT_LIST_HEAD(&td->io_u_freelist);
848 INIT_LIST_HEAD(&td->io_u_busylist);
849 INIT_LIST_HEAD(&td->io_u_requeues);
850 INIT_LIST_HEAD(&td->io_log_list);
851 INIT_LIST_HEAD(&td->io_hist_list);
852 td->io_hist_tree = RB_ROOT;
854 td_set_runstate(td, TD_INITIALIZED);
855 fio_mutex_up(startup_mutex);
856 fio_mutex_down(td->mutex);
859 * the ->mutex mutex is now no longer used, close it to avoid
860 * eating a file descriptor
862 fio_mutex_remove(td->mutex);
865 * May alter parameters that init_io_u() will use, so we need to
874 if (td->o.cpumask_set && fio_setaffinity(td) == -1) {
875 td_verror(td, errno, "cpu_set_affinity");
879 if (td->ioprio_set) {
880 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
881 td_verror(td, errno, "ioprio_set");
886 if (nice(td->o.nice) == -1) {
887 td_verror(td, errno, "nice");
891 if (td->o.ioscheduler && switch_ioscheduler(td))
894 if (!td->o.create_serialize && setup_files(td))
903 if (init_random_map(td))
906 if (td->o.exec_prerun) {
907 if (system(td->o.exec_prerun) < 0)
911 fio_gettime(&td->epoch, NULL);
912 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
913 getrusage(RUSAGE_SELF, &td->ts.ru_start);
915 runtime[0] = runtime[1] = 0;
917 while (keep_running(td)) {
918 fio_gettime(&td->start, NULL);
919 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
922 memcpy(&td->lastrate, &td->ts.stat_sample_time,
923 sizeof(td->lastrate));
925 if (clear_state && clear_io_state(td))
928 prune_io_piece_log(td);
934 if (td_read(td) && td->io_bytes[DDIR_READ]) {
935 if (td->rw_end_set[DDIR_READ])
936 elapsed = utime_since(&td->start,
937 &td->rw_end[DDIR_READ]);
939 elapsed = utime_since_now(&td->start);
941 runtime[DDIR_READ] += elapsed;
943 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
944 if (td->rw_end_set[DDIR_WRITE])
945 elapsed = utime_since(&td->start,
946 &td->rw_end[DDIR_WRITE]);
948 elapsed = utime_since_now(&td->start);
950 runtime[DDIR_WRITE] += elapsed;
953 if (td->error || td->terminate)
956 if (!td->o.do_verify ||
957 td->o.verify == VERIFY_NONE ||
958 (td->io_ops->flags & FIO_UNIDIR))
961 if (clear_io_state(td))
964 fio_gettime(&td->start, NULL);
968 runtime[DDIR_READ] += utime_since_now(&td->start);
970 if (td->error || td->terminate)
974 update_rusage_stat(td);
975 td->ts.runtime[0] = (runtime[0] + 999) / 1000;
976 td->ts.runtime[1] = (runtime[1] + 999) / 1000;
977 td->ts.total_run_time = mtime_since_now(&td->epoch);
978 td->ts.io_bytes[0] = td->io_bytes[0];
979 td->ts.io_bytes[1] = td->io_bytes[1];
982 finish_log(td, td->ts.bw_log, "bw");
984 finish_log(td, td->ts.slat_log, "slat");
986 finish_log(td, td->ts.clat_log, "clat");
987 if (td->o.exec_postrun) {
988 if (system(td->o.exec_postrun) < 0)
989 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
992 if (exitall_on_terminate)
993 terminate_threads(td->groupid);
997 printf("fio: pid=%d, err=%d/%s\n", (int) td->pid, td->error,
999 close_and_free_files(td);
1004 * do this very late, it will log file closing as well
1006 if (td->o.write_iolog_file)
1007 write_iolog_close(td);
1009 options_mem_free(td);
1010 td_set_runstate(td, TD_EXITED);
1011 return (void *) (unsigned long) td->error;
1015 * We cannot pass the td data into a forked process, so attach the td and
1016 * pass it to the thread worker.
1018 static int fork_main(int shmid, int offset)
1020 struct thread_data *td;
1023 data = shmat(shmid, NULL, 0);
1024 if (data == (void *) -1) {
1031 td = data + offset * sizeof(struct thread_data);
1032 ret = thread_main(td);
1034 return (int) (unsigned long) ret;
1038 * Run over the job map and reap the threads that have exited, if any.
1040 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
1042 struct thread_data *td;
1043 int i, cputhreads, realthreads, pending, status, ret;
1046 * reap exited threads (TD_EXITED -> TD_REAPED)
1048 realthreads = pending = cputhreads = 0;
1049 for_each_td(td, i) {
1053 * ->io_ops is NULL for a thread that has closed its
1056 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
1065 if (td->runstate == TD_REAPED)
1067 if (td->o.use_thread) {
1068 if (td->runstate == TD_EXITED) {
1069 td_set_runstate(td, TD_REAPED);
1076 if (td->runstate == TD_EXITED)
1080 * check if someone quit or got killed in an unusual way
1082 ret = waitpid(td->pid, &status, flags);
1084 if (errno == ECHILD) {
1085 log_err("fio: pid=%d disappeared %d\n",
1086 (int) td->pid, td->runstate);
1087 td_set_runstate(td, TD_REAPED);
1091 } else if (ret == td->pid) {
1092 if (WIFSIGNALED(status)) {
1093 int sig = WTERMSIG(status);
1096 log_err("fio: pid=%d, got signal=%d\n",
1097 (int) td->pid, sig);
1098 td_set_runstate(td, TD_REAPED);
1101 if (WIFEXITED(status)) {
1102 if (WEXITSTATUS(status) && !td->error)
1103 td->error = WEXITSTATUS(status);
1105 td_set_runstate(td, TD_REAPED);
1111 * thread is not dead, continue
1117 (*m_rate) -= td->o.ratemin;
1118 (*t_rate) -= td->o.rate;
1125 done_secs += mtime_since_now(&td->epoch) / 1000;
1128 if (*nr_running == cputhreads && !pending && realthreads)
1129 terminate_threads(TERMINATE_ALL);
1133 * Main function for kicking off and reaping jobs, as needed.
1135 static void run_threads(void)
1137 struct thread_data *td;
1138 unsigned long spent;
1139 int i, todo, nr_running, m_rate, t_rate, nr_started;
1141 if (fio_pin_memory())
1144 if (!terse_output) {
1145 printf("Starting ");
1147 printf("%d thread%s", nr_thread,
1148 nr_thread > 1 ? "s" : "");
1152 printf("%d process%s", nr_process,
1153 nr_process > 1 ? "es" : "");
1159 set_sig_handlers(sig_handler);
1161 todo = thread_number;
1164 m_rate = t_rate = 0;
1166 for_each_td(td, i) {
1167 print_status_init(td->thread_number - 1);
1169 if (!td->o.create_serialize) {
1175 * do file setup here so it happens sequentially,
1176 * we don't want X number of threads getting their
1177 * client data interspersed on disk
1179 if (setup_files(td)) {
1182 log_err("fio: pid=%d, err=%d/%s\n",
1183 (int) td->pid, td->error, td->verror);
1184 td_set_runstate(td, TD_REAPED);
1191 * for sharing to work, each job must always open
1192 * its own files. so close them, if we opened them
1195 for_each_file(td, f, i)
1196 td_io_close_file(td, f);
1205 struct thread_data *map[MAX_JOBS];
1206 struct timeval this_start;
1207 int this_jobs = 0, left;
1210 * create threads (TD_NOT_CREATED -> TD_CREATED)
1212 for_each_td(td, i) {
1213 if (td->runstate != TD_NOT_CREATED)
1217 * never got a chance to start, killed by other
1218 * thread for some reason
1220 if (td->terminate) {
1225 if (td->o.start_delay) {
1226 spent = mtime_since_genesis();
1228 if (td->o.start_delay * 1000 > spent)
1232 if (td->o.stonewall && (nr_started || nr_running)) {
1233 dprint(FD_PROCESS, "%s: stonewall wait\n",
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("pthread_create");
1254 if (pthread_detach(td->thread) < 0)
1255 perror("pthread_detach");
1258 dprint(FD_PROCESS, "will fork\n");
1261 int ret = fork_main(shm_id, i);
1264 } else if (i == fio_debug_jobno)
1265 *fio_debug_jobp = pid;
1267 fio_mutex_down(startup_mutex);
1271 * Wait for the started threads to transition to
1274 fio_gettime(&this_start, NULL);
1276 while (left && !fio_abort) {
1277 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1282 for (i = 0; i < this_jobs; i++) {
1286 if (td->runstate == TD_INITIALIZED) {
1289 } else if (td->runstate >= TD_EXITED) {
1293 nr_running++; /* work-around... */
1299 log_err("fio: %d jobs failed to start\n", left);
1300 for (i = 0; i < this_jobs; i++) {
1304 kill(td->pid, SIGTERM);
1310 * start created threads (TD_INITIALIZED -> TD_RUNNING).
1312 for_each_td(td, i) {
1313 if (td->runstate != TD_INITIALIZED)
1316 td_set_runstate(td, TD_RUNNING);
1319 m_rate += td->o.ratemin;
1320 t_rate += td->o.rate;
1322 fio_mutex_up(td->mutex);
1325 reap_threads(&nr_running, &t_rate, &m_rate);
1331 while (nr_running) {
1332 reap_threads(&nr_running, &t_rate, &m_rate);
1340 int main(int argc, char *argv[])
1347 * We need locale for number printing, if it isn't set then just
1348 * go with the US format.
1350 if (!getenv("LC_NUMERIC"))
1351 setlocale(LC_NUMERIC, "en_US");
1353 if (parse_options(argc, argv))
1359 ps = sysconf(_SC_PAGESIZE);
1361 log_err("Failed to get page size\n");
1369 setup_log(&agg_io_log[DDIR_READ]);
1370 setup_log(&agg_io_log[DDIR_WRITE]);
1373 startup_mutex = fio_mutex_init(0);
1384 __finish_log(agg_io_log[DDIR_READ], "agg-read_bw.log");
1385 __finish_log(agg_io_log[DDIR_WRITE],
1386 "agg-write_bw.log");
1390 fio_mutex_remove(startup_mutex);