Lines Matching refs:td
373 static void set_cmd_options(struct thread_data *td) in set_cmd_options() argument
375 struct thread_options *o = &td->o; in set_cmd_options()
387 struct thread_data *td; in get_new_job() local
403 td = &threads[thread_number++]; in get_new_job()
404 *td = *parent; in get_new_job()
406 td->io_ops = NULL; in get_new_job()
408 td->eo = NULL; in get_new_job()
410 td->o.uid = td->o.gid = -1U; in get_new_job()
412 dup_files(td, parent); in get_new_job()
413 fio_options_mem_dupe(td); in get_new_job()
415 profile_add_hooks(td); in get_new_job()
417 td->thread_number = thread_number; in get_new_job()
418 td->subjob_number = 0; in get_new_job()
421 td->o.name = strdup(jobname); in get_new_job()
426 set_cmd_options(td); in get_new_job()
427 return td; in get_new_job()
430 static void put_job(struct thread_data *td) in put_job() argument
432 if (td == &def_thread) in put_job()
435 profile_td_exit(td); in put_job()
436 flow_exit_job(td); in put_job()
438 if (td->error) in put_job()
439 log_info("fio: %s\n", td->verror); in put_job()
441 fio_options_free(td); in put_job()
442 if (td->io_ops) in put_job()
443 free_ioengine(td); in put_job()
445 if (td->o.name) in put_job()
446 free(td->o.name); in put_job()
448 memset(&threads[td->thread_number - 1], 0, sizeof(*td)); in put_job()
452 static int __setup_rate(struct thread_data *td, enum fio_ddir ddir) in __setup_rate() argument
454 unsigned int bs = td->o.min_bs[ddir]; in __setup_rate()
458 if (td->o.rate[ddir]) in __setup_rate()
459 td->rate_bps[ddir] = td->o.rate[ddir]; in __setup_rate()
461 td->rate_bps[ddir] = td->o.rate_iops[ddir] * bs; in __setup_rate()
463 if (!td->rate_bps[ddir]) { in __setup_rate()
468 td->rate_pending_usleep[ddir] = 0; in __setup_rate()
472 static int setup_rate(struct thread_data *td) in setup_rate() argument
476 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ]) in setup_rate()
477 ret = __setup_rate(td, DDIR_READ); in setup_rate()
478 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE]) in setup_rate()
479 ret |= __setup_rate(td, DDIR_WRITE); in setup_rate()
480 if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM]) in setup_rate()
481 ret |= __setup_rate(td, DDIR_TRIM); in setup_rate()
496 static unsigned long long get_rand_start_delay(struct thread_data *td) in get_rand_start_delay() argument
501 delayrange = td->o.start_delay_high - td->o.start_delay; in get_rand_start_delay()
503 r = __rand(&td->delay_state); in get_rand_start_delay()
506 delayrange += td->o.start_delay; in get_rand_start_delay()
514 static int fixup_options(struct thread_data *td) in fixup_options() argument
516 struct thread_options *o = &td->o; in fixup_options()
552 if (td_read(td) || td_rw(td)) in fixup_options()
574 if (!o->ba[DDIR_READ] || !td_random(td)) in fixup_options()
576 if (!o->ba[DDIR_WRITE] || !td_random(td)) in fixup_options()
578 if (!o->ba[DDIR_TRIM] || !td_random(td)) in fixup_options()
594 o->start_delay = get_rand_start_delay(td); in fixup_options()
602 if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO)) in fixup_options()
623 if (o->nr_files > td->files_index) in fixup_options()
624 o->nr_files = td->files_index; in fixup_options()
656 if (td_write(td) && o->do_verify && o->numjobs > 1) { in fixup_options()
674 else if (td_read(td) && o->verify_interval > o->min_bs[DDIR_READ]) in fixup_options()
680 if (td->io_ops->flags & FIO_PIPEIO) { in fixup_options()
688 if (td->io_ops->flags & FIO_BIT_BASED) in fixup_options()
711 if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) { in fixup_options()
723 if (td->o.compress_percentage == 100) { in fixup_options()
724 td->o.zero_buffers = 1; in fixup_options()
725 td->o.compress_percentage = 0; in fixup_options()
732 if (td->o.random_distribution != FIO_RAND_DIST_RANDOM) in fixup_options()
733 td->o.norandommap = 1; in fixup_options()
738 if (o->size && o->size < td_min_bs(td)) { in fixup_options()
746 if (td->o.oatomic) in fixup_options()
747 td->o.odirect = 1; in fixup_options()
752 if (td->o.rand_seed) in fixup_options()
753 td->o.rand_repeatable = 0; in fixup_options()
755 if ((td->io_ops->flags & FIO_NOEXTEND) && td->o.file_append) { in fixup_options()
756 log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name); in fixup_options()
766 td->loops = o->loops; in fixup_options()
767 if (!td->loops) in fixup_options()
768 td->loops = 1; in fixup_options()
823 static void td_fill_rand_seeds_internal(struct thread_data *td) in td_fill_rand_seeds_internal() argument
825 init_rand_seed(&td->bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF]); in td_fill_rand_seeds_internal()
826 init_rand_seed(&td->verify_state, td->rand_seeds[FIO_RAND_VER_OFF]); in td_fill_rand_seeds_internal()
827 init_rand_seed(&td->rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF]); in td_fill_rand_seeds_internal()
829 if (td->o.file_service_type == FIO_FSERVICE_RANDOM) in td_fill_rand_seeds_internal()
830 init_rand_seed(&td->next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF]); in td_fill_rand_seeds_internal()
832 init_rand_seed(&td->file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF]); in td_fill_rand_seeds_internal()
833 init_rand_seed(&td->trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF]); in td_fill_rand_seeds_internal()
834 init_rand_seed(&td->delay_state, td->rand_seeds[FIO_RAND_START_DELAY]); in td_fill_rand_seeds_internal()
836 if (!td_random(td)) in td_fill_rand_seeds_internal()
839 if (td->o.rand_repeatable) in td_fill_rand_seeds_internal()
840 td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number; in td_fill_rand_seeds_internal()
842 init_rand_seed(&td->random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF]); in td_fill_rand_seeds_internal()
843 init_rand_seed(&td->seq_rand_state[DDIR_READ], td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF]); in td_fill_rand_seeds_internal()
844 init_rand_seed(&td->seq_rand_state[DDIR_WRITE], td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF]); in td_fill_rand_seeds_internal()
845 init_rand_seed(&td->seq_rand_state[DDIR_TRIM], td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF]); in td_fill_rand_seeds_internal()
848 void td_fill_rand_seeds(struct thread_data *td) in td_fill_rand_seeds() argument
850 if (td->o.allrand_repeatable) { in td_fill_rand_seeds()
854 td->rand_seeds[i] = FIO_RANDSEED * td->thread_number in td_fill_rand_seeds()
858 td_fill_rand_seeds_internal(td); in td_fill_rand_seeds()
860 init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF]); in td_fill_rand_seeds()
861 frand_copy(&td->buf_state_prev, &td->buf_state); in td_fill_rand_seeds()
863 init_rand_seed(&td->dedupe_state, td->rand_seeds[FIO_DEDUPE_OFF]); in td_fill_rand_seeds()
870 int ioengine_load(struct thread_data *td) in ioengine_load() argument
877 if (td->io_ops) in ioengine_load()
879 if (!td->o.ioengine) { in ioengine_load()
884 engine = get_engine_name(td->o.ioengine); in ioengine_load()
885 td->io_ops = load_ioengine(td, engine); in ioengine_load()
886 if (!td->io_ops) { in ioengine_load()
891 if (td->io_ops->option_struct_size && td->io_ops->options) { in ioengine_load()
898 void *origeo = td->eo; in ioengine_load()
902 if (!origeo && td != &def_thread && def_thread.eo && in ioengine_load()
903 def_thread.io_ops->options == td->io_ops->options) in ioengine_load()
906 options_init(td->io_ops->options); in ioengine_load()
907 td->eo = malloc(td->io_ops->option_struct_size); in ioengine_load()
914 memcpy(td->eo, origeo, td->io_ops->option_struct_size); in ioengine_load()
915 options_mem_dupe(td->eo, td->io_ops->options); in ioengine_load()
917 memset(td->eo, 0, td->io_ops->option_struct_size); in ioengine_load()
918 fill_default_options(td->eo, td->io_ops->options); in ioengine_load()
920 *(struct thread_data **)td->eo = td; in ioengine_load()
926 static void init_flags(struct thread_data *td) in init_flags() argument
928 struct thread_options *o = &td->o; in init_flags()
931 td->flags |= TD_F_VER_BACKLOG; in init_flags()
933 td->flags |= TD_F_TRIM_BACKLOG; in init_flags()
935 td->flags |= TD_F_READ_IOLOG; in init_flags()
937 td->flags |= TD_F_REFILL_BUFFERS; in init_flags()
942 td->flags |= TD_F_SCRAMBLE_BUFFERS; in init_flags()
949 td->flags |= TD_F_SCRAMBLE_BUFFERS; in init_flags()
951 td->flags |= TD_F_VER_NONE; in init_flags()
954 static int setup_random_seeds(struct thread_data *td) in setup_random_seeds() argument
959 if (!td->o.rand_repeatable && !td->o.rand_seed) in setup_random_seeds()
960 return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds)); in setup_random_seeds()
962 if (!td->o.rand_seed) in setup_random_seeds()
965 seed = td->o.rand_seed; in setup_random_seeds()
971 td->rand_seeds[i] = seed; in setup_random_seeds()
975 td_fill_rand_seeds(td); in setup_random_seeds()
1109 static int add_job(struct thread_data *td, const char *jobname, int job_add_num, in add_job() argument
1115 struct thread_options *o = &td->o; in add_job()
1121 if (td == &def_thread) in add_job()
1124 init_flags(td); in add_job()
1130 put_job(td); in add_job()
1134 td->client_type = client_type; in add_job()
1136 if (profile_td_init(td)) in add_job()
1139 if (ioengine_load(td)) in add_job()
1143 td->io_ops->flags |= FIO_RAWIO; in add_job()
1146 if (!o->filename && !td->files_index && !o->read_iolog_file) { in add_job()
1150 add_file(td, jobname, job_add_num, 0); in add_job()
1153 add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0); in add_job()
1157 if (fixup_options(td)) in add_job()
1160 flow_init_job(td); in add_job()
1166 if (td->eo) in add_job()
1167 *(struct thread_data **)td->eo = NULL; in add_job()
1169 if (td->io_ops->flags & FIO_DISKLESSIO) { in add_job()
1172 for_each_file(td, f, i) in add_job()
1176 td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED); in add_job()
1178 td->ts.clat_percentiles = o->clat_percentiles; in add_job()
1179 td->ts.percentile_precision = o->percentile_precision; in add_job()
1180 memcpy(td->ts.percentile_list, o->percentile_list, sizeof(o->percentile_list)); in add_job()
1183 td->ts.clat_stat[i].min_val = ULONG_MAX; in add_job()
1184 td->ts.slat_stat[i].min_val = ULONG_MAX; in add_job()
1185 td->ts.lat_stat[i].min_val = ULONG_MAX; in add_job()
1186 td->ts.bw_stat[i].min_val = ULONG_MAX; in add_job()
1188 td->ddir_seq_nr = o->ddir_seq_nr; in add_job()
1195 td->groupid = groupid; in add_job()
1198 if (setup_random_seeds(td)) { in add_job()
1199 td_verror(td, errno, "init_random_state"); in add_job()
1203 if (setup_rate(td)) in add_job()
1208 .td = td, in add_job()
1223 o->lat_log_file, td->thread_number, suf); in add_job()
1224 setup_log(&td->lat_log, &p, logname); in add_job()
1226 o->lat_log_file, td->thread_number, suf); in add_job()
1227 setup_log(&td->slat_log, &p, logname); in add_job()
1229 o->lat_log_file, td->thread_number, suf); in add_job()
1230 setup_log(&td->clat_log, &p, logname); in add_job()
1234 .td = td, in add_job()
1249 o->bw_log_file, td->thread_number, suf); in add_job()
1250 setup_log(&td->bw_log, &p, logname); in add_job()
1254 .td = td, in add_job()
1269 o->iops_log_file, td->thread_number, suf); in add_job()
1270 setup_log(&td->iops_log, &p, logname); in add_job()
1279 fio_server_send_add_job(td); in add_job()
1281 if (!(td->io_ops->flags & FIO_NOIO)) { in add_job()
1295 log_info("%s: (g=%d): rw=%s, ", td->o.name, in add_job()
1296 td->groupid, in add_job()
1307 td->io_ops->name, o->iodepth); in add_job()
1326 struct thread_data *td_new = get_new_job(0, td, 1, jobname); in add_job()
1361 put_job(td); in add_job()
1370 struct thread_data *td, *td_parent; in add_job_opts() local
1375 td_parent = td = NULL; in add_job_opts()
1379 if (td) in add_job_opts()
1380 add_job(td, jobname, 0, 0, client_type); in add_job_opts()
1381 td = NULL; in add_job_opts()
1386 else if (!in_global && !td) { in add_job_opts()
1389 td = get_new_job(0, td_parent, 0, jobname); in add_job_opts()
1394 fio_options_parse(td, (char **) &o[i], 1, 0); in add_job_opts()
1398 if (td) in add_job_opts()
1399 add_job(td, jobname, 0, 0, client_type); in add_job_opts()
1437 int __parse_jobs_ini(struct thread_data *td, in __parse_jobs_ini() argument
1453 assert(td || !nested); in __parse_jobs_ini()
1467 if (td) in __parse_jobs_ini()
1468 td_verror(td, __err, "job file open"); in __parse_jobs_ini()
1550 td = get_new_job(global, &def_thread, 0, name); in __parse_jobs_ini()
1551 if (!td) { in __parse_jobs_ini()
1560 td->o.stonewall = stonewall; in __parse_jobs_ini()
1607 if ((ret = __parse_jobs_ini(td, filename, in __parse_jobs_ini()
1634 ret = fio_options_parse(td, opts, num_opts, dump_cmdline); in __parse_jobs_ini()
1636 ret = add_job(td, name, 0, 0, type); in __parse_jobs_ini()
1639 put_job(td); in __parse_jobs_ini()
1941 struct thread_data *td = NULL; in parse_cmd_line() local
2114 if (!strncmp(opt, "name", 4) && td) { in parse_cmd_line()
2115 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); in parse_cmd_line()
2118 td = NULL; in parse_cmd_line()
2121 if (!td) { in parse_cmd_line()
2131 td = get_new_job(global, &def_thread, 1, NULL); in parse_cmd_line()
2132 if (!td || ioengine_load(td)) { in parse_cmd_line()
2133 if (td) { in parse_cmd_line()
2134 put_job(td); in parse_cmd_line()
2135 td = NULL; in parse_cmd_line()
2140 fio_options_set_ioengine_opts(l_opts, td); in parse_cmd_line()
2148 ret = fio_cmd_option_parse(td, opt, val); in parse_cmd_line()
2151 if (td) { in parse_cmd_line()
2152 put_job(td); in parse_cmd_line()
2153 td = NULL; in parse_cmd_line()
2159 free_ioengine(td); in parse_cmd_line()
2160 if (ioengine_load(td)) { in parse_cmd_line()
2161 put_job(td); in parse_cmd_line()
2162 td = NULL; in parse_cmd_line()
2166 fio_options_set_ioengine_opts(l_opts, td); in parse_cmd_line()
2174 if (!td) in parse_cmd_line()
2177 ret = fio_cmd_ioengine_option_parse(td, opt, val); in parse_cmd_line()
2328 if (td) { in parse_cmd_line()
2330 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); in parse_cmd_line()