Lines Matching refs:td
386 static void dump_opt_list(struct thread_data *td) in dump_opt_list() argument
391 if (flist_empty(&td->opt_list)) in dump_opt_list()
394 flist_for_each(entry, &td->opt_list) { in dump_opt_list()
400 static void fio_dump_options_free(struct thread_data *td) in fio_dump_options_free() argument
402 while (!flist_empty(&td->opt_list)) { in fio_dump_options_free()
405 p = flist_first_entry(&td->opt_list, struct print_option, list); in fio_dump_options_free()
440 struct thread_data *td; in get_new_job() local
454 td = &threads[thread_number++]; in get_new_job()
455 *td = *parent; in get_new_job()
457 INIT_FLIST_HEAD(&td->opt_list); in get_new_job()
459 copy_opt_list(td, parent); in get_new_job()
461 td->io_ops = NULL; in get_new_job()
462 td->io_ops_init = 0; in get_new_job()
464 td->eo = NULL; in get_new_job()
466 td->o.uid = td->o.gid = -1U; in get_new_job()
468 dup_files(td, parent); in get_new_job()
469 fio_options_mem_dupe(td); in get_new_job()
471 profile_add_hooks(td); in get_new_job()
473 td->thread_number = thread_number; in get_new_job()
474 td->subjob_number = 0; in get_new_job()
477 td->o.name = strdup(jobname); in get_new_job()
482 return td; in get_new_job()
485 static void put_job(struct thread_data *td) in put_job() argument
487 if (td == &def_thread) in put_job()
490 profile_td_exit(td); in put_job()
491 flow_exit_job(td); in put_job()
493 if (td->error) in put_job()
494 log_info("fio: %s\n", td->verror); in put_job()
496 fio_options_free(td); in put_job()
497 fio_dump_options_free(td); in put_job()
498 if (td->io_ops) in put_job()
499 free_ioengine(td); in put_job()
501 if (td->o.name) in put_job()
502 free(td->o.name); in put_job()
504 memset(&threads[td->thread_number - 1], 0, sizeof(*td)); in put_job()
508 static int __setup_rate(struct thread_data *td, enum fio_ddir ddir) in __setup_rate() argument
510 unsigned int bs = td->o.min_bs[ddir]; in __setup_rate()
514 if (td->o.rate[ddir]) in __setup_rate()
515 td->rate_bps[ddir] = td->o.rate[ddir]; in __setup_rate()
517 td->rate_bps[ddir] = (uint64_t) td->o.rate_iops[ddir] * bs; in __setup_rate()
519 if (!td->rate_bps[ddir]) { in __setup_rate()
524 td->rate_next_io_time[ddir] = 0; in __setup_rate()
525 td->rate_io_issue_bytes[ddir] = 0; in __setup_rate()
526 td->last_usec[ddir] = 0; in __setup_rate()
530 static int setup_rate(struct thread_data *td) in setup_rate() argument
534 if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ]) in setup_rate()
535 ret = __setup_rate(td, DDIR_READ); in setup_rate()
536 if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE]) in setup_rate()
537 ret |= __setup_rate(td, DDIR_WRITE); in setup_rate()
538 if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM]) in setup_rate()
539 ret |= __setup_rate(td, DDIR_TRIM); in setup_rate()
554 static unsigned long long get_rand_start_delay(struct thread_data *td) in get_rand_start_delay() argument
560 delayrange = td->o.start_delay_high - td->o.start_delay; in get_rand_start_delay()
562 frand_max = rand_max(&td->delay_state); in get_rand_start_delay()
563 r = __rand(&td->delay_state); in get_rand_start_delay()
566 delayrange += td->o.start_delay; in get_rand_start_delay()
585 static int fixup_options(struct thread_data *td) in fixup_options() argument
587 struct thread_options *o = &td->o; in fixup_options()
623 if (td_read(td)) in fixup_options()
645 if (!o->ba[DDIR_READ] || !td_random(td)) in fixup_options()
647 if (!o->ba[DDIR_WRITE] || !td_random(td)) in fixup_options()
649 if (!o->ba[DDIR_TRIM] || !td_random(td)) in fixup_options()
665 o->start_delay = get_rand_start_delay(td); in fixup_options()
673 if (o->bs_unaligned && (o->odirect || td_ioengine_flagged(td, FIO_RAWIO))) in fixup_options()
701 if (o->nr_files > td->files_index) in fixup_options()
702 o->nr_files = td->files_index; in fixup_options()
734 if (td_write(td) && o->do_verify && o->numjobs > 1) { in fixup_options()
754 else if (td_read(td) && o->verify_interval > o->min_bs[DDIR_READ]) in fixup_options()
770 if (td_ioengine_flagged(td, FIO_PIPEIO)) { in fixup_options()
778 if (td_ioengine_flagged(td, FIO_BIT_BASED)) in fixup_options()
801 if (td_ioengine_flagged(td, FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) { in fixup_options()
827 if (td->o.random_distribution != FIO_RAND_DIST_RANDOM) in fixup_options()
828 td->o.norandommap = 1; in fixup_options()
833 if (o->size && o->size < td_min_bs(td)) { in fixup_options()
835 (unsigned long long) o->size, td_min_bs(td)); in fixup_options()
842 if (td->o.oatomic) in fixup_options()
843 td->o.odirect = 1; in fixup_options()
848 if (fio_option_is_set(&td->o, rand_seed)) in fixup_options()
849 td->o.rand_repeatable = 0; in fixup_options()
851 if (td_ioengine_flagged(td, FIO_NOEXTEND) && td->o.file_append) { in fixup_options()
852 log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name); in fixup_options()
862 td->loops = o->loops; in fixup_options()
863 if (!td->loops) in fixup_options()
864 td->loops = 1; in fixup_options()
866 if (td->o.block_error_hist && td->o.nr_files != 1) { in fixup_options()
869 "provided\n", td->o.nr_files); in fixup_options()
890 static void init_rand_file_service(struct thread_data *td) in init_rand_file_service() argument
892 unsigned long nranges = td->o.nr_files << FIO_FSERVICE_SHIFT; in init_rand_file_service()
893 const unsigned int seed = td->rand_seeds[FIO_RAND_FILE_OFF]; in init_rand_file_service()
895 if (td->o.file_service_type == FIO_FSERVICE_ZIPF) { in init_rand_file_service()
896 zipf_init(&td->next_file_zipf, nranges, td->zipf_theta, seed); in init_rand_file_service()
897 zipf_disable_hash(&td->next_file_zipf); in init_rand_file_service()
898 } else if (td->o.file_service_type == FIO_FSERVICE_PARETO) { in init_rand_file_service()
899 pareto_init(&td->next_file_zipf, nranges, td->pareto_h, seed); in init_rand_file_service()
900 zipf_disable_hash(&td->next_file_zipf); in init_rand_file_service()
901 } else if (td->o.file_service_type == FIO_FSERVICE_GAUSS) { in init_rand_file_service()
902 gauss_init(&td->next_file_gauss, nranges, td->gauss_dev, seed); in init_rand_file_service()
903 gauss_disable_hash(&td->next_file_gauss); in init_rand_file_service()
907 void td_fill_verify_state_seed(struct thread_data *td) in td_fill_verify_state_seed() argument
911 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64) in td_fill_verify_state_seed()
916 init_rand_seed(&td->verify_state, td->rand_seeds[FIO_RAND_VER_OFF], in td_fill_verify_state_seed()
920 static void td_fill_rand_seeds_internal(struct thread_data *td, bool use64) in td_fill_rand_seeds_internal() argument
924 init_rand_seed(&td->bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF], use64); in td_fill_rand_seeds_internal()
925 td_fill_verify_state_seed(td); in td_fill_rand_seeds_internal()
926 init_rand_seed(&td->rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF], false); in td_fill_rand_seeds_internal()
928 if (td->o.file_service_type == FIO_FSERVICE_RANDOM) in td_fill_rand_seeds_internal()
929 init_rand_seed(&td->next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF], use64); in td_fill_rand_seeds_internal()
930 else if (td->o.file_service_type & __FIO_FSERVICE_NONUNIFORM) in td_fill_rand_seeds_internal()
931 init_rand_file_service(td); in td_fill_rand_seeds_internal()
933 init_rand_seed(&td->file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF], use64); in td_fill_rand_seeds_internal()
934 init_rand_seed(&td->trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF], use64); in td_fill_rand_seeds_internal()
935 init_rand_seed(&td->delay_state, td->rand_seeds[FIO_RAND_START_DELAY], use64); in td_fill_rand_seeds_internal()
936 init_rand_seed(&td->poisson_state[0], td->rand_seeds[FIO_RAND_POISSON_OFF], 0); in td_fill_rand_seeds_internal()
937 init_rand_seed(&td->poisson_state[1], td->rand_seeds[FIO_RAND_POISSON2_OFF], 0); in td_fill_rand_seeds_internal()
938 init_rand_seed(&td->poisson_state[2], td->rand_seeds[FIO_RAND_POISSON3_OFF], 0); in td_fill_rand_seeds_internal()
939 init_rand_seed(&td->dedupe_state, td->rand_seeds[FIO_DEDUPE_OFF], false); in td_fill_rand_seeds_internal()
940 init_rand_seed(&td->zone_state, td->rand_seeds[FIO_RAND_ZONE_OFF], false); in td_fill_rand_seeds_internal()
942 if (!td_random(td)) in td_fill_rand_seeds_internal()
945 if (td->o.rand_repeatable) in td_fill_rand_seeds_internal()
946 td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number; in td_fill_rand_seeds_internal()
948 init_rand_seed(&td->random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF], use64); in td_fill_rand_seeds_internal()
951 struct frand_state *s = &td->seq_rand_state[i]; in td_fill_rand_seeds_internal()
953 init_rand_seed(s, td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], false); in td_fill_rand_seeds_internal()
957 void td_fill_rand_seeds(struct thread_data *td) in td_fill_rand_seeds() argument
961 if (td->o.allrand_repeatable) { in td_fill_rand_seeds()
965 td->rand_seeds[i] = FIO_RANDSEED * td->thread_number in td_fill_rand_seeds()
969 if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64) in td_fill_rand_seeds()
974 td_fill_rand_seeds_internal(td, use64); in td_fill_rand_seeds()
976 init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF], use64); in td_fill_rand_seeds()
977 frand_copy(&td->buf_state_prev, &td->buf_state); in td_fill_rand_seeds()
984 int ioengine_load(struct thread_data *td) in ioengine_load() argument
991 if (td->io_ops) in ioengine_load()
993 if (!td->o.ioengine) { in ioengine_load()
998 engine = get_engine_name(td->o.ioengine); in ioengine_load()
999 td->io_ops = load_ioengine(td, engine); in ioengine_load()
1000 if (!td->io_ops) { in ioengine_load()
1005 if (td->io_ops->option_struct_size && td->io_ops->options) { in ioengine_load()
1012 void *origeo = td->eo; in ioengine_load()
1016 if (!origeo && td != &def_thread && def_thread.eo && in ioengine_load()
1017 def_thread.io_ops->options == td->io_ops->options) in ioengine_load()
1020 options_init(td->io_ops->options); in ioengine_load()
1021 td->eo = malloc(td->io_ops->option_struct_size); in ioengine_load()
1028 memcpy(td->eo, origeo, td->io_ops->option_struct_size); in ioengine_load()
1029 options_mem_dupe(td->io_ops->options, td->eo); in ioengine_load()
1031 memset(td->eo, 0, td->io_ops->option_struct_size); in ioengine_load()
1032 fill_default_options(td->eo, td->io_ops->options); in ioengine_load()
1034 *(struct thread_data **)td->eo = td; in ioengine_load()
1037 if (td->o.odirect) in ioengine_load()
1038 td->io_ops->flags |= FIO_RAWIO; in ioengine_load()
1040 td_set_ioengine_flags(td); in ioengine_load()
1044 static void init_flags(struct thread_data *td) in init_flags() argument
1046 struct thread_options *o = &td->o; in init_flags()
1049 td->flags |= TD_F_VER_BACKLOG; in init_flags()
1051 td->flags |= TD_F_TRIM_BACKLOG; in init_flags()
1053 td->flags |= TD_F_READ_IOLOG; in init_flags()
1055 td->flags |= TD_F_REFILL_BUFFERS; in init_flags()
1060 td->flags |= TD_F_SCRAMBLE_BUFFERS; in init_flags()
1067 td->flags |= TD_F_SCRAMBLE_BUFFERS; in init_flags()
1069 td->flags |= TD_F_VER_NONE; in init_flags()
1072 td->flags |= TD_F_NEED_LOCK; in init_flags()
1075 td->flags &= ~TD_F_SCRAMBLE_BUFFERS; in init_flags()
1078 static int setup_random_seeds(struct thread_data *td) in setup_random_seeds() argument
1083 if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed)) in setup_random_seeds()
1084 return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds)); in setup_random_seeds()
1086 seed = td->o.rand_seed; in setup_random_seeds()
1091 td->rand_seeds[i] = seed * td->thread_number + i; in setup_random_seeds()
1095 td_fill_rand_seeds(td); in setup_random_seeds()
1236 struct thread_data *td; in check_waitees() local
1239 for_each_td(td, i) { in check_waitees()
1240 if (td->subjob_number) in check_waitees()
1243 ret += !strcmp(td->o.name, waitee); in check_waitees()
1282 static int add_job(struct thread_data *td, const char *jobname, int job_add_num, in add_job() argument
1288 struct thread_options *o = &td->o; in add_job()
1294 if (td == &def_thread) in add_job()
1297 init_flags(td); in add_job()
1303 put_job(td); in add_job()
1307 td->client_type = client_type; in add_job()
1309 if (profile_td_init(td)) in add_job()
1312 if (ioengine_load(td)) in add_job()
1316 if (!o->filename && !td->files_index && !o->read_iolog_file) { in add_job()
1320 add_file(td, jobname, job_add_num, 0); in add_job()
1323 add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0); in add_job()
1327 if (fixup_options(td)) in add_job()
1336 flow_init_job(td); in add_job()
1342 if (td->eo) in add_job()
1343 *(struct thread_data **)td->eo = NULL; in add_job()
1345 if (td_ioengine_flagged(td, FIO_DISKLESSIO)) { in add_job()
1348 for_each_file(td, f, i) in add_job()
1352 td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED); in add_job()
1354 td->ts.clat_percentiles = o->clat_percentiles; in add_job()
1355 td->ts.percentile_precision = o->percentile_precision; in add_job()
1356 memcpy(td->ts.percentile_list, o->percentile_list, sizeof(o->percentile_list)); in add_job()
1359 td->ts.clat_stat[i].min_val = ULONG_MAX; in add_job()
1360 td->ts.slat_stat[i].min_val = ULONG_MAX; in add_job()
1361 td->ts.lat_stat[i].min_val = ULONG_MAX; in add_job()
1362 td->ts.bw_stat[i].min_val = ULONG_MAX; in add_job()
1364 td->ddir_seq_nr = o->ddir_seq_nr; in add_job()
1375 td->groupid = groupid; in add_job()
1378 if (setup_random_seeds(td)) { in add_job()
1379 td_verror(td, errno, "init_random_state"); in add_job()
1383 if (setup_rate(td)) in add_job()
1388 .td = td, in add_job()
1406 td->thread_number, suf, o->per_job_logs); in add_job()
1407 setup_log(&td->lat_log, &p, logname); in add_job()
1410 td->thread_number, suf, o->per_job_logs); in add_job()
1411 setup_log(&td->slat_log, &p, logname); in add_job()
1414 td->thread_number, suf, o->per_job_logs); in add_job()
1415 setup_log(&td->clat_log, &p, logname); in add_job()
1420 .td = td, in add_job()
1433 if (td->client_type) { in add_job()
1445 td->thread_number, suf, o->per_job_logs); in add_job()
1446 setup_log(&td->clat_hist_log, &p, logname); in add_job()
1451 .td = td, in add_job()
1477 td->thread_number, suf, o->per_job_logs); in add_job()
1478 setup_log(&td->bw_log, &p, logname); in add_job()
1482 .td = td, in add_job()
1508 td->thread_number, suf, o->per_job_logs); in add_job()
1509 setup_log(&td->iops_log, &p, logname); in add_job()
1518 fio_server_send_add_job(td); in add_job()
1520 if (!td_ioengine_flagged(td, FIO_NOIO)) { in add_job()
1535 log_info("%s: (g=%d): rw=%s, ", td->o.name, in add_job()
1536 td->groupid, in add_job()
1547 td->io_ops->name, o->iodepth); in add_job()
1560 if (td_steadystate_init(td)) in add_job()
1569 struct thread_data *td_new = get_new_job(false, td, true, jobname); in add_job()
1606 put_job(td); in add_job()
1615 struct thread_data *td, *td_parent; in add_job_opts() local
1620 td_parent = td = NULL; in add_job_opts()
1624 if (td) in add_job_opts()
1625 add_job(td, jobname, 0, 0, client_type); in add_job_opts()
1626 td = NULL; in add_job_opts()
1631 else if (!in_global && !td) { in add_job_opts()
1634 td = get_new_job(false, td_parent, false, jobname); in add_job_opts()
1639 fio_options_parse(td, (char **) &o[i], 1); in add_job_opts()
1643 if (td) in add_job_opts()
1644 add_job(td, jobname, 0, 0, client_type); in add_job_opts()
1682 static int __parse_jobs_ini(struct thread_data *td, in __parse_jobs_ini() argument
1698 assert(td || !nested); in __parse_jobs_ini()
1712 if (td) in __parse_jobs_ini()
1713 td_verror(td, __err, "job file open"); in __parse_jobs_ini()
1795 td = get_new_job(global, &def_thread, false, name); in __parse_jobs_ini()
1796 if (!td) { in __parse_jobs_ini()
1805 td->o.stonewall = stonewall; in __parse_jobs_ini()
1875 ret = __parse_jobs_ini(td, filename, is_buf, in __parse_jobs_ini()
1912 ret = fio_options_parse(td, opts, num_opts); in __parse_jobs_ini()
1915 dump_opt_list(td); in __parse_jobs_ini()
1917 ret = add_job(td, name, 0, 0, type); in __parse_jobs_ini()
1920 put_job(td); in __parse_jobs_ini()
2302 struct thread_data *td = NULL; in parse_cmd_line() local
2467 if (!strncmp(opt, "name", 4) && td) { in parse_cmd_line()
2468 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); in parse_cmd_line()
2471 td = NULL; in parse_cmd_line()
2474 if (!td) { in parse_cmd_line()
2484 td = get_new_job(global, &def_thread, true, NULL); in parse_cmd_line()
2485 if (!td || ioengine_load(td)) { in parse_cmd_line()
2486 if (td) { in parse_cmd_line()
2487 put_job(td); in parse_cmd_line()
2488 td = NULL; in parse_cmd_line()
2494 fio_options_set_ioengine_opts(l_opts, td); in parse_cmd_line()
2502 ret = fio_cmd_option_parse(td, opt, val); in parse_cmd_line()
2505 if (td) { in parse_cmd_line()
2506 put_job(td); in parse_cmd_line()
2507 td = NULL; in parse_cmd_line()
2514 free_ioengine(td); in parse_cmd_line()
2515 if (ioengine_load(td)) { in parse_cmd_line()
2516 put_job(td); in parse_cmd_line()
2517 td = NULL; in parse_cmd_line()
2522 fio_options_set_ioengine_opts(l_opts, td); in parse_cmd_line()
2530 if (!td) in parse_cmd_line()
2533 ret = fio_cmd_ioengine_option_parse(td, opt, val); in parse_cmd_line()
2718 if (td) { in parse_cmd_line()
2720 ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); in parse_cmd_line()