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_ioengine_cb(void *, const char *);
26 static int str_mem_cb(void *, const char *);
27 static int str_lockmem_cb(void *, unsigned long *);
28 #ifdef FIO_HAVE_IOPRIO
29 static int str_prio_cb(void *, unsigned int *);
30 static int str_prioclass_cb(void *, unsigned int *);
32 static int str_exitall_cb(void);
33 static int str_cpumask_cb(void *, unsigned int *);
35 #define __stringify_1(x) #x
36 #define __stringify(x) __stringify_1(x)
39 * Map of job/command line options
41 static struct fio_option options[] = {
43 .name = "description",
44 .type = FIO_OPT_STR_STORE,
45 .off1 = td_var_offset(description),
46 .help = "Text job description",
50 .type = FIO_OPT_STR_STORE,
51 .off1 = td_var_offset(name),
52 .help = "Name of this job",
56 .type = FIO_OPT_STR_STORE,
57 .off1 = td_var_offset(directory),
58 .help = "Directory to store files in",
62 .type = FIO_OPT_STR_STORE,
63 .off1 = td_var_offset(filename),
64 .help = "Force the use of a specific file",
69 .off1 = td_var_offset(td_ddir),
70 .help = "IO direction",
73 { .ival = "read", .oval = TD_DDIR_READ },
74 { .ival = "write", .oval = TD_DDIR_WRITE },
75 { .ival = "randread", .oval = TD_DDIR_RANDREAD },
76 { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE },
77 { .ival = "rw", .oval = TD_DDIR_RW },
78 { .ival = "randrw", .oval = TD_DDIR_RANDRW },
84 .cb = str_ioengine_cb,
85 .help = "IO engine to use",
88 { .ival = "sync", }, { .ival = "libaio", },
89 { .ival = "posixaio", }, { .ival = "mmap", },
90 { .ival = "splice", }, { .ival = "sg", },
91 { .ival = "null", }, { .ival = "net", },
92 { .ival = "syslet-rw", },
98 .off1 = td_var_offset(iodepth),
99 .help = "Amount of IO buffers to keep in flight",
103 .name = "iodepth_low",
105 .off1 = td_var_offset(iodepth_low),
106 .help = "Low water mark for queuing depth",
110 .type = FIO_OPT_STR_VAL,
111 .off1 = td_var_offset(total_file_size),
112 .help = "Size of device or file",
116 .type = FIO_OPT_STR_VAL_INT,
117 .off1 = td_var_offset(bs[DDIR_READ]),
118 .off2 = td_var_offset(bs[DDIR_WRITE]),
119 .help = "Block size unit",
124 .type = FIO_OPT_RANGE,
125 .off1 = td_var_offset(min_bs[DDIR_READ]),
126 .off2 = td_var_offset(max_bs[DDIR_READ]),
127 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
128 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
129 .help = "Set block size range (in more detail than bs)",
132 .name = "bs_unaligned",
133 .type = FIO_OPT_STR_SET,
134 .off1 = td_var_offset(bs_unaligned),
135 .help = "Don't sector align IO buffer sizes",
139 .type = FIO_OPT_STR_VAL,
140 .off1 = td_var_offset(start_offset),
141 .help = "Start IO from this offset",
145 .name = "randrepeat",
146 .type = FIO_OPT_BOOL,
147 .off1 = td_var_offset(rand_repeatable),
148 .help = "Use repeatable random IO pattern",
152 .name = "norandommap",
153 .type = FIO_OPT_STR_SET,
154 .off1 = td_var_offset(norandommap),
155 .help = "Accept potential duplicate random blocks",
160 .off1 = td_var_offset(nr_files),
161 .help = "Split job workload between this number of files",
165 .name = "file_service_type",
167 .off1 = td_var_offset(file_service_type),
168 .help = "How to select which file to service next",
171 { .ival = "random", .oval = FIO_FSERVICE_RANDOM },
172 { .ival = "roundrobin", .oval = FIO_FSERVICE_RR },
178 .off1 = td_var_offset(fsync_blocks),
179 .help = "Issue fsync for writes every given number of blocks",
184 .type = FIO_OPT_BOOL,
185 .off1 = td_var_offset(odirect),
186 .help = "Use O_DIRECT IO (negates buffered)",
191 .type = FIO_OPT_BOOL,
192 .off1 = td_var_offset(odirect),
194 .help = "Use buffered IO (negates direct)",
199 .type = FIO_OPT_BOOL,
200 .off1 = td_var_offset(overwrite),
201 .help = "When writing, set whether to overwrite current data",
207 .off1 = td_var_offset(loops),
208 .help = "Number of times to run the job",
214 .off1 = td_var_offset(numjobs),
215 .help = "Duplicate this job this many times",
219 .name = "startdelay",
221 .off1 = td_var_offset(start_delay),
222 .help = "Only start job when this period has passed",
228 .type = FIO_OPT_STR_VAL_TIME,
229 .off1 = td_var_offset(timeout),
230 .help = "Stop workload when this amount of time has passed",
237 .off1 = td_var_offset(mem_type),
238 .help = "Backing type for IO buffers",
241 { .ival = "malloc", .oval = MEM_MALLOC },
242 { .ival = "shm", .oval = MEM_SHM },
243 #ifdef FIO_HAVE_HUGETLB
244 { .ival = "shmhuge", .oval = MEM_SHMHUGE },
246 { .ival = "mmap", .oval = MEM_MMAP },
247 #ifdef FIO_HAVE_HUGETLB
248 { .ival = "mmaphuge", .oval = MEM_MMAPHUGE },
255 .off1 = td_var_offset(verify),
256 .help = "Verify sum function",
259 { .ival = "0", .oval = VERIFY_NONE },
260 { .ival = "crc32", .oval = VERIFY_CRC32 },
261 { .ival = "md5", .oval = VERIFY_MD5 },
265 .name = "write_iolog",
266 .type = FIO_OPT_STR_STORE,
267 .off1 = td_var_offset(write_iolog_file),
268 .help = "Store IO pattern to file",
271 .name = "read_iolog",
272 .type = FIO_OPT_STR_STORE,
273 .off1 = td_var_offset(read_iolog_file),
274 .help = "Playback IO pattern from file",
277 .name = "exec_prerun",
278 .type = FIO_OPT_STR_STORE,
279 .off1 = td_var_offset(exec_prerun),
280 .help = "Execute this file prior to running job",
283 .name = "exec_postrun",
284 .type = FIO_OPT_STR_STORE,
285 .off1 = td_var_offset(exec_postrun),
286 .help = "Execute this file after running job",
288 #ifdef FIO_HAVE_IOSCHED_SWITCH
290 .name = "ioscheduler",
291 .type = FIO_OPT_STR_STORE,
292 .off1 = td_var_offset(ioscheduler),
293 .help = "Use this IO scheduler on the backing device",
298 .type = FIO_OPT_STR_VAL,
299 .off1 = td_var_offset(zone_size),
300 .help = "Give size of an IO zone",
305 .type = FIO_OPT_STR_VAL,
306 .off1 = td_var_offset(zone_skip),
307 .help = "Space between IO zones",
312 .type = FIO_OPT_STR_VAL,
313 .cb = str_lockmem_cb,
314 .help = "Lock down this amount of memory",
318 .name = "rwmixcycle",
320 .off1 = td_var_offset(rwmixcycle),
321 .help = "Cycle period for mixed read/write workloads (msec)",
327 .off1 = td_var_offset(rwmixread),
329 .help = "Percentage of mixed workload that is reads",
333 .name = "rwmixwrite",
335 .off1 = td_var_offset(rwmixwrite),
337 .help = "Percentage of mixed workload that is writes",
343 .off1 = td_var_offset(nice),
344 .help = "Set job CPU nice value",
349 #ifdef FIO_HAVE_IOPRIO
354 .help = "Set job IO priority value",
361 .cb = str_prioclass_cb,
362 .help = "Set job IO priority class",
370 .off1 = td_var_offset(thinktime),
371 .help = "Idle time between IO buffers (usec)",
375 .name = "thinktime_spin",
377 .off1 = td_var_offset(thinktime_spin),
378 .help = "Start thinktime by spinning this amount (usec)",
382 .name = "thinktime_blocks",
384 .off1 = td_var_offset(thinktime_blocks),
385 .help = "IO buffer period between 'thinktime'",
391 .off1 = td_var_offset(rate),
392 .help = "Set bandwidth rate",
397 .off1 = td_var_offset(ratemin),
398 .help = "The bottom limit accepted",
403 .off1 = td_var_offset(ratecycle),
404 .help = "Window average for rate limits (msec)",
408 .name = "invalidate",
409 .type = FIO_OPT_BOOL,
410 .off1 = td_var_offset(invalidate_cache),
411 .help = "Invalidate buffer/page cache prior to running job",
416 .type = FIO_OPT_BOOL,
417 .off1 = td_var_offset(sync_io),
418 .help = "Use O_SYNC for buffered writes",
424 .off1 = td_var_offset(bw_avg_time),
425 .help = "Time window over which to calculate bandwidth (msec)",
429 .name = "create_serialize",
430 .type = FIO_OPT_BOOL,
431 .off1 = td_var_offset(create_serialize),
432 .help = "Serialize creating of job files",
436 .name = "create_fsync",
437 .type = FIO_OPT_BOOL,
438 .off1 = td_var_offset(create_fsync),
439 .help = "Fsync file after creation",
445 .off1 = td_var_offset(cpuload),
446 .help = "Use this percentage of CPU",
451 .off1 = td_var_offset(cpucycle),
452 .help = "Length of the CPU burn cycles",
454 #ifdef FIO_HAVE_CPU_AFFINITY
458 .cb = str_cpumask_cb,
459 .help = "CPU affinity mask",
464 .type = FIO_OPT_BOOL,
465 .off1 = td_var_offset(end_fsync),
466 .help = "Include fsync at the end of job",
471 .type = FIO_OPT_BOOL,
472 .off1 = td_var_offset(unlink),
473 .help = "Unlink created files after job has completed",
478 .type = FIO_OPT_STR_SET,
479 .cb = str_exitall_cb,
480 .help = "Terminate all jobs when one exits",
484 .type = FIO_OPT_STR_SET,
485 .off1 = td_var_offset(stonewall),
486 .help = "Insert a hard barrier between this job and previous",
490 .type = FIO_OPT_STR_SET,
491 .off1 = td_var_offset(use_thread),
492 .help = "Use threads instead of forks",
495 .name = "write_bw_log",
496 .type = FIO_OPT_STR_SET,
497 .off1 = td_var_offset(write_bw_log),
498 .help = "Write log of bandwidth during run",
501 .name = "write_lat_log",
502 .type = FIO_OPT_STR_SET,
503 .off1 = td_var_offset(write_lat_log),
504 .help = "Write log of latency during run",
507 .name = "hugepage-size",
508 .type = FIO_OPT_STR_VAL,
509 .off1 = td_var_offset(hugepage_size),
510 .help = "When using hugepages, specify size of each page",
511 .def = __stringify(FIO_HUGE_PAGE),
518 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
519 #define FIO_CMD_OPTS (16)
520 #define FIO_GETOPT_JOB (0x89988998)
523 * Command line options. These will contain the above, plus a few
524 * extra that only pertain to fio itself and not jobs.
526 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
529 .has_arg = required_argument,
534 .has_arg = required_argument,
538 .name = "latency-log",
539 .has_arg = required_argument,
543 .name = "bandwidth-log",
544 .has_arg = required_argument,
549 .has_arg = optional_argument,
554 .has_arg = no_argument,
559 .has_arg = no_argument,
564 .has_arg = required_argument,
572 static int def_timeout = 0;
574 static char fio_version_string[] = "fio 1.11";
576 static char **ini_file;
577 static int max_jobs = MAX_JOBS;
579 struct thread_data def_thread;
580 struct thread_data *threads = NULL;
582 int exitall_on_terminate = 0;
583 int terse_output = 0;
584 unsigned long long mlock_size = 0;
588 static int write_lat_log = 0;
589 int write_bw_log = 0;
592 * Return a free job structure.
594 static struct thread_data *get_new_job(int global, struct thread_data *parent)
596 struct thread_data *td;
600 if (thread_number >= max_jobs)
603 td = &threads[thread_number++];
606 td->thread_number = thread_number;
610 static void put_job(struct thread_data *td)
612 if (td == &def_thread)
616 fprintf(f_out, "fio: %s\n", td->verror);
618 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
623 * Lazy way of fixing up options that depend on each other. We could also
624 * define option callback handlers, but this is easier.
626 static void fixup_options(struct thread_data *td)
628 if (!td->rwmixread && td->rwmixwrite)
629 td->rwmixread = 100 - td->rwmixwrite;
631 if (td->write_iolog_file && td->read_iolog_file) {
632 log_err("fio: read iolog overrides write_iolog\n");
633 free(td->write_iolog_file);
634 td->write_iolog_file = NULL;
637 if (td->io_ops->flags & FIO_SYNCIO)
641 td->iodepth = td->nr_files;
645 * only really works for sequential io for now, and with 1 file
647 if (td->zone_size && td_random(td) && td->nr_files == 1)
651 * Reads can do overwrites, we always need to pre-create the file
653 if (td_read(td) || td_rw(td))
656 if (!td->min_bs[DDIR_READ])
657 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
658 if (!td->max_bs[DDIR_READ])
659 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
660 if (!td->min_bs[DDIR_WRITE])
661 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
662 if (!td->max_bs[DDIR_WRITE])
663 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
665 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
667 if (td_read(td) && !td_rw(td))
670 if (td->norandommap && td->verify != VERIFY_NONE) {
671 log_err("fio: norandommap given, verify disabled\n");
672 td->verify = VERIFY_NONE;
674 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
675 log_err("fio: bs_unaligned may not work with raw io\n");
678 * O_DIRECT and char doesn't mix, clear that flag if necessary.
680 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
684 * thinktime_spin must be less than thinktime
686 if (td->thinktime_spin > td->thinktime)
687 td->thinktime_spin = td->thinktime;
690 * The low water mark cannot be bigger than the iodepth
692 if (td->iodepth_low > td->iodepth || !td->iodepth_low)
693 td->iodepth_low = td->iodepth;
697 * This function leaks the buffer
699 static char *to_kmg(unsigned int val)
701 char *buf = malloc(32);
702 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
713 snprintf(buf, 31, "%u%c", val, *p);
718 * Adds a job to the list of things todo. Sanitizes the various options
719 * to make sure we don't have conflicts, and initializes various
722 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
724 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
725 "randread", "randwrite", "randrw" };
731 * the def_thread is just for options, it's not a real job
733 if (td == &def_thread)
739 td->io_ops->flags |= FIO_RAWIO;
741 td->filetype = FIO_TYPE_FILE;
742 if (td->filename && !lstat(td->filename, &sb)) {
743 if (S_ISBLK(sb.st_mode))
744 td->filetype = FIO_TYPE_BD;
745 else if (S_ISCHR(sb.st_mode))
746 td->filetype = FIO_TYPE_CHAR;
752 td->nr_uniq_files = 1;
754 td->nr_uniq_files = td->nr_files;
756 if (td->filetype == FIO_TYPE_FILE || td->filename) {
760 if (td->directory && td->directory[0] != '\0') {
761 if (lstat(td->directory, &sb) < 0) {
762 log_err("fio: %s is not a directory\n", td->directory);
763 td_verror(td, errno, "lstat");
766 if (!S_ISDIR(sb.st_mode)) {
767 log_err("fio: %s is not a directory\n", td->directory);
770 len = sprintf(tmp, "%s/", td->directory);
773 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
775 for_each_file(td, f, i) {
776 memset(f, 0, sizeof(*f));
780 sprintf(tmp + len, "%s", td->filename);
782 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
783 f->file_name = strdup(tmp);
787 td->files = malloc(sizeof(struct fio_file));
790 memset(f, 0, sizeof(*f));
792 f->file_name = strdup(jobname);
795 for_each_file(td, f, i) {
796 f->file_size = td->total_file_size / td->nr_files;
797 f->file_offset = td->start_offset;
800 fio_sem_init(&td->mutex, 0);
802 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
803 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
804 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
806 if (td->stonewall && td->thread_number > 1)
809 td->groupid = groupid;
814 if (td->write_lat_log) {
815 setup_log(&td->ts.slat_log);
816 setup_log(&td->ts.clat_log);
818 if (td->write_bw_log)
819 setup_log(&td->ts.bw_log);
822 td->name = strdup(jobname);
826 if (td->io_ops->flags & FIO_CPUIO)
827 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
829 char *c1, *c2, *c3, *c4;
831 c1 = to_kmg(td->min_bs[DDIR_READ]);
832 c2 = to_kmg(td->max_bs[DDIR_READ]);
833 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
834 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
836 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);
843 } else if (job_add_num == 1)
844 fprintf(f_out, "...\n");
848 * recurse add identical jobs, clear numjobs and stonewall options
849 * as they don't apply to sub-jobs
851 numjobs = td->numjobs;
853 struct thread_data *td_new = get_new_job(0, td);
859 td_new->stonewall = 0;
860 job_add_num = numjobs - 1;
862 if (add_job(td_new, jobname, job_add_num))
872 * Initialize the various random states we need (random io, block size ranges,
873 * read/write mix, etc).
875 int init_random_state(struct thread_data *td)
877 unsigned long seeds[5];
878 int fd, num_maps, blocks, i;
881 if (td->io_ops->flags & FIO_CPUIO)
884 fd = open("/dev/urandom", O_RDONLY);
886 td_verror(td, errno, "open");
890 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
891 td_verror(td, EIO, "read");
898 os_random_seed(seeds[0], &td->bsrange_state);
899 os_random_seed(seeds[1], &td->verify_state);
900 os_random_seed(seeds[2], &td->rwmix_state);
902 if (td->file_service_type == FIO_FSERVICE_RANDOM)
903 os_random_seed(seeds[3], &td->next_file_state);
908 if (td->rand_repeatable)
909 seeds[4] = FIO_RANDSEED * td->thread_number;
911 if (!td->norandommap) {
912 for_each_file(td, f, i) {
913 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
914 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
915 f->file_map = malloc(num_maps * sizeof(long));
916 f->num_maps = num_maps;
917 memset(f->file_map, 0, num_maps * sizeof(long));
921 os_random_seed(seeds[4], &td->random_state);
925 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
927 #ifdef FIO_HAVE_CPU_AFFINITY
932 for (i = 0; i < sizeof(int) * 8; i++) {
934 CPU_SET(i, &cpumask);
939 static int is_empty_or_comment(char *line)
943 for (i = 0; i < strlen(line); i++) {
948 if (!isspace(line[i]) && !iscntrl(line[i]))
956 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
958 static char *get_mmap_file(const char *str)
960 char *p = strstr(str, ":");
966 strip_blank_front(&p);
971 static int str_mem_cb(void *data, const char *mem)
973 struct thread_data *td = data;
975 if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
976 td->mmapfile = get_mmap_file(mem);
977 if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
978 log_err("fio: mmaphuge:/path/to/file\n");
986 static int str_ioengine_cb(void *data, const char *str)
988 struct thread_data *td = data;
990 td->io_ops = load_ioengine(td, str);
997 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1003 #ifdef FIO_HAVE_IOPRIO
1004 static int str_prioclass_cb(void *data, unsigned int *val)
1006 struct thread_data *td = data;
1008 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1012 static int str_prio_cb(void *data, unsigned int *val)
1014 struct thread_data *td = data;
1021 static int str_exitall_cb(void)
1023 exitall_on_terminate = 1;
1027 static int str_cpumask_cb(void *data, unsigned int *val)
1029 struct thread_data *td = data;
1031 fill_cpu_mask(td->cpumask, *val);
1036 * This is our [ini] type file parser.
1038 static int parse_jobs_ini(char *file, int stonewall_flag)
1040 unsigned int global;
1041 struct thread_data *td;
1042 char *string, *name;
1046 int ret = 0, stonewall;
1048 f = fopen(file, "r");
1050 perror("fopen job file");
1054 string = malloc(4096);
1056 memset(name, 0, 256);
1058 stonewall = stonewall_flag;
1060 p = fgets(string, 4095, f);
1063 if (is_empty_or_comment(p))
1065 if (sscanf(p, "[%255s]", name) != 1)
1068 global = !strncmp(name, "global", 6);
1070 name[strlen(name) - 1] = '\0';
1072 td = get_new_job(global, &def_thread);
1079 * Seperate multiple job files by a stonewall
1081 if (!global && stonewall) {
1082 td->stonewall = stonewall;
1087 while ((p = fgets(string, 4096, f)) != NULL) {
1088 if (is_empty_or_comment(p))
1091 strip_blank_front(&p);
1101 * Don't break here, continue parsing options so we
1102 * dump all the bad ones. Makes trial/error fixups
1103 * easier on the user.
1105 ret |= parse_option(p, options, td);
1110 ret = add_job(td, name, 0);
1112 log_err("fio: job %s dropped\n", name);
1123 static int fill_def_thread(void)
1125 memset(&def_thread, 0, sizeof(def_thread));
1127 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1128 perror("sched_getaffinity");
1133 * fill default options
1135 fill_default_options(&def_thread, options);
1137 def_thread.timeout = def_timeout;
1138 def_thread.write_bw_log = write_bw_log;
1139 def_thread.write_lat_log = write_lat_log;
1141 #ifdef FIO_HAVE_DISK_UTIL
1142 def_thread.do_disk_util = 1;
1148 static void usage(void)
1150 printf("%s\n", fio_version_string);
1151 printf("\t--output\tWrite output to file\n");
1152 printf("\t--timeout\tRuntime in seconds\n");
1153 printf("\t--latency-log\tGenerate per-job latency logs\n");
1154 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1155 printf("\t--minimal\tMinimal (terse) output\n");
1156 printf("\t--version\tPrint version info and exit\n");
1157 printf("\t--help\t\tPrint this page\n");
1158 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1161 static int parse_cmd_line(int argc, char *argv[])
1163 struct thread_data *td = NULL;
1164 int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
1166 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1169 def_timeout = atoi(optarg);
1178 f_out = fopen(optarg, "w+");
1180 perror("fopen output");
1192 ret = show_cmd_help(options, optarg);
1195 printf("%s\n", fio_version_string);
1197 case FIO_GETOPT_JOB: {
1198 const char *opt = long_options[lidx].name;
1201 if (!strncmp(opt, "name", 4) && td) {
1202 ret = add_job(td, td->name ?: "fio", 0);
1210 int global = !strncmp(val, "global", 6);
1212 td = get_new_job(global, &def_thread);
1217 ret = parse_cmd_option(opt, val, options, td);
1231 ret = add_job(td, td->name ?: "fio", 0);
1237 while (optind < argc) {
1239 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1240 ini_file[ini_idx - 1] = strdup(argv[optind]);
1247 static void free_shm(void)
1249 struct shmid_ds sbuf;
1252 shmdt((void *) threads);
1254 shmctl(shm_id, IPC_RMID, &sbuf);
1259 * The thread area is shared between the main process and the job
1260 * threads/processes. So setup a shared memory segment that will hold
1263 static int setup_thread_area(void)
1266 * 1024 is too much on some machines, scale max_jobs if
1267 * we get a failure that looks like too large a shm segment
1270 size_t size = max_jobs * sizeof(struct thread_data);
1272 shm_id = shmget(0, size, IPC_CREAT | 0600);
1275 if (errno != EINVAL) {
1286 threads = shmat(shm_id, NULL, 0);
1287 if (threads == (void *) -1) {
1297 * Copy the fio options into the long options map, so we mirror
1298 * job and cmd line options.
1300 static void dupe_job_options(void)
1302 struct fio_option *o;
1306 while (long_options[i].name)
1311 long_options[i].name = o->name;
1312 long_options[i].val = FIO_GETOPT_JOB;
1313 if (o->type == FIO_OPT_STR_SET)
1314 long_options[i].has_arg = no_argument;
1316 long_options[i].has_arg = required_argument;
1320 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1324 int parse_options(int argc, char *argv[])
1331 options_init(options);
1335 if (setup_thread_area())
1337 if (fill_def_thread())
1340 job_files = parse_cmd_line(argc, argv);
1342 for (i = 0; i < job_files; i++) {
1343 if (fill_def_thread())
1345 if (parse_jobs_ini(ini_file[i], i))
1352 if (!thread_number) {
1353 log_err("No jobs defined(s)\n");