Lines Matching refs:td

36 static void mark_random_map(struct thread_data *td, struct io_u *io_u)  in mark_random_map()  argument
38 unsigned int min_bs = td->o.rw_min_bs; in mark_random_map()
53 static uint64_t last_block(struct thread_data *td, struct fio_file *f, in last_block() argument
68 if (td->o.zone_range) in last_block()
69 max_size = td->o.zone_range; in last_block()
71 if (td->o.min_bs[ddir] > td->o.ba[ddir]) in last_block()
72 max_size -= td->o.min_bs[ddir] - td->o.ba[ddir]; in last_block()
74 max_blocks = max_size / (uint64_t) td->o.ba[ddir]; in last_block()
86 static int __get_next_rand_offset(struct thread_data *td, struct fio_file *f, in __get_next_rand_offset() argument
91 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE) { in __get_next_rand_offset()
94 lastb = last_block(td, f, ddir); in __get_next_rand_offset()
98 r = __rand(&td->random_state); in __get_next_rand_offset()
117 if (!file_randommap(td, f)) in __get_next_rand_offset()
136 static int __get_next_rand_offset_zipf(struct thread_data *td, in __get_next_rand_offset_zipf() argument
144 static int __get_next_rand_offset_pareto(struct thread_data *td, in __get_next_rand_offset_pareto() argument
160 static int get_off_from_method(struct thread_data *td, struct fio_file *f, in get_off_from_method() argument
163 if (td->o.random_distribution == FIO_RAND_DIST_RANDOM) in get_off_from_method()
164 return __get_next_rand_offset(td, f, ddir, b); in get_off_from_method()
165 else if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) in get_off_from_method()
166 return __get_next_rand_offset_zipf(td, f, ddir, b); in get_off_from_method()
167 else if (td->o.random_distribution == FIO_RAND_DIST_PARETO) in get_off_from_method()
168 return __get_next_rand_offset_pareto(td, f, ddir, b); in get_off_from_method()
170 log_err("fio: unknown random distribution: %d\n", td->o.random_distribution); in get_off_from_method()
178 static inline int should_sort_io(struct thread_data *td) in should_sort_io() argument
180 if (!td->o.verifysort_nr || !td->o.do_verify) in should_sort_io()
182 if (!td_random(td)) in should_sort_io()
184 if (td->runstate != TD_VERIFYING) in should_sort_io()
186 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE) in should_sort_io()
192 static int should_do_random(struct thread_data *td, enum fio_ddir ddir) in should_do_random() argument
197 if (td->o.perc_rand[ddir] == 100) in should_do_random()
200 r = __rand(&td->seq_rand_state[ddir]); in should_do_random()
203 return v <= td->o.perc_rand[ddir]; in should_do_random()
206 static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, in get_next_rand_offset() argument
212 if (!should_sort_io(td)) in get_next_rand_offset()
213 return get_off_from_method(td, f, ddir, b); in get_next_rand_offset()
215 if (!flist_empty(&td->next_rand_list)) { in get_next_rand_offset()
217 r = flist_first_entry(&td->next_rand_list, struct rand_off, list); in get_next_rand_offset()
224 for (i = 0; i < td->o.verifysort_nr; i++) { in get_next_rand_offset()
227 ret = get_off_from_method(td, f, ddir, &r->off); in get_next_rand_offset()
233 flist_add(&r->list, &td->next_rand_list); in get_next_rand_offset()
239 assert(!flist_empty(&td->next_rand_list)); in get_next_rand_offset()
240 flist_sort(NULL, &td->next_rand_list, flist_cmp); in get_next_rand_offset()
244 static int get_next_rand_block(struct thread_data *td, struct fio_file *f, in get_next_rand_block() argument
247 if (!get_next_rand_offset(td, f, ddir, b)) in get_next_rand_block()
250 if (td->o.time_based) { in get_next_rand_block()
251 fio_file_reset(td, f); in get_next_rand_block()
252 if (!get_next_rand_offset(td, f, ddir, b)) in get_next_rand_block()
262 static int get_next_seq_offset(struct thread_data *td, struct fio_file *f, in get_next_seq_offset() argument
265 struct thread_options *o = &td->o; in get_next_seq_offset()
269 if (f->last_pos[ddir] >= f->io_size + get_start_offset(td, f) && in get_next_seq_offset()
299 static int get_next_block(struct thread_data *td, struct io_u *io_u, in get_next_block() argument
312 if (td_random(td)) { in get_next_block()
313 if (should_do_random(td, ddir)) { in get_next_block()
314 ret = get_next_rand_block(td, f, ddir, &b); in get_next_block()
319 ret = get_next_seq_offset(td, f, ddir, &offset); in get_next_block()
321 ret = get_next_rand_block(td, f, ddir, &b); in get_next_block()
325 ret = get_next_seq_offset(td, f, ddir, &offset); in get_next_block()
331 if (td->o.rw_seq == RW_SEQ_SEQ) { in get_next_block()
332 ret = get_next_seq_offset(td, f, ddir, &offset); in get_next_block()
334 ret = get_next_rand_block(td, f, ddir, &b); in get_next_block()
337 } else if (td->o.rw_seq == RW_SEQ_IDENT) { in get_next_block()
344 log_err("fio: unknown rw_seq=%d\n", td->o.rw_seq); in get_next_block()
353 io_u->offset = b * td->o.ba[ddir]; in get_next_block()
368 static int __get_next_offset(struct thread_data *td, struct io_u *io_u, in __get_next_offset() argument
377 if (td->o.ddir_seq_nr && !--td->ddir_seq_nr) { in __get_next_offset()
379 td->ddir_seq_nr = td->o.ddir_seq_nr; in __get_next_offset()
382 if (get_next_block(td, io_u, ddir, rw_seq_hit, is_random)) in __get_next_offset()
403 static int get_next_offset(struct thread_data *td, struct io_u *io_u, in get_next_offset() argument
406 if (td->flags & TD_F_PROFILE_OPS) { in get_next_offset()
407 struct prof_io_ops *ops = &td->prof_io_ops; in get_next_offset()
410 return ops->fill_io_u_off(td, io_u, is_random); in get_next_offset()
413 return __get_next_offset(td, io_u, is_random); in get_next_offset()
416 static inline int io_u_fits(struct thread_data *td, struct io_u *io_u, in io_u_fits() argument
421 return io_u->offset + buflen <= f->io_size + get_start_offset(td, f); in io_u_fits()
424 static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u, in __get_next_buflen() argument
434 if (td->o.bs_is_seq_rand) in __get_next_buflen()
437 minbs = td->o.min_bs[ddir]; in __get_next_buflen()
438 maxbs = td->o.max_bs[ddir]; in __get_next_buflen()
446 if (!io_u_fits(td, io_u, minbs)) in __get_next_buflen()
450 r = __rand(&td->bsrange_state); in __get_next_buflen()
452 if (!td->o.bssplit_nr[ddir]) { in __get_next_buflen()
461 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) { in __get_next_buflen()
462 struct bssplit *bsp = &td->o.bssplit[ddir][i]; in __get_next_buflen()
467 io_u_fits(td, io_u, buflen)) in __get_next_buflen()
472 if (td->o.do_verify && td->o.verify != VERIFY_NONE) in __get_next_buflen()
473 buflen = (buflen + td->o.verify_interval - 1) & in __get_next_buflen()
474 ~(td->o.verify_interval - 1); in __get_next_buflen()
476 if (!td->o.bs_unaligned && is_power_of_2(minbs)) in __get_next_buflen()
479 } while (!io_u_fits(td, io_u, buflen)); in __get_next_buflen()
484 static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u, in get_next_buflen() argument
487 if (td->flags & TD_F_PROFILE_OPS) { in get_next_buflen()
488 struct prof_io_ops *ops = &td->prof_io_ops; in get_next_buflen()
491 return ops->fill_io_u_size(td, io_u, is_random); in get_next_buflen()
494 return __get_next_buflen(td, io_u, is_random); in get_next_buflen()
497 static void set_rwmix_bytes(struct thread_data *td) in set_rwmix_bytes() argument
506 diff = td->o.rwmix[td->rwmix_ddir ^ 1]; in set_rwmix_bytes()
507 td->rwmix_issues = (td->io_issues[td->rwmix_ddir] * diff) / 100; in set_rwmix_bytes()
510 static inline enum fio_ddir get_rand_ddir(struct thread_data *td) in get_rand_ddir() argument
515 r = __rand(&td->rwmix_state); in get_rand_ddir()
518 if (v <= td->o.rwmix[DDIR_READ]) in get_rand_ddir()
524 void io_u_quiesce(struct thread_data *td) in io_u_quiesce() argument
535 if (td->io_u_queued || td->cur_depth) { in io_u_quiesce()
538 ret = td_io_commit(td); in io_u_quiesce()
541 while (td->io_u_in_flight) { in io_u_quiesce()
544 ret = io_u_queued_complete(td, 1, NULL); in io_u_quiesce()
548 static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir) in rate_ddir() argument
555 if (td->rate_pending_usleep[ddir] <= 0) in rate_ddir()
562 if (td_rw(td) && td->o.rwmix[odir]) { in rate_ddir()
566 if (td->rate_pending_usleep[odir] < 100000) in rate_ddir()
573 if (td->rate_pending_usleep[ddir] <= in rate_ddir()
574 td->rate_pending_usleep[odir]) { in rate_ddir()
575 usec = td->rate_pending_usleep[ddir]; in rate_ddir()
577 usec = td->rate_pending_usleep[odir]; in rate_ddir()
581 usec = td->rate_pending_usleep[ddir]; in rate_ddir()
583 io_u_quiesce(td); in rate_ddir()
585 usec = usec_sleep(td, usec); in rate_ddir()
587 td->rate_pending_usleep[ddir] -= usec; in rate_ddir()
590 if (td_rw(td) && __should_check_rate(td, odir)) in rate_ddir()
591 td->rate_pending_usleep[odir] -= usec; in rate_ddir()
604 static enum fio_ddir get_rw_ddir(struct thread_data *td) in get_rw_ddir() argument
611 if (td->o.fsync_blocks && in get_rw_ddir()
612 !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks) && in get_rw_ddir()
613 td->io_issues[DDIR_WRITE] && should_fsync(td)) in get_rw_ddir()
619 if (td->o.fdatasync_blocks && in get_rw_ddir()
620 !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks) && in get_rw_ddir()
621 td->io_issues[DDIR_WRITE] && should_fsync(td)) in get_rw_ddir()
627 if (td->sync_file_range_nr && in get_rw_ddir()
628 !(td->io_issues[DDIR_WRITE] % td->sync_file_range_nr) && in get_rw_ddir()
629 td->io_issues[DDIR_WRITE] && should_fsync(td)) in get_rw_ddir()
632 if (td_rw(td)) { in get_rw_ddir()
636 if (td->io_issues[td->rwmix_ddir] >= td->rwmix_issues) { in get_rw_ddir()
642 ddir = get_rand_ddir(td); in get_rw_ddir()
644 if (ddir != td->rwmix_ddir) in get_rw_ddir()
645 set_rwmix_bytes(td); in get_rw_ddir()
647 td->rwmix_ddir = ddir; in get_rw_ddir()
649 ddir = td->rwmix_ddir; in get_rw_ddir()
650 } else if (td_read(td)) in get_rw_ddir()
652 else if (td_write(td)) in get_rw_ddir()
657 td->rwmix_ddir = rate_ddir(td, ddir); in get_rw_ddir()
658 return td->rwmix_ddir; in get_rw_ddir()
661 static void set_rw_ddir(struct thread_data *td, struct io_u *io_u) in set_rw_ddir() argument
663 io_u->ddir = io_u->acct_ddir = get_rw_ddir(td); in set_rw_ddir()
665 if (io_u->ddir == DDIR_WRITE && (td->io_ops->flags & FIO_BARRIER) && in set_rw_ddir()
666 td->o.barrier_blocks && in set_rw_ddir()
667 !(td->io_issues[DDIR_WRITE] % td->o.barrier_blocks) && in set_rw_ddir()
668 td->io_issues[DDIR_WRITE]) in set_rw_ddir()
672 void put_file_log(struct thread_data *td, struct fio_file *f) in put_file_log() argument
674 unsigned int ret = put_file(td, f); in put_file_log()
677 td_verror(td, ret, "file close"); in put_file_log()
680 void put_io_u(struct thread_data *td, struct io_u *io_u) in put_io_u() argument
682 td_io_u_lock(td); in put_io_u()
685 put_file_log(td, io_u->file); in put_io_u()
691 td->cur_depth--; in put_io_u()
692 io_u_qpush(&td->io_u_freelist, io_u); in put_io_u()
693 td_io_u_unlock(td); in put_io_u()
694 td_io_u_free_notify(td); in put_io_u()
697 void clear_io_u(struct thread_data *td, struct io_u *io_u) in clear_io_u() argument
700 put_io_u(td, io_u); in clear_io_u()
703 void requeue_io_u(struct thread_data *td, struct io_u **io_u) in requeue_io_u() argument
710 td_io_u_lock(td); in requeue_io_u()
714 td->io_issues[ddir]--; in requeue_io_u()
718 td->cur_depth--; in requeue_io_u()
720 io_u_rpush(&td->io_u_requeues, __io_u); in requeue_io_u()
721 td_io_u_unlock(td); in requeue_io_u()
725 static int fill_io_u(struct thread_data *td, struct io_u *io_u) in fill_io_u() argument
729 if (td->io_ops->flags & FIO_NOIO) in fill_io_u()
732 set_rw_ddir(td, io_u); in fill_io_u()
743 if (td->zone_bytes >= td->o.zone_size && td->o.zone_skip) { in fill_io_u()
746 td->zone_bytes = 0; in fill_io_u()
747 f->file_offset += td->o.zone_range + td->o.zone_skip; in fill_io_u()
755 td->io_skip_bytes += td->o.zone_skip; in fill_io_u()
762 if (get_next_offset(td, io_u, &is_random)) { in fill_io_u()
767 io_u->buflen = get_next_buflen(td, io_u, is_random); in fill_io_u()
784 if (td_random(td) && file_randommap(td, io_u->file)) in fill_io_u()
785 mark_random_map(td, io_u); in fill_io_u()
789 td->zone_bytes += io_u->buflen; in fill_io_u()
822 void io_u_mark_submit(struct thread_data *td, unsigned int nr) in io_u_mark_submit() argument
824 __io_u_mark_map(td->ts.io_u_submit, nr); in io_u_mark_submit()
825 td->ts.total_submit++; in io_u_mark_submit()
828 void io_u_mark_complete(struct thread_data *td, unsigned int nr) in io_u_mark_complete() argument
830 __io_u_mark_map(td->ts.io_u_complete, nr); in io_u_mark_complete()
831 td->ts.total_complete++; in io_u_mark_complete()
834 void io_u_mark_depth(struct thread_data *td, unsigned int nr) in io_u_mark_depth() argument
838 switch (td->cur_depth) { in io_u_mark_depth()
860 td->ts.io_u_map[idx] += nr; in io_u_mark_depth()
863 static void io_u_mark_lat_usec(struct thread_data *td, unsigned long usec) in io_u_mark_lat_usec() argument
901 td->ts.io_u_lat_u[idx]++; in io_u_mark_lat_usec()
904 static void io_u_mark_lat_msec(struct thread_data *td, unsigned long msec) in io_u_mark_lat_msec() argument
946 td->ts.io_u_lat_m[idx]++; in io_u_mark_lat_msec()
949 static void io_u_mark_latency(struct thread_data *td, unsigned long usec) in io_u_mark_latency() argument
952 io_u_mark_lat_usec(td, usec); in io_u_mark_latency()
954 io_u_mark_lat_msec(td, usec / 1000); in io_u_mark_latency()
960 static struct fio_file *get_next_file_rand(struct thread_data *td, in get_next_file_rand() argument
971 r = __rand(&td->next_file_state); in get_next_file_rand()
972 fno = (unsigned int) ((double) td->o.nr_files in get_next_file_rand()
975 f = td->files[fno]; in get_next_file_rand()
982 if (td->nr_open_files >= td->o.open_files) in get_next_file_rand()
985 err = td_io_open_file(td, f); in get_next_file_rand()
996 td_io_close_file(td, f); in get_next_file_rand()
1003 static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf, in get_next_file_rr() argument
1006 unsigned int old_next_file = td->next_file; in get_next_file_rr()
1012 f = td->files[td->next_file]; in get_next_file_rr()
1014 td->next_file++; in get_next_file_rr()
1015 if (td->next_file >= td->o.nr_files) in get_next_file_rr()
1016 td->next_file = 0; in get_next_file_rr()
1027 if (td->nr_open_files >= td->o.open_files) in get_next_file_rr()
1030 err = td_io_open_file(td, f); in get_next_file_rr()
1046 td_io_close_file(td, f); in get_next_file_rr()
1049 } while (td->next_file != old_next_file); in get_next_file_rr()
1055 static struct fio_file *__get_next_file(struct thread_data *td) in __get_next_file() argument
1059 assert(td->o.nr_files <= td->files_index); in __get_next_file()
1061 if (td->nr_done_files >= td->o.nr_files) { in __get_next_file()
1063 " nr_files=%d\n", td->nr_open_files, in __get_next_file()
1064 td->nr_done_files, in __get_next_file()
1065 td->o.nr_files); in __get_next_file()
1069 f = td->file_service_file; in __get_next_file()
1071 if (td->o.file_service_type == FIO_FSERVICE_SEQ) in __get_next_file()
1073 if (td->file_service_left--) in __get_next_file()
1077 if (td->o.file_service_type == FIO_FSERVICE_RR || in __get_next_file()
1078 td->o.file_service_type == FIO_FSERVICE_SEQ) in __get_next_file()
1079 f = get_next_file_rr(td, FIO_FILE_open, FIO_FILE_closing); in __get_next_file()
1081 f = get_next_file_rand(td, FIO_FILE_open, FIO_FILE_closing); in __get_next_file()
1086 td->file_service_file = f; in __get_next_file()
1087 td->file_service_left = td->file_service_nr - 1; in __get_next_file()
1096 static struct fio_file *get_next_file(struct thread_data *td) in get_next_file() argument
1098 if (td->flags & TD_F_PROFILE_OPS) { in get_next_file()
1099 struct prof_io_ops *ops = &td->prof_io_ops; in get_next_file()
1102 return ops->get_next_file(td); in get_next_file()
1105 return __get_next_file(td); in get_next_file()
1108 static long set_io_u_file(struct thread_data *td, struct io_u *io_u) in set_io_u_file() argument
1113 f = get_next_file(td); in set_io_u_file()
1120 if (!fill_io_u(td, io_u)) in set_io_u_file()
1123 put_file_log(td, f); in set_io_u_file()
1124 td_io_close_file(td, f); in set_io_u_file()
1127 td->nr_done_files++; in set_io_u_file()
1129 td->nr_done_files, td->o.nr_files); in set_io_u_file()
1135 static void lat_fatal(struct thread_data *td, struct io_completion_data *icd, in lat_fatal() argument
1138 if (!td->error) in lat_fatal()
1140 td_verror(td, ETIMEDOUT, "max latency exceeded"); in lat_fatal()
1144 static void lat_new_cycle(struct thread_data *td) in lat_new_cycle() argument
1146 fio_gettime(&td->latency_ts, NULL); in lat_new_cycle()
1147 td->latency_ios = ddir_rw_sum(td->io_blocks); in lat_new_cycle()
1148 td->latency_failed = 0; in lat_new_cycle()
1155 static int __lat_target_failed(struct thread_data *td) in __lat_target_failed() argument
1157 if (td->latency_qd == 1) in __lat_target_failed()
1160 td->latency_qd_high = td->latency_qd; in __lat_target_failed()
1162 if (td->latency_qd == td->latency_qd_low) in __lat_target_failed()
1163 td->latency_qd_low--; in __lat_target_failed()
1165 td->latency_qd = (td->latency_qd + td->latency_qd_low) / 2; in __lat_target_failed()
1167 …dprint(FD_RATE, "Ramped down: %d %d %d\n", td->latency_qd_low, td->latency_qd, td->latency_qd_high… in __lat_target_failed()
1173 io_u_quiesce(td); in __lat_target_failed()
1174 lat_new_cycle(td); in __lat_target_failed()
1178 static int lat_target_failed(struct thread_data *td) in lat_target_failed() argument
1180 if (td->o.latency_percentile.u.f == 100.0) in lat_target_failed()
1181 return __lat_target_failed(td); in lat_target_failed()
1183 td->latency_failed++; in lat_target_failed()
1187 void lat_target_init(struct thread_data *td) in lat_target_init() argument
1189 td->latency_end_run = 0; in lat_target_init()
1191 if (td->o.latency_target) { in lat_target_init()
1192 dprint(FD_RATE, "Latency target=%llu\n", td->o.latency_target); in lat_target_init()
1193 fio_gettime(&td->latency_ts, NULL); in lat_target_init()
1194 td->latency_qd = 1; in lat_target_init()
1195 td->latency_qd_high = td->o.iodepth; in lat_target_init()
1196 td->latency_qd_low = 1; in lat_target_init()
1197 td->latency_ios = ddir_rw_sum(td->io_blocks); in lat_target_init()
1199 td->latency_qd = td->o.iodepth; in lat_target_init()
1202 void lat_target_reset(struct thread_data *td) in lat_target_reset() argument
1204 if (!td->latency_end_run) in lat_target_reset()
1205 lat_target_init(td); in lat_target_reset()
1208 static void lat_target_success(struct thread_data *td) in lat_target_success() argument
1210 const unsigned int qd = td->latency_qd; in lat_target_success()
1211 struct thread_options *o = &td->o; in lat_target_success()
1213 td->latency_qd_low = td->latency_qd; in lat_target_success()
1220 if (td->latency_qd_high != o->iodepth) in lat_target_success()
1221 td->latency_qd = (td->latency_qd + td->latency_qd_high) / 2; in lat_target_success()
1223 td->latency_qd *= 2; in lat_target_success()
1225 if (td->latency_qd > o->iodepth) in lat_target_success()
1226 td->latency_qd = o->iodepth; in lat_target_success()
1228 dprint(FD_RATE, "Ramped up: %d %d %d\n", td->latency_qd_low, td->latency_qd, td->latency_qd_high); in lat_target_success()
1234 if (td->latency_qd == qd) { in lat_target_success()
1235 if (td->latency_end_run) { in lat_target_success()
1237 td->done = 1; in lat_target_success()
1240 io_u_quiesce(td); in lat_target_success()
1241 td->latency_end_run = 1; in lat_target_success()
1242 reset_all_stats(td); in lat_target_success()
1243 reset_io_stats(td); in lat_target_success()
1247 lat_new_cycle(td); in lat_target_success()
1253 void lat_target_check(struct thread_data *td) in lat_target_check() argument
1259 usec_window = utime_since_now(&td->latency_ts); in lat_target_check()
1260 if (usec_window < td->o.latency_window) in lat_target_check()
1263 ios = ddir_rw_sum(td->io_blocks) - td->latency_ios; in lat_target_check()
1264 success_ios = (double) (ios - td->latency_failed) / (double) ios; in lat_target_check()
1267 …dprint(FD_RATE, "Success rate: %.2f%% (target %.2f%%)\n", success_ios, td->o.latency_percentile.u.… in lat_target_check()
1269 if (success_ios >= td->o.latency_percentile.u.f) in lat_target_check()
1270 lat_target_success(td); in lat_target_check()
1272 __lat_target_failed(td); in lat_target_check()
1279 int queue_full(const struct thread_data *td) in queue_full() argument
1281 const int qempty = io_u_qempty(&td->io_u_freelist); in queue_full()
1285 if (!td->o.latency_target) in queue_full()
1288 return td->cur_depth >= td->latency_qd; in queue_full()
1291 struct io_u *__get_io_u(struct thread_data *td) in __get_io_u() argument
1295 if (td->stop_io) in __get_io_u()
1298 td_io_u_lock(td); in __get_io_u()
1301 if (!io_u_rempty(&td->io_u_requeues)) in __get_io_u()
1302 io_u = io_u_rpop(&td->io_u_requeues); in __get_io_u()
1303 else if (!queue_full(td)) { in __get_io_u()
1304 io_u = io_u_qpop(&td->io_u_freelist); in __get_io_u()
1320 td->cur_depth++; in __get_io_u()
1323 } else if (td->o.verify_async) { in __get_io_u()
1328 pthread_cond_wait(&td->free_cond, &td->io_u_lock); in __get_io_u()
1332 td_io_u_unlock(td); in __get_io_u()
1336 static int check_get_trim(struct thread_data *td, struct io_u *io_u) in check_get_trim() argument
1338 if (!(td->flags & TD_F_TRIM_BACKLOG)) in check_get_trim()
1341 if (td->trim_entries) { in check_get_trim()
1344 if (td->trim_batch) { in check_get_trim()
1345 td->trim_batch--; in check_get_trim()
1347 } else if (!(td->io_hist_len % td->o.trim_backlog) && in check_get_trim()
1348 td->last_ddir != DDIR_READ) { in check_get_trim()
1349 td->trim_batch = td->o.trim_batch; in check_get_trim()
1350 if (!td->trim_batch) in check_get_trim()
1351 td->trim_batch = td->o.trim_backlog; in check_get_trim()
1355 if (get_trim && !get_next_trim(td, io_u)) in check_get_trim()
1362 static int check_get_verify(struct thread_data *td, struct io_u *io_u) in check_get_verify() argument
1364 if (!(td->flags & TD_F_VER_BACKLOG)) in check_get_verify()
1367 if (td->io_hist_len) { in check_get_verify()
1370 if (td->verify_batch) in check_get_verify()
1372 else if (!(td->io_hist_len % td->o.verify_backlog) && in check_get_verify()
1373 td->last_ddir != DDIR_READ) { in check_get_verify()
1374 td->verify_batch = td->o.verify_batch; in check_get_verify()
1375 if (!td->verify_batch) in check_get_verify()
1376 td->verify_batch = td->o.verify_backlog; in check_get_verify()
1380 if (get_verify && !get_next_verify(td, io_u)) { in check_get_verify()
1381 td->verify_batch--; in check_get_verify()
1432 struct io_u *get_io_u(struct thread_data *td) in get_io_u() argument
1439 io_u = __get_io_u(td); in get_io_u()
1445 if (check_get_verify(td, io_u)) in get_io_u()
1447 if (check_get_trim(td, io_u)) in get_io_u()
1459 if (td->flags & TD_F_READ_IOLOG) { in get_io_u()
1460 if (read_iolog_get(td, io_u)) in get_io_u()
1462 } else if (set_io_u_file(td, io_u)) { in get_io_u()
1477 if (!io_u->buflen && !(td->io_ops->flags & FIO_NOIO)) { in get_io_u()
1486 if (td->flags & TD_F_REFILL_BUFFERS) { in get_io_u()
1487 io_u_fill_buffer(td, io_u, in get_io_u()
1488 td->o.min_bs[DDIR_WRITE], in get_io_u()
1490 } else if ((td->flags & TD_F_SCRAMBLE_BUFFERS) && in get_io_u()
1491 !(td->flags & TD_F_COMPRESS)) in get_io_u()
1493 if (td->flags & TD_F_VER_NONE) { in get_io_u()
1494 populate_verify_io_u(td, io_u); in get_io_u()
1514 if (!td_io_prep(td, io_u)) { in get_io_u()
1515 if (!td->o.disable_slat) in get_io_u()
1523 put_io_u(td, io_u); in get_io_u()
1527 void io_u_log_error(struct thread_data *td, struct io_u *io_u) in io_u_log_error() argument
1531 if (td_non_fatal_error(td, eb, io_u->error) && !td->o.error_dump) in io_u_log_error()
1541 if (!td->error) in io_u_log_error()
1542 td_verror(td, io_u->error, "io_u error"); in io_u_log_error()
1545 static inline int gtod_reduce(struct thread_data *td) in gtod_reduce() argument
1547 return td->o.disable_clat && td->o.disable_lat && td->o.disable_slat in gtod_reduce()
1548 && td->o.disable_bw; in gtod_reduce()
1551 static void account_io_completion(struct thread_data *td, struct io_u *io_u, in account_io_completion() argument
1557 if (!gtod_reduce(td)) in account_io_completion()
1560 if (!td->o.disable_lat) { in account_io_completion()
1564 add_lat_sample(td, idx, tusec, bytes, io_u->offset); in account_io_completion()
1566 if (td->flags & TD_F_PROFILE_OPS) { in account_io_completion()
1567 struct prof_io_ops *ops = &td->prof_io_ops; in account_io_completion()
1570 icd->error = ops->io_u_lat(td, tusec); in account_io_completion()
1573 if (td->o.max_latency && tusec > td->o.max_latency) in account_io_completion()
1574 lat_fatal(td, icd, tusec, td->o.max_latency); in account_io_completion()
1575 if (td->o.latency_target && tusec > td->o.latency_target) { in account_io_completion()
1576 if (lat_target_failed(td)) in account_io_completion()
1577 lat_fatal(td, icd, tusec, td->o.latency_target); in account_io_completion()
1581 if (!td->o.disable_clat) { in account_io_completion()
1582 add_clat_sample(td, idx, lusec, bytes, io_u->offset); in account_io_completion()
1583 io_u_mark_latency(td, lusec); in account_io_completion()
1586 if (!td->o.disable_bw) in account_io_completion()
1587 add_bw_sample(td, idx, bytes, &icd->time); in account_io_completion()
1589 if (!gtod_reduce(td)) in account_io_completion()
1590 add_iops_sample(td, idx, bytes, &icd->time); in account_io_completion()
1593 static long long usec_for_io(struct thread_data *td, enum fio_ddir ddir) in usec_for_io() argument
1597 bytes = td->this_io_bytes[ddir]; in usec_for_io()
1598 bps = td->rate_bps[ddir]; in usec_for_io()
1604 static void io_completed(struct thread_data *td, struct io_u **io_u_ptr, in io_completed() argument
1613 td_io_u_lock(td); in io_completed()
1625 unlog_io_piece(td, io_u); in io_completed()
1632 td_io_u_unlock(td); in io_completed()
1635 td->last_was_sync = 1; in io_completed()
1643 td->last_was_sync = 0; in io_completed()
1644 td->last_ddir = ddir; in io_completed()
1651 td->io_blocks[ddir]++; in io_completed()
1652 td->this_io_blocks[ddir]++; in io_completed()
1653 td->io_bytes[ddir] += bytes; in io_completed()
1656 td->this_io_bytes[ddir] += bytes; in io_completed()
1667 if (td->last_write_comp) { in io_completed()
1668 int idx = td->last_write_idx++; in io_completed()
1670 td->last_write_comp[idx] = io_u->offset; in io_completed()
1671 if (td->last_write_idx == td->o.iodepth) in io_completed()
1672 td->last_write_idx = 0; in io_completed()
1676 if (ramp_time_over(td) && (td->runstate == TD_RUNNING || in io_completed()
1677 td->runstate == TD_VERIFYING)) { in io_completed()
1678 account_io_completion(td, io_u, icd, ddir, bytes); in io_completed()
1680 if (__should_check_rate(td, ddir)) { in io_completed()
1681 td->rate_pending_usleep[ddir] = in io_completed()
1682 (usec_for_io(td, ddir) - in io_completed()
1683 utime_since_now(&td->start)); in io_completed()
1686 __should_check_rate(td, oddir)) { in io_completed()
1687 td->rate_pending_usleep[oddir] = in io_completed()
1688 (usec_for_io(td, oddir) - in io_completed()
1689 utime_since_now(&td->start)); in io_completed()
1696 ret = io_u->end_io(td, io_u_ptr); in io_completed()
1703 io_u_log_error(td, io_u); in io_completed()
1708 if (!td_non_fatal_error(td, eb, icd->error)) in io_completed()
1715 update_error_count(td, icd->error); in io_completed()
1716 td_clear_error(td); in io_completed()
1723 static void init_icd(struct thread_data *td, struct io_completion_data *icd, in init_icd() argument
1728 if (!gtod_reduce(td)) in init_icd()
1738 static void ios_completed(struct thread_data *td, in ios_completed() argument
1745 io_u = td->io_ops->event(td, i); in ios_completed()
1747 io_completed(td, &io_u, icd); in ios_completed()
1750 put_io_u(td, io_u); in ios_completed()
1757 int io_u_sync_complete(struct thread_data *td, struct io_u *io_u, in io_u_sync_complete() argument
1762 init_icd(td, &icd, 1); in io_u_sync_complete()
1763 io_completed(td, &io_u, &icd); in io_u_sync_complete()
1766 put_io_u(td, io_u); in io_u_sync_complete()
1769 td_verror(td, icd.error, "io_u_sync_complete"); in io_u_sync_complete()
1786 int io_u_queued_complete(struct thread_data *td, int min_evts, in io_u_queued_complete() argument
1798 else if (min_evts > td->cur_depth) in io_u_queued_complete()
1799 min_evts = td->cur_depth; in io_u_queued_complete()
1801 ret = td_io_getevents(td, min_evts, td->o.iodepth_batch_complete, tvp); in io_u_queued_complete()
1803 td_verror(td, -ret, "td_io_getevents"); in io_u_queued_complete()
1808 init_icd(td, &icd, ret); in io_u_queued_complete()
1809 ios_completed(td, &icd); in io_u_queued_complete()
1811 td_verror(td, icd.error, "io_u_queued_complete"); in io_u_queued_complete()
1828 void io_u_queued(struct thread_data *td, struct io_u *io_u) in io_u_queued() argument
1830 if (!td->o.disable_slat) { in io_u_queued()
1834 add_slat_sample(td, io_u->ddir, slat_time, io_u->xfer_buflen, in io_u_queued()
1842 static struct frand_state *get_buf_state(struct thread_data *td) in get_buf_state() argument
1847 if (!td->o.dedupe_percentage) in get_buf_state()
1848 return &td->buf_state; in get_buf_state()
1849 else if (td->o.dedupe_percentage == 100) in get_buf_state()
1850 return &td->buf_state_prev; in get_buf_state()
1852 r = __rand(&td->dedupe_state); in get_buf_state()
1855 if (v <= td->o.dedupe_percentage) in get_buf_state()
1856 return &td->buf_state_prev; in get_buf_state()
1858 return &td->buf_state; in get_buf_state()
1861 static void save_buf_state(struct thread_data *td, struct frand_state *rs) in save_buf_state() argument
1863 if (rs == &td->buf_state) in save_buf_state()
1864 frand_copy(&td->buf_state_prev, rs); in save_buf_state()
1867 void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write, in fill_io_buffer() argument
1870 struct thread_options *o = &td->o; in fill_io_buffer()
1873 unsigned int perc = td->o.compress_percentage; in fill_io_buffer()
1878 rs = get_buf_state(td); in fill_io_buffer()
1885 seg = min(min_write, td->o.compress_chunk); in fill_io_buffer()
1897 save_buf_state(td, rs); in fill_io_buffer()
1900 fill_buffer_pattern(td, buf, max_bs); in fill_io_buffer()
1908 void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u, in io_u_fill_buffer() argument
1912 fill_io_buffer(td, io_u->buf, min_write, max_bs); in io_u_fill_buffer()