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",
89 #ifdef FIO_HAVE_LIBAIO
90 { .ival = "libaio", },
92 #ifdef FIO_HAVE_POSIXAIO
93 { .ival = "posixaio", },
96 #ifdef FIO_HAVE_SPLICE
97 { .ival = "splice", },
102 { .ival = "null", }, { .ival = "net", },
103 #ifdef FIO_HAVE_SYSLET
104 { .ival = "syslet-rw", },
111 .off1 = td_var_offset(iodepth),
112 .help = "Amount of IO buffers to keep in flight",
116 .name = "iodepth_low",
118 .off1 = td_var_offset(iodepth_low),
119 .help = "Low water mark for queuing depth",
123 .type = FIO_OPT_STR_VAL,
124 .off1 = td_var_offset(total_file_size),
125 .help = "Size of device or file",
129 .type = FIO_OPT_STR_VAL_INT,
130 .off1 = td_var_offset(bs[DDIR_READ]),
131 .off2 = td_var_offset(bs[DDIR_WRITE]),
132 .help = "Block size unit",
137 .type = FIO_OPT_RANGE,
138 .off1 = td_var_offset(min_bs[DDIR_READ]),
139 .off2 = td_var_offset(max_bs[DDIR_READ]),
140 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
141 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
142 .help = "Set block size range (in more detail than bs)",
145 .name = "bs_unaligned",
146 .type = FIO_OPT_STR_SET,
147 .off1 = td_var_offset(bs_unaligned),
148 .help = "Don't sector align IO buffer sizes",
152 .type = FIO_OPT_STR_VAL,
153 .off1 = td_var_offset(start_offset),
154 .help = "Start IO from this offset",
158 .name = "randrepeat",
159 .type = FIO_OPT_BOOL,
160 .off1 = td_var_offset(rand_repeatable),
161 .help = "Use repeatable random IO pattern",
165 .name = "norandommap",
166 .type = FIO_OPT_STR_SET,
167 .off1 = td_var_offset(norandommap),
168 .help = "Accept potential duplicate random blocks",
173 .off1 = td_var_offset(nr_files),
174 .help = "Split job workload between this number of files",
178 .name = "file_service_type",
180 .off1 = td_var_offset(file_service_type),
181 .help = "How to select which file to service next",
184 { .ival = "random", .oval = FIO_FSERVICE_RANDOM },
185 { .ival = "roundrobin", .oval = FIO_FSERVICE_RR },
191 .off1 = td_var_offset(fsync_blocks),
192 .help = "Issue fsync for writes every given number of blocks",
197 .type = FIO_OPT_BOOL,
198 .off1 = td_var_offset(odirect),
199 .help = "Use O_DIRECT IO (negates buffered)",
204 .type = FIO_OPT_BOOL,
205 .off1 = td_var_offset(odirect),
207 .help = "Use buffered IO (negates direct)",
212 .type = FIO_OPT_BOOL,
213 .off1 = td_var_offset(overwrite),
214 .help = "When writing, set whether to overwrite current data",
220 .off1 = td_var_offset(loops),
221 .help = "Number of times to run the job",
227 .off1 = td_var_offset(numjobs),
228 .help = "Duplicate this job this many times",
232 .name = "startdelay",
234 .off1 = td_var_offset(start_delay),
235 .help = "Only start job when this period has passed",
241 .type = FIO_OPT_STR_VAL_TIME,
242 .off1 = td_var_offset(timeout),
243 .help = "Stop workload when this amount of time has passed",
250 .off1 = td_var_offset(mem_type),
251 .help = "Backing type for IO buffers",
254 { .ival = "malloc", .oval = MEM_MALLOC },
255 { .ival = "shm", .oval = MEM_SHM },
256 #ifdef FIO_HAVE_HUGETLB
257 { .ival = "shmhuge", .oval = MEM_SHMHUGE },
259 { .ival = "mmap", .oval = MEM_MMAP },
260 #ifdef FIO_HAVE_HUGETLB
261 { .ival = "mmaphuge", .oval = MEM_MMAPHUGE },
268 .off1 = td_var_offset(verify),
269 .help = "Verify sum function",
272 { .ival = "0", .oval = VERIFY_NONE },
273 { .ival = "crc32", .oval = VERIFY_CRC32 },
274 { .ival = "md5", .oval = VERIFY_MD5 },
278 .name = "write_iolog",
279 .type = FIO_OPT_STR_STORE,
280 .off1 = td_var_offset(write_iolog_file),
281 .help = "Store IO pattern to file",
284 .name = "read_iolog",
285 .type = FIO_OPT_STR_STORE,
286 .off1 = td_var_offset(read_iolog_file),
287 .help = "Playback IO pattern from file",
290 .name = "exec_prerun",
291 .type = FIO_OPT_STR_STORE,
292 .off1 = td_var_offset(exec_prerun),
293 .help = "Execute this file prior to running job",
296 .name = "exec_postrun",
297 .type = FIO_OPT_STR_STORE,
298 .off1 = td_var_offset(exec_postrun),
299 .help = "Execute this file after running job",
301 #ifdef FIO_HAVE_IOSCHED_SWITCH
303 .name = "ioscheduler",
304 .type = FIO_OPT_STR_STORE,
305 .off1 = td_var_offset(ioscheduler),
306 .help = "Use this IO scheduler on the backing device",
311 .type = FIO_OPT_STR_VAL,
312 .off1 = td_var_offset(zone_size),
313 .help = "Give size of an IO zone",
318 .type = FIO_OPT_STR_VAL,
319 .off1 = td_var_offset(zone_skip),
320 .help = "Space between IO zones",
325 .type = FIO_OPT_STR_VAL,
326 .cb = str_lockmem_cb,
327 .help = "Lock down this amount of memory",
331 .name = "rwmixcycle",
333 .off1 = td_var_offset(rwmixcycle),
334 .help = "Cycle period for mixed read/write workloads (msec)",
340 .off1 = td_var_offset(rwmixread),
342 .help = "Percentage of mixed workload that is reads",
346 .name = "rwmixwrite",
348 .off1 = td_var_offset(rwmixwrite),
350 .help = "Percentage of mixed workload that is writes",
356 .off1 = td_var_offset(nice),
357 .help = "Set job CPU nice value",
362 #ifdef FIO_HAVE_IOPRIO
367 .help = "Set job IO priority value",
374 .cb = str_prioclass_cb,
375 .help = "Set job IO priority class",
383 .off1 = td_var_offset(thinktime),
384 .help = "Idle time between IO buffers (usec)",
388 .name = "thinktime_spin",
390 .off1 = td_var_offset(thinktime_spin),
391 .help = "Start thinktime by spinning this amount (usec)",
395 .name = "thinktime_blocks",
397 .off1 = td_var_offset(thinktime_blocks),
398 .help = "IO buffer period between 'thinktime'",
404 .off1 = td_var_offset(rate),
405 .help = "Set bandwidth rate",
410 .off1 = td_var_offset(ratemin),
411 .help = "The bottom limit accepted",
416 .off1 = td_var_offset(ratecycle),
417 .help = "Window average for rate limits (msec)",
421 .name = "invalidate",
422 .type = FIO_OPT_BOOL,
423 .off1 = td_var_offset(invalidate_cache),
424 .help = "Invalidate buffer/page cache prior to running job",
429 .type = FIO_OPT_BOOL,
430 .off1 = td_var_offset(sync_io),
431 .help = "Use O_SYNC for buffered writes",
437 .off1 = td_var_offset(bw_avg_time),
438 .help = "Time window over which to calculate bandwidth (msec)",
442 .name = "create_serialize",
443 .type = FIO_OPT_BOOL,
444 .off1 = td_var_offset(create_serialize),
445 .help = "Serialize creating of job files",
449 .name = "create_fsync",
450 .type = FIO_OPT_BOOL,
451 .off1 = td_var_offset(create_fsync),
452 .help = "Fsync file after creation",
458 .off1 = td_var_offset(cpuload),
459 .help = "Use this percentage of CPU",
464 .off1 = td_var_offset(cpucycle),
465 .help = "Length of the CPU burn cycles",
467 #ifdef FIO_HAVE_CPU_AFFINITY
471 .cb = str_cpumask_cb,
472 .help = "CPU affinity mask",
477 .type = FIO_OPT_BOOL,
478 .off1 = td_var_offset(end_fsync),
479 .help = "Include fsync at the end of job",
484 .type = FIO_OPT_BOOL,
485 .off1 = td_var_offset(unlink),
486 .help = "Unlink created files after job has completed",
491 .type = FIO_OPT_STR_SET,
492 .cb = str_exitall_cb,
493 .help = "Terminate all jobs when one exits",
497 .type = FIO_OPT_STR_SET,
498 .off1 = td_var_offset(stonewall),
499 .help = "Insert a hard barrier between this job and previous",
503 .type = FIO_OPT_STR_SET,
504 .off1 = td_var_offset(use_thread),
505 .help = "Use threads instead of forks",
508 .name = "write_bw_log",
509 .type = FIO_OPT_STR_SET,
510 .off1 = td_var_offset(write_bw_log),
511 .help = "Write log of bandwidth during run",
514 .name = "write_lat_log",
515 .type = FIO_OPT_STR_SET,
516 .off1 = td_var_offset(write_lat_log),
517 .help = "Write log of latency during run",
520 .name = "hugepage-size",
521 .type = FIO_OPT_STR_VAL,
522 .off1 = td_var_offset(hugepage_size),
523 .help = "When using hugepages, specify size of each page",
524 .def = __stringify(FIO_HUGE_PAGE),
531 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
532 #define FIO_CMD_OPTS (16)
533 #define FIO_GETOPT_JOB (0x89988998)
536 * Command line options. These will contain the above, plus a few
537 * extra that only pertain to fio itself and not jobs.
539 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
542 .has_arg = required_argument,
547 .has_arg = required_argument,
551 .name = "latency-log",
552 .has_arg = required_argument,
556 .name = "bandwidth-log",
557 .has_arg = required_argument,
562 .has_arg = optional_argument,
567 .has_arg = no_argument,
572 .has_arg = no_argument,
577 .has_arg = required_argument,
585 static int def_timeout = 0;
587 static char fio_version_string[] = "fio 1.11";
589 static char **ini_file;
590 static int max_jobs = MAX_JOBS;
592 struct thread_data def_thread;
593 struct thread_data *threads = NULL;
595 int exitall_on_terminate = 0;
596 int terse_output = 0;
597 unsigned long long mlock_size = 0;
601 static int write_lat_log = 0;
602 int write_bw_log = 0;
605 * Return a free job structure.
607 static struct thread_data *get_new_job(int global, struct thread_data *parent)
609 struct thread_data *td;
613 if (thread_number >= max_jobs)
616 td = &threads[thread_number++];
619 td->thread_number = thread_number;
623 static void put_job(struct thread_data *td)
625 if (td == &def_thread)
629 fprintf(f_out, "fio: %s\n", td->verror);
631 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
636 * Lazy way of fixing up options that depend on each other. We could also
637 * define option callback handlers, but this is easier.
639 static void fixup_options(struct thread_data *td)
641 if (!td->rwmixread && td->rwmixwrite)
642 td->rwmixread = 100 - td->rwmixwrite;
644 if (td->write_iolog_file && td->read_iolog_file) {
645 log_err("fio: read iolog overrides write_iolog\n");
646 free(td->write_iolog_file);
647 td->write_iolog_file = NULL;
650 if (td->io_ops->flags & FIO_SYNCIO)
654 td->iodepth = td->nr_files;
658 * only really works for sequential io for now, and with 1 file
660 if (td->zone_size && td_random(td) && td->nr_files == 1)
664 * Reads can do overwrites, we always need to pre-create the file
666 if (td_read(td) || td_rw(td))
669 if (!td->min_bs[DDIR_READ])
670 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
671 if (!td->max_bs[DDIR_READ])
672 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
673 if (!td->min_bs[DDIR_WRITE])
674 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
675 if (!td->max_bs[DDIR_WRITE])
676 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
678 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
680 if (td_read(td) && !td_rw(td))
683 if (td->norandommap && td->verify != VERIFY_NONE) {
684 log_err("fio: norandommap given, verify disabled\n");
685 td->verify = VERIFY_NONE;
687 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
688 log_err("fio: bs_unaligned may not work with raw io\n");
691 * O_DIRECT and char doesn't mix, clear that flag if necessary.
693 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
697 * thinktime_spin must be less than thinktime
699 if (td->thinktime_spin > td->thinktime)
700 td->thinktime_spin = td->thinktime;
703 * The low water mark cannot be bigger than the iodepth
705 if (td->iodepth_low > td->iodepth || !td->iodepth_low)
706 td->iodepth_low = td->iodepth;
710 * This function leaks the buffer
712 static char *to_kmg(unsigned int val)
714 char *buf = malloc(32);
715 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
726 snprintf(buf, 31, "%u%c", val, *p);
731 * Adds a job to the list of things todo. Sanitizes the various options
732 * to make sure we don't have conflicts, and initializes various
735 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
737 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
738 "randread", "randwrite", "randrw" };
744 * the def_thread is just for options, it's not a real job
746 if (td == &def_thread)
752 td->io_ops->flags |= FIO_RAWIO;
754 td->filetype = FIO_TYPE_FILE;
755 if (td->filename && !lstat(td->filename, &sb)) {
756 if (S_ISBLK(sb.st_mode))
757 td->filetype = FIO_TYPE_BD;
758 else if (S_ISCHR(sb.st_mode))
759 td->filetype = FIO_TYPE_CHAR;
765 td->nr_uniq_files = 1;
767 td->nr_uniq_files = td->nr_files;
769 if (td->filetype == FIO_TYPE_FILE || td->filename) {
773 if (td->directory && td->directory[0] != '\0') {
774 if (lstat(td->directory, &sb) < 0) {
775 log_err("fio: %s is not a directory\n", td->directory);
776 td_verror(td, errno, "lstat");
779 if (!S_ISDIR(sb.st_mode)) {
780 log_err("fio: %s is not a directory\n", td->directory);
783 len = sprintf(tmp, "%s/", td->directory);
786 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
788 for_each_file(td, f, i) {
789 memset(f, 0, sizeof(*f));
793 sprintf(tmp + len, "%s", td->filename);
795 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
796 f->file_name = strdup(tmp);
800 td->files = malloc(sizeof(struct fio_file));
803 memset(f, 0, sizeof(*f));
805 f->file_name = strdup(jobname);
808 for_each_file(td, f, i) {
809 f->file_size = td->total_file_size / td->nr_files;
810 f->file_offset = td->start_offset;
813 fio_sem_init(&td->mutex, 0);
815 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
816 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
817 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
819 if (td->stonewall && td->thread_number > 1)
822 td->groupid = groupid;
827 if (td->write_lat_log) {
828 setup_log(&td->ts.slat_log);
829 setup_log(&td->ts.clat_log);
831 if (td->write_bw_log)
832 setup_log(&td->ts.bw_log);
835 td->name = strdup(jobname);
839 if (td->io_ops->flags & FIO_CPUIO)
840 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
842 char *c1, *c2, *c3, *c4;
844 c1 = to_kmg(td->min_bs[DDIR_READ]);
845 c2 = to_kmg(td->max_bs[DDIR_READ]);
846 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
847 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
849 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);
856 } else if (job_add_num == 1)
857 fprintf(f_out, "...\n");
861 * recurse add identical jobs, clear numjobs and stonewall options
862 * as they don't apply to sub-jobs
864 numjobs = td->numjobs;
866 struct thread_data *td_new = get_new_job(0, td);
872 td_new->stonewall = 0;
873 job_add_num = numjobs - 1;
875 if (add_job(td_new, jobname, job_add_num))
885 * Initialize the various random states we need (random io, block size ranges,
886 * read/write mix, etc).
888 int init_random_state(struct thread_data *td)
890 unsigned long seeds[5];
891 int fd, num_maps, blocks, i;
894 if (td->io_ops->flags & FIO_CPUIO)
897 fd = open("/dev/urandom", O_RDONLY);
899 td_verror(td, errno, "open");
903 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
904 td_verror(td, EIO, "read");
911 os_random_seed(seeds[0], &td->bsrange_state);
912 os_random_seed(seeds[1], &td->verify_state);
913 os_random_seed(seeds[2], &td->rwmix_state);
915 if (td->file_service_type == FIO_FSERVICE_RANDOM)
916 os_random_seed(seeds[3], &td->next_file_state);
921 if (td->rand_repeatable)
922 seeds[4] = FIO_RANDSEED * td->thread_number;
924 if (!td->norandommap) {
925 for_each_file(td, f, i) {
926 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
927 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
928 f->file_map = malloc(num_maps * sizeof(long));
929 f->num_maps = num_maps;
930 memset(f->file_map, 0, num_maps * sizeof(long));
934 os_random_seed(seeds[4], &td->random_state);
938 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
940 #ifdef FIO_HAVE_CPU_AFFINITY
945 for (i = 0; i < sizeof(int) * 8; i++) {
947 CPU_SET(i, &cpumask);
952 static int is_empty_or_comment(char *line)
956 for (i = 0; i < strlen(line); i++) {
961 if (!isspace(line[i]) && !iscntrl(line[i]))
969 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
971 static char *get_mmap_file(const char *str)
973 char *p = strstr(str, ":");
979 strip_blank_front(&p);
984 static int str_mem_cb(void *data, const char *mem)
986 struct thread_data *td = data;
988 if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
989 td->mmapfile = get_mmap_file(mem);
990 if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
991 log_err("fio: mmaphuge:/path/to/file\n");
999 static int str_ioengine_cb(void *data, const char *str)
1001 struct thread_data *td = data;
1003 td->io_ops = load_ioengine(td, str);
1010 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1016 #ifdef FIO_HAVE_IOPRIO
1017 static int str_prioclass_cb(void *data, unsigned int *val)
1019 struct thread_data *td = data;
1021 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1025 static int str_prio_cb(void *data, unsigned int *val)
1027 struct thread_data *td = data;
1034 static int str_exitall_cb(void)
1036 exitall_on_terminate = 1;
1040 static int str_cpumask_cb(void *data, unsigned int *val)
1042 struct thread_data *td = data;
1044 fill_cpu_mask(td->cpumask, *val);
1049 * This is our [ini] type file parser.
1051 static int parse_jobs_ini(char *file, int stonewall_flag)
1053 unsigned int global;
1054 struct thread_data *td;
1055 char *string, *name;
1059 int ret = 0, stonewall;
1061 f = fopen(file, "r");
1063 perror("fopen job file");
1067 string = malloc(4096);
1069 memset(name, 0, 256);
1071 stonewall = stonewall_flag;
1073 p = fgets(string, 4095, f);
1076 if (is_empty_or_comment(p))
1078 if (sscanf(p, "[%255s]", name) != 1)
1081 global = !strncmp(name, "global", 6);
1083 name[strlen(name) - 1] = '\0';
1085 td = get_new_job(global, &def_thread);
1092 * Seperate multiple job files by a stonewall
1094 if (!global && stonewall) {
1095 td->stonewall = stonewall;
1100 while ((p = fgets(string, 4096, f)) != NULL) {
1101 if (is_empty_or_comment(p))
1104 strip_blank_front(&p);
1114 * Don't break here, continue parsing options so we
1115 * dump all the bad ones. Makes trial/error fixups
1116 * easier on the user.
1118 ret |= parse_option(p, options, td);
1123 ret = add_job(td, name, 0);
1125 log_err("fio: job %s dropped\n", name);
1136 static int fill_def_thread(void)
1138 memset(&def_thread, 0, sizeof(def_thread));
1140 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1141 perror("sched_getaffinity");
1146 * fill default options
1148 fill_default_options(&def_thread, options);
1150 def_thread.timeout = def_timeout;
1151 def_thread.write_bw_log = write_bw_log;
1152 def_thread.write_lat_log = write_lat_log;
1154 #ifdef FIO_HAVE_DISK_UTIL
1155 def_thread.do_disk_util = 1;
1161 static void usage(void)
1163 printf("%s\n", fio_version_string);
1164 printf("\t--output\tWrite output to file\n");
1165 printf("\t--timeout\tRuntime in seconds\n");
1166 printf("\t--latency-log\tGenerate per-job latency logs\n");
1167 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1168 printf("\t--minimal\tMinimal (terse) output\n");
1169 printf("\t--version\tPrint version info and exit\n");
1170 printf("\t--help\t\tPrint this page\n");
1171 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1174 static int parse_cmd_line(int argc, char *argv[])
1176 struct thread_data *td = NULL;
1177 int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
1179 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1182 def_timeout = atoi(optarg);
1191 f_out = fopen(optarg, "w+");
1193 perror("fopen output");
1205 ret = show_cmd_help(options, optarg);
1208 printf("%s\n", fio_version_string);
1210 case FIO_GETOPT_JOB: {
1211 const char *opt = long_options[lidx].name;
1214 if (!strncmp(opt, "name", 4) && td) {
1215 ret = add_job(td, td->name ?: "fio", 0);
1223 int global = !strncmp(val, "global", 6);
1225 td = get_new_job(global, &def_thread);
1230 ret = parse_cmd_option(opt, val, options, td);
1244 ret = add_job(td, td->name ?: "fio", 0);
1250 while (optind < argc) {
1252 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1253 ini_file[ini_idx - 1] = strdup(argv[optind]);
1260 static void free_shm(void)
1262 struct shmid_ds sbuf;
1265 shmdt((void *) threads);
1267 shmctl(shm_id, IPC_RMID, &sbuf);
1272 * The thread area is shared between the main process and the job
1273 * threads/processes. So setup a shared memory segment that will hold
1276 static int setup_thread_area(void)
1279 * 1024 is too much on some machines, scale max_jobs if
1280 * we get a failure that looks like too large a shm segment
1283 size_t size = max_jobs * sizeof(struct thread_data);
1285 shm_id = shmget(0, size, IPC_CREAT | 0600);
1288 if (errno != EINVAL) {
1299 threads = shmat(shm_id, NULL, 0);
1300 if (threads == (void *) -1) {
1310 * Copy the fio options into the long options map, so we mirror
1311 * job and cmd line options.
1313 static void dupe_job_options(void)
1315 struct fio_option *o;
1319 while (long_options[i].name)
1324 long_options[i].name = o->name;
1325 long_options[i].val = FIO_GETOPT_JOB;
1326 if (o->type == FIO_OPT_STR_SET)
1327 long_options[i].has_arg = no_argument;
1329 long_options[i].has_arg = required_argument;
1333 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1337 int parse_options(int argc, char *argv[])
1344 options_init(options);
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");