2 * This file contains job initialization and setup functions.
15 #include <sys/types.h>
25 #define DEF_TIMEOUT (0)
26 #define DEF_RATE_CYCLE (1000)
27 #define DEF_ODIRECT (1)
28 #define DEF_IO_ENGINE (FIO_SYNCIO)
29 #define DEF_IO_ENGINE_NAME "sync"
30 #define DEF_SEQUENTIAL (1)
31 #define DEF_RAND_REPEAT (1)
32 #define DEF_OVERWRITE (0)
33 #define DEF_INVALIDATE (1)
34 #define DEF_SYNCIO (0)
35 #define DEF_RANDSEED (0xb1899bedUL)
36 #define DEF_BWAVGTIME (500)
37 #define DEF_CREATE_SER (1)
38 #define DEF_CREATE_FSYNC (1)
40 #define DEF_VERIFY (0)
41 #define DEF_STONEWALL (0)
42 #define DEF_NUMJOBS (1)
43 #define DEF_USE_THREAD (0)
44 #define DEF_FILE_SIZE (1024 * 1024 * 1024UL)
45 #define DEF_ZONE_SIZE (0)
46 #define DEF_ZONE_SKIP (0)
47 #define DEF_RWMIX_CYCLE (500)
48 #define DEF_RWMIX_READ (50)
50 #define DEF_NR_FILES (1)
51 #define DEF_UNLINK (1)
52 #define DEF_WRITE_BW_LOG (0)
53 #define DEF_WRITE_LAT_LOG (0)
54 #define DEF_NO_RAND_MAP (0)
55 #define DEF_HUGEPAGE_SIZE FIO_HUGE_PAGE
56 #define DEF_THINKTIME_BLOCKS (1)
58 #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
60 static int str_rw_cb(void *, const char *);
61 static int str_ioengine_cb(void *, const char *);
62 static int str_mem_cb(void *, const char *);
63 static int str_verify_cb(void *, const char *);
64 static int str_lockmem_cb(void *, unsigned long *);
65 #ifdef FIO_HAVE_IOPRIO
66 static int str_prio_cb(void *, unsigned int *);
67 static int str_prioclass_cb(void *, unsigned int *);
69 static int str_exitall_cb(void);
70 static int str_cpumask_cb(void *, unsigned int *);
73 * Map of job/command line options
75 static struct fio_option options[] = {
78 .type = FIO_OPT_STR_STORE,
79 .off1 = td_var_offset(name),
80 .help = "Name of this job",
84 .type = FIO_OPT_STR_STORE,
85 .off1 = td_var_offset(directory),
86 .help = "Directory to store files in",
90 .type = FIO_OPT_STR_STORE,
91 .off1 = td_var_offset(filename),
92 .help = "Force the use of a specific file",
98 .help = "IO direction (read, write, rw, etc)",
103 .cb = str_ioengine_cb,
104 .help = "IO engine to use (sync, aio, etc)",
110 .help = "Backing type for IO buffers (malloc, shm, etc)",
116 .help = "Verify sum function (md5 or crc32)",
119 .name = "write_iolog",
120 .type = FIO_OPT_STR_STORE,
121 .off1 = td_var_offset(write_iolog_file),
122 .help = "Store IO pattern to file",
125 .name = "read_iolog",
126 .type = FIO_OPT_STR_STORE,
127 .off1 = td_var_offset(read_iolog_file),
128 .help = "Playback IO pattern from file",
131 .name = "exec_prerun",
132 .type = FIO_OPT_STR_STORE,
133 .off1 = td_var_offset(exec_prerun),
134 .help = "Execute this file prior to running job",
137 .name = "exec_postrun",
138 .type = FIO_OPT_STR_STORE,
139 .off1 = td_var_offset(exec_postrun),
140 .help = "Execute this file after running job",
142 #ifdef FIO_HAVE_IOSCHED_SWITCH
144 .name = "ioscheduler",
145 .type = FIO_OPT_STR_STORE,
146 .off1 = td_var_offset(ioscheduler),
147 .help = "Use this IO scheduler on the backing device",
152 .type = FIO_OPT_STR_VAL,
153 .off1 = td_var_offset(total_file_size),
154 .help = "Size of device or file",
158 .type = FIO_OPT_STR_VAL_INT,
159 .off1 = td_var_offset(bs[DDIR_READ]),
160 .off2 = td_var_offset(bs[DDIR_WRITE]),
161 .help = "Block size unit",
165 .type = FIO_OPT_STR_VAL,
166 .off1 = td_var_offset(start_offset),
167 .help = "Start IO from this offset",
171 .type = FIO_OPT_STR_VAL,
172 .off1 = td_var_offset(zone_size),
173 .help = "Give size of an IO zone",
177 .type = FIO_OPT_STR_VAL,
178 .off1 = td_var_offset(zone_skip),
179 .help = "Space between IO zones",
183 .type = FIO_OPT_STR_VAL,
184 .cb = str_lockmem_cb,
185 .help = "Lock down this amount of memory",
189 .type = FIO_OPT_RANGE,
190 .off1 = td_var_offset(min_bs[DDIR_READ]),
191 .off2 = td_var_offset(max_bs[DDIR_READ]),
192 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
193 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
194 .help = "Set block size range",
199 .off1 = td_var_offset(nr_files),
200 .help = "Split job workload between this number of files",
205 .off1 = td_var_offset(iodepth),
206 .help = "Amount of IO buffers to keep in flight",
211 .off1 = td_var_offset(fsync_blocks),
212 .help = "Issue fsync for writes every given number of blocks",
215 .name = "rwmixcycle",
217 .off1 = td_var_offset(rwmixcycle),
218 .help = "Cycle period for mixed read/write workloads",
223 .off1 = td_var_offset(rwmixread),
225 .help = "Percentage of mixed workload that is reads",
228 .name = "rwmixwrite",
230 .off1 = td_var_offset(rwmixwrite),
232 .help = "Percentage of mixed workload that is writes",
237 .off1 = td_var_offset(nice),
238 .help = "Set job CPU nice value",
240 #ifdef FIO_HAVE_IOPRIO
245 .help = "Set job IO priority value",
250 .cb = str_prioclass_cb,
251 .help = "Set job IO priority class",
257 .off1 = td_var_offset(thinktime),
258 .help = "Idle time between IO buffers",
261 .name = "thinktime_blocks",
263 .off1 = td_var_offset(thinktime_blocks),
264 .help = "IO buffer period between 'thinktime'",
269 .off1 = td_var_offset(rate),
270 .help = "Set bandwidth rate",
275 .off1 = td_var_offset(ratemin),
276 .help = "The bottom limit accepted",
281 .off1 = td_var_offset(ratecycle),
282 .name = "Window average for rate limits",
285 .name = "startdelay",
287 .off1 = td_var_offset(start_delay),
288 .help = "Only start job when this period has passed",
292 .type = FIO_OPT_STR_VAL_TIME,
293 .off1 = td_var_offset(timeout),
294 .help = "Stop workload when this amount of time has passed",
297 .name = "invalidate",
299 .off1 = td_var_offset(invalidate_cache),
300 .help = "Invalidate buffer/page cache prior to running job",
305 .off1 = td_var_offset(sync_io),
306 .help = "Use O_SYNC for buffered writes",
311 .off1 = td_var_offset(bw_avg_time),
312 .help = "Time window over which to calculate bandwidth",
315 .name = "create_serialize",
317 .off1 = td_var_offset(create_serialize),
318 .help = "Serialize creating of job files",
321 .name = "create_fsync",
323 .off1 = td_var_offset(create_fsync),
324 .help = "Fsync file after creation",
329 .off1 = td_var_offset(loops),
330 .help = "Number of times to run the job",
335 .off1 = td_var_offset(numjobs),
336 .help = "Duplicate this job this many times",
341 .off1 = td_var_offset(cpuload),
342 .help = "Use this percentage of CPU",
347 .off1 = td_var_offset(cpucycle),
348 .help = "Length of the CPU burn cycles",
353 .off1 = td_var_offset(odirect),
354 .help = "Use O_DIRECT IO",
359 .off1 = td_var_offset(overwrite),
360 .help = "When writing, set whether to overwrite current data",
362 #ifdef FIO_HAVE_CPU_AFFINITY
366 .cb = str_cpumask_cb,
367 .help = "CPU affinity mask",
373 .off1 = td_var_offset(end_fsync),
374 .help = "Include fsync at the end of job",
379 .off1 = td_var_offset(unlink),
380 .help = "Unlink files after job has completed",
384 .type = FIO_OPT_STR_SET,
385 .cb = str_exitall_cb,
386 .help = "Terminate all jobs when one exits",
390 .type = FIO_OPT_STR_SET,
391 .off1 = td_var_offset(stonewall),
392 .help = "Insert a hard barrier between this job and previous",
396 .type = FIO_OPT_STR_SET,
397 .off1 = td_var_offset(thread),
398 .help = "Use threads instead of forks",
401 .name = "write_bw_log",
402 .type = FIO_OPT_STR_SET,
403 .off1 = td_var_offset(write_bw_log),
404 .help = "Write log of bandwidth during run",
407 .name = "write_lat_log",
408 .type = FIO_OPT_STR_SET,
409 .off1 = td_var_offset(write_lat_log),
410 .help = "Write log of latency during run",
413 .name = "norandommap",
414 .type = FIO_OPT_STR_SET,
415 .off1 = td_var_offset(norandommap),
416 .help = "Accept potential duplicate random blocks",
419 .name = "bs_unaligned",
420 .type = FIO_OPT_STR_SET,
421 .off1 = td_var_offset(bs_unaligned),
422 .help = "Don't sector align IO buffer sizes",
425 .name = "hugepage-size",
426 .type = FIO_OPT_STR_VAL,
427 .off1 = td_var_offset(hugepage_size),
428 .help = "When using hugepages, specify size of each page",
435 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
436 #define FIO_CMD_OPTS (16)
437 #define FIO_GETOPT_JOB (0x89988998)
440 * Command line options. These will contain the above, plus a few
441 * extra that only pertain to fio itself and not jobs.
443 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
446 .has_arg = required_argument,
451 .has_arg = required_argument,
455 .name = "latency-log",
456 .has_arg = required_argument,
460 .name = "bandwidth-log",
461 .has_arg = required_argument,
466 .has_arg = optional_argument,
471 .has_arg = no_argument,
476 .has_arg = no_argument,
481 .has_arg = required_argument,
489 static int def_timeout = DEF_TIMEOUT;
491 static char fio_version_string[] = "fio 1.11";
493 static char **ini_file;
494 static int max_jobs = MAX_JOBS;
496 struct thread_data def_thread;
497 struct thread_data *threads = NULL;
499 int exitall_on_terminate = 0;
500 int terse_output = 0;
501 unsigned long long mlock_size = 0;
505 static int write_lat_log = DEF_WRITE_LAT_LOG;
506 static int write_bw_log = DEF_WRITE_BW_LOG;
509 * Return a free job structure.
511 static struct thread_data *get_new_job(int global, struct thread_data *parent)
513 struct thread_data *td;
517 if (thread_number >= max_jobs)
520 td = &threads[thread_number++];
523 td->thread_number = thread_number;
527 static void put_job(struct thread_data *td)
529 if (td == &def_thread)
532 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
537 * Lazy way of fixing up options that depend on each other. We could also
538 * define option callback handlers, but this is easier.
540 static void fixup_options(struct thread_data *td)
542 if (!td->rwmixread && td->rwmixwrite)
543 td->rwmixread = 100 - td->rwmixwrite;
545 if (td->write_iolog_file && td->read_iolog_file) {
546 log_err("fio: read iolog overrides write_iolog\n");
547 free(td->write_iolog_file);
548 td->write_iolog_file = NULL;
551 if (td->io_ops->flags & FIO_SYNCIO)
555 td->iodepth = td->nr_files;
559 * only really works for sequential io for now, and with 1 file
561 if (td->zone_size && !td->sequential && td->nr_files == 1)
565 * Reads can do overwrites, we always need to pre-create the file
567 if (td_read(td) || td_rw(td))
570 if (!td->min_bs[DDIR_READ])
571 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
572 if (!td->max_bs[DDIR_READ])
573 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
574 if (!td->min_bs[DDIR_WRITE])
575 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
576 if (!td->max_bs[DDIR_WRITE])
577 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
579 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
581 if (td_read(td) && !td_rw(td))
584 if (td->norandommap && td->verify != VERIFY_NONE) {
585 log_err("fio: norandommap given, verify disabled\n");
586 td->verify = VERIFY_NONE;
588 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
589 log_err("fio: bs_unaligned may not work with raw io\n");
592 * O_DIRECT and char doesn't mix, clear that flag if necessary.
594 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
599 * This function leaks the buffer
601 static char *to_kmg(unsigned int val)
603 char *buf = malloc(32);
604 char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
615 snprintf(buf, 31, "%u%c", val, *p);
620 * Adds a job to the list of things todo. Sanitizes the various options
621 * to make sure we don't have conflicts, and initializes various
624 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
626 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
627 "rw", NULL, "randrw" };
629 int numjobs, ddir, i;
633 * the def_thread is just for options, it's not a real job
635 if (td == &def_thread)
639 * Set default io engine, if none set
642 td->io_ops = load_ioengine(td, DEF_IO_ENGINE_NAME);
644 log_err("default engine %s not there?\n", DEF_IO_ENGINE_NAME);
650 td->io_ops->flags |= FIO_RAWIO;
652 td->filetype = FIO_TYPE_FILE;
653 if (!stat(jobname, &sb)) {
654 if (S_ISBLK(sb.st_mode))
655 td->filetype = FIO_TYPE_BD;
656 else if (S_ISCHR(sb.st_mode))
657 td->filetype = FIO_TYPE_CHAR;
663 td->nr_uniq_files = 1;
665 td->nr_uniq_files = td->nr_files;
667 if (td->filetype == FIO_TYPE_FILE || td->filename) {
671 if (td->directory && td->directory[0] != '\0')
672 len = sprintf(tmp, "%s/", td->directory);
674 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
676 for_each_file(td, f, i) {
677 memset(f, 0, sizeof(*f));
681 sprintf(tmp + len, "%s", td->filename);
683 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
684 f->file_name = strdup(tmp);
688 td->files = malloc(sizeof(struct fio_file));
691 memset(f, 0, sizeof(*f));
693 f->file_name = strdup(jobname);
696 for_each_file(td, f, i) {
697 f->file_size = td->total_file_size / td->nr_files;
698 f->file_offset = td->start_offset;
701 fio_sem_init(&td->mutex, 0);
703 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
704 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
705 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
707 if (td->stonewall && td->thread_number > 1)
710 td->groupid = groupid;
715 if (td->write_lat_log) {
716 setup_log(&td->slat_log);
717 setup_log(&td->clat_log);
719 if (td->write_bw_log)
720 setup_log(&td->bw_log);
723 td->name = strdup(jobname);
725 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
729 if (td->io_ops->flags & FIO_CPUIO)
730 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
732 char *c1, *c2, *c3, *c4;
734 c1 = to_kmg(td->min_bs[DDIR_READ]);
735 c2 = to_kmg(td->max_bs[DDIR_READ]);
736 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
737 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
739 fprintf(f_out, "%s: (g=%d): rw=%s, odir=%u, bs=%s-%s/%s-%s, rate=%u, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[ddir], td->odirect, c1, c2, c3, c4, td->rate, td->io_ops->name, td->iodepth);
746 } else if (job_add_num == 1)
747 fprintf(f_out, "...\n");
751 * recurse add identical jobs, clear numjobs and stonewall options
752 * as they don't apply to sub-jobs
754 numjobs = td->numjobs;
756 struct thread_data *td_new = get_new_job(0, td);
762 td_new->stonewall = 0;
763 job_add_num = numjobs - 1;
765 if (add_job(td_new, jobname, job_add_num))
775 * Initialize the various random states we need (random io, block size ranges,
776 * read/write mix, etc).
778 int init_random_state(struct thread_data *td)
780 unsigned long seeds[4];
781 int fd, num_maps, blocks, i;
784 if (td->io_ops->flags & FIO_CPUIO)
787 fd = open("/dev/urandom", O_RDONLY);
789 td_verror(td, errno);
793 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
801 os_random_seed(seeds[0], &td->bsrange_state);
802 os_random_seed(seeds[1], &td->verify_state);
803 os_random_seed(seeds[2], &td->rwmix_state);
808 if (td->rand_repeatable)
809 seeds[3] = DEF_RANDSEED;
811 if (!td->norandommap) {
812 for_each_file(td, f, i) {
813 blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs;
814 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
815 f->file_map = malloc(num_maps * sizeof(long));
816 f->num_maps = num_maps;
817 memset(f->file_map, 0, num_maps * sizeof(long));
821 os_random_seed(seeds[3], &td->random_state);
825 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
827 #ifdef FIO_HAVE_CPU_AFFINITY
832 for (i = 0; i < sizeof(int) * 8; i++) {
834 CPU_SET(i, &cpumask);
839 static int is_empty_or_comment(char *line)
843 for (i = 0; i < strlen(line); i++) {
846 if (!isspace(line[i]) && !iscntrl(line[i]))
853 static int str_rw_cb(void *data, const char *mem)
855 struct thread_data *td = data;
857 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
858 td->ddir = DDIR_READ;
861 } else if (!strncmp(mem, "randread", 8)) {
862 td->ddir = DDIR_READ;
865 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
866 td->ddir = DDIR_WRITE;
869 } else if (!strncmp(mem, "randwrite", 9)) {
870 td->ddir = DDIR_WRITE;
873 } else if (!strncmp(mem, "rw", 2)) {
874 td->ddir = DDIR_READ;
878 } else if (!strncmp(mem, "randrw", 6)) {
879 td->ddir = DDIR_READ;
885 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
889 static int str_verify_cb(void *data, const char *mem)
891 struct thread_data *td = data;
893 if (!strncmp(mem, "0", 1)) {
894 td->verify = VERIFY_NONE;
896 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
897 td->verify = VERIFY_MD5;
899 } else if (!strncmp(mem, "crc32", 5)) {
900 td->verify = VERIFY_CRC32;
904 log_err("fio: verify types: md5, crc32\n");
909 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
911 static char *get_mmap_file(const char *str)
913 char *p = strstr(str, ":");
919 strip_blank_front(&p);
924 static int str_mem_cb(void *data, const char *mem)
926 struct thread_data *td = data;
928 if (!strncmp(mem, "malloc", 6)) {
929 td->mem_type = MEM_MALLOC;
931 } else if (!strncmp(mem, "mmaphuge", 8)) {
932 #ifdef FIO_HAVE_HUGETLB
934 * mmaphuge must be appended with the actual file
936 td->mmapfile = get_mmap_file(mem);
938 log_err("fio: mmaphuge:/path/to/file\n");
942 td->mem_type = MEM_MMAPHUGE;
945 log_err("fio: mmaphuge not available\n");
948 } else if (!strncmp(mem, "mmap", 4)) {
950 * Check if the user wants file backed memory. It's ok
951 * if there's no file given, we'll just use anon mamp then.
953 td->mmapfile = get_mmap_file(mem);
954 td->mem_type = MEM_MMAP;
956 } else if (!strncmp(mem, "shmhuge", 7)) {
957 #ifdef FIO_HAVE_HUGETLB
958 td->mem_type = MEM_SHMHUGE;
961 log_err("fio: shmhuge not available\n");
964 } else if (!strncmp(mem, "shm", 3)) {
965 td->mem_type = MEM_SHM;
969 log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
973 static int str_ioengine_cb(void *data, const char *str)
975 struct thread_data *td = data;
977 td->io_ops = load_ioengine(td, str);
981 log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
982 log_err("fio: or specify path to dynamic ioengine module\n");
986 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
992 #ifdef FIO_HAVE_IOPRIO
993 static int str_prioclass_cb(void *data, unsigned int *val)
995 struct thread_data *td = data;
997 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1001 static int str_prio_cb(void *data, unsigned int *val)
1003 struct thread_data *td = data;
1010 static int str_exitall_cb(void)
1012 exitall_on_terminate = 1;
1016 static int str_cpumask_cb(void *data, unsigned int *val)
1018 struct thread_data *td = data;
1020 fill_cpu_mask(td->cpumask, *val);
1025 * This is our [ini] type file parser.
1027 static int parse_jobs_ini(char *file, int stonewall_flag)
1029 unsigned int global;
1030 struct thread_data *td;
1031 char *string, *name;
1035 int ret = 0, stonewall;
1037 f = fopen(file, "r");
1039 perror("fopen job file");
1043 string = malloc(4096);
1045 memset(name, 0, 256);
1047 stonewall = stonewall_flag;
1049 p = fgets(string, 4095, f);
1052 if (is_empty_or_comment(p))
1054 if (sscanf(p, "[%255s]", name) != 1)
1057 global = !strncmp(name, "global", 6);
1059 name[strlen(name) - 1] = '\0';
1061 td = get_new_job(global, &def_thread);
1068 * Seperate multiple job files by a stonewall
1070 if (!global && stonewall) {
1071 td->stonewall = stonewall;
1076 while ((p = fgets(string, 4096, f)) != NULL) {
1077 if (is_empty_or_comment(p))
1080 strip_blank_front(&p);
1090 * Don't break here, continue parsing options so we
1091 * dump all the bad ones. Makes trial/error fixups
1092 * easier on the user.
1094 ret |= parse_option(p, options, td);
1099 ret = add_job(td, name, 0);
1101 log_err("fio: job %s dropped\n", name);
1112 static int fill_def_thread(void)
1114 memset(&def_thread, 0, sizeof(def_thread));
1116 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1117 perror("sched_getaffinity");
1124 def_thread.ddir = DDIR_READ;
1125 def_thread.iomix = 0;
1126 def_thread.bs[DDIR_READ] = DEF_BS;
1127 def_thread.bs[DDIR_WRITE] = DEF_BS;
1128 def_thread.min_bs[DDIR_READ] = def_thread.min_bs[DDIR_WRITE] = 0;
1129 def_thread.max_bs[DDIR_READ] = def_thread.max_bs[DDIR_WRITE] = 0;
1130 def_thread.odirect = DEF_ODIRECT;
1131 def_thread.ratecycle = DEF_RATE_CYCLE;
1132 def_thread.sequential = DEF_SEQUENTIAL;
1133 def_thread.timeout = def_timeout;
1134 def_thread.overwrite = DEF_OVERWRITE;
1135 def_thread.invalidate_cache = DEF_INVALIDATE;
1136 def_thread.sync_io = DEF_SYNCIO;
1137 def_thread.mem_type = MEM_MALLOC;
1138 def_thread.bw_avg_time = DEF_BWAVGTIME;
1139 def_thread.create_serialize = DEF_CREATE_SER;
1140 def_thread.create_fsync = DEF_CREATE_FSYNC;
1141 def_thread.loops = DEF_LOOPS;
1142 def_thread.verify = DEF_VERIFY;
1143 def_thread.stonewall = DEF_STONEWALL;
1144 def_thread.numjobs = DEF_NUMJOBS;
1145 def_thread.use_thread = DEF_USE_THREAD;
1146 def_thread.rwmixcycle = DEF_RWMIX_CYCLE;
1147 def_thread.rwmixread = DEF_RWMIX_READ;
1148 def_thread.nice = DEF_NICE;
1149 def_thread.rand_repeatable = DEF_RAND_REPEAT;
1150 def_thread.nr_files = DEF_NR_FILES;
1151 def_thread.unlink = DEF_UNLINK;
1152 def_thread.write_bw_log = write_bw_log;
1153 def_thread.write_lat_log = write_lat_log;
1154 def_thread.norandommap = DEF_NO_RAND_MAP;
1155 def_thread.hugepage_size = DEF_HUGEPAGE_SIZE;
1156 def_thread.thinktime_blocks = DEF_THINKTIME_BLOCKS;
1157 #ifdef FIO_HAVE_DISK_UTIL
1158 def_thread.do_disk_util = 1;
1164 static void usage(void)
1166 printf("%s\n", fio_version_string);
1167 printf("\t--output\tWrite output to file\n");
1168 printf("\t--timeout\tRuntime in seconds\n");
1169 printf("\t--latency-log\tGenerate per-job latency logs\n");
1170 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1171 printf("\t--minimal\tMinimal (terse) output\n");
1172 printf("\t--version\tPrint version info and exit\n");
1173 printf("\t--help\t\tPrint this page\n");
1174 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1177 static int parse_cmd_line(int argc, char *argv[])
1179 struct thread_data *td = NULL;
1180 int c, ini_idx = 0, lidx, ret;
1182 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1185 def_timeout = atoi(optarg);
1194 f_out = fopen(optarg, "w+");
1196 perror("fopen output");
1208 ret = show_cmd_help(options, optarg);
1211 printf("%s\n", fio_version_string);
1213 case FIO_GETOPT_JOB: {
1214 const char *opt = long_options[lidx].name;
1217 if (!strncmp(opt, "name", 4) && td) {
1218 ret = add_job(td, td->name ?: "fio", 0);
1226 int global = !strncmp(val, "global", 6);
1228 td = get_new_job(global, &def_thread);
1233 ret = parse_cmd_option(opt, val, options, td);
1235 log_err("fio: job dropped\n");
1247 ret = add_job(td, td->name ?: "fio", 0);
1252 while (optind < argc) {
1254 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1255 ini_file[ini_idx - 1] = strdup(argv[optind]);
1262 static void free_shm(void)
1264 struct shmid_ds sbuf;
1267 shmdt((void *) threads);
1269 shmctl(shm_id, IPC_RMID, &sbuf);
1274 * The thread area is shared between the main process and the job
1275 * threads/processes. So setup a shared memory segment that will hold
1278 static int setup_thread_area(void)
1281 * 1024 is too much on some machines, scale max_jobs if
1282 * we get a failure that looks like too large a shm segment
1285 size_t size = max_jobs * sizeof(struct thread_data);
1287 shm_id = shmget(0, size, IPC_CREAT | 0600);
1290 if (errno != EINVAL) {
1301 threads = shmat(shm_id, NULL, 0);
1302 if (threads == (void *) -1) {
1312 * Copy the fio options into the long options map, so we mirror
1313 * job and cmd line options.
1315 static void dupe_job_options(void)
1317 struct fio_option *o;
1321 while (long_options[i].name)
1326 long_options[i].name = o->name;
1327 long_options[i].val = FIO_GETOPT_JOB;
1328 if (o->type == FIO_OPT_STR_SET)
1329 long_options[i].has_arg = no_argument;
1331 long_options[i].has_arg = required_argument;
1335 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1339 int parse_options(int argc, char *argv[])
1348 if (setup_thread_area())
1350 if (fill_def_thread())
1353 job_files = parse_cmd_line(argc, argv);
1355 for (i = 0; i < job_files; i++) {
1356 if (fill_def_thread())
1358 if (parse_jobs_ini(ini_file[i], i))
1365 if (!thread_number) {
1366 log_err("No jobs defined(s)\n");