X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=init.c;h=badd635a394f45656fc8c027c83a5ad34cea6e6c;hp=732cceb993755a7ac2c5b6f3672c13c5950664b8;hb=02bcaa8c31feb93c61b701d143a7eea3efd2124d;hpb=fee3bb48f748afe5cf10f8505e1efd36b87c627e diff --git a/init.c b/init.c index 732cceb9..badd635a 100644 --- a/init.c +++ b/init.c @@ -51,6 +51,7 @@ #define DEF_UNLINK (0) #define DEF_WRITE_BW_LOG (0) #define DEF_WRITE_LAT_LOG (0) +#define DEF_NO_RAND_MAP (0) #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var) @@ -59,8 +60,10 @@ static int str_ioengine_cb(void *, const char *); static int str_mem_cb(void *, const char *); static int str_verify_cb(void *, const char *); static int str_lockmem_cb(void *, unsigned long *); +#ifdef FIO_HAVE_IOPRIO static int str_prio_cb(void *, unsigned int *); static int str_prioclass_cb(void *, unsigned int *); +#endif static int str_exitall_cb(void); static int str_cpumask_cb(void *, unsigned int *); @@ -137,8 +140,9 @@ static struct fio_option options[] = { }, { .name = "bs", - .type = FIO_OPT_STR_VAL, - .off1 = td_var_offset(bs), + .type = FIO_OPT_STR_VAL_INT, + .off1 = td_var_offset(bs[DDIR_READ]), + .off2 = td_var_offset(bs[DDIR_WRITE]), }, { .name = "offset", @@ -163,8 +167,10 @@ static struct fio_option options[] = { { .name = "bsrange", .type = FIO_OPT_RANGE, - .off1 = td_var_offset(min_bs), - .off2 = td_var_offset(max_bs), + .off1 = td_var_offset(min_bs[DDIR_READ]), + .off2 = td_var_offset(max_bs[DDIR_READ]), + .off3 = td_var_offset(min_bs[DDIR_WRITE]), + .off4 = td_var_offset(max_bs[DDIR_WRITE]), }, { .name = "nrfiles", @@ -342,6 +348,16 @@ static struct fio_option options[] = { .type = FIO_OPT_STR_SET, .off1 = td_var_offset(write_lat_log), }, + { + .name = "norandommap", + .type = FIO_OPT_STR_SET, + .off1 = td_var_offset(norandommap), + }, + { + .name = "bs_unaligned", + .type = FIO_OPT_STR_SET, + .off1 = td_var_offset(bs_unaligned), + }, { .name = NULL, }, @@ -393,7 +409,7 @@ static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = { static int def_timeout = DEF_TIMEOUT; -static char fio_version_string[] = "fio 1.7"; +static char fio_version_string[] = "fio 1.9"; static char **ini_file; static int max_jobs = MAX_JOBS; @@ -401,7 +417,6 @@ static int max_jobs = MAX_JOBS; struct thread_data def_thread; struct thread_data *threads = NULL; -int rate_quit = 0; int exitall_on_terminate = 0; int terse_output = 0; unsigned long long mlock_size = 0; @@ -473,12 +488,47 @@ static void fixup_options(struct thread_data *td) if (td_read(td) || td_rw(td)) td->overwrite = 1; - if (!td->min_bs) - td->min_bs = td->bs; - if (!td->max_bs) - td->max_bs = td->bs; + if (!td->min_bs[DDIR_READ]) + td->min_bs[DDIR_READ]= td->bs[DDIR_READ]; + if (!td->max_bs[DDIR_READ]) + td->max_bs[DDIR_READ] = td->bs[DDIR_READ]; + if (!td->min_bs[DDIR_WRITE]) + td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE]; + if (!td->max_bs[DDIR_WRITE]) + td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE]; + + td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]); + if (td_read(td) && !td_rw(td)) td->verify = 0; + + if (td->norandommap && td->verify != VERIFY_NONE) { + log_err("fio: norandommap given, verify disabled\n"); + td->verify = VERIFY_NONE; + } + if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO)) + log_err("fio: bs_unaligned may not work with raw io\n"); +} + +/* + * This function leaks the buffer + */ +static char *to_kmg(unsigned int val) +{ + char *buf = malloc(32); + char post[] = { 0, 'K', 'M', 'G', 'P', 0 }; + char *p = post; + + do { + if (val & 1023) + break; + + val >>= 10; + p++; + } while (*p); + + snprintf(buf, 31, "%u%c", val, *p); + return buf; } /* @@ -488,25 +538,12 @@ static void fixup_options(struct thread_data *td) */ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) { - char *ddir_str[] = { "read", "write", "randread", "randwrite", - "rw", NULL, "randrw" }; + const char *ddir_str[] = { "read", "write", "randread", "randwrite", + "rw", NULL, "randrw" }; struct stat sb; int numjobs, ddir, i; struct fio_file *f; -#ifndef FIO_HAVE_LIBAIO - if (td->io_engine == FIO_LIBAIO) { - log_err("Linux libaio not available\n"); - return 1; - } -#endif -#ifndef FIO_HAVE_POSIXAIO - if (td->io_engine == FIO_POSIXAIO) { - log_err("posix aio not available\n"); - return 1; - } -#endif - /* * the def_thread is just for options, it's not a real job */ @@ -524,6 +561,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) } } + if (td->odirect) + td->io_ops->flags |= FIO_RAWIO; + fixup_options(td); td->filetype = FIO_TYPE_FILE; @@ -534,9 +574,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td->filetype = FIO_TYPE_CHAR; } - if (td->odirect) - td->io_ops->flags |= FIO_RAWIO; - if (td->filename) td->nr_uniq_files = 1; else @@ -607,8 +644,21 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) if (!job_add_num) { if (td->io_ops->flags & FIO_CPUIO) fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); - else - fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_ops->name, td->iodepth); + else { + char *c1, *c2, *c3, *c4; + + c1 = to_kmg(td->min_bs[DDIR_READ]); + c2 = to_kmg(td->max_bs[DDIR_READ]); + c3 = to_kmg(td->min_bs[DDIR_WRITE]); + c4 = to_kmg(td->max_bs[DDIR_WRITE]); + + fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%s-%s/%s-%s, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, c1, c2, c3, c4, td->rate, td->io_ops->name, td->iodepth); + + free(c1); + free(c2); + free(c3); + free(c4); + } } else if (job_add_num == 1) fprintf(f_out, "...\n"); } @@ -674,12 +724,14 @@ int init_random_state(struct thread_data *td) if (td->rand_repeatable) seeds[3] = DEF_RANDSEED; - for_each_file(td, f, i) { - blocks = (f->file_size + td->min_bs - 1) / td->min_bs; - num_maps = blocks / BLOCKS_PER_MAP; - f->file_map = malloc(num_maps * sizeof(long)); - f->num_maps = num_maps; - memset(f->file_map, 0, num_maps * sizeof(long)); + if (!td->norandommap) { + for_each_file(td, f, i) { + blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs; + num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; + f->file_map = malloc(num_maps * sizeof(long)); + f->num_maps = num_maps; + memset(f->file_map, 0, num_maps * sizeof(long)); + } } os_random_seed(seeds[3], &td->random_state); @@ -797,6 +849,7 @@ static int str_ioengine_cb(void *data, const char *str) return 0; log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice, cpu\n"); + log_err("fio: or specify path to dynamic ioengine module\n"); return 1; } @@ -806,6 +859,7 @@ static int str_lockmem_cb(void fio_unused *data, unsigned long *val) return 0; } +#ifdef FIO_HAVE_IOPRIO static int str_prioclass_cb(void *data, unsigned int *val) { struct thread_data *td = data; @@ -821,6 +875,7 @@ static int str_prio_cb(void *data, unsigned int *val) td->ioprio |= *val; return 0; } +#endif static int str_exitall_cb(void) { @@ -860,8 +915,9 @@ int parse_jobs_ini(char *file, int stonewall_flag) memset(name, 0, 256); stonewall = stonewall_flag; - while ((p = fgets(string, 4096, f)) != NULL) { - if (ret) + do { + p = fgets(string, 4095, f); + if (!p) break; if (is_empty_or_comment(p)) continue; @@ -890,10 +946,12 @@ int parse_jobs_ini(char *file, int stonewall_flag) while ((p = fgets(string, 4096, f)) != NULL) { if (is_empty_or_comment(p)) continue; - if (strstr(p, "[")) - break; strip_blank_front(&p); + + if (p[0] == '[') + break; + strip_blank_end(p); fgetpos(f, &off); @@ -903,16 +961,17 @@ int parse_jobs_ini(char *file, int stonewall_flag) * dump all the bad ones. Makes trial/error fixups * easier on the user. */ - ret = parse_option(p, options, td); + ret |= parse_option(p, options, td); } if (!ret) { fsetpos(f, &off); ret = add_job(td, name, 0); + } else { + log_err("fio: job %s dropped\n", name); + put_job(td); } - if (ret) - break; - } + } while (!ret); free(string); free(name); @@ -934,9 +993,10 @@ static int fill_def_thread(void) */ def_thread.ddir = DDIR_READ; def_thread.iomix = 0; - def_thread.bs = DEF_BS; - def_thread.min_bs = 0; - def_thread.max_bs = 0; + def_thread.bs[DDIR_READ] = DEF_BS; + def_thread.bs[DDIR_WRITE] = DEF_BS; + def_thread.min_bs[DDIR_READ] = def_thread.min_bs[DDIR_WRITE] = 0; + def_thread.max_bs[DDIR_READ] = def_thread.max_bs[DDIR_WRITE] = 0; def_thread.odirect = DEF_ODIRECT; def_thread.ratecycle = DEF_RATE_CYCLE; def_thread.sequential = DEF_SEQUENTIAL; @@ -961,6 +1021,7 @@ static int fill_def_thread(void) def_thread.unlink = DEF_UNLINK; def_thread.write_bw_log = write_bw_log; def_thread.write_lat_log = write_lat_log; + def_thread.norandommap = DEF_NO_RAND_MAP; #ifdef FIO_HAVE_DISK_UTIL def_thread.do_disk_util = 1; #endif @@ -1032,7 +1093,12 @@ static int parse_cmd_line(int argc, char *argv[]) return 0; } - parse_cmd_option(opt, val, options, td); + ret = parse_cmd_option(opt, val, options, td); + if (ret) { + log_err("fio: job dropped\n"); + put_job(td); + td = NULL; + } break; } default: @@ -1162,7 +1228,6 @@ int parse_options(int argc, char *argv[]) if (!thread_number) { log_err("No jobs defined(s)\n"); - usage(); return 1; }