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 (read, write, rw, etc)",
72 .cb = str_ioengine_cb,
73 .help = "IO engine to use (sync, aio, etc)",
80 .help = "Backing type for IO buffers (malloc, shm, etc)",
87 .help = "Verify sum function (md5 or crc32)",
91 .name = "write_iolog",
92 .type = FIO_OPT_STR_STORE,
93 .off1 = td_var_offset(write_iolog_file),
94 .help = "Store IO pattern to file",
98 .type = FIO_OPT_STR_STORE,
99 .off1 = td_var_offset(read_iolog_file),
100 .help = "Playback IO pattern from file",
103 .name = "exec_prerun",
104 .type = FIO_OPT_STR_STORE,
105 .off1 = td_var_offset(exec_prerun),
106 .help = "Execute this file prior to running job",
109 .name = "exec_postrun",
110 .type = FIO_OPT_STR_STORE,
111 .off1 = td_var_offset(exec_postrun),
112 .help = "Execute this file after running job",
114 #ifdef FIO_HAVE_IOSCHED_SWITCH
116 .name = "ioscheduler",
117 .type = FIO_OPT_STR_STORE,
118 .off1 = td_var_offset(ioscheduler),
119 .help = "Use this IO scheduler on the backing device",
124 .type = FIO_OPT_STR_VAL,
125 .off1 = td_var_offset(total_file_size),
126 .help = "Size of device or file",
130 .type = FIO_OPT_STR_VAL_INT,
131 .off1 = td_var_offset(bs[DDIR_READ]),
132 .off2 = td_var_offset(bs[DDIR_WRITE]),
133 .help = "Block size unit",
138 .type = FIO_OPT_STR_VAL,
139 .off1 = td_var_offset(start_offset),
140 .help = "Start IO from this offset",
145 .type = FIO_OPT_STR_VAL,
146 .off1 = td_var_offset(zone_size),
147 .help = "Give size of an IO zone",
152 .type = FIO_OPT_STR_VAL,
153 .off1 = td_var_offset(zone_skip),
154 .help = "Space between IO zones",
159 .type = FIO_OPT_STR_VAL,
160 .cb = str_lockmem_cb,
161 .help = "Lock down this amount of memory",
166 .type = FIO_OPT_RANGE,
167 .off1 = td_var_offset(min_bs[DDIR_READ]),
168 .off2 = td_var_offset(max_bs[DDIR_READ]),
169 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
170 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
171 .help = "Set block size range",
174 .name = "randrepeat",
176 .off1 = td_var_offset(rand_repeatable),
177 .help = "Use repeatable random IO pattern",
183 .off1 = td_var_offset(nr_files),
184 .help = "Split job workload between this number of files",
190 .off1 = td_var_offset(iodepth),
191 .help = "Amount of IO buffers to keep in flight",
197 .off1 = td_var_offset(fsync_blocks),
198 .help = "Issue fsync for writes every given number of blocks",
202 .name = "rwmixcycle",
204 .off1 = td_var_offset(rwmixcycle),
205 .help = "Cycle period for mixed read/write workloads (msec)",
211 .off1 = td_var_offset(rwmixread),
213 .help = "Percentage of mixed workload that is reads",
217 .name = "rwmixwrite",
219 .off1 = td_var_offset(rwmixwrite),
221 .help = "Percentage of mixed workload that is writes",
227 .off1 = td_var_offset(nice),
228 .help = "Set job CPU nice value",
232 #ifdef FIO_HAVE_IOPRIO
237 .help = "Set job IO priority value",
242 .cb = str_prioclass_cb,
243 .help = "Set job IO priority class",
249 .off1 = td_var_offset(thinktime),
250 .help = "Idle time between IO buffers",
254 .name = "thinktime_blocks",
256 .off1 = td_var_offset(thinktime_blocks),
257 .help = "IO buffer period between 'thinktime'",
263 .off1 = td_var_offset(rate),
264 .help = "Set bandwidth rate",
269 .off1 = td_var_offset(ratemin),
270 .help = "The bottom limit accepted",
275 .off1 = td_var_offset(ratecycle),
276 .help = "Window average for rate limits (msec)",
280 .name = "startdelay",
282 .off1 = td_var_offset(start_delay),
283 .help = "Only start job when this period has passed",
288 .type = FIO_OPT_STR_VAL_TIME,
289 .off1 = td_var_offset(timeout),
290 .help = "Stop workload when this amount of time has passed",
294 .name = "invalidate",
296 .off1 = td_var_offset(invalidate_cache),
297 .help = "Invalidate buffer/page cache prior to running job",
303 .off1 = td_var_offset(sync_io),
304 .help = "Use O_SYNC for buffered writes",
310 .off1 = td_var_offset(bw_avg_time),
311 .help = "Time window over which to calculate bandwidth (msec)",
315 .name = "create_serialize",
317 .off1 = td_var_offset(create_serialize),
318 .help = "Serialize creating of job files",
322 .name = "create_fsync",
324 .off1 = td_var_offset(create_fsync),
325 .help = "Fsync file after creation",
331 .off1 = td_var_offset(loops),
332 .help = "Number of times to run the job",
338 .off1 = td_var_offset(numjobs),
339 .help = "Duplicate this job this many times",
345 .off1 = td_var_offset(cpuload),
346 .help = "Use this percentage of CPU",
351 .off1 = td_var_offset(cpucycle),
352 .help = "Length of the CPU burn cycles",
357 .off1 = td_var_offset(odirect),
358 .help = "Use O_DIRECT IO",
364 .off1 = td_var_offset(overwrite),
365 .help = "When writing, set whether to overwrite current data",
368 #ifdef FIO_HAVE_CPU_AFFINITY
372 .cb = str_cpumask_cb,
373 .help = "CPU affinity mask",
379 .off1 = td_var_offset(end_fsync),
380 .help = "Include fsync at the end of job",
386 .off1 = td_var_offset(unlink),
387 .help = "Unlink created files after job has completed",
392 .type = FIO_OPT_STR_SET,
393 .cb = str_exitall_cb,
394 .help = "Terminate all jobs when one exits",
398 .type = FIO_OPT_STR_SET,
399 .off1 = td_var_offset(stonewall),
400 .help = "Insert a hard barrier between this job and previous",
404 .type = FIO_OPT_STR_SET,
405 .off1 = td_var_offset(thread),
406 .help = "Use threads instead of forks",
409 .name = "write_bw_log",
410 .type = FIO_OPT_STR_SET,
411 .off1 = td_var_offset(write_bw_log),
412 .help = "Write log of bandwidth during run",
415 .name = "write_lat_log",
416 .type = FIO_OPT_STR_SET,
417 .off1 = td_var_offset(write_lat_log),
418 .help = "Write log of latency during run",
421 .name = "norandommap",
422 .type = FIO_OPT_STR_SET,
423 .off1 = td_var_offset(norandommap),
424 .help = "Accept potential duplicate random blocks",
427 .name = "bs_unaligned",
428 .type = FIO_OPT_STR_SET,
429 .off1 = td_var_offset(bs_unaligned),
430 .help = "Don't sector align IO buffer sizes",
433 .name = "hugepage-size",
434 .type = FIO_OPT_STR_VAL,
435 .off1 = td_var_offset(hugepage_size),
436 .help = "When using hugepages, specify size of each page",
437 .def = __stringify(FIO_HUGE_PAGE),
444 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
445 #define FIO_CMD_OPTS (16)
446 #define FIO_GETOPT_JOB (0x89988998)
449 * Command line options. These will contain the above, plus a few
450 * extra that only pertain to fio itself and not jobs.
452 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
455 .has_arg = required_argument,
460 .has_arg = required_argument,
464 .name = "latency-log",
465 .has_arg = required_argument,
469 .name = "bandwidth-log",
470 .has_arg = required_argument,
475 .has_arg = optional_argument,
480 .has_arg = no_argument,
485 .has_arg = no_argument,
490 .has_arg = required_argument,
498 static int def_timeout = 0;
500 static char fio_version_string[] = "fio 1.11";
502 static char **ini_file;
503 static int max_jobs = MAX_JOBS;
505 struct thread_data def_thread;
506 struct thread_data *threads = NULL;
508 int exitall_on_terminate = 0;
509 int terse_output = 0;
510 unsigned long long mlock_size = 0;
514 static int write_lat_log = 0;
515 static int write_bw_log = 0;
518 * Return a free job structure.
520 static struct thread_data *get_new_job(int global, struct thread_data *parent)
522 struct thread_data *td;
526 if (thread_number >= max_jobs)
529 td = &threads[thread_number++];
532 td->thread_number = thread_number;
536 static void put_job(struct thread_data *td)
538 if (td == &def_thread)
541 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
546 * Lazy way of fixing up options that depend on each other. We could also
547 * define option callback handlers, but this is easier.
549 static void fixup_options(struct thread_data *td)
551 if (!td->rwmixread && td->rwmixwrite)
552 td->rwmixread = 100 - td->rwmixwrite;
554 if (td->write_iolog_file && td->read_iolog_file) {
555 log_err("fio: read iolog overrides write_iolog\n");
556 free(td->write_iolog_file);
557 td->write_iolog_file = NULL;
560 if (td->io_ops->flags & FIO_SYNCIO)
564 td->iodepth = td->nr_files;
568 * only really works for sequential io for now, and with 1 file
570 if (td->zone_size && !td->sequential && td->nr_files == 1)
574 * Reads can do overwrites, we always need to pre-create the file
576 if (td_read(td) || td_rw(td))
579 if (!td->min_bs[DDIR_READ])
580 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
581 if (!td->max_bs[DDIR_READ])
582 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
583 if (!td->min_bs[DDIR_WRITE])
584 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
585 if (!td->max_bs[DDIR_WRITE])
586 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
588 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
590 if (td_read(td) && !td_rw(td))
593 if (td->norandommap && td->verify != VERIFY_NONE) {
594 log_err("fio: norandommap given, verify disabled\n");
595 td->verify = VERIFY_NONE;
597 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
598 log_err("fio: bs_unaligned may not work with raw io\n");
601 * O_DIRECT and char doesn't mix, clear that flag if necessary.
603 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
608 * This function leaks the buffer
610 static char *to_kmg(unsigned int val)
612 char *buf = malloc(32);
613 char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
624 snprintf(buf, 31, "%u%c", val, *p);
629 * Adds a job to the list of things todo. Sanitizes the various options
630 * to make sure we don't have conflicts, and initializes various
633 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
635 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
636 "rw", NULL, "randrw" };
638 int numjobs, ddir, i;
642 * the def_thread is just for options, it's not a real job
644 if (td == &def_thread)
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] = FIO_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");
1122 * fill default options
1124 fill_default_options(&def_thread, options);
1126 def_thread.timeout = def_timeout;
1127 def_thread.write_bw_log = write_bw_log;
1128 def_thread.write_lat_log = write_lat_log;
1130 #ifdef FIO_HAVE_DISK_UTIL
1131 def_thread.do_disk_util = 1;
1137 static void usage(void)
1139 printf("%s\n", fio_version_string);
1140 printf("\t--output\tWrite output to file\n");
1141 printf("\t--timeout\tRuntime in seconds\n");
1142 printf("\t--latency-log\tGenerate per-job latency logs\n");
1143 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1144 printf("\t--minimal\tMinimal (terse) output\n");
1145 printf("\t--version\tPrint version info and exit\n");
1146 printf("\t--help\t\tPrint this page\n");
1147 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1150 static int parse_cmd_line(int argc, char *argv[])
1152 struct thread_data *td = NULL;
1153 int c, ini_idx = 0, lidx, ret;
1155 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1158 def_timeout = atoi(optarg);
1167 f_out = fopen(optarg, "w+");
1169 perror("fopen output");
1181 ret = show_cmd_help(options, optarg);
1184 printf("%s\n", fio_version_string);
1186 case FIO_GETOPT_JOB: {
1187 const char *opt = long_options[lidx].name;
1190 if (!strncmp(opt, "name", 4) && td) {
1191 ret = add_job(td, td->name ?: "fio", 0);
1199 int global = !strncmp(val, "global", 6);
1201 td = get_new_job(global, &def_thread);
1206 ret = parse_cmd_option(opt, val, options, td);
1208 log_err("fio: job dropped\n");
1220 ret = add_job(td, td->name ?: "fio", 0);
1225 while (optind < argc) {
1227 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1228 ini_file[ini_idx - 1] = strdup(argv[optind]);
1235 static void free_shm(void)
1237 struct shmid_ds sbuf;
1240 shmdt((void *) threads);
1242 shmctl(shm_id, IPC_RMID, &sbuf);
1247 * The thread area is shared between the main process and the job
1248 * threads/processes. So setup a shared memory segment that will hold
1251 static int setup_thread_area(void)
1254 * 1024 is too much on some machines, scale max_jobs if
1255 * we get a failure that looks like too large a shm segment
1258 size_t size = max_jobs * sizeof(struct thread_data);
1260 shm_id = shmget(0, size, IPC_CREAT | 0600);
1263 if (errno != EINVAL) {
1274 threads = shmat(shm_id, NULL, 0);
1275 if (threads == (void *) -1) {
1285 * Copy the fio options into the long options map, so we mirror
1286 * job and cmd line options.
1288 static void dupe_job_options(void)
1290 struct fio_option *o;
1294 while (long_options[i].name)
1299 long_options[i].name = o->name;
1300 long_options[i].val = FIO_GETOPT_JOB;
1301 if (o->type == FIO_OPT_STR_SET)
1302 long_options[i].has_arg = no_argument;
1304 long_options[i].has_arg = required_argument;
1308 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1312 int parse_options(int argc, char *argv[])
1321 if (setup_thread_area())
1323 if (fill_def_thread())
1326 job_files = parse_cmd_line(argc, argv);
1328 for (i = 0; i < job_files; i++) {
1329 if (fill_def_thread())
1331 if (parse_jobs_ini(ini_file[i], i))
1338 if (!thread_number) {
1339 log_err("No jobs defined(s)\n");