X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=init.c;h=4af00ff98b2273d9788312de6640caf80b157dd7;hb=f4c4f4d74bf101a685f3f9839144c52c4ed29e30;hp=9fc8ff740fd85013f57e94c217addc4b6a28214b;hpb=48946b4c03a31750c76175046a9d590686d80023;p=fio.git diff --git a/init.c b/init.c index 9fc8ff74..4af00ff9 100644 --- a/init.c +++ b/init.c @@ -82,13 +82,31 @@ static struct fio_option options[] = { .help = "IO direction", .def = "read", .posval = { - { .ival = "read", .oval = TD_DDIR_READ }, - { .ival = "write", .oval = TD_DDIR_WRITE }, - { .ival = "randread", .oval = TD_DDIR_RANDREAD }, - { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE }, - { .ival = "rw", .oval = TD_DDIR_RW }, - { .ival = "randrw", .oval = TD_DDIR_RANDRW }, + { .ival = "read", + .oval = TD_DDIR_READ, + .help = "Sequential read", }, + { .ival = "write", + .oval = TD_DDIR_WRITE, + .help = "Sequential write", + }, + { .ival = "randread", + .oval = TD_DDIR_RANDREAD, + .help = "Random read", + }, + { .ival = "randwrite", + .oval = TD_DDIR_RANDWRITE, + .help = "Random write", + }, + { .ival = "rw", + .oval = TD_DDIR_RW, + .help = "Sequential read and write mix", + }, + { .ival = "randrw", + .oval = TD_DDIR_RANDRW, + .help = "Random read and write mix" + }, + }, }, { .name = "ioengine", @@ -97,27 +115,50 @@ static struct fio_option options[] = { .help = "IO engine to use", .def = "sync", .posval = { - { .ival = "sync", }, + { .ival = "sync", + .help = "Use read/write", + }, #ifdef FIO_HAVE_LIBAIO - { .ival = "libaio", }, + { .ival = "libaio", + .help = "Linux native asynchronous IO", + }, #endif #ifdef FIO_HAVE_POSIXAIO - { .ival = "posixaio", }, + { .ival = "posixaio", + .help = "POSIX asynchronous IO", + }, #endif - { .ival = "mmap", }, + { .ival = "mmap", + .help = "Memory mapped IO", + }, #ifdef FIO_HAVE_SPLICE - { .ival = "splice", }, + { .ival = "splice", + .help = "splice/vmsplice based IO", + }, #endif #ifdef FIO_HAVE_SGIO - { .ival = "sg", }, + { .ival = "sg", + .help = "SCSI generic v3 IO", + }, #endif - { .ival = "null", }, { .ival = "net", }, + { .ival = "null", + .help = "Testing engine (no data transfer)", + }, + { .ival = "net", + .help = "Network IO", + }, #ifdef FIO_HAVE_SYSLET - { .ival = "syslet-rw", }, + { .ival = "syslet-rw", + .help = "syslet enabled async pread/pwrite IO", + }, #endif - { .ival = "cpuio", }, - { .ival = "external", }, + { .ival = "cpuio", + .help = "CPU cycler burner engine", + }, + { .ival = "external", + .help = "Load external engine (append name)", }, + }, }, { .name = "iodepth", @@ -142,7 +183,14 @@ static struct fio_option options[] = { .name = "size", .type = FIO_OPT_STR_VAL, .off1 = td_var_offset(total_file_size), - .help = "Size of device or file", + .help = "Total size of device or files", + }, + { + .name = "filesize", + .type = FIO_OPT_STR_VAL, + .off1 = td_var_offset(file_size_low), + .off2 = td_var_offset(file_size_high), + .help = "Size of individual files", }, { .name = "bs", @@ -208,9 +256,15 @@ static struct fio_option options[] = { .help = "How to select which file to service next", .def = "roundrobin", .posval = { - { .ival = "random", .oval = FIO_FSERVICE_RANDOM }, - { .ival = "roundrobin", .oval = FIO_FSERVICE_RR }, + { .ival = "random", + .oval = FIO_FSERVICE_RANDOM, + .help = "Choose a file at random", }, + { .ival = "roundrobin", + .oval = FIO_FSERVICE_RR, + .help = "Round robin select files", + }, + }, }, { .name = "fsync", @@ -278,28 +332,52 @@ static struct fio_option options[] = { .help = "Backing type for IO buffers", .def = "malloc", .posval = { - { .ival = "malloc", .oval = MEM_MALLOC }, - { .ival = "shm", .oval = MEM_SHM }, + { .ival = "malloc", + .oval = MEM_MALLOC, + .help = "Use malloc(3) for IO buffers", + }, + { .ival = "shm", + .oval = MEM_SHM, + .help = "Use shared memory segments for IO buffers", + }, #ifdef FIO_HAVE_HUGETLB - { .ival = "shmhuge", .oval = MEM_SHMHUGE }, + { .ival = "shmhuge", + .oval = MEM_SHMHUGE, + .help = "Like shm, but use huge pages", + }, #endif - { .ival = "mmap", .oval = MEM_MMAP }, + { .ival = "mmap", + .oval = MEM_MMAP, + .help = "Use mmap(2) (file or anon) for IO buffers", + }, #ifdef FIO_HAVE_HUGETLB - { .ival = "mmaphuge", .oval = MEM_MMAPHUGE }, -#endif + { .ival = "mmaphuge", + .oval = MEM_MMAPHUGE, + .help = "Like mmap, but use huge pages", }, +#endif + }, }, { .name = "verify", .type = FIO_OPT_STR, .off1 = td_var_offset(verify), - .help = "Verify sum function", + .help = "Verify data written", .def = "0", .posval = { - { .ival = "0", .oval = VERIFY_NONE }, - { .ival = "crc32", .oval = VERIFY_CRC32 }, - { .ival = "md5", .oval = VERIFY_MD5 }, + { .ival = "0", + .oval = VERIFY_NONE, + .help = "Don't do IO verification", }, + { .ival = "crc32", + .oval = VERIFY_CRC32, + .help = "Use crc32 checksums for verification", + }, + { .ival = "md5", + .oval = VERIFY_MD5, + .help = "Use md5 checksums for verification", + }, + }, }, { .name = "write_iolog", @@ -625,7 +703,7 @@ static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = { static int def_timeout = 0; -static char fio_version_string[] = "fio 1.14"; +static char fio_version_string[] = "fio 1.14a"; static char **ini_file; static int max_jobs = MAX_JOBS; @@ -679,7 +757,7 @@ static void put_job(struct thread_data *td) return; if (td->error) - fprintf(f_out, "fio: %s\n", td->verror); + log_info("fio: %s\n", td->verror); memset(&threads[td->thread_number - 1], 0, sizeof(*td)); thread_number--; @@ -730,6 +808,9 @@ static void fixup_options(struct thread_data *td) td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]); + if (!td->file_size_high) + td->file_size_high = td->file_size_low; + if (td_read(td) && !td_rw(td)) td->verify = 0; @@ -809,6 +890,78 @@ static const char *get_engine_name(const char *str) return p; } +static int exists_and_not_file(const char *filename) +{ + struct stat sb; + + if (lstat(filename, &sb) == -1) + return 0; + + if (S_ISREG(sb.st_mode)) + return 0; + + return 1; +} + +/* + * Initialize the various random states we need (random io, block size ranges, + * read/write mix, etc). + */ +static int init_random_state(struct thread_data *td) +{ + unsigned long seeds[6]; + int fd, num_maps, blocks; + struct fio_file *f; + unsigned int i; + + fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + td_verror(td, errno, "open"); + return 1; + } + + if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { + td_verror(td, EIO, "read"); + close(fd); + return 1; + } + + close(fd); + + os_random_seed(seeds[0], &td->bsrange_state); + os_random_seed(seeds[1], &td->verify_state); + os_random_seed(seeds[2], &td->rwmix_state); + + if (td->file_service_type == FIO_FSERVICE_RANDOM) + os_random_seed(seeds[3], &td->next_file_state); + + os_random_seed(seeds[5], &td->file_size_state); + + if (!td_random(td)) + return 0; + + if (td->rand_repeatable) + seeds[4] = FIO_RANDSEED * td->thread_number; + + if (!td->norandommap) { + for_each_file(td, f, i) { + blocks = (f->real_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)); + if (!f->file_map) { + log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); + return 1; + } + f->num_maps = num_maps; + memset(f->file_map, 0, num_maps * sizeof(long)); + } + } + + os_random_seed(seeds[4], &td->random_state); + return 0; +} + + /* * Adds a job to the list of things todo. Sanitizes the various options * to make sure we don't have conflicts, and initializes various @@ -822,7 +975,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) struct fio_file *f; const char *engine; char fname[PATH_MAX]; - int numjobs; + int numjobs, file_alloced; /* * the def_thread is just for options, it's not a real job @@ -845,14 +998,15 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) if (td->odirect) td->io_ops->flags |= FIO_RAWIO; + file_alloced = 0; if (!td->filename && !td->files_index) { - td->filename = strdup(jobname); + file_alloced = 1; - if (td->nr_files == 1) - add_file(td, td->filename); + if (td->nr_files == 1 && exists_and_not_file(jobname)) + add_file(td, jobname); else { for (i = 0; i < td->nr_files; i++) { - sprintf(fname, "%s.%d.%d", td->filename, td->thread_number, i); + sprintf(fname, "%s.%d.%d", jobname, td->thread_number, i); add_file(td, fname); } } @@ -881,6 +1035,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td->groupid = groupid; prev_group_jobs++; + if (init_random_state(td)) + goto err; + if (setup_rate(td)) goto err; @@ -897,7 +1054,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) if (!terse_output) { if (!job_add_num) { if (!strcmp(td->io_ops->name, "cpuio")) - fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); + log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); else { char *c1, *c2, *c3, *c4; @@ -906,7 +1063,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) c3 = to_kmg(td->min_bs[DDIR_WRITE]); c4 = to_kmg(td->max_bs[DDIR_WRITE]); - fprintf(f_out, "%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth); + log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth); free(c1); free(c2); @@ -914,7 +1071,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) free(c4); } } else if (job_add_num == 1) - fprintf(f_out, "...\n"); + log_info("...\n"); } /* @@ -930,6 +1087,13 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td_new->numjobs = 1; td_new->stonewall = 0; + + if (file_alloced) { + td_new->filename = NULL; + td_new->files_index = 0; + td_new->files = NULL; + } + job_add_num = numjobs - 1; if (add_job(td_new, jobname, job_add_num)) @@ -947,65 +1111,6 @@ err: return -1; } -/* - * Initialize the various random states we need (random io, block size ranges, - * read/write mix, etc). - */ -int init_random_state(struct thread_data *td) -{ - unsigned long seeds[5]; - int fd, num_maps, blocks; - struct fio_file *f; - unsigned int i; - - if (td->io_ops->flags & FIO_DISKLESSIO) - return 0; - - fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) { - td_verror(td, errno, "open"); - return 1; - } - - if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { - td_verror(td, EIO, "read"); - close(fd); - return 1; - } - - close(fd); - - os_random_seed(seeds[0], &td->bsrange_state); - os_random_seed(seeds[1], &td->verify_state); - os_random_seed(seeds[2], &td->rwmix_state); - - if (td->file_service_type == FIO_FSERVICE_RANDOM) - os_random_seed(seeds[3], &td->next_file_state); - - if (!td_random(td)) - return 0; - - if (td->rand_repeatable) - seeds[4] = FIO_RANDSEED * td->thread_number; - - if (!td->norandommap) { - for_each_file(td, f, i) { - blocks = (f->real_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)); - if (!f->file_map) { - log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); - return 1; - } - f->num_maps = num_maps; - memset(f->file_map, 0, num_maps * sizeof(long)); - } - } - - os_random_seed(seeds[4], &td->random_state); - return 0; -} - static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) { #ifdef FIO_HAVE_CPU_AFFINITY