Lines Matching refs:td
38 static void mark_random_map(struct thread_data *td, struct io_u *io_u) in mark_random_map() argument
40 unsigned int min_bs = td->o.rw_min_bs; in mark_random_map()
55 static uint64_t last_block(struct thread_data *td, struct fio_file *f, in last_block() argument
71 if (td->o.zone_range) in last_block()
72 max_size = td->o.zone_range; in last_block()
74 if (td->o.min_bs[ddir] > td->o.ba[ddir]) in last_block()
75 max_size -= td->o.min_bs[ddir] - td->o.ba[ddir]; in last_block()
77 max_blocks = max_size / (uint64_t) td->o.ba[ddir]; in last_block()
89 static int __get_next_rand_offset(struct thread_data *td, struct fio_file *f, in __get_next_rand_offset() argument
95 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE || in __get_next_rand_offset()
96 td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64) { in __get_next_rand_offset()
98 r = __rand(&td->random_state); in __get_next_rand_offset()
102 *b = lastb * (r / (rand_max(&td->random_state) + 1.0)); 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
152 static int __get_next_rand_offset_gauss(struct thread_data *td, in __get_next_rand_offset_gauss() argument
160 static int __get_next_rand_offset_zoned(struct thread_data *td, in __get_next_rand_offset_zoned() argument
169 lastb = last_block(td, f, ddir); in __get_next_rand_offset_zoned()
173 if (!td->o.zone_split_nr[ddir]) { in __get_next_rand_offset_zoned()
175 return __get_next_rand_offset(td, f, ddir, b, lastb); in __get_next_rand_offset_zoned()
181 v = rand32_between(&td->zone_state, 1, 100); in __get_next_rand_offset_zoned()
183 zsi = &td->zone_state_index[ddir][v - 1]; in __get_next_rand_offset_zoned()
213 if (__get_next_rand_offset(td, f, ddir, b, lastb) == 1) in __get_next_rand_offset_zoned()
233 static int get_off_from_method(struct thread_data *td, struct fio_file *f, in get_off_from_method() argument
236 if (td->o.random_distribution == FIO_RAND_DIST_RANDOM) { in get_off_from_method()
239 lastb = last_block(td, f, ddir); in get_off_from_method()
243 return __get_next_rand_offset(td, f, ddir, b, lastb); in get_off_from_method()
244 } else if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) in get_off_from_method()
245 return __get_next_rand_offset_zipf(td, f, ddir, b); in get_off_from_method()
246 else if (td->o.random_distribution == FIO_RAND_DIST_PARETO) in get_off_from_method()
247 return __get_next_rand_offset_pareto(td, f, ddir, b); in get_off_from_method()
248 else if (td->o.random_distribution == FIO_RAND_DIST_GAUSS) in get_off_from_method()
249 return __get_next_rand_offset_gauss(td, f, ddir, b); in get_off_from_method()
250 else if (td->o.random_distribution == FIO_RAND_DIST_ZONED) in get_off_from_method()
251 return __get_next_rand_offset_zoned(td, f, ddir, b); in get_off_from_method()
253 log_err("fio: unknown random distribution: %d\n", td->o.random_distribution); in get_off_from_method()
261 static inline bool should_sort_io(struct thread_data *td) in should_sort_io() argument
263 if (!td->o.verifysort_nr || !td->o.do_verify) in should_sort_io()
265 if (!td_random(td)) in should_sort_io()
267 if (td->runstate != TD_VERIFYING) in should_sort_io()
269 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE || in should_sort_io()
270 td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64) in should_sort_io()
276 static bool should_do_random(struct thread_data *td, enum fio_ddir ddir) in should_do_random() argument
280 if (td->o.perc_rand[ddir] == 100) in should_do_random()
283 v = rand32_between(&td->seq_rand_state[ddir], 1, 100); in should_do_random()
285 return v <= td->o.perc_rand[ddir]; in should_do_random()
288 static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, in get_next_rand_offset() argument
294 if (!should_sort_io(td)) in get_next_rand_offset()
295 return get_off_from_method(td, f, ddir, b); in get_next_rand_offset()
297 if (!flist_empty(&td->next_rand_list)) { in get_next_rand_offset()
299 r = flist_first_entry(&td->next_rand_list, struct rand_off, list); in get_next_rand_offset()
306 for (i = 0; i < td->o.verifysort_nr; i++) { in get_next_rand_offset()
309 ret = get_off_from_method(td, f, ddir, &r->off); in get_next_rand_offset()
315 flist_add(&r->list, &td->next_rand_list); in get_next_rand_offset()
321 assert(!flist_empty(&td->next_rand_list)); in get_next_rand_offset()
322 flist_sort(NULL, &td->next_rand_list, flist_cmp); in get_next_rand_offset()
326 static int get_next_rand_block(struct thread_data *td, struct fio_file *f, in get_next_rand_block() argument
329 if (!get_next_rand_offset(td, f, ddir, b)) in get_next_rand_block()
332 if (td->o.time_based || in get_next_rand_block()
333 (td->o.file_service_type & __FIO_FSERVICE_NONUNIFORM)) { in get_next_rand_block()
334 fio_file_reset(td, f); in get_next_rand_block()
335 if (!get_next_rand_offset(td, f, ddir, b)) in get_next_rand_block()
345 static int get_next_seq_offset(struct thread_data *td, struct fio_file *f, in get_next_seq_offset() argument
348 struct thread_options *o = &td->o; in get_next_seq_offset()
352 if (f->last_pos[ddir] >= f->io_size + get_start_offset(td, f) && in get_next_seq_offset()
354 struct thread_options *o = &td->o; in get_next_seq_offset()
404 static int get_next_block(struct thread_data *td, struct io_u *io_u, in get_next_block() argument
417 if (td_random(td)) { in get_next_block()
418 if (should_do_random(td, ddir)) { in get_next_block()
419 ret = get_next_rand_block(td, f, ddir, &b); in get_next_block()
423 io_u_set(td, io_u, IO_U_F_BUSY_OK); in get_next_block()
424 ret = get_next_seq_offset(td, f, ddir, &offset); in get_next_block()
426 ret = get_next_rand_block(td, f, ddir, &b); in get_next_block()
430 ret = get_next_seq_offset(td, f, ddir, &offset); in get_next_block()
433 io_u_set(td, io_u, IO_U_F_BUSY_OK); in get_next_block()
436 if (td->o.rw_seq == RW_SEQ_SEQ) { in get_next_block()
437 ret = get_next_seq_offset(td, f, ddir, &offset); in get_next_block()
439 ret = get_next_rand_block(td, f, ddir, &b); in get_next_block()
442 } else if (td->o.rw_seq == RW_SEQ_IDENT) { in get_next_block()
449 log_err("fio: unknown rw_seq=%d\n", td->o.rw_seq); in get_next_block()
458 io_u->offset = b * td->o.ba[ddir]; in get_next_block()
473 static int __get_next_offset(struct thread_data *td, struct io_u *io_u, in __get_next_offset() argument
482 if (td->o.ddir_seq_nr && !--td->ddir_seq_nr) { in __get_next_offset()
484 td->ddir_seq_nr = td->o.ddir_seq_nr; in __get_next_offset()
487 if (get_next_block(td, io_u, ddir, rw_seq_hit, is_random)) in __get_next_offset()
508 static int get_next_offset(struct thread_data *td, struct io_u *io_u, in get_next_offset() argument
511 if (td->flags & TD_F_PROFILE_OPS) { in get_next_offset()
512 struct prof_io_ops *ops = &td->prof_io_ops; in get_next_offset()
515 return ops->fill_io_u_off(td, io_u, is_random); in get_next_offset()
518 return __get_next_offset(td, io_u, is_random); in get_next_offset()
521 static inline bool io_u_fits(struct thread_data *td, struct io_u *io_u, in io_u_fits() argument
526 return io_u->offset + buflen <= f->io_size + get_start_offset(td, f); in io_u_fits()
529 static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u, in __get_next_buflen() argument
540 if (td->o.bs_is_seq_rand) in __get_next_buflen()
543 minbs = td->o.min_bs[ddir]; in __get_next_buflen()
544 maxbs = td->o.max_bs[ddir]; in __get_next_buflen()
552 if (!io_u_fits(td, io_u, minbs)) in __get_next_buflen()
555 frand_max = rand_max(&td->bsrange_state); in __get_next_buflen()
557 r = __rand(&td->bsrange_state); in __get_next_buflen()
559 if (!td->o.bssplit_nr[ddir]) { in __get_next_buflen()
568 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) { in __get_next_buflen()
569 struct bssplit *bsp = &td->o.bssplit[ddir][i]; in __get_next_buflen()
576 io_u_fits(td, io_u, buflen)) in __get_next_buflen()
582 if (!td->o.bs_unaligned && power_2) in __get_next_buflen()
584 else if (!td->o.bs_unaligned && !power_2) in __get_next_buflen()
586 } while (!io_u_fits(td, io_u, buflen)); in __get_next_buflen()
591 static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u, in get_next_buflen() argument
594 if (td->flags & TD_F_PROFILE_OPS) { in get_next_buflen()
595 struct prof_io_ops *ops = &td->prof_io_ops; in get_next_buflen()
598 return ops->fill_io_u_size(td, io_u, is_random); in get_next_buflen()
601 return __get_next_buflen(td, io_u, is_random); in get_next_buflen()
604 static void set_rwmix_bytes(struct thread_data *td) in set_rwmix_bytes() argument
613 diff = td->o.rwmix[td->rwmix_ddir ^ 1]; in set_rwmix_bytes()
614 td->rwmix_issues = (td->io_issues[td->rwmix_ddir] * diff) / 100; in set_rwmix_bytes()
617 static inline enum fio_ddir get_rand_ddir(struct thread_data *td) in get_rand_ddir() argument
621 v = rand32_between(&td->rwmix_state, 1, 100); in get_rand_ddir()
623 if (v <= td->o.rwmix[DDIR_READ]) in get_rand_ddir()
629 int io_u_quiesce(struct thread_data *td) in io_u_quiesce() argument
642 if (td->io_u_queued || td->cur_depth) { in io_u_quiesce()
645 ret = td_io_commit(td); in io_u_quiesce()
648 while (td->io_u_in_flight) { in io_u_quiesce()
651 ret = io_u_queued_complete(td, 1); in io_u_quiesce()
656 if (td->flags & TD_F_REGROW_LOGS) in io_u_quiesce()
657 regrow_logs(td); in io_u_quiesce()
662 static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir) in rate_ddir() argument
669 now = utime_since_now(&td->start); in rate_ddir()
674 if (td->rate_next_io_time[ddir] <= now) in rate_ddir()
681 if (td_rw(td) && td->o.rwmix[odir]) { in rate_ddir()
685 if (td->rate_next_io_time[odir] <= now) in rate_ddir()
692 if (td->rate_next_io_time[ddir] <= in rate_ddir()
693 td->rate_next_io_time[odir]) { in rate_ddir()
694 usec = td->rate_next_io_time[ddir] - now; in rate_ddir()
696 usec = td->rate_next_io_time[odir] - now; in rate_ddir()
700 usec = td->rate_next_io_time[ddir] - now; in rate_ddir()
702 if (td->o.io_submit_mode == IO_MODE_INLINE) in rate_ddir()
703 io_u_quiesce(td); in rate_ddir()
705 usec = usec_sleep(td, usec); in rate_ddir()
715 static enum fio_ddir get_rw_ddir(struct thread_data *td) in get_rw_ddir() argument
723 if (should_fsync(td)) { in get_rw_ddir()
724 if (td->o.fsync_blocks && td->io_issues[DDIR_WRITE] && in get_rw_ddir()
725 !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks)) in get_rw_ddir()
728 if (td->o.fdatasync_blocks && td->io_issues[DDIR_WRITE] && in get_rw_ddir()
729 !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks)) in get_rw_ddir()
732 if (td->sync_file_range_nr && td->io_issues[DDIR_WRITE] && in get_rw_ddir()
733 !(td->io_issues[DDIR_WRITE] % td->sync_file_range_nr)) in get_rw_ddir()
737 if (td_rw(td)) { in get_rw_ddir()
741 if (td->io_issues[td->rwmix_ddir] >= td->rwmix_issues) { in get_rw_ddir()
747 ddir = get_rand_ddir(td); in get_rw_ddir()
749 if (ddir != td->rwmix_ddir) in get_rw_ddir()
750 set_rwmix_bytes(td); in get_rw_ddir()
752 td->rwmix_ddir = ddir; in get_rw_ddir()
754 ddir = td->rwmix_ddir; in get_rw_ddir()
755 } else if (td_read(td)) in get_rw_ddir()
757 else if (td_write(td)) in get_rw_ddir()
759 else if (td_trim(td)) in get_rw_ddir()
764 td->rwmix_ddir = rate_ddir(td, ddir); in get_rw_ddir()
765 return td->rwmix_ddir; in get_rw_ddir()
768 static void set_rw_ddir(struct thread_data *td, struct io_u *io_u) in set_rw_ddir() argument
770 enum fio_ddir ddir = get_rw_ddir(td); in set_rw_ddir()
772 if (td_trimwrite(td)) { in set_rw_ddir()
782 if (io_u->ddir == DDIR_WRITE && td_ioengine_flagged(td, FIO_BARRIER) && in set_rw_ddir()
783 td->o.barrier_blocks && in set_rw_ddir()
784 !(td->io_issues[DDIR_WRITE] % td->o.barrier_blocks) && in set_rw_ddir()
785 td->io_issues[DDIR_WRITE]) in set_rw_ddir()
786 io_u_set(td, io_u, IO_U_F_BARRIER); in set_rw_ddir()
789 void put_file_log(struct thread_data *td, struct fio_file *f) in put_file_log() argument
791 unsigned int ret = put_file(td, f); in put_file_log()
794 td_verror(td, ret, "file close"); in put_file_log()
797 void put_io_u(struct thread_data *td, struct io_u *io_u) in put_io_u() argument
799 if (td->parent) in put_io_u()
800 td = td->parent; in put_io_u()
802 td_io_u_lock(td); in put_io_u()
805 put_file_log(td, io_u->file); in put_io_u()
808 io_u_set(td, io_u, IO_U_F_FREE); in put_io_u()
811 td->cur_depth--; in put_io_u()
812 assert(!(td->flags & TD_F_CHILD)); in put_io_u()
814 io_u_qpush(&td->io_u_freelist, io_u); in put_io_u()
815 td_io_u_unlock(td); in put_io_u()
816 td_io_u_free_notify(td); in put_io_u()
819 void clear_io_u(struct thread_data *td, struct io_u *io_u) in clear_io_u() argument
821 io_u_clear(td, io_u, IO_U_F_FLIGHT); in clear_io_u()
822 put_io_u(td, io_u); in clear_io_u()
825 void requeue_io_u(struct thread_data *td, struct io_u **io_u) in requeue_io_u() argument
832 if (td->parent) in requeue_io_u()
833 td = td->parent; in requeue_io_u()
835 td_io_u_lock(td); in requeue_io_u()
837 io_u_set(td, __io_u, IO_U_F_FREE); in requeue_io_u()
839 td->io_issues[ddir]--; in requeue_io_u()
841 io_u_clear(td, __io_u, IO_U_F_FLIGHT); in requeue_io_u()
843 td->cur_depth--; in requeue_io_u()
844 assert(!(td->flags & TD_F_CHILD)); in requeue_io_u()
847 io_u_rpush(&td->io_u_requeues, __io_u); in requeue_io_u()
848 td_io_u_unlock(td); in requeue_io_u()
849 td_io_u_free_notify(td); in requeue_io_u()
853 static int fill_io_u(struct thread_data *td, struct io_u *io_u) in fill_io_u() argument
857 if (td_ioengine_flagged(td, FIO_NOIO)) in fill_io_u()
860 set_rw_ddir(td, io_u); in fill_io_u()
871 if (td->zone_bytes >= td->o.zone_size && td->o.zone_skip) { in fill_io_u()
874 td->zone_bytes = 0; in fill_io_u()
875 f->file_offset += td->o.zone_range + td->o.zone_skip; in fill_io_u()
883 td->io_skip_bytes += td->o.zone_skip; in fill_io_u()
890 if (get_next_offset(td, io_u, &is_random)) { in fill_io_u()
895 io_u->buflen = get_next_buflen(td, io_u, is_random); in fill_io_u()
913 if (td_random(td) && file_randommap(td, io_u->file)) in fill_io_u()
914 mark_random_map(td, io_u); in fill_io_u()
918 td->zone_bytes += io_u->buflen; in fill_io_u()
951 void io_u_mark_submit(struct thread_data *td, unsigned int nr) in io_u_mark_submit() argument
953 __io_u_mark_map(td->ts.io_u_submit, nr); in io_u_mark_submit()
954 td->ts.total_submit++; in io_u_mark_submit()
957 void io_u_mark_complete(struct thread_data *td, unsigned int nr) in io_u_mark_complete() argument
959 __io_u_mark_map(td->ts.io_u_complete, nr); in io_u_mark_complete()
960 td->ts.total_complete++; in io_u_mark_complete()
963 void io_u_mark_depth(struct thread_data *td, unsigned int nr) in io_u_mark_depth() argument
967 switch (td->cur_depth) { in io_u_mark_depth()
989 td->ts.io_u_map[idx] += nr; in io_u_mark_depth()
992 static void io_u_mark_lat_usec(struct thread_data *td, unsigned long usec) in io_u_mark_lat_usec() argument
1030 td->ts.io_u_lat_u[idx]++; in io_u_mark_lat_usec()
1033 static void io_u_mark_lat_msec(struct thread_data *td, unsigned long msec) in io_u_mark_lat_msec() argument
1075 td->ts.io_u_lat_m[idx]++; in io_u_mark_lat_msec()
1078 static void io_u_mark_latency(struct thread_data *td, unsigned long usec) in io_u_mark_latency() argument
1081 io_u_mark_lat_usec(td, usec); in io_u_mark_latency()
1083 io_u_mark_lat_msec(td, usec / 1000); in io_u_mark_latency()
1086 static unsigned int __get_next_fileno_rand(struct thread_data *td) in __get_next_fileno_rand() argument
1090 if (td->o.file_service_type == FIO_FSERVICE_RANDOM) { in __get_next_fileno_rand()
1091 uint64_t frand_max = rand_max(&td->next_file_state); in __get_next_fileno_rand()
1094 r = __rand(&td->next_file_state); in __get_next_fileno_rand()
1095 return (unsigned int) ((double) td->o.nr_files in __get_next_fileno_rand()
1099 if (td->o.file_service_type == FIO_FSERVICE_ZIPF) in __get_next_fileno_rand()
1100 fileno = zipf_next(&td->next_file_zipf); in __get_next_fileno_rand()
1101 else if (td->o.file_service_type == FIO_FSERVICE_PARETO) in __get_next_fileno_rand()
1102 fileno = pareto_next(&td->next_file_zipf); in __get_next_fileno_rand()
1103 else if (td->o.file_service_type == FIO_FSERVICE_GAUSS) in __get_next_fileno_rand()
1104 fileno = gauss_next(&td->next_file_gauss); in __get_next_fileno_rand()
1106 log_err("fio: bad file service type: %d\n", td->o.file_service_type); in __get_next_fileno_rand()
1117 static struct fio_file *get_next_file_rand(struct thread_data *td, in get_next_file_rand() argument
1127 fno = __get_next_fileno_rand(td); in get_next_file_rand()
1129 f = td->files[fno]; in get_next_file_rand()
1136 if (td->nr_open_files >= td->o.open_files) in get_next_file_rand()
1139 err = td_io_open_file(td, f); in get_next_file_rand()
1150 td_io_close_file(td, f); in get_next_file_rand()
1157 static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf, in get_next_file_rr() argument
1160 unsigned int old_next_file = td->next_file; in get_next_file_rr()
1166 f = td->files[td->next_file]; in get_next_file_rr()
1168 td->next_file++; in get_next_file_rr()
1169 if (td->next_file >= td->o.nr_files) in get_next_file_rr()
1170 td->next_file = 0; in get_next_file_rr()
1181 if (td->nr_open_files >= td->o.open_files) in get_next_file_rr()
1184 err = td_io_open_file(td, f); in get_next_file_rr()
1200 td_io_close_file(td, f); in get_next_file_rr()
1203 } while (td->next_file != old_next_file); in get_next_file_rr()
1209 static struct fio_file *__get_next_file(struct thread_data *td) in __get_next_file() argument
1213 assert(td->o.nr_files <= td->files_index); in __get_next_file()
1215 if (td->nr_done_files >= td->o.nr_files) { in __get_next_file()
1217 " nr_files=%d\n", td->nr_open_files, in __get_next_file()
1218 td->nr_done_files, in __get_next_file()
1219 td->o.nr_files); in __get_next_file()
1223 f = td->file_service_file; in __get_next_file()
1225 if (td->o.file_service_type == FIO_FSERVICE_SEQ) in __get_next_file()
1227 if (td->file_service_left--) in __get_next_file()
1231 if (td->o.file_service_type == FIO_FSERVICE_RR || in __get_next_file()
1232 td->o.file_service_type == FIO_FSERVICE_SEQ) in __get_next_file()
1233 f = get_next_file_rr(td, FIO_FILE_open, FIO_FILE_closing); in __get_next_file()
1235 f = get_next_file_rand(td, FIO_FILE_open, FIO_FILE_closing); in __get_next_file()
1240 td->file_service_file = f; in __get_next_file()
1241 td->file_service_left = td->file_service_nr - 1; in __get_next_file()
1250 static struct fio_file *get_next_file(struct thread_data *td) in get_next_file() argument
1252 if (td->flags & TD_F_PROFILE_OPS) { in get_next_file()
1253 struct prof_io_ops *ops = &td->prof_io_ops; in get_next_file()
1256 return ops->get_next_file(td); in get_next_file()
1259 return __get_next_file(td); in get_next_file()
1262 static long set_io_u_file(struct thread_data *td, struct io_u *io_u) in set_io_u_file() argument
1267 f = get_next_file(td); in set_io_u_file()
1274 if (!fill_io_u(td, io_u)) in set_io_u_file()
1277 put_file_log(td, f); in set_io_u_file()
1278 td_io_close_file(td, f); in set_io_u_file()
1280 if (td->o.file_service_type & __FIO_FSERVICE_NONUNIFORM) in set_io_u_file()
1281 fio_file_reset(td, f); in set_io_u_file()
1284 td->nr_done_files++; in set_io_u_file()
1286 td->nr_done_files, td->o.nr_files); in set_io_u_file()
1293 static void lat_fatal(struct thread_data *td, struct io_completion_data *icd, in lat_fatal() argument
1296 if (!td->error) in lat_fatal()
1298 td_verror(td, ETIMEDOUT, "max latency exceeded"); in lat_fatal()
1302 static void lat_new_cycle(struct thread_data *td) in lat_new_cycle() argument
1304 fio_gettime(&td->latency_ts, NULL); in lat_new_cycle()
1305 td->latency_ios = ddir_rw_sum(td->io_blocks); in lat_new_cycle()
1306 td->latency_failed = 0; in lat_new_cycle()
1313 static bool __lat_target_failed(struct thread_data *td) in __lat_target_failed() argument
1315 if (td->latency_qd == 1) in __lat_target_failed()
1318 td->latency_qd_high = td->latency_qd; in __lat_target_failed()
1320 if (td->latency_qd == td->latency_qd_low) in __lat_target_failed()
1321 td->latency_qd_low--; in __lat_target_failed()
1323 td->latency_qd = (td->latency_qd + td->latency_qd_low) / 2; in __lat_target_failed()
1325 …dprint(FD_RATE, "Ramped down: %d %d %d\n", td->latency_qd_low, td->latency_qd, td->latency_qd_high… in __lat_target_failed()
1331 io_u_quiesce(td); in __lat_target_failed()
1332 lat_new_cycle(td); in __lat_target_failed()
1336 static bool lat_target_failed(struct thread_data *td) in lat_target_failed() argument
1338 if (td->o.latency_percentile.u.f == 100.0) in lat_target_failed()
1339 return __lat_target_failed(td); in lat_target_failed()
1341 td->latency_failed++; in lat_target_failed()
1345 void lat_target_init(struct thread_data *td) in lat_target_init() argument
1347 td->latency_end_run = 0; in lat_target_init()
1349 if (td->o.latency_target) { in lat_target_init()
1350 dprint(FD_RATE, "Latency target=%llu\n", td->o.latency_target); in lat_target_init()
1351 fio_gettime(&td->latency_ts, NULL); in lat_target_init()
1352 td->latency_qd = 1; in lat_target_init()
1353 td->latency_qd_high = td->o.iodepth; in lat_target_init()
1354 td->latency_qd_low = 1; in lat_target_init()
1355 td->latency_ios = ddir_rw_sum(td->io_blocks); in lat_target_init()
1357 td->latency_qd = td->o.iodepth; in lat_target_init()
1360 void lat_target_reset(struct thread_data *td) in lat_target_reset() argument
1362 if (!td->latency_end_run) in lat_target_reset()
1363 lat_target_init(td); in lat_target_reset()
1366 static void lat_target_success(struct thread_data *td) in lat_target_success() argument
1368 const unsigned int qd = td->latency_qd; in lat_target_success()
1369 struct thread_options *o = &td->o; in lat_target_success()
1371 td->latency_qd_low = td->latency_qd; in lat_target_success()
1378 if (td->latency_qd_high != o->iodepth) in lat_target_success()
1379 td->latency_qd = (td->latency_qd + td->latency_qd_high) / 2; in lat_target_success()
1381 td->latency_qd *= 2; in lat_target_success()
1383 if (td->latency_qd > o->iodepth) in lat_target_success()
1384 td->latency_qd = o->iodepth; in lat_target_success()
1386 dprint(FD_RATE, "Ramped up: %d %d %d\n", td->latency_qd_low, td->latency_qd, td->latency_qd_high); in lat_target_success()
1392 if (td->latency_qd == qd) { in lat_target_success()
1393 if (td->latency_end_run) { in lat_target_success()
1395 td->done = 1; in lat_target_success()
1398 io_u_quiesce(td); in lat_target_success()
1399 td->latency_end_run = 1; in lat_target_success()
1400 reset_all_stats(td); in lat_target_success()
1401 reset_io_stats(td); in lat_target_success()
1405 lat_new_cycle(td); in lat_target_success()
1411 void lat_target_check(struct thread_data *td) in lat_target_check() argument
1417 usec_window = utime_since_now(&td->latency_ts); in lat_target_check()
1418 if (usec_window < td->o.latency_window) in lat_target_check()
1421 ios = ddir_rw_sum(td->io_blocks) - td->latency_ios; in lat_target_check()
1422 success_ios = (double) (ios - td->latency_failed) / (double) ios; in lat_target_check()
1425 …dprint(FD_RATE, "Success rate: %.2f%% (target %.2f%%)\n", success_ios, td->o.latency_percentile.u.… in lat_target_check()
1427 if (success_ios >= td->o.latency_percentile.u.f) in lat_target_check()
1428 lat_target_success(td); in lat_target_check()
1430 __lat_target_failed(td); in lat_target_check()
1437 bool queue_full(const struct thread_data *td) in queue_full() argument
1439 const int qempty = io_u_qempty(&td->io_u_freelist); in queue_full()
1443 if (!td->o.latency_target) in queue_full()
1446 return td->cur_depth >= td->latency_qd; in queue_full()
1449 struct io_u *__get_io_u(struct thread_data *td) in __get_io_u() argument
1453 if (td->stop_io) in __get_io_u()
1456 td_io_u_lock(td); in __get_io_u()
1459 if (!io_u_rempty(&td->io_u_requeues)) in __get_io_u()
1460 io_u = io_u_rpop(&td->io_u_requeues); in __get_io_u()
1461 else if (!queue_full(td)) { in __get_io_u()
1462 io_u = io_u_qpop(&td->io_u_freelist); in __get_io_u()
1472 io_u_clear(td, io_u, IO_U_F_FREE | IO_U_F_NO_FILE_PUT | in __get_io_u()
1478 td->cur_depth++; in __get_io_u()
1479 assert(!(td->flags & TD_F_CHILD)); in __get_io_u()
1480 io_u_set(td, io_u, IO_U_F_IN_CUR_DEPTH); in __get_io_u()
1482 } else if (td_async_processing(td)) { in __get_io_u()
1487 assert(!(td->flags & TD_F_CHILD)); in __get_io_u()
1488 assert(!pthread_cond_wait(&td->free_cond, &td->io_u_lock)); in __get_io_u()
1492 td_io_u_unlock(td); in __get_io_u()
1496 static bool check_get_trim(struct thread_data *td, struct io_u *io_u) in check_get_trim() argument
1498 if (!(td->flags & TD_F_TRIM_BACKLOG)) in check_get_trim()
1501 if (td->trim_entries) { in check_get_trim()
1504 if (td->trim_batch) { in check_get_trim()
1505 td->trim_batch--; in check_get_trim()
1507 } else if (!(td->io_hist_len % td->o.trim_backlog) && in check_get_trim()
1508 td->last_ddir != DDIR_READ) { in check_get_trim()
1509 td->trim_batch = td->o.trim_batch; in check_get_trim()
1510 if (!td->trim_batch) in check_get_trim()
1511 td->trim_batch = td->o.trim_backlog; in check_get_trim()
1515 if (get_trim && get_next_trim(td, io_u)) in check_get_trim()
1522 static bool check_get_verify(struct thread_data *td, struct io_u *io_u) in check_get_verify() argument
1524 if (!(td->flags & TD_F_VER_BACKLOG)) in check_get_verify()
1527 if (td->io_hist_len) { in check_get_verify()
1530 if (td->verify_batch) in check_get_verify()
1532 else if (!(td->io_hist_len % td->o.verify_backlog) && in check_get_verify()
1533 td->last_ddir != DDIR_READ) { in check_get_verify()
1534 td->verify_batch = td->o.verify_batch; in check_get_verify()
1535 if (!td->verify_batch) in check_get_verify()
1536 td->verify_batch = td->o.verify_backlog; in check_get_verify()
1540 if (get_verify && !get_next_verify(td, io_u)) { in check_get_verify()
1541 td->verify_batch--; in check_get_verify()
1592 struct io_u *get_io_u(struct thread_data *td) in get_io_u() argument
1599 io_u = __get_io_u(td); in get_io_u()
1605 if (check_get_verify(td, io_u)) in get_io_u()
1607 if (check_get_trim(td, io_u)) in get_io_u()
1619 if (td->flags & TD_F_READ_IOLOG) { in get_io_u()
1620 if (read_iolog_get(td, io_u)) in get_io_u()
1622 } else if (set_io_u_file(td, io_u)) { in get_io_u()
1637 if (!io_u->buflen && !td_ioengine_flagged(td, FIO_NOIO)) { in get_io_u()
1646 if (td->flags & TD_F_REFILL_BUFFERS) { in get_io_u()
1647 io_u_fill_buffer(td, io_u, in get_io_u()
1648 td->o.min_bs[DDIR_WRITE], in get_io_u()
1650 } else if ((td->flags & TD_F_SCRAMBLE_BUFFERS) && in get_io_u()
1651 !(td->flags & TD_F_COMPRESS)) in get_io_u()
1653 if (td->flags & TD_F_VER_NONE) { in get_io_u()
1654 populate_verify_io_u(td, io_u); in get_io_u()
1674 if (!td_io_prep(td, io_u)) { in get_io_u()
1675 if (!td->o.disable_lat) in get_io_u()
1685 put_io_u(td, io_u); in get_io_u()
1689 static void __io_u_log_error(struct thread_data *td, struct io_u *io_u) in __io_u_log_error() argument
1693 if (td_non_fatal_error(td, eb, io_u->error) && !td->o.error_dump) in __io_u_log_error()
1703 if (td->io_ops->errdetails) { in __io_u_log_error()
1704 char *err = td->io_ops->errdetails(io_u); in __io_u_log_error()
1710 if (!td->error) in __io_u_log_error()
1711 td_verror(td, io_u->error, "io_u error"); in __io_u_log_error()
1714 void io_u_log_error(struct thread_data *td, struct io_u *io_u) in io_u_log_error() argument
1716 __io_u_log_error(td, io_u); in io_u_log_error()
1717 if (td->parent) in io_u_log_error()
1718 __io_u_log_error(td->parent, io_u); in io_u_log_error()
1721 static inline bool gtod_reduce(struct thread_data *td) in gtod_reduce() argument
1723 return (td->o.disable_clat && td->o.disable_slat && td->o.disable_bw) in gtod_reduce()
1724 || td->o.gtod_reduce; in gtod_reduce()
1727 static void account_io_completion(struct thread_data *td, struct io_u *io_u, in account_io_completion() argument
1731 const int no_reduce = !gtod_reduce(td); in account_io_completion()
1734 if (td->parent) in account_io_completion()
1735 td = td->parent; in account_io_completion()
1737 if (!td->o.stats) in account_io_completion()
1743 if (!td->o.disable_lat) { in account_io_completion()
1747 add_lat_sample(td, idx, tusec, bytes, io_u->offset); in account_io_completion()
1749 if (td->flags & TD_F_PROFILE_OPS) { in account_io_completion()
1750 struct prof_io_ops *ops = &td->prof_io_ops; in account_io_completion()
1753 icd->error = ops->io_u_lat(td, tusec); in account_io_completion()
1756 if (td->o.max_latency && tusec > td->o.max_latency) in account_io_completion()
1757 lat_fatal(td, icd, tusec, td->o.max_latency); in account_io_completion()
1758 if (td->o.latency_target && tusec > td->o.latency_target) { in account_io_completion()
1759 if (lat_target_failed(td)) in account_io_completion()
1760 lat_fatal(td, icd, tusec, td->o.latency_target); in account_io_completion()
1765 if (!td->o.disable_clat) { in account_io_completion()
1766 add_clat_sample(td, idx, lusec, bytes, io_u->offset); in account_io_completion()
1767 io_u_mark_latency(td, lusec); in account_io_completion()
1770 if (!td->o.disable_bw && per_unit_log(td->bw_log)) in account_io_completion()
1771 add_bw_sample(td, io_u, bytes, lusec); in account_io_completion()
1773 if (no_reduce && per_unit_log(td->iops_log)) in account_io_completion()
1774 add_iops_sample(td, io_u, bytes); in account_io_completion()
1777 if (td->ts.nr_block_infos && io_u->ddir == DDIR_TRIM) { in account_io_completion()
1778 uint32_t *info = io_u_block_info(td, io_u); in account_io_completion()
1791 static void file_log_write_comp(const struct thread_data *td, struct fio_file *f, in file_log_write_comp() argument
1809 if (f->last_write_idx == td->o.iodepth) in file_log_write_comp()
1813 static void io_completed(struct thread_data *td, struct io_u **io_u_ptr, in io_completed() argument
1823 io_u_clear(td, io_u, IO_U_F_FLIGHT | IO_U_F_BUSY_OK); in io_completed()
1833 unlog_io_piece(td, io_u); in io_completed()
1841 td->last_was_sync = 1; in io_completed()
1849 td->last_was_sync = 0; in io_completed()
1850 td->last_ddir = ddir; in io_completed()
1856 td->io_blocks[ddir]++; in io_completed()
1857 td->this_io_blocks[ddir]++; in io_completed()
1858 td->io_bytes[ddir] += bytes; in io_completed()
1861 td->this_io_bytes[ddir] += bytes; in io_completed()
1864 file_log_write_comp(td, f, io_u->offset, bytes); in io_completed()
1866 if (ramp_time_over(td) && (td->runstate == TD_RUNNING || in io_completed()
1867 td->runstate == TD_VERIFYING)) in io_completed()
1868 account_io_completion(td, io_u, icd, ddir, bytes); in io_completed()
1873 ret = io_u->end_io(td, io_u_ptr); in io_completed()
1880 io_u_log_error(td, io_u); in io_completed()
1885 if (!td_non_fatal_error(td, eb, icd->error)) in io_completed()
1892 update_error_count(td, icd->error); in io_completed()
1893 td_clear_error(td); in io_completed()
1900 static void init_icd(struct thread_data *td, struct io_completion_data *icd, in init_icd() argument
1905 if (!gtod_reduce(td)) in init_icd()
1915 static void ios_completed(struct thread_data *td, in ios_completed() argument
1922 io_u = td->io_ops->event(td, i); in ios_completed()
1924 io_completed(td, &io_u, icd); in ios_completed()
1927 put_io_u(td, io_u); in ios_completed()
1934 int io_u_sync_complete(struct thread_data *td, struct io_u *io_u) in io_u_sync_complete() argument
1939 init_icd(td, &icd, 1); in io_u_sync_complete()
1940 io_completed(td, &io_u, &icd); in io_u_sync_complete()
1943 put_io_u(td, io_u); in io_u_sync_complete()
1946 td_verror(td, icd.error, "io_u_sync_complete"); in io_u_sync_complete()
1951 td->bytes_done[ddir] += icd.bytes_done[ddir]; in io_u_sync_complete()
1959 int io_u_queued_complete(struct thread_data *td, int min_evts) in io_u_queued_complete() argument
1970 else if (min_evts > td->cur_depth) in io_u_queued_complete()
1971 min_evts = td->cur_depth; in io_u_queued_complete()
1975 ret = td_io_getevents(td, min_evts, td->o.iodepth_batch_complete_max, tvp); in io_u_queued_complete()
1977 td_verror(td, -ret, "td_io_getevents"); in io_u_queued_complete()
1982 init_icd(td, &icd, ret); in io_u_queued_complete()
1983 ios_completed(td, &icd); in io_u_queued_complete()
1985 td_verror(td, icd.error, "io_u_queued_complete"); in io_u_queued_complete()
1990 td->bytes_done[ddir] += icd.bytes_done[ddir]; in io_u_queued_complete()
1998 void io_u_queued(struct thread_data *td, struct io_u *io_u) in io_u_queued() argument
2000 if (!td->o.disable_slat && ramp_time_over(td) && td->o.stats) { in io_u_queued()
2005 if (td->parent) in io_u_queued()
2006 td = td->parent; in io_u_queued()
2008 add_slat_sample(td, io_u->ddir, slat_time, io_u->xfer_buflen, in io_u_queued()
2016 static struct frand_state *get_buf_state(struct thread_data *td) in get_buf_state() argument
2020 if (!td->o.dedupe_percentage) in get_buf_state()
2021 return &td->buf_state; in get_buf_state()
2022 else if (td->o.dedupe_percentage == 100) { in get_buf_state()
2023 frand_copy(&td->buf_state_prev, &td->buf_state); in get_buf_state()
2024 return &td->buf_state; in get_buf_state()
2027 v = rand32_between(&td->dedupe_state, 1, 100); in get_buf_state()
2029 if (v <= td->o.dedupe_percentage) in get_buf_state()
2030 return &td->buf_state_prev; in get_buf_state()
2032 return &td->buf_state; in get_buf_state()
2035 static void save_buf_state(struct thread_data *td, struct frand_state *rs) in save_buf_state() argument
2037 if (td->o.dedupe_percentage == 100) in save_buf_state()
2038 frand_copy(rs, &td->buf_state_prev); in save_buf_state()
2039 else if (rs == &td->buf_state) in save_buf_state()
2040 frand_copy(&td->buf_state_prev, rs); in save_buf_state()
2043 void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write, in fill_io_buffer() argument
2046 struct thread_options *o = &td->o; in fill_io_buffer()
2052 unsigned int perc = td->o.compress_percentage; in fill_io_buffer()
2058 rs = get_buf_state(td); in fill_io_buffer()
2064 td->o.compress_chunk); in fill_io_buffer()
2077 save_buf_state(td, rs); in fill_io_buffer()
2080 fill_buffer_pattern(td, buf, max_bs); in fill_io_buffer()
2084 fill_random_buf(get_buf_state(td), buf, max_bs); in fill_io_buffer()
2090 void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u, in io_u_fill_buffer() argument
2094 fill_io_buffer(td, io_u->buf, min_write, max_bs); in io_u_fill_buffer()
2097 static int do_sync_file_range(const struct thread_data *td, in do_sync_file_range() argument
2108 return sync_file_range(f->fd, offset, nbytes, td->o.sync_file_range); in do_sync_file_range()
2111 int do_io_u_sync(const struct thread_data *td, struct io_u *io_u) in do_io_u_sync() argument
2125 ret = do_sync_file_range(td, io_u->file); in do_io_u_sync()
2137 int do_io_u_trim(const struct thread_data *td, struct io_u *io_u) in do_io_u_trim() argument