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[] = {
46 .type = FIO_OPT_STR_STORE,
47 .off1 = td_var_offset(name),
48 .help = "Name of this job",
52 .type = FIO_OPT_STR_STORE,
53 .off1 = td_var_offset(directory),
54 .help = "Directory to store files in",
58 .type = FIO_OPT_STR_STORE,
59 .off1 = td_var_offset(filename),
60 .help = "Force the use of a specific file",
66 .help = "IO direction",
68 .posval = { "read", "write", "randwrite", "randread", "rw",
74 .cb = str_ioengine_cb,
75 .help = "IO engine to use",
77 .posval = { "sync", "libaio", "posixaio", "mmap", "splice",
83 .off1 = td_var_offset(iodepth),
84 .help = "Amount of IO buffers to keep in flight",
89 .type = FIO_OPT_STR_VAL,
90 .off1 = td_var_offset(total_file_size),
91 .help = "Size of device or file",
95 .type = FIO_OPT_STR_VAL_INT,
96 .off1 = td_var_offset(bs[DDIR_READ]),
97 .off2 = td_var_offset(bs[DDIR_WRITE]),
98 .help = "Block size unit",
103 .type = FIO_OPT_RANGE,
104 .off1 = td_var_offset(min_bs[DDIR_READ]),
105 .off2 = td_var_offset(max_bs[DDIR_READ]),
106 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
107 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
108 .help = "Set block size range (in more detail than bs)",
111 .name = "bs_unaligned",
112 .type = FIO_OPT_STR_SET,
113 .off1 = td_var_offset(bs_unaligned),
114 .help = "Don't sector align IO buffer sizes",
118 .type = FIO_OPT_STR_VAL,
119 .off1 = td_var_offset(start_offset),
120 .help = "Start IO from this offset",
124 .name = "randrepeat",
125 .type = FIO_OPT_BOOL,
126 .off1 = td_var_offset(rand_repeatable),
127 .help = "Use repeatable random IO pattern",
131 .name = "norandommap",
132 .type = FIO_OPT_STR_SET,
133 .off1 = td_var_offset(norandommap),
134 .help = "Accept potential duplicate random blocks",
139 .off1 = td_var_offset(nr_files),
140 .help = "Split job workload between this number of files",
146 .off1 = td_var_offset(fsync_blocks),
147 .help = "Issue fsync for writes every given number of blocks",
152 .type = FIO_OPT_BOOL,
153 .off1 = td_var_offset(odirect),
154 .help = "Use O_DIRECT IO (negates buffered)",
159 .type = FIO_OPT_BOOL,
160 .off1 = td_var_offset(odirect),
162 .help = "Use buffered IO (negates direct)",
167 .type = FIO_OPT_BOOL,
168 .off1 = td_var_offset(overwrite),
169 .help = "When writing, set whether to overwrite current data",
175 .off1 = td_var_offset(loops),
176 .help = "Number of times to run the job",
182 .off1 = td_var_offset(numjobs),
183 .help = "Duplicate this job this many times",
187 .name = "startdelay",
189 .off1 = td_var_offset(start_delay),
190 .help = "Only start job when this period has passed",
196 .type = FIO_OPT_STR_VAL_TIME,
197 .off1 = td_var_offset(timeout),
198 .help = "Stop workload when this amount of time has passed",
205 .help = "Backing type for IO buffers",
207 .posval = { "malloc", "shm", "shmhuge", "mmap", "mmaphuge", },
213 .help = "Verify sum function",
215 .posval = { "crc32", "md5", },
218 .name = "write_iolog",
219 .type = FIO_OPT_STR_STORE,
220 .off1 = td_var_offset(write_iolog_file),
221 .help = "Store IO pattern to file",
224 .name = "read_iolog",
225 .type = FIO_OPT_STR_STORE,
226 .off1 = td_var_offset(read_iolog_file),
227 .help = "Playback IO pattern from file",
230 .name = "exec_prerun",
231 .type = FIO_OPT_STR_STORE,
232 .off1 = td_var_offset(exec_prerun),
233 .help = "Execute this file prior to running job",
236 .name = "exec_postrun",
237 .type = FIO_OPT_STR_STORE,
238 .off1 = td_var_offset(exec_postrun),
239 .help = "Execute this file after running job",
241 #ifdef FIO_HAVE_IOSCHED_SWITCH
243 .name = "ioscheduler",
244 .type = FIO_OPT_STR_STORE,
245 .off1 = td_var_offset(ioscheduler),
246 .help = "Use this IO scheduler on the backing device",
251 .type = FIO_OPT_STR_VAL,
252 .off1 = td_var_offset(zone_size),
253 .help = "Give size of an IO zone",
258 .type = FIO_OPT_STR_VAL,
259 .off1 = td_var_offset(zone_skip),
260 .help = "Space between IO zones",
265 .type = FIO_OPT_STR_VAL,
266 .cb = str_lockmem_cb,
267 .help = "Lock down this amount of memory",
271 .name = "rwmixcycle",
273 .off1 = td_var_offset(rwmixcycle),
274 .help = "Cycle period for mixed read/write workloads (msec)",
280 .off1 = td_var_offset(rwmixread),
282 .help = "Percentage of mixed workload that is reads",
286 .name = "rwmixwrite",
288 .off1 = td_var_offset(rwmixwrite),
290 .help = "Percentage of mixed workload that is writes",
296 .off1 = td_var_offset(nice),
297 .help = "Set job CPU nice value",
302 #ifdef FIO_HAVE_IOPRIO
307 .help = "Set job IO priority value",
314 .cb = str_prioclass_cb,
315 .help = "Set job IO priority class",
323 .off1 = td_var_offset(thinktime),
324 .help = "Idle time between IO buffers (usec)",
328 .name = "thinktime_blocks",
330 .off1 = td_var_offset(thinktime_blocks),
331 .help = "IO buffer period between 'thinktime'",
337 .off1 = td_var_offset(rate),
338 .help = "Set bandwidth rate",
343 .off1 = td_var_offset(ratemin),
344 .help = "The bottom limit accepted",
349 .off1 = td_var_offset(ratecycle),
350 .help = "Window average for rate limits (msec)",
354 .name = "invalidate",
355 .type = FIO_OPT_BOOL,
356 .off1 = td_var_offset(invalidate_cache),
357 .help = "Invalidate buffer/page cache prior to running job",
362 .type = FIO_OPT_BOOL,
363 .off1 = td_var_offset(sync_io),
364 .help = "Use O_SYNC for buffered writes",
370 .off1 = td_var_offset(bw_avg_time),
371 .help = "Time window over which to calculate bandwidth (msec)",
375 .name = "create_serialize",
376 .type = FIO_OPT_BOOL,
377 .off1 = td_var_offset(create_serialize),
378 .help = "Serialize creating of job files",
382 .name = "create_fsync",
383 .type = FIO_OPT_BOOL,
384 .off1 = td_var_offset(create_fsync),
385 .help = "Fsync file after creation",
391 .off1 = td_var_offset(cpuload),
392 .help = "Use this percentage of CPU",
397 .off1 = td_var_offset(cpucycle),
398 .help = "Length of the CPU burn cycles",
400 #ifdef FIO_HAVE_CPU_AFFINITY
404 .cb = str_cpumask_cb,
405 .help = "CPU affinity mask",
410 .type = FIO_OPT_BOOL,
411 .off1 = td_var_offset(end_fsync),
412 .help = "Include fsync at the end of job",
417 .type = FIO_OPT_BOOL,
418 .off1 = td_var_offset(unlink),
419 .help = "Unlink created files after job has completed",
424 .type = FIO_OPT_STR_SET,
425 .cb = str_exitall_cb,
426 .help = "Terminate all jobs when one exits",
430 .type = FIO_OPT_STR_SET,
431 .off1 = td_var_offset(stonewall),
432 .help = "Insert a hard barrier between this job and previous",
436 .type = FIO_OPT_STR_SET,
437 .off1 = td_var_offset(use_thread),
438 .help = "Use threads instead of forks",
441 .name = "write_bw_log",
442 .type = FIO_OPT_STR_SET,
443 .off1 = td_var_offset(write_bw_log),
444 .help = "Write log of bandwidth during run",
447 .name = "write_lat_log",
448 .type = FIO_OPT_STR_SET,
449 .off1 = td_var_offset(write_lat_log),
450 .help = "Write log of latency during run",
453 .name = "hugepage-size",
454 .type = FIO_OPT_STR_VAL,
455 .off1 = td_var_offset(hugepage_size),
456 .help = "When using hugepages, specify size of each page",
457 .def = __stringify(FIO_HUGE_PAGE),
464 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
465 #define FIO_CMD_OPTS (16)
466 #define FIO_GETOPT_JOB (0x89988998)
469 * Command line options. These will contain the above, plus a few
470 * extra that only pertain to fio itself and not jobs.
472 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
475 .has_arg = required_argument,
480 .has_arg = required_argument,
484 .name = "latency-log",
485 .has_arg = required_argument,
489 .name = "bandwidth-log",
490 .has_arg = required_argument,
495 .has_arg = optional_argument,
500 .has_arg = no_argument,
505 .has_arg = no_argument,
510 .has_arg = required_argument,
518 static int def_timeout = 0;
520 static char fio_version_string[] = "fio 1.11";
522 static char **ini_file;
523 static int max_jobs = MAX_JOBS;
525 struct thread_data def_thread;
526 struct thread_data *threads = NULL;
528 int exitall_on_terminate = 0;
529 int terse_output = 0;
530 unsigned long long mlock_size = 0;
534 static int write_lat_log = 0;
535 static int write_bw_log = 0;
538 * Return a free job structure.
540 static struct thread_data *get_new_job(int global, struct thread_data *parent)
542 struct thread_data *td;
546 if (thread_number >= max_jobs)
549 td = &threads[thread_number++];
552 td->thread_number = thread_number;
556 static void put_job(struct thread_data *td)
558 if (td == &def_thread)
561 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
566 * Lazy way of fixing up options that depend on each other. We could also
567 * define option callback handlers, but this is easier.
569 static void fixup_options(struct thread_data *td)
571 if (!td->rwmixread && td->rwmixwrite)
572 td->rwmixread = 100 - td->rwmixwrite;
574 if (td->write_iolog_file && td->read_iolog_file) {
575 log_err("fio: read iolog overrides write_iolog\n");
576 free(td->write_iolog_file);
577 td->write_iolog_file = NULL;
580 if (td->io_ops->flags & FIO_SYNCIO)
584 td->iodepth = td->nr_files;
588 * only really works for sequential io for now, and with 1 file
590 if (td->zone_size && !td->sequential && td->nr_files == 1)
594 * Reads can do overwrites, we always need to pre-create the file
596 if (td_read(td) || td_rw(td))
599 if (!td->min_bs[DDIR_READ])
600 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
601 if (!td->max_bs[DDIR_READ])
602 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
603 if (!td->min_bs[DDIR_WRITE])
604 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
605 if (!td->max_bs[DDIR_WRITE])
606 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
608 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
610 if (td_read(td) && !td_rw(td))
613 if (td->norandommap && td->verify != VERIFY_NONE) {
614 log_err("fio: norandommap given, verify disabled\n");
615 td->verify = VERIFY_NONE;
617 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
618 log_err("fio: bs_unaligned may not work with raw io\n");
621 * O_DIRECT and char doesn't mix, clear that flag if necessary.
623 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
628 * This function leaks the buffer
630 static char *to_kmg(unsigned int val)
632 char *buf = malloc(32);
633 char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
644 snprintf(buf, 31, "%u%c", val, *p);
649 * Adds a job to the list of things todo. Sanitizes the various options
650 * to make sure we don't have conflicts, and initializes various
653 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
655 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
656 "rw", NULL, "randrw" };
658 int numjobs, ddir, i;
662 * the def_thread is just for options, it's not a real job
664 if (td == &def_thread)
670 td->io_ops->flags |= FIO_RAWIO;
672 td->filetype = FIO_TYPE_FILE;
673 if (!stat(jobname, &sb)) {
674 if (S_ISBLK(sb.st_mode))
675 td->filetype = FIO_TYPE_BD;
676 else if (S_ISCHR(sb.st_mode))
677 td->filetype = FIO_TYPE_CHAR;
683 td->nr_uniq_files = 1;
685 td->nr_uniq_files = td->nr_files;
687 if (td->filetype == FIO_TYPE_FILE || td->filename) {
691 if (td->directory && td->directory[0] != '\0')
692 len = sprintf(tmp, "%s/", td->directory);
694 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
696 for_each_file(td, f, i) {
697 memset(f, 0, sizeof(*f));
701 sprintf(tmp + len, "%s", td->filename);
703 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
704 f->file_name = strdup(tmp);
708 td->files = malloc(sizeof(struct fio_file));
711 memset(f, 0, sizeof(*f));
713 f->file_name = strdup(jobname);
716 for_each_file(td, f, i) {
717 f->file_size = td->total_file_size / td->nr_files;
718 f->file_offset = td->start_offset;
721 fio_sem_init(&td->mutex, 0);
723 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
724 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
725 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
727 if (td->stonewall && td->thread_number > 1)
730 td->groupid = groupid;
735 if (td->write_lat_log) {
736 setup_log(&td->slat_log);
737 setup_log(&td->clat_log);
739 if (td->write_bw_log)
740 setup_log(&td->bw_log);
743 td->name = strdup(jobname);
745 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
749 if (td->io_ops->flags & FIO_CPUIO)
750 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
752 char *c1, *c2, *c3, *c4;
754 c1 = to_kmg(td->min_bs[DDIR_READ]);
755 c2 = to_kmg(td->max_bs[DDIR_READ]);
756 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
757 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
759 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);
766 } else if (job_add_num == 1)
767 fprintf(f_out, "...\n");
771 * recurse add identical jobs, clear numjobs and stonewall options
772 * as they don't apply to sub-jobs
774 numjobs = td->numjobs;
776 struct thread_data *td_new = get_new_job(0, td);
782 td_new->stonewall = 0;
783 job_add_num = numjobs - 1;
785 if (add_job(td_new, jobname, job_add_num))
795 * Initialize the various random states we need (random io, block size ranges,
796 * read/write mix, etc).
798 int init_random_state(struct thread_data *td)
800 unsigned long seeds[4];
801 int fd, num_maps, blocks, i;
804 if (td->io_ops->flags & FIO_CPUIO)
807 fd = open("/dev/urandom", O_RDONLY);
809 td_verror(td, errno);
813 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
821 os_random_seed(seeds[0], &td->bsrange_state);
822 os_random_seed(seeds[1], &td->verify_state);
823 os_random_seed(seeds[2], &td->rwmix_state);
828 if (td->rand_repeatable)
829 seeds[3] = FIO_RANDSEED;
831 if (!td->norandommap) {
832 for_each_file(td, f, i) {
833 blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs;
834 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
835 f->file_map = malloc(num_maps * sizeof(long));
836 f->num_maps = num_maps;
837 memset(f->file_map, 0, num_maps * sizeof(long));
841 os_random_seed(seeds[3], &td->random_state);
845 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
847 #ifdef FIO_HAVE_CPU_AFFINITY
852 for (i = 0; i < sizeof(int) * 8; i++) {
854 CPU_SET(i, &cpumask);
859 static int is_empty_or_comment(char *line)
863 for (i = 0; i < strlen(line); i++) {
866 if (!isspace(line[i]) && !iscntrl(line[i]))
873 static int str_rw_cb(void *data, const char *mem)
875 struct thread_data *td = data;
877 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
878 td->ddir = DDIR_READ;
881 } else if (!strncmp(mem, "randread", 8)) {
882 td->ddir = DDIR_READ;
885 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
886 td->ddir = DDIR_WRITE;
889 } else if (!strncmp(mem, "randwrite", 9)) {
890 td->ddir = DDIR_WRITE;
893 } else if (!strncmp(mem, "rw", 2)) {
894 td->ddir = DDIR_READ;
898 } else if (!strncmp(mem, "randrw", 6)) {
899 td->ddir = DDIR_READ;
905 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
909 static int str_verify_cb(void *data, const char *mem)
911 struct thread_data *td = data;
913 if (!strncmp(mem, "0", 1)) {
914 td->verify = VERIFY_NONE;
916 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
917 td->verify = VERIFY_MD5;
919 } else if (!strncmp(mem, "crc32", 5)) {
920 td->verify = VERIFY_CRC32;
924 log_err("fio: verify types: md5, crc32\n");
929 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
931 static char *get_mmap_file(const char *str)
933 char *p = strstr(str, ":");
939 strip_blank_front(&p);
944 static int str_mem_cb(void *data, const char *mem)
946 struct thread_data *td = data;
948 if (!strncmp(mem, "malloc", 6)) {
949 td->mem_type = MEM_MALLOC;
951 } else if (!strncmp(mem, "mmaphuge", 8)) {
952 #ifdef FIO_HAVE_HUGETLB
954 * mmaphuge must be appended with the actual file
956 td->mmapfile = get_mmap_file(mem);
958 log_err("fio: mmaphuge:/path/to/file\n");
962 td->mem_type = MEM_MMAPHUGE;
965 log_err("fio: mmaphuge not available\n");
968 } else if (!strncmp(mem, "mmap", 4)) {
970 * Check if the user wants file backed memory. It's ok
971 * if there's no file given, we'll just use anon mamp then.
973 td->mmapfile = get_mmap_file(mem);
974 td->mem_type = MEM_MMAP;
976 } else if (!strncmp(mem, "shmhuge", 7)) {
977 #ifdef FIO_HAVE_HUGETLB
978 td->mem_type = MEM_SHMHUGE;
981 log_err("fio: shmhuge not available\n");
984 } else if (!strncmp(mem, "shm", 3)) {
985 td->mem_type = MEM_SHM;
989 log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
993 static int str_ioengine_cb(void *data, const char *str)
995 struct thread_data *td = data;
997 td->io_ops = load_ioengine(td, str);
1001 log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
1002 log_err("fio: or specify path to dynamic ioengine module\n");
1006 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1012 #ifdef FIO_HAVE_IOPRIO
1013 static int str_prioclass_cb(void *data, unsigned int *val)
1015 struct thread_data *td = data;
1017 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1021 static int str_prio_cb(void *data, unsigned int *val)
1023 struct thread_data *td = data;
1030 static int str_exitall_cb(void)
1032 exitall_on_terminate = 1;
1036 static int str_cpumask_cb(void *data, unsigned int *val)
1038 struct thread_data *td = data;
1040 fill_cpu_mask(td->cpumask, *val);
1045 * This is our [ini] type file parser.
1047 static int parse_jobs_ini(char *file, int stonewall_flag)
1049 unsigned int global;
1050 struct thread_data *td;
1051 char *string, *name;
1055 int ret = 0, stonewall;
1057 f = fopen(file, "r");
1059 perror("fopen job file");
1063 string = malloc(4096);
1065 memset(name, 0, 256);
1067 stonewall = stonewall_flag;
1069 p = fgets(string, 4095, f);
1072 if (is_empty_or_comment(p))
1074 if (sscanf(p, "[%255s]", name) != 1)
1077 global = !strncmp(name, "global", 6);
1079 name[strlen(name) - 1] = '\0';
1081 td = get_new_job(global, &def_thread);
1088 * Seperate multiple job files by a stonewall
1090 if (!global && stonewall) {
1091 td->stonewall = stonewall;
1096 while ((p = fgets(string, 4096, f)) != NULL) {
1097 if (is_empty_or_comment(p))
1100 strip_blank_front(&p);
1110 * Don't break here, continue parsing options so we
1111 * dump all the bad ones. Makes trial/error fixups
1112 * easier on the user.
1114 ret |= parse_option(p, options, td);
1119 ret = add_job(td, name, 0);
1121 log_err("fio: job %s dropped\n", name);
1132 static int fill_def_thread(void)
1134 memset(&def_thread, 0, sizeof(def_thread));
1136 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1137 perror("sched_getaffinity");
1142 * fill default options
1144 fill_default_options(&def_thread, options);
1146 def_thread.timeout = def_timeout;
1147 def_thread.write_bw_log = write_bw_log;
1148 def_thread.write_lat_log = write_lat_log;
1150 #ifdef FIO_HAVE_DISK_UTIL
1151 def_thread.do_disk_util = 1;
1157 static void usage(void)
1159 printf("%s\n", fio_version_string);
1160 printf("\t--output\tWrite output to file\n");
1161 printf("\t--timeout\tRuntime in seconds\n");
1162 printf("\t--latency-log\tGenerate per-job latency logs\n");
1163 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1164 printf("\t--minimal\tMinimal (terse) output\n");
1165 printf("\t--version\tPrint version info and exit\n");
1166 printf("\t--help\t\tPrint this page\n");
1167 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1170 static int parse_cmd_line(int argc, char *argv[])
1172 struct thread_data *td = NULL;
1173 int c, ini_idx = 0, lidx, ret;
1175 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1178 def_timeout = atoi(optarg);
1187 f_out = fopen(optarg, "w+");
1189 perror("fopen output");
1201 ret = show_cmd_help(options, optarg);
1204 printf("%s\n", fio_version_string);
1206 case FIO_GETOPT_JOB: {
1207 const char *opt = long_options[lidx].name;
1210 if (!strncmp(opt, "name", 4) && td) {
1211 ret = add_job(td, td->name ?: "fio", 0);
1219 int global = !strncmp(val, "global", 6);
1221 td = get_new_job(global, &def_thread);
1226 ret = parse_cmd_option(opt, val, options, td);
1228 log_err("fio: job dropped\n");
1240 ret = add_job(td, td->name ?: "fio", 0);
1245 while (optind < argc) {
1247 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1248 ini_file[ini_idx - 1] = strdup(argv[optind]);
1255 static void free_shm(void)
1257 struct shmid_ds sbuf;
1260 shmdt((void *) threads);
1262 shmctl(shm_id, IPC_RMID, &sbuf);
1267 * The thread area is shared between the main process and the job
1268 * threads/processes. So setup a shared memory segment that will hold
1271 static int setup_thread_area(void)
1274 * 1024 is too much on some machines, scale max_jobs if
1275 * we get a failure that looks like too large a shm segment
1278 size_t size = max_jobs * sizeof(struct thread_data);
1280 shm_id = shmget(0, size, IPC_CREAT | 0600);
1283 if (errno != EINVAL) {
1294 threads = shmat(shm_id, NULL, 0);
1295 if (threads == (void *) -1) {
1305 * Copy the fio options into the long options map, so we mirror
1306 * job and cmd line options.
1308 static void dupe_job_options(void)
1310 struct fio_option *o;
1314 while (long_options[i].name)
1319 long_options[i].name = o->name;
1320 long_options[i].val = FIO_GETOPT_JOB;
1321 if (o->type == FIO_OPT_STR_SET)
1322 long_options[i].has_arg = no_argument;
1324 long_options[i].has_arg = required_argument;
1328 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1332 int parse_options(int argc, char *argv[])
1339 options_init(options);
1343 if (setup_thread_area())
1345 if (fill_def_thread())
1348 job_files = parse_cmd_line(argc, argv);
1350 for (i = 0; i < job_files; i++) {
1351 if (fill_def_thread())
1353 if (parse_jobs_ini(ini_file[i], i))
1360 if (!thread_number) {
1361 log_err("No jobs defined(s)\n");