2 * This file contains job initialization and setup functions.
15 #include <sys/types.h>
21 #define FIO_RANDSEED (0xb1899bedUL)
23 #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
25 static int str_rw_cb(void *, const char *);
26 static int str_ioengine_cb(void *, const char *);
27 static int str_mem_cb(void *, const char *);
28 static int str_verify_cb(void *, const char *);
29 static int str_lockmem_cb(void *, unsigned long *);
30 #ifdef FIO_HAVE_IOPRIO
31 static int str_prio_cb(void *, unsigned int *);
32 static int str_prioclass_cb(void *, unsigned int *);
34 static int str_exitall_cb(void);
35 static int str_cpumask_cb(void *, unsigned int *);
37 #define __stringify_1(x) #x
38 #define __stringify(x) __stringify_1(x)
41 * Map of job/command line options
43 static struct fio_option options[] = {
45 .name = "description",
46 .type = FIO_OPT_STR_STORE,
47 .off1 = td_var_offset(description),
48 .help = "Text job description",
52 .type = FIO_OPT_STR_STORE,
53 .off1 = td_var_offset(name),
54 .help = "Name of this job",
58 .type = FIO_OPT_STR_STORE,
59 .off1 = td_var_offset(directory),
60 .help = "Directory to store files in",
64 .type = FIO_OPT_STR_STORE,
65 .off1 = td_var_offset(filename),
66 .help = "Force the use of a specific file",
72 .help = "IO direction",
74 .posval = { "read", "write", "randwrite", "randread", "rw",
80 .cb = str_ioengine_cb,
81 .help = "IO engine to use",
83 .posval = { "sync", "libaio", "posixaio", "mmap", "splice",
84 "sg", "null", "net", "syslet-rw" },
89 .off1 = td_var_offset(iodepth),
90 .help = "Amount of IO buffers to keep in flight",
95 .type = FIO_OPT_STR_VAL,
96 .off1 = td_var_offset(total_file_size),
97 .help = "Size of device or file",
101 .type = FIO_OPT_STR_VAL_INT,
102 .off1 = td_var_offset(bs[DDIR_READ]),
103 .off2 = td_var_offset(bs[DDIR_WRITE]),
104 .help = "Block size unit",
109 .type = FIO_OPT_RANGE,
110 .off1 = td_var_offset(min_bs[DDIR_READ]),
111 .off2 = td_var_offset(max_bs[DDIR_READ]),
112 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
113 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
114 .help = "Set block size range (in more detail than bs)",
117 .name = "bs_unaligned",
118 .type = FIO_OPT_STR_SET,
119 .off1 = td_var_offset(bs_unaligned),
120 .help = "Don't sector align IO buffer sizes",
124 .type = FIO_OPT_STR_VAL,
125 .off1 = td_var_offset(start_offset),
126 .help = "Start IO from this offset",
130 .name = "randrepeat",
131 .type = FIO_OPT_BOOL,
132 .off1 = td_var_offset(rand_repeatable),
133 .help = "Use repeatable random IO pattern",
137 .name = "norandommap",
138 .type = FIO_OPT_STR_SET,
139 .off1 = td_var_offset(norandommap),
140 .help = "Accept potential duplicate random blocks",
145 .off1 = td_var_offset(nr_files),
146 .help = "Split job workload between this number of files",
152 .off1 = td_var_offset(fsync_blocks),
153 .help = "Issue fsync for writes every given number of blocks",
158 .type = FIO_OPT_BOOL,
159 .off1 = td_var_offset(odirect),
160 .help = "Use O_DIRECT IO (negates buffered)",
165 .type = FIO_OPT_BOOL,
166 .off1 = td_var_offset(odirect),
168 .help = "Use buffered IO (negates direct)",
173 .type = FIO_OPT_BOOL,
174 .off1 = td_var_offset(overwrite),
175 .help = "When writing, set whether to overwrite current data",
181 .off1 = td_var_offset(loops),
182 .help = "Number of times to run the job",
188 .off1 = td_var_offset(numjobs),
189 .help = "Duplicate this job this many times",
193 .name = "startdelay",
195 .off1 = td_var_offset(start_delay),
196 .help = "Only start job when this period has passed",
202 .type = FIO_OPT_STR_VAL_TIME,
203 .off1 = td_var_offset(timeout),
204 .help = "Stop workload when this amount of time has passed",
211 .help = "Backing type for IO buffers",
213 .posval = { "malloc", "shm", "shmhuge", "mmap", "mmaphuge", },
219 .help = "Verify sum function",
221 .posval = { "crc32", "md5", },
224 .name = "write_iolog",
225 .type = FIO_OPT_STR_STORE,
226 .off1 = td_var_offset(write_iolog_file),
227 .help = "Store IO pattern to file",
230 .name = "read_iolog",
231 .type = FIO_OPT_STR_STORE,
232 .off1 = td_var_offset(read_iolog_file),
233 .help = "Playback IO pattern from file",
236 .name = "exec_prerun",
237 .type = FIO_OPT_STR_STORE,
238 .off1 = td_var_offset(exec_prerun),
239 .help = "Execute this file prior to running job",
242 .name = "exec_postrun",
243 .type = FIO_OPT_STR_STORE,
244 .off1 = td_var_offset(exec_postrun),
245 .help = "Execute this file after running job",
247 #ifdef FIO_HAVE_IOSCHED_SWITCH
249 .name = "ioscheduler",
250 .type = FIO_OPT_STR_STORE,
251 .off1 = td_var_offset(ioscheduler),
252 .help = "Use this IO scheduler on the backing device",
257 .type = FIO_OPT_STR_VAL,
258 .off1 = td_var_offset(zone_size),
259 .help = "Give size of an IO zone",
264 .type = FIO_OPT_STR_VAL,
265 .off1 = td_var_offset(zone_skip),
266 .help = "Space between IO zones",
271 .type = FIO_OPT_STR_VAL,
272 .cb = str_lockmem_cb,
273 .help = "Lock down this amount of memory",
277 .name = "rwmixcycle",
279 .off1 = td_var_offset(rwmixcycle),
280 .help = "Cycle period for mixed read/write workloads (msec)",
286 .off1 = td_var_offset(rwmixread),
288 .help = "Percentage of mixed workload that is reads",
292 .name = "rwmixwrite",
294 .off1 = td_var_offset(rwmixwrite),
296 .help = "Percentage of mixed workload that is writes",
302 .off1 = td_var_offset(nice),
303 .help = "Set job CPU nice value",
308 #ifdef FIO_HAVE_IOPRIO
313 .help = "Set job IO priority value",
320 .cb = str_prioclass_cb,
321 .help = "Set job IO priority class",
329 .off1 = td_var_offset(thinktime),
330 .help = "Idle time between IO buffers (usec)",
334 .name = "thinktime_spin",
336 .off1 = td_var_offset(thinktime_spin),
337 .help = "Start thinktime by spinning this amount (usec)",
341 .name = "thinktime_blocks",
343 .off1 = td_var_offset(thinktime_blocks),
344 .help = "IO buffer period between 'thinktime'",
350 .off1 = td_var_offset(rate),
351 .help = "Set bandwidth rate",
356 .off1 = td_var_offset(ratemin),
357 .help = "The bottom limit accepted",
362 .off1 = td_var_offset(ratecycle),
363 .help = "Window average for rate limits (msec)",
367 .name = "invalidate",
368 .type = FIO_OPT_BOOL,
369 .off1 = td_var_offset(invalidate_cache),
370 .help = "Invalidate buffer/page cache prior to running job",
375 .type = FIO_OPT_BOOL,
376 .off1 = td_var_offset(sync_io),
377 .help = "Use O_SYNC for buffered writes",
383 .off1 = td_var_offset(bw_avg_time),
384 .help = "Time window over which to calculate bandwidth (msec)",
388 .name = "create_serialize",
389 .type = FIO_OPT_BOOL,
390 .off1 = td_var_offset(create_serialize),
391 .help = "Serialize creating of job files",
395 .name = "create_fsync",
396 .type = FIO_OPT_BOOL,
397 .off1 = td_var_offset(create_fsync),
398 .help = "Fsync file after creation",
404 .off1 = td_var_offset(cpuload),
405 .help = "Use this percentage of CPU",
410 .off1 = td_var_offset(cpucycle),
411 .help = "Length of the CPU burn cycles",
413 #ifdef FIO_HAVE_CPU_AFFINITY
417 .cb = str_cpumask_cb,
418 .help = "CPU affinity mask",
423 .type = FIO_OPT_BOOL,
424 .off1 = td_var_offset(end_fsync),
425 .help = "Include fsync at the end of job",
430 .type = FIO_OPT_BOOL,
431 .off1 = td_var_offset(unlink),
432 .help = "Unlink created files after job has completed",
437 .type = FIO_OPT_STR_SET,
438 .cb = str_exitall_cb,
439 .help = "Terminate all jobs when one exits",
443 .type = FIO_OPT_STR_SET,
444 .off1 = td_var_offset(stonewall),
445 .help = "Insert a hard barrier between this job and previous",
449 .type = FIO_OPT_STR_SET,
450 .off1 = td_var_offset(use_thread),
451 .help = "Use threads instead of forks",
454 .name = "write_bw_log",
455 .type = FIO_OPT_STR_SET,
456 .off1 = td_var_offset(write_bw_log),
457 .help = "Write log of bandwidth during run",
460 .name = "write_lat_log",
461 .type = FIO_OPT_STR_SET,
462 .off1 = td_var_offset(write_lat_log),
463 .help = "Write log of latency during run",
466 .name = "hugepage-size",
467 .type = FIO_OPT_STR_VAL,
468 .off1 = td_var_offset(hugepage_size),
469 .help = "When using hugepages, specify size of each page",
470 .def = __stringify(FIO_HUGE_PAGE),
477 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
478 #define FIO_CMD_OPTS (16)
479 #define FIO_GETOPT_JOB (0x89988998)
482 * Command line options. These will contain the above, plus a few
483 * extra that only pertain to fio itself and not jobs.
485 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
488 .has_arg = required_argument,
493 .has_arg = required_argument,
497 .name = "latency-log",
498 .has_arg = required_argument,
502 .name = "bandwidth-log",
503 .has_arg = required_argument,
508 .has_arg = optional_argument,
513 .has_arg = no_argument,
518 .has_arg = no_argument,
523 .has_arg = required_argument,
531 static int def_timeout = 0;
533 static char fio_version_string[] = "fio 1.11";
535 static char **ini_file;
536 static int max_jobs = MAX_JOBS;
538 struct thread_data def_thread;
539 struct thread_data *threads = NULL;
541 int exitall_on_terminate = 0;
542 int terse_output = 0;
543 unsigned long long mlock_size = 0;
547 static int write_lat_log = 0;
548 int write_bw_log = 0;
551 * Return a free job structure.
553 static struct thread_data *get_new_job(int global, struct thread_data *parent)
555 struct thread_data *td;
559 if (thread_number >= max_jobs)
562 td = &threads[thread_number++];
565 td->thread_number = thread_number;
569 static void put_job(struct thread_data *td)
571 if (td == &def_thread)
575 fprintf(f_out, "fio: %s\n", td->verror);
577 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
582 * Lazy way of fixing up options that depend on each other. We could also
583 * define option callback handlers, but this is easier.
585 static void fixup_options(struct thread_data *td)
587 if (!td->rwmixread && td->rwmixwrite)
588 td->rwmixread = 100 - td->rwmixwrite;
590 if (td->write_iolog_file && td->read_iolog_file) {
591 log_err("fio: read iolog overrides write_iolog\n");
592 free(td->write_iolog_file);
593 td->write_iolog_file = NULL;
596 if (td->io_ops->flags & FIO_SYNCIO)
600 td->iodepth = td->nr_files;
604 * only really works for sequential io for now, and with 1 file
606 if (td->zone_size && !td->sequential && td->nr_files == 1)
610 * Reads can do overwrites, we always need to pre-create the file
612 if (td_read(td) || td_rw(td))
615 if (!td->min_bs[DDIR_READ])
616 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
617 if (!td->max_bs[DDIR_READ])
618 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
619 if (!td->min_bs[DDIR_WRITE])
620 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
621 if (!td->max_bs[DDIR_WRITE])
622 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
624 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
626 if (td_read(td) && !td_rw(td))
629 if (td->norandommap && td->verify != VERIFY_NONE) {
630 log_err("fio: norandommap given, verify disabled\n");
631 td->verify = VERIFY_NONE;
633 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
634 log_err("fio: bs_unaligned may not work with raw io\n");
637 * O_DIRECT and char doesn't mix, clear that flag if necessary.
639 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
643 * thinktime_spin must be less than thinktime
645 if (td->thinktime_spin > td->thinktime)
646 td->thinktime_spin = td->thinktime;
650 * This function leaks the buffer
652 static char *to_kmg(unsigned int val)
654 char *buf = malloc(32);
655 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
666 snprintf(buf, 31, "%u%c", val, *p);
671 * Adds a job to the list of things todo. Sanitizes the various options
672 * to make sure we don't have conflicts, and initializes various
675 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
677 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
678 "rw", NULL, "randrw" };
680 int numjobs, ddir, i;
684 * the def_thread is just for options, it's not a real job
686 if (td == &def_thread)
692 td->io_ops->flags |= FIO_RAWIO;
694 td->filetype = FIO_TYPE_FILE;
695 if (td->filename && !lstat(td->filename, &sb)) {
696 if (S_ISBLK(sb.st_mode))
697 td->filetype = FIO_TYPE_BD;
698 else if (S_ISCHR(sb.st_mode))
699 td->filetype = FIO_TYPE_CHAR;
705 td->nr_uniq_files = 1;
707 td->nr_uniq_files = td->nr_files;
709 if (td->filetype == FIO_TYPE_FILE || td->filename) {
713 if (td->directory && td->directory[0] != '\0') {
714 if (lstat(td->directory, &sb) < 0) {
715 log_err("fio: %s is not a directory\n", td->directory);
716 td_verror(td, errno);
719 if (!S_ISDIR(sb.st_mode)) {
720 log_err("fio: %s is not a directory\n", td->directory);
723 len = sprintf(tmp, "%s/", td->directory);
726 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
728 for_each_file(td, f, i) {
729 memset(f, 0, sizeof(*f));
733 sprintf(tmp + len, "%s", td->filename);
735 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
736 f->file_name = strdup(tmp);
740 td->files = malloc(sizeof(struct fio_file));
743 memset(f, 0, sizeof(*f));
745 f->file_name = strdup(jobname);
748 for_each_file(td, f, i) {
749 f->file_size = td->total_file_size / td->nr_files;
750 f->file_offset = td->start_offset;
753 fio_sem_init(&td->mutex, 0);
755 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
756 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
757 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
759 if (td->stonewall && td->thread_number > 1)
762 td->groupid = groupid;
767 if (td->write_lat_log) {
768 setup_log(&td->slat_log);
769 setup_log(&td->clat_log);
771 if (td->write_bw_log)
772 setup_log(&td->bw_log);
775 td->name = strdup(jobname);
777 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
781 if (td->io_ops->flags & FIO_CPUIO)
782 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
784 char *c1, *c2, *c3, *c4;
786 c1 = to_kmg(td->min_bs[DDIR_READ]);
787 c2 = to_kmg(td->max_bs[DDIR_READ]);
788 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
789 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
791 fprintf(f_out, "%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth);
798 } else if (job_add_num == 1)
799 fprintf(f_out, "...\n");
803 * recurse add identical jobs, clear numjobs and stonewall options
804 * as they don't apply to sub-jobs
806 numjobs = td->numjobs;
808 struct thread_data *td_new = get_new_job(0, td);
814 td_new->stonewall = 0;
815 job_add_num = numjobs - 1;
817 if (add_job(td_new, jobname, job_add_num))
827 * Initialize the various random states we need (random io, block size ranges,
828 * read/write mix, etc).
830 int init_random_state(struct thread_data *td)
832 unsigned long seeds[4];
833 int fd, num_maps, blocks, i;
836 if (td->io_ops->flags & FIO_CPUIO)
839 fd = open("/dev/urandom", O_RDONLY);
841 td_verror(td, errno);
845 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
853 os_random_seed(seeds[0], &td->bsrange_state);
854 os_random_seed(seeds[1], &td->verify_state);
855 os_random_seed(seeds[2], &td->rwmix_state);
860 if (td->rand_repeatable)
861 seeds[3] = FIO_RANDSEED * td->thread_number;
863 if (!td->norandommap) {
864 for_each_file(td, f, i) {
865 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
866 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
867 f->file_map = malloc(num_maps * sizeof(long));
868 f->num_maps = num_maps;
869 memset(f->file_map, 0, num_maps * sizeof(long));
873 os_random_seed(seeds[3], &td->random_state);
877 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
879 #ifdef FIO_HAVE_CPU_AFFINITY
884 for (i = 0; i < sizeof(int) * 8; i++) {
886 CPU_SET(i, &cpumask);
891 static int is_empty_or_comment(char *line)
895 for (i = 0; i < strlen(line); i++) {
900 if (!isspace(line[i]) && !iscntrl(line[i]))
907 static int str_rw_cb(void *data, const char *mem)
909 struct thread_data *td = data;
911 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
912 td->ddir = DDIR_READ;
915 } else if (!strncmp(mem, "randread", 8)) {
916 td->ddir = DDIR_READ;
919 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
920 td->ddir = DDIR_WRITE;
923 } else if (!strncmp(mem, "randwrite", 9)) {
924 td->ddir = DDIR_WRITE;
927 } else if (!strncmp(mem, "rw", 2)) {
928 td->ddir = DDIR_READ;
932 } else if (!strncmp(mem, "randrw", 6)) {
933 td->ddir = DDIR_READ;
939 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
943 static int str_verify_cb(void *data, const char *mem)
945 struct thread_data *td = data;
947 if (!strncmp(mem, "0", 1)) {
948 td->verify = VERIFY_NONE;
950 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
951 td->verify = VERIFY_MD5;
953 } else if (!strncmp(mem, "crc32", 5)) {
954 td->verify = VERIFY_CRC32;
958 log_err("fio: verify types: md5, crc32\n");
963 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
965 static char *get_mmap_file(const char *str)
967 char *p = strstr(str, ":");
973 strip_blank_front(&p);
978 static int str_mem_cb(void *data, const char *mem)
980 struct thread_data *td = data;
982 if (!strncmp(mem, "malloc", 6)) {
983 td->mem_type = MEM_MALLOC;
985 } else if (!strncmp(mem, "mmaphuge", 8)) {
986 #ifdef FIO_HAVE_HUGETLB
988 * mmaphuge must be appended with the actual file
990 td->mmapfile = get_mmap_file(mem);
992 log_err("fio: mmaphuge:/path/to/file\n");
996 td->mem_type = MEM_MMAPHUGE;
999 log_err("fio: mmaphuge not available\n");
1002 } else if (!strncmp(mem, "mmap", 4)) {
1004 * Check if the user wants file backed memory. It's ok
1005 * if there's no file given, we'll just use anon mamp then.
1007 td->mmapfile = get_mmap_file(mem);
1008 td->mem_type = MEM_MMAP;
1010 } else if (!strncmp(mem, "shmhuge", 7)) {
1011 #ifdef FIO_HAVE_HUGETLB
1012 td->mem_type = MEM_SHMHUGE;
1015 log_err("fio: shmhuge not available\n");
1018 } else if (!strncmp(mem, "shm", 3)) {
1019 td->mem_type = MEM_SHM;
1023 log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
1027 static int str_ioengine_cb(void *data, const char *str)
1029 struct thread_data *td = data;
1031 td->io_ops = load_ioengine(td, str);
1035 log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
1036 log_err("fio: or specify path to dynamic ioengine module\n");
1040 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1046 #ifdef FIO_HAVE_IOPRIO
1047 static int str_prioclass_cb(void *data, unsigned int *val)
1049 struct thread_data *td = data;
1051 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1055 static int str_prio_cb(void *data, unsigned int *val)
1057 struct thread_data *td = data;
1064 static int str_exitall_cb(void)
1066 exitall_on_terminate = 1;
1070 static int str_cpumask_cb(void *data, unsigned int *val)
1072 struct thread_data *td = data;
1074 fill_cpu_mask(td->cpumask, *val);
1079 * This is our [ini] type file parser.
1081 static int parse_jobs_ini(char *file, int stonewall_flag)
1083 unsigned int global;
1084 struct thread_data *td;
1085 char *string, *name;
1089 int ret = 0, stonewall;
1091 f = fopen(file, "r");
1093 perror("fopen job file");
1097 string = malloc(4096);
1099 memset(name, 0, 256);
1101 stonewall = stonewall_flag;
1103 p = fgets(string, 4095, f);
1106 if (is_empty_or_comment(p))
1108 if (sscanf(p, "[%255s]", name) != 1)
1111 global = !strncmp(name, "global", 6);
1113 name[strlen(name) - 1] = '\0';
1115 td = get_new_job(global, &def_thread);
1122 * Seperate multiple job files by a stonewall
1124 if (!global && stonewall) {
1125 td->stonewall = stonewall;
1130 while ((p = fgets(string, 4096, f)) != NULL) {
1131 if (is_empty_or_comment(p))
1134 strip_blank_front(&p);
1144 * Don't break here, continue parsing options so we
1145 * dump all the bad ones. Makes trial/error fixups
1146 * easier on the user.
1148 ret |= parse_option(p, options, td);
1153 ret = add_job(td, name, 0);
1155 log_err("fio: job %s dropped\n", name);
1166 static int fill_def_thread(void)
1168 memset(&def_thread, 0, sizeof(def_thread));
1170 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1171 perror("sched_getaffinity");
1176 * fill default options
1178 fill_default_options(&def_thread, options);
1180 def_thread.timeout = def_timeout;
1181 def_thread.write_bw_log = write_bw_log;
1182 def_thread.write_lat_log = write_lat_log;
1184 #ifdef FIO_HAVE_DISK_UTIL
1185 def_thread.do_disk_util = 1;
1191 static void usage(void)
1193 printf("%s\n", fio_version_string);
1194 printf("\t--output\tWrite output to file\n");
1195 printf("\t--timeout\tRuntime in seconds\n");
1196 printf("\t--latency-log\tGenerate per-job latency logs\n");
1197 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1198 printf("\t--minimal\tMinimal (terse) output\n");
1199 printf("\t--version\tPrint version info and exit\n");
1200 printf("\t--help\t\tPrint this page\n");
1201 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1204 static int parse_cmd_line(int argc, char *argv[])
1206 struct thread_data *td = NULL;
1207 int c, ini_idx = 0, lidx, ret;
1209 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1212 def_timeout = atoi(optarg);
1221 f_out = fopen(optarg, "w+");
1223 perror("fopen output");
1235 ret = show_cmd_help(options, optarg);
1238 printf("%s\n", fio_version_string);
1240 case FIO_GETOPT_JOB: {
1241 const char *opt = long_options[lidx].name;
1244 if (!strncmp(opt, "name", 4) && td) {
1245 ret = add_job(td, td->name ?: "fio", 0);
1253 int global = !strncmp(val, "global", 6);
1255 td = get_new_job(global, &def_thread);
1260 ret = parse_cmd_option(opt, val, options, td);
1262 log_err("fio: job dropped\n");
1274 ret = add_job(td, td->name ?: "fio", 0);
1279 while (optind < argc) {
1281 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1282 ini_file[ini_idx - 1] = strdup(argv[optind]);
1289 static void free_shm(void)
1291 struct shmid_ds sbuf;
1294 shmdt((void *) threads);
1296 shmctl(shm_id, IPC_RMID, &sbuf);
1301 * The thread area is shared between the main process and the job
1302 * threads/processes. So setup a shared memory segment that will hold
1305 static int setup_thread_area(void)
1308 * 1024 is too much on some machines, scale max_jobs if
1309 * we get a failure that looks like too large a shm segment
1312 size_t size = max_jobs * sizeof(struct thread_data);
1314 shm_id = shmget(0, size, IPC_CREAT | 0600);
1317 if (errno != EINVAL) {
1328 threads = shmat(shm_id, NULL, 0);
1329 if (threads == (void *) -1) {
1339 * Copy the fio options into the long options map, so we mirror
1340 * job and cmd line options.
1342 static void dupe_job_options(void)
1344 struct fio_option *o;
1348 while (long_options[i].name)
1353 long_options[i].name = o->name;
1354 long_options[i].val = FIO_GETOPT_JOB;
1355 if (o->type == FIO_OPT_STR_SET)
1356 long_options[i].has_arg = no_argument;
1358 long_options[i].has_arg = required_argument;
1362 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1366 int parse_options(int argc, char *argv[])
1373 options_init(options);
1377 if (setup_thread_area())
1379 if (fill_def_thread())
1382 job_files = parse_cmd_line(argc, argv);
1384 for (i = 0; i < job_files; i++) {
1385 if (fill_def_thread())
1387 if (parse_jobs_ini(ini_file[i], i))
1394 if (!thread_number) {
1395 log_err("No jobs defined(s)\n");