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);
128 static void set_sig_handlers(void)
130 struct sigaction act;
132 memset(&act, 0, sizeof(act));
133 act.sa_handler = sig_alrm;
134 act.sa_flags = SA_RESTART;
135 sigaction(SIGALRM, &act, NULL);
137 memset(&act, 0, sizeof(act));
138 act.sa_handler = sig_int;
139 act.sa_flags = SA_RESTART;
140 sigaction(SIGINT, &act, NULL);
144 * Check if we are above the minimum rate given.
146 static int check_min_rate(struct thread_data *td, struct timeval *now)
148 unsigned long long bytes = 0;
149 unsigned long iops = 0;
154 * No minimum rate set, always ok
156 if (!td->o.ratemin && !td->o.rate_iops_min)
160 * allow a 2 second settle period in the beginning
162 if (mtime_since(&td->start, now) < 2000)
166 iops += td->io_blocks[DDIR_READ];
167 bytes += td->this_io_bytes[DDIR_READ];
170 iops += td->io_blocks[DDIR_WRITE];
171 bytes += td->this_io_bytes[DDIR_WRITE];
175 * if rate blocks is set, sample is running
177 if (td->rate_bytes || td->rate_blocks) {
178 spent = mtime_since(&td->lastrate, now);
179 if (spent < td->o.ratecycle)
184 * check bandwidth specified rate
186 if (bytes < td->rate_bytes) {
187 log_err("%s: min rate %u not met\n", td->o.name,
191 rate = (bytes - td->rate_bytes) / spent;
192 if (rate < td->o.ratemin ||
193 bytes < td->rate_bytes) {
194 log_err("%s: min rate %u not met, got"
195 " %luKiB/sec\n", td->o.name,
196 td->o.ratemin, rate);
202 * checks iops specified rate
204 if (iops < td->o.rate_iops) {
205 log_err("%s: min iops rate %u not met\n",
206 td->o.name, td->o.rate_iops);
209 rate = (iops - td->rate_blocks) / spent;
210 if (rate < td->o.rate_iops_min ||
211 iops < td->rate_blocks) {
212 log_err("%s: min iops rate %u not met,"
213 " got %lu\n", td->o.name,
221 td->rate_bytes = bytes;
222 td->rate_blocks = iops;
223 memcpy(&td->lastrate, now, sizeof(*now));
227 static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
231 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
238 * When job exits, we can cancel the in-flight IO if we are using async
239 * io. Attempt to do so.
241 static void cleanup_pending_aio(struct thread_data *td)
243 struct flist_head *entry, *n;
248 * get immediately available events, if any
250 r = io_u_queued_complete(td, 0);
255 * now cancel remaining active events
257 if (td->io_ops->cancel) {
258 flist_for_each_safe(entry, n, &td->io_u_busylist) {
259 io_u = flist_entry(entry, struct io_u, list);
262 * if the io_u isn't in flight, then that generally
263 * means someone leaked an io_u. complain but fix
264 * it up, so we don't stall here.
266 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
267 log_err("fio: non-busy IO on busy list\n");
270 r = td->io_ops->cancel(td, io_u);
278 r = io_u_queued_complete(td, td->cur_depth);
282 * Helper to handle the final sync of a file. Works just like the normal
283 * io path, just does everything sync.
285 static int fio_io_sync(struct thread_data *td, struct fio_file *f)
287 struct io_u *io_u = __get_io_u(td);
293 io_u->ddir = DDIR_SYNC;
296 if (td_io_prep(td, io_u)) {
302 ret = td_io_queue(td, io_u);
304 td_verror(td, io_u->error, "td_io_queue");
307 } else if (ret == FIO_Q_QUEUED) {
308 if (io_u_queued_complete(td, 1) < 0)
310 } else if (ret == FIO_Q_COMPLETED) {
312 td_verror(td, io_u->error, "td_io_queue");
316 if (io_u_sync_complete(td, io_u) < 0)
318 } else if (ret == FIO_Q_BUSY) {
319 if (td_io_commit(td))
328 * The main verify engine. Runs over the writes we previously submitted,
329 * reads the blocks back in, and checks the crc/md5 of the data.
331 static void do_verify(struct thread_data *td)
339 * sync io first and invalidate cache, to make sure we really
342 for_each_file(td, f, i) {
343 if (!(f->flags & FIO_FILE_OPEN))
345 if (fio_io_sync(td, f))
347 if (file_invalidate_cache(td, f))
354 td_set_runstate(td, TD_VERIFYING);
357 while (!td->terminate) {
360 io_u = __get_io_u(td);
364 if (runtime_exceeded(td, &io_u->start_time)) {
370 if (get_next_verify(td, io_u)) {
375 if (td_io_prep(td, io_u)) {
380 io_u->end_io = verify_io_u;
382 ret = td_io_queue(td, io_u);
384 case FIO_Q_COMPLETED:
387 else if (io_u->resid) {
388 int bytes = io_u->xfer_buflen - io_u->resid;
389 struct fio_file *f = io_u->file;
395 td_verror(td, EIO, "full resid");
400 io_u->xfer_buflen = io_u->resid;
401 io_u->xfer_buf += bytes;
402 io_u->offset += bytes;
404 td->ts.short_io_u[io_u->ddir]++;
406 if (io_u->offset == f->real_file_size)
409 requeue_io_u(td, &io_u);
412 ret = io_u_sync_complete(td, io_u);
420 requeue_io_u(td, &io_u);
421 ret2 = td_io_commit(td);
427 td_verror(td, -ret, "td_io_queue");
431 if (ret < 0 || td->error)
435 * if we can queue more, do so. but check if there are
436 * completed io_u's first.
438 full = queue_full(td) || ret == FIO_Q_BUSY;
439 if (full || !td->o.iodepth_batch_complete) {
440 min_events = td->o.iodepth_batch_complete;
441 if (full && !min_events)
446 * Reap required number of io units, if any,
447 * and do the verification on them through
448 * the callback handler
450 if (io_u_queued_complete(td, min_events) < 0) {
454 } while (full && (td->cur_depth > td->o.iodepth_low));
461 min_events = td->cur_depth;
464 ret = io_u_queued_complete(td, min_events);
466 cleanup_pending_aio(td);
468 td_set_runstate(td, TD_RUNNING);
472 * Main IO worker function. It retrieves io_u's to process and queues
473 * and reaps them, checking for rate and errors along the way.
475 static void do_io(struct thread_data *td)
482 td_set_runstate(td, TD_RUNNING);
484 while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) {
485 struct timeval comp_time;
498 memcpy(&s, &io_u->start_time, sizeof(s));
500 if (runtime_exceeded(td, &s)) {
507 * Add verification end_io handler, if asked to verify
508 * a previously written file.
510 if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ) {
511 io_u->end_io = verify_io_u;
512 td_set_runstate(td, TD_VERIFYING);
514 td_set_runstate(td, TD_RUNNING);
516 ret = td_io_queue(td, io_u);
518 case FIO_Q_COMPLETED:
521 else if (io_u->resid) {
522 int bytes = io_u->xfer_buflen - io_u->resid;
523 struct fio_file *f = io_u->file;
529 td_verror(td, EIO, "full resid");
534 io_u->xfer_buflen = io_u->resid;
535 io_u->xfer_buf += bytes;
536 io_u->offset += bytes;
538 td->ts.short_io_u[io_u->ddir]++;
540 if (io_u->offset == f->real_file_size)
543 requeue_io_u(td, &io_u);
546 fio_gettime(&comp_time, NULL);
547 bytes_done = io_u_sync_complete(td, io_u);
554 * if the engine doesn't have a commit hook,
555 * the io_u is really queued. if it does have such
556 * a hook, it has to call io_u_queued() itself.
558 if (td->io_ops->commit == NULL)
559 io_u_queued(td, io_u);
562 requeue_io_u(td, &io_u);
563 ret2 = td_io_commit(td);
573 if (ret < 0 || td->error)
577 * See if we need to complete some commands
579 full = queue_full(td) || ret == FIO_Q_BUSY;
580 if (full || !td->o.iodepth_batch_complete) {
581 min_evts = td->o.iodepth_batch_complete;
582 if (full && !min_evts)
585 fio_gettime(&comp_time, NULL);
588 ret = io_u_queued_complete(td, min_evts);
593 } while (full && (td->cur_depth > td->o.iodepth_low));
602 * the rate is batched for now, it should work for batches
603 * of completions except the very first one which may look
606 usec = utime_since(&s, &comp_time);
608 rate_throttle(td, usec, bytes_done);
610 if (check_min_rate(td, &comp_time)) {
611 if (exitall_on_terminate)
612 terminate_threads(td->groupid);
613 td_verror(td, EIO, "check_min_rate");
617 if (td->o.thinktime) {
618 unsigned long long b;
620 b = td->io_blocks[0] + td->io_blocks[1];
621 if (!(b % td->o.thinktime_blocks)) {
624 if (td->o.thinktime_spin)
625 __usec_sleep(td->o.thinktime_spin);
627 left = td->o.thinktime - td->o.thinktime_spin;
629 usec_sleep(td, left);
634 if (td->o.fill_device && td->error == ENOSPC) {
643 ret = io_u_queued_complete(td, i);
645 if (should_fsync(td) && td->o.end_fsync) {
646 td_set_runstate(td, TD_FSYNCING);
648 for_each_file(td, f, i) {
649 if (!(f->flags & FIO_FILE_OPEN))
655 cleanup_pending_aio(td);
658 * stop job if we failed doing any IO
660 if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
664 static void cleanup_io_u(struct thread_data *td)
666 struct flist_head *entry, *n;
669 flist_for_each_safe(entry, n, &td->io_u_freelist) {
670 io_u = flist_entry(entry, struct io_u, list);
672 flist_del(&io_u->list);
679 static int init_io_u(struct thread_data *td)
686 max_units = td->o.iodepth;
687 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
688 td->orig_buffer_size = (unsigned long long) max_bs
689 * (unsigned long long) max_units;
691 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
694 bs = td->orig_buffer_size + td->o.hugepage_size - 1;
695 td->orig_buffer_size = bs & ~(td->o.hugepage_size - 1);
698 if (td->orig_buffer_size != (size_t) td->orig_buffer_size) {
699 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
703 if (allocate_io_mem(td))
707 p = ALIGN(td->orig_buffer);
711 for (i = 0; i < max_units; i++) {
714 io_u = malloc(sizeof(*io_u));
715 memset(io_u, 0, sizeof(*io_u));
716 INIT_FLIST_HEAD(&io_u->list);
718 if (!(td->io_ops->flags & FIO_NOIO)) {
719 io_u->buf = p + max_bs * i;
721 if (td_write(td) && !td->o.refill_buffers)
722 io_u_fill_buffer(td, io_u, max_bs);
726 io_u->flags = IO_U_F_FREE;
727 flist_add(&io_u->list, &td->io_u_freelist);
735 static int switch_ioscheduler(struct thread_data *td)
737 char tmp[256], tmp2[128];
741 if (td->io_ops->flags & FIO_DISKLESSIO)
744 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
746 f = fopen(tmp, "r+");
748 if (errno == ENOENT) {
749 log_err("fio: os or kernel doesn't support IO scheduler"
753 td_verror(td, errno, "fopen iosched");
760 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
761 if (ferror(f) || ret != 1) {
762 td_verror(td, errno, "fwrite");
770 * Read back and check that the selected scheduler is now the default.
772 ret = fread(tmp, 1, sizeof(tmp), f);
773 if (ferror(f) || ret < 0) {
774 td_verror(td, errno, "fread");
779 sprintf(tmp2, "[%s]", td->o.ioscheduler);
780 if (!strstr(tmp, tmp2)) {
781 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
782 td_verror(td, EINVAL, "iosched_switch");
791 static int keep_running(struct thread_data *td)
793 unsigned long long io_done;
797 if (td->o.time_based)
804 io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]
806 if (io_done < td->o.size)
812 static int clear_io_state(struct thread_data *td)
818 td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0;
819 td->this_io_bytes[0] = td->this_io_bytes[1] = 0;
823 td->rw_end_set[0] = td->rw_end_set[1] = 0;
825 td->last_was_sync = 0;
828 * reset file done count if we are to start over
830 if (td->o.time_based || td->o.loops)
831 td->nr_done_files = 0;
836 for_each_file(td, f, i) {
837 f->flags &= ~FIO_FILE_DONE;
838 ret = td_io_open_file(td, f);
847 * Entry point for the thread based jobs. The process based jobs end up
848 * here as well, after a little setup.
850 static void *thread_main(void *data)
852 unsigned long long runtime[2], elapsed;
853 struct thread_data *td = data;
856 if (!td->o.use_thread)
861 dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
863 INIT_FLIST_HEAD(&td->io_u_freelist);
864 INIT_FLIST_HEAD(&td->io_u_busylist);
865 INIT_FLIST_HEAD(&td->io_u_requeues);
866 INIT_FLIST_HEAD(&td->io_log_list);
867 INIT_FLIST_HEAD(&td->io_hist_list);
868 td->io_hist_tree = RB_ROOT;
870 td_set_runstate(td, TD_INITIALIZED);
871 fio_mutex_up(startup_mutex);
872 fio_mutex_down(td->mutex);
875 * the ->mutex mutex is now no longer used, close it to avoid
876 * eating a file descriptor
878 fio_mutex_remove(td->mutex);
881 * May alter parameters that init_io_u() will use, so we need to
890 if (td->o.cpumask_set && fio_setaffinity(td) == -1) {
891 td_verror(td, errno, "cpu_set_affinity");
895 if (td->ioprio_set) {
896 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
897 td_verror(td, errno, "ioprio_set");
902 if (nice(td->o.nice) == -1) {
903 td_verror(td, errno, "nice");
907 if (td->o.ioscheduler && switch_ioscheduler(td))
910 if (!td->o.create_serialize && setup_files(td))
919 if (init_random_map(td))
922 if (td->o.exec_prerun) {
923 if (system(td->o.exec_prerun) < 0)
927 fio_gettime(&td->epoch, NULL);
928 memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch));
929 getrusage(RUSAGE_SELF, &td->ts.ru_start);
931 runtime[0] = runtime[1] = 0;
933 while (keep_running(td)) {
934 fio_gettime(&td->start, NULL);
935 memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start));
938 memcpy(&td->lastrate, &td->ts.stat_sample_time,
939 sizeof(td->lastrate));
941 if (clear_state && clear_io_state(td))
944 prune_io_piece_log(td);
950 if (td_read(td) && td->io_bytes[DDIR_READ]) {
951 if (td->rw_end_set[DDIR_READ])
952 elapsed = utime_since(&td->start,
953 &td->rw_end[DDIR_READ]);
955 elapsed = utime_since_now(&td->start);
957 runtime[DDIR_READ] += elapsed;
959 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
960 if (td->rw_end_set[DDIR_WRITE])
961 elapsed = utime_since(&td->start,
962 &td->rw_end[DDIR_WRITE]);
964 elapsed = utime_since_now(&td->start);
966 runtime[DDIR_WRITE] += elapsed;
969 if (td->error || td->terminate)
972 if (!td->o.do_verify ||
973 td->o.verify == VERIFY_NONE ||
974 (td->io_ops->flags & FIO_UNIDIR))
977 if (clear_io_state(td))
980 fio_gettime(&td->start, NULL);
984 runtime[DDIR_READ] += utime_since_now(&td->start);
986 if (td->error || td->terminate)
990 update_rusage_stat(td);
991 td->ts.runtime[0] = (runtime[0] + 999) / 1000;
992 td->ts.runtime[1] = (runtime[1] + 999) / 1000;
993 td->ts.total_run_time = mtime_since_now(&td->epoch);
994 td->ts.io_bytes[0] = td->io_bytes[0];
995 td->ts.io_bytes[1] = td->io_bytes[1];
998 finish_log(td, td->ts.bw_log, "bw");
1000 finish_log(td, td->ts.slat_log, "slat");
1001 if (td->ts.clat_log)
1002 finish_log(td, td->ts.clat_log, "clat");
1003 if (td->o.exec_postrun) {
1004 if (system(td->o.exec_postrun) < 0)
1005 log_err("fio: postrun %s failed\n", td->o.exec_postrun);
1008 if (exitall_on_terminate)
1009 terminate_threads(td->groupid);
1013 printf("fio: pid=%d, err=%d/%s\n", (int) td->pid, td->error,
1015 close_and_free_files(td);
1020 * do this very late, it will log file closing as well
1022 if (td->o.write_iolog_file)
1023 write_iolog_close(td);
1025 options_mem_free(td);
1026 td_set_runstate(td, TD_EXITED);
1027 return (void *) (unsigned long) td->error;
1031 * We cannot pass the td data into a forked process, so attach the td and
1032 * pass it to the thread worker.
1034 static int fork_main(int shmid, int offset)
1036 struct thread_data *td;
1039 data = shmat(shmid, NULL, 0);
1040 if (data == (void *) -1) {
1047 td = data + offset * sizeof(struct thread_data);
1048 ret = thread_main(td);
1050 return (int) (unsigned long) ret;
1054 * Run over the job map and reap the threads that have exited, if any.
1056 static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
1058 struct thread_data *td;
1059 int i, cputhreads, realthreads, pending, status, ret;
1062 * reap exited threads (TD_EXITED -> TD_REAPED)
1064 realthreads = pending = cputhreads = 0;
1065 for_each_td(td, i) {
1069 * ->io_ops is NULL for a thread that has closed its
1072 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
1081 if (td->runstate == TD_REAPED)
1083 if (td->o.use_thread) {
1084 if (td->runstate == TD_EXITED) {
1085 td_set_runstate(td, TD_REAPED);
1092 if (td->runstate == TD_EXITED)
1096 * check if someone quit or got killed in an unusual way
1098 ret = waitpid(td->pid, &status, flags);
1100 if (errno == ECHILD) {
1101 log_err("fio: pid=%d disappeared %d\n",
1102 (int) td->pid, td->runstate);
1103 td_set_runstate(td, TD_REAPED);
1107 } else if (ret == td->pid) {
1108 if (WIFSIGNALED(status)) {
1109 int sig = WTERMSIG(status);
1112 log_err("fio: pid=%d, got signal=%d\n",
1113 (int) td->pid, sig);
1114 td_set_runstate(td, TD_REAPED);
1117 if (WIFEXITED(status)) {
1118 if (WEXITSTATUS(status) && !td->error)
1119 td->error = WEXITSTATUS(status);
1121 td_set_runstate(td, TD_REAPED);
1127 * thread is not dead, continue
1133 (*m_rate) -= td->o.ratemin;
1134 (*t_rate) -= td->o.rate;
1141 done_secs += mtime_since_now(&td->epoch) / 1000;
1144 if (*nr_running == cputhreads && !pending && realthreads)
1145 terminate_threads(TERMINATE_ALL);
1149 * Main function for kicking off and reaping jobs, as needed.
1151 static void run_threads(void)
1153 struct thread_data *td;
1154 unsigned long spent;
1155 int i, todo, nr_running, m_rate, t_rate, nr_started;
1157 if (fio_pin_memory())
1160 if (!terse_output) {
1161 printf("Starting ");
1163 printf("%d thread%s", nr_thread,
1164 nr_thread > 1 ? "s" : "");
1168 printf("%d process%s", nr_process,
1169 nr_process > 1 ? "es" : "");
1177 todo = thread_number;
1180 m_rate = t_rate = 0;
1182 for_each_td(td, i) {
1183 print_status_init(td->thread_number - 1);
1185 if (!td->o.create_serialize) {
1191 * do file setup here so it happens sequentially,
1192 * we don't want X number of threads getting their
1193 * client data interspersed on disk
1195 if (setup_files(td)) {
1198 log_err("fio: pid=%d, err=%d/%s\n",
1199 (int) td->pid, td->error, td->verror);
1200 td_set_runstate(td, TD_REAPED);
1207 * for sharing to work, each job must always open
1208 * its own files. so close them, if we opened them
1211 for_each_file(td, f, i)
1212 td_io_close_file(td, f);
1221 struct thread_data *map[MAX_JOBS];
1222 struct timeval this_start;
1223 int this_jobs = 0, left;
1226 * create threads (TD_NOT_CREATED -> TD_CREATED)
1228 for_each_td(td, i) {
1229 if (td->runstate != TD_NOT_CREATED)
1233 * never got a chance to start, killed by other
1234 * thread for some reason
1236 if (td->terminate) {
1241 if (td->o.start_delay) {
1242 spent = mtime_since_genesis();
1244 if (td->o.start_delay * 1000 > spent)
1248 if (td->o.stonewall && (nr_started || nr_running)) {
1249 dprint(FD_PROCESS, "%s: stonewall wait\n",
1255 * Set state to created. Thread will transition
1256 * to TD_INITIALIZED when it's done setting up.
1258 td_set_runstate(td, TD_CREATED);
1259 map[this_jobs++] = td;
1262 if (td->o.use_thread) {
1263 dprint(FD_PROCESS, "will pthread_create\n");
1264 if (pthread_create(&td->thread, NULL,
1266 perror("pthread_create");
1270 if (pthread_detach(td->thread) < 0)
1271 perror("pthread_detach");
1274 dprint(FD_PROCESS, "will fork\n");
1277 int ret = fork_main(shm_id, i);
1280 } else if (i == fio_debug_jobno)
1281 *fio_debug_jobp = pid;
1283 fio_mutex_down(startup_mutex);
1287 * Wait for the started threads to transition to
1290 fio_gettime(&this_start, NULL);
1292 while (left && !fio_abort) {
1293 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1298 for (i = 0; i < this_jobs; i++) {
1302 if (td->runstate == TD_INITIALIZED) {
1305 } else if (td->runstate >= TD_EXITED) {
1309 nr_running++; /* work-around... */
1315 log_err("fio: %d jobs failed to start\n", left);
1316 for (i = 0; i < this_jobs; i++) {
1320 kill(td->pid, SIGTERM);
1326 * start created threads (TD_INITIALIZED -> TD_RUNNING).
1328 for_each_td(td, i) {
1329 if (td->runstate != TD_INITIALIZED)
1332 td_set_runstate(td, TD_RUNNING);
1335 m_rate += td->o.ratemin;
1336 t_rate += td->o.rate;
1338 fio_mutex_up(td->mutex);
1341 reap_threads(&nr_running, &t_rate, &m_rate);
1347 while (nr_running) {
1348 reap_threads(&nr_running, &t_rate, &m_rate);
1356 int main(int argc, char *argv[])
1363 * We need locale for number printing, if it isn't set then just
1364 * go with the US format.
1366 if (!getenv("LC_NUMERIC"))
1367 setlocale(LC_NUMERIC, "en_US");
1369 if (parse_options(argc, argv))
1375 ps = sysconf(_SC_PAGESIZE);
1377 log_err("Failed to get page size\n");
1385 setup_log(&agg_io_log[DDIR_READ]);
1386 setup_log(&agg_io_log[DDIR_WRITE]);
1389 startup_mutex = fio_mutex_init(0);
1400 __finish_log(agg_io_log[DDIR_READ], "agg-read_bw.log");
1401 __finish_log(agg_io_log[DDIR_WRITE],
1402 "agg-write_bw.log");
1406 fio_mutex_remove(startup_mutex);