2 * This file contains job initialization and setup functions.
15 #include <sys/types.h>
25 #define DEF_TIMEOUT (0)
26 #define DEF_RATE_CYCLE (1000)
27 #define DEF_ODIRECT (1)
28 #define DEF_IO_ENGINE (FIO_SYNCIO)
29 #define DEF_IO_ENGINE_NAME "sync"
30 #define DEF_SEQUENTIAL (1)
31 #define DEF_RAND_REPEAT (1)
32 #define DEF_OVERWRITE (0)
33 #define DEF_INVALIDATE (1)
34 #define DEF_SYNCIO (0)
35 #define DEF_RANDSEED (0xb1899bedUL)
36 #define DEF_BWAVGTIME (500)
37 #define DEF_CREATE_SER (1)
38 #define DEF_CREATE_FSYNC (1)
40 #define DEF_VERIFY (0)
41 #define DEF_STONEWALL (0)
42 #define DEF_NUMJOBS (1)
43 #define DEF_USE_THREAD (0)
44 #define DEF_FILE_SIZE (1024 * 1024 * 1024UL)
45 #define DEF_ZONE_SIZE (0)
46 #define DEF_ZONE_SKIP (0)
47 #define DEF_RWMIX_CYCLE (500)
48 #define DEF_RWMIX_READ (50)
50 #define DEF_NR_FILES (1)
51 #define DEF_UNLINK (1)
52 #define DEF_WRITE_BW_LOG (0)
53 #define DEF_WRITE_LAT_LOG (0)
54 #define DEF_NO_RAND_MAP (0)
55 #define DEF_HUGEPAGE_SIZE FIO_HUGE_PAGE
57 #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
59 static int str_rw_cb(void *, const char *);
60 static int str_ioengine_cb(void *, const char *);
61 static int str_mem_cb(void *, const char *);
62 static int str_verify_cb(void *, const char *);
63 static int str_lockmem_cb(void *, unsigned long *);
64 #ifdef FIO_HAVE_IOPRIO
65 static int str_prio_cb(void *, unsigned int *);
66 static int str_prioclass_cb(void *, unsigned int *);
68 static int str_exitall_cb(void);
69 static int str_cpumask_cb(void *, unsigned int *);
72 * Map of job/command line options
74 static struct fio_option options[] = {
77 .type = FIO_OPT_STR_STORE,
78 .off1 = td_var_offset(name),
82 .type = FIO_OPT_STR_STORE,
83 .off1 = td_var_offset(directory),
87 .type = FIO_OPT_STR_STORE,
88 .off1 = td_var_offset(filename),
98 .cb = str_ioengine_cb,
111 .name = "write_iolog",
112 .type = FIO_OPT_STR_STORE,
113 .off1 = td_var_offset(write_iolog_file),
116 .name = "read_iolog",
117 .type = FIO_OPT_STR_STORE,
118 .off1 = td_var_offset(read_iolog_file),
121 .name = "exec_prerun",
122 .type = FIO_OPT_STR_STORE,
123 .off1 = td_var_offset(exec_prerun),
126 .name = "exec_postrun",
127 .type = FIO_OPT_STR_STORE,
128 .off1 = td_var_offset(exec_postrun),
130 #ifdef FIO_HAVE_IOSCHED_SWITCH
132 .name = "ioscheduler",
133 .type = FIO_OPT_STR_STORE,
134 .off1 = td_var_offset(ioscheduler),
139 .type = FIO_OPT_STR_VAL,
140 .off1 = td_var_offset(total_file_size),
144 .type = FIO_OPT_STR_VAL_INT,
145 .off1 = td_var_offset(bs[DDIR_READ]),
146 .off2 = td_var_offset(bs[DDIR_WRITE]),
150 .type = FIO_OPT_STR_VAL,
151 .off1 = td_var_offset(start_offset),
155 .type = FIO_OPT_STR_VAL,
156 .off1 = td_var_offset(zone_size),
160 .type = FIO_OPT_STR_VAL,
161 .off1 = td_var_offset(zone_skip),
165 .type = FIO_OPT_STR_VAL,
166 .cb = str_lockmem_cb,
170 .type = FIO_OPT_RANGE,
171 .off1 = td_var_offset(min_bs[DDIR_READ]),
172 .off2 = td_var_offset(max_bs[DDIR_READ]),
173 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
174 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
179 .off1 = td_var_offset(nr_files),
184 .off1 = td_var_offset(iodepth),
189 .off1 = td_var_offset(fsync_blocks),
192 .name = "rwmixcycle",
194 .off1 = td_var_offset(rwmixcycle),
199 .off1 = td_var_offset(rwmixread),
203 .name = "rwmixwrite",
205 .off1 = td_var_offset(rwmixwrite),
211 .off1 = td_var_offset(nice),
213 #ifdef FIO_HAVE_IOPRIO
222 .cb = str_prioclass_cb,
228 .off1 = td_var_offset(thinktime)
233 .off1 = td_var_offset(rate)
238 .off1 = td_var_offset(ratemin)
243 .off1 = td_var_offset(ratecycle)
246 .name = "startdelay",
248 .off1 = td_var_offset(start_delay)
252 .type = FIO_OPT_STR_VAL_TIME,
253 .off1 = td_var_offset(timeout)
256 .name = "invalidate",
258 .off1 = td_var_offset(invalidate_cache)
263 .off1 = td_var_offset(sync_io)
268 .off1 = td_var_offset(bw_avg_time)
271 .name = "create_serialize",
273 .off1 = td_var_offset(create_serialize)
276 .name = "create_fsync",
278 .off1 = td_var_offset(create_fsync)
283 .off1 = td_var_offset(loops)
288 .off1 = td_var_offset(numjobs)
293 .off1 = td_var_offset(cpuload)
298 .off1 = td_var_offset(cpucycle)
303 .off1 = td_var_offset(odirect)
308 .off1 = td_var_offset(overwrite)
310 #ifdef FIO_HAVE_CPU_AFFINITY
314 .cb = str_cpumask_cb,
320 .off1 = td_var_offset(end_fsync)
324 .type = FIO_OPT_STR_SET,
325 .off1 = td_var_offset(unlink),
329 .type = FIO_OPT_STR_SET,
330 .cb = str_exitall_cb,
334 .type = FIO_OPT_STR_SET,
335 .off1 = td_var_offset(stonewall),
339 .type = FIO_OPT_STR_SET,
340 .off1 = td_var_offset(thread),
343 .name = "write_bw_log",
344 .type = FIO_OPT_STR_SET,
345 .off1 = td_var_offset(write_bw_log),
348 .name = "write_lat_log",
349 .type = FIO_OPT_STR_SET,
350 .off1 = td_var_offset(write_lat_log),
353 .name = "norandommap",
354 .type = FIO_OPT_STR_SET,
355 .off1 = td_var_offset(norandommap),
358 .name = "bs_unaligned",
359 .type = FIO_OPT_STR_SET,
360 .off1 = td_var_offset(bs_unaligned),
363 .name = "hugepage-size",
364 .type = FIO_OPT_STR_VAL,
365 .off1 = td_var_offset(hugepage_size),
372 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
373 #define FIO_CMD_OPTS (16)
374 #define FIO_GETOPT_JOB (0x89988998)
377 * Command line options. These will contain the above, plus a few
378 * extra that only pertain to fio itself and not jobs.
380 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
383 .has_arg = required_argument,
388 .has_arg = required_argument,
392 .name = "latency-log",
393 .has_arg = required_argument,
397 .name = "bandwidth-log",
398 .has_arg = required_argument,
403 .has_arg = optional_argument,
408 .has_arg = no_argument,
416 static int def_timeout = DEF_TIMEOUT;
418 static char fio_version_string[] = "fio 1.9";
420 static char **ini_file;
421 static int max_jobs = MAX_JOBS;
423 struct thread_data def_thread;
424 struct thread_data *threads = NULL;
426 int exitall_on_terminate = 0;
427 int terse_output = 0;
428 unsigned long long mlock_size = 0;
432 static int write_lat_log = DEF_WRITE_LAT_LOG;
433 static int write_bw_log = DEF_WRITE_BW_LOG;
436 * Return a free job structure.
438 static struct thread_data *get_new_job(int global, struct thread_data *parent)
440 struct thread_data *td;
444 if (thread_number >= max_jobs)
447 td = &threads[thread_number++];
450 td->thread_number = thread_number;
454 static void put_job(struct thread_data *td)
456 if (td == &def_thread)
459 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
464 * Lazy way of fixing up options that depend on each other. We could also
465 * define option callback handlers, but this is easier.
467 static void fixup_options(struct thread_data *td)
469 if (!td->rwmixread && td->rwmixwrite)
470 td->rwmixread = 100 - td->rwmixwrite;
472 if (td->write_iolog_file && td->read_iolog_file) {
473 log_err("fio: read iolog overrides write_iolog\n");
474 free(td->write_iolog_file);
475 td->write_iolog_file = NULL;
478 if (td->io_ops->flags & FIO_SYNCIO)
482 td->iodepth = td->nr_files;
486 * only really works for sequential io for now, and with 1 file
488 if (td->zone_size && !td->sequential && td->nr_files == 1)
492 * Reads can do overwrites, we always need to pre-create the file
494 if (td_read(td) || td_rw(td))
497 if (!td->min_bs[DDIR_READ])
498 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
499 if (!td->max_bs[DDIR_READ])
500 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
501 if (!td->min_bs[DDIR_WRITE])
502 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
503 if (!td->max_bs[DDIR_WRITE])
504 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
506 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
508 if (td_read(td) && !td_rw(td))
511 if (td->norandommap && td->verify != VERIFY_NONE) {
512 log_err("fio: norandommap given, verify disabled\n");
513 td->verify = VERIFY_NONE;
515 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
516 log_err("fio: bs_unaligned may not work with raw io\n");
519 * O_DIRECT and char doesn't mix, clear that flag if necessary.
521 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
526 * This function leaks the buffer
528 static char *to_kmg(unsigned int val)
530 char *buf = malloc(32);
531 char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
542 snprintf(buf, 31, "%u%c", val, *p);
547 * Adds a job to the list of things todo. Sanitizes the various options
548 * to make sure we don't have conflicts, and initializes various
551 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
553 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
554 "rw", NULL, "randrw" };
556 int numjobs, ddir, i;
560 * the def_thread is just for options, it's not a real job
562 if (td == &def_thread)
566 * Set default io engine, if none set
569 td->io_ops = load_ioengine(td, DEF_IO_ENGINE_NAME);
571 log_err("default engine %s not there?\n", DEF_IO_ENGINE_NAME);
577 td->io_ops->flags |= FIO_RAWIO;
579 td->filetype = FIO_TYPE_FILE;
580 if (!stat(jobname, &sb)) {
581 if (S_ISBLK(sb.st_mode))
582 td->filetype = FIO_TYPE_BD;
583 else if (S_ISCHR(sb.st_mode))
584 td->filetype = FIO_TYPE_CHAR;
590 td->nr_uniq_files = 1;
592 td->nr_uniq_files = td->nr_files;
594 if (td->filetype == FIO_TYPE_FILE || td->filename) {
598 if (td->directory && td->directory[0] != '\0')
599 sprintf(tmp, "%s/", td->directory);
601 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
603 for_each_file(td, f, i) {
604 memset(f, 0, sizeof(*f));
608 sprintf(tmp + len, "%s", td->filename);
610 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
611 f->file_name = strdup(tmp);
615 td->files = malloc(sizeof(struct fio_file));
618 memset(f, 0, sizeof(*f));
620 f->file_name = strdup(jobname);
623 for_each_file(td, f, i) {
624 f->file_size = td->total_file_size / td->nr_files;
625 f->file_offset = td->start_offset;
628 fio_sem_init(&td->mutex, 0);
630 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
631 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
632 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
634 if (td->stonewall && td->thread_number > 1)
637 td->groupid = groupid;
642 if (td->write_lat_log) {
643 setup_log(&td->slat_log);
644 setup_log(&td->clat_log);
646 if (td->write_bw_log)
647 setup_log(&td->bw_log);
650 td->name = strdup(jobname);
652 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
656 if (td->io_ops->flags & FIO_CPUIO)
657 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
659 char *c1, *c2, *c3, *c4;
661 c1 = to_kmg(td->min_bs[DDIR_READ]);
662 c2 = to_kmg(td->max_bs[DDIR_READ]);
663 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
664 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
666 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);
673 } else if (job_add_num == 1)
674 fprintf(f_out, "...\n");
678 * recurse add identical jobs, clear numjobs and stonewall options
679 * as they don't apply to sub-jobs
681 numjobs = td->numjobs;
683 struct thread_data *td_new = get_new_job(0, td);
689 td_new->stonewall = 0;
690 job_add_num = numjobs - 1;
692 if (add_job(td_new, jobname, job_add_num))
702 * Initialize the various random states we need (random io, block size ranges,
703 * read/write mix, etc).
705 int init_random_state(struct thread_data *td)
707 unsigned long seeds[4];
708 int fd, num_maps, blocks, i;
711 if (td->io_ops->flags & FIO_CPUIO)
714 fd = open("/dev/urandom", O_RDONLY);
716 td_verror(td, errno);
720 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
728 os_random_seed(seeds[0], &td->bsrange_state);
729 os_random_seed(seeds[1], &td->verify_state);
730 os_random_seed(seeds[2], &td->rwmix_state);
735 if (td->rand_repeatable)
736 seeds[3] = DEF_RANDSEED;
738 if (!td->norandommap) {
739 for_each_file(td, f, i) {
740 blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs;
741 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
742 f->file_map = malloc(num_maps * sizeof(long));
743 f->num_maps = num_maps;
744 memset(f->file_map, 0, num_maps * sizeof(long));
748 os_random_seed(seeds[3], &td->random_state);
752 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
754 #ifdef FIO_HAVE_CPU_AFFINITY
759 for (i = 0; i < sizeof(int) * 8; i++) {
761 CPU_SET(i, &cpumask);
766 static int is_empty_or_comment(char *line)
770 for (i = 0; i < strlen(line); i++) {
773 if (!isspace(line[i]) && !iscntrl(line[i]))
780 static int str_rw_cb(void *data, const char *mem)
782 struct thread_data *td = data;
784 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
785 td->ddir = DDIR_READ;
788 } else if (!strncmp(mem, "randread", 8)) {
789 td->ddir = DDIR_READ;
792 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
793 td->ddir = DDIR_WRITE;
796 } else if (!strncmp(mem, "randwrite", 9)) {
797 td->ddir = DDIR_WRITE;
800 } else if (!strncmp(mem, "rw", 2)) {
801 td->ddir = DDIR_READ;
805 } else if (!strncmp(mem, "randrw", 6)) {
806 td->ddir = DDIR_READ;
812 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
816 static int str_verify_cb(void *data, const char *mem)
818 struct thread_data *td = data;
820 if (!strncmp(mem, "0", 1)) {
821 td->verify = VERIFY_NONE;
823 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
824 td->verify = VERIFY_MD5;
826 } else if (!strncmp(mem, "crc32", 5)) {
827 td->verify = VERIFY_CRC32;
831 log_err("fio: verify types: md5, crc32\n");
835 static int str_mem_cb(void *data, const char *mem)
837 struct thread_data *td = data;
839 if (!strncmp(mem, "malloc", 6)) {
840 td->mem_type = MEM_MALLOC;
842 } else if (!strncmp(mem, "mmaphuge", 8)) {
843 #ifdef FIO_HAVE_HUGETLB
847 * mmaphuge must be appended with the actual file
849 hugefile = strstr(mem, ":");
851 log_err("fio: mmaphuge:/path/to/file\n");
856 strip_blank_front(&hugefile);
857 strip_blank_end(hugefile);
858 td->hugefile = strdup(hugefile);
859 td->mem_type = MEM_MMAPHUGE;
862 log_err("fio: mmaphuge not available\n");
865 } else if (!strncmp(mem, "mmap", 4)) {
866 td->mem_type = MEM_MMAP;
868 } else if (!strncmp(mem, "shmhuge", 7)) {
869 #ifdef FIO_HAVE_HUGETLB
870 td->mem_type = MEM_SHMHUGE;
873 log_err("fio: shmhuge not available\n");
876 } else if (!strncmp(mem, "shm", 3)) {
877 td->mem_type = MEM_SHM;
881 log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
885 static int str_ioengine_cb(void *data, const char *str)
887 struct thread_data *td = data;
889 td->io_ops = load_ioengine(td, str);
893 log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
894 log_err("fio: or specify path to dynamic ioengine module\n");
898 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
904 #ifdef FIO_HAVE_IOPRIO
905 static int str_prioclass_cb(void *data, unsigned int *val)
907 struct thread_data *td = data;
909 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
913 static int str_prio_cb(void *data, unsigned int *val)
915 struct thread_data *td = data;
922 static int str_exitall_cb(void)
924 exitall_on_terminate = 1;
928 static int str_cpumask_cb(void *data, unsigned int *val)
930 struct thread_data *td = data;
932 fill_cpu_mask(td->cpumask, *val);
937 * This is our [ini] type file parser.
939 static int parse_jobs_ini(char *file, int stonewall_flag)
942 struct thread_data *td;
947 int ret = 0, stonewall;
949 f = fopen(file, "r");
951 perror("fopen job file");
955 string = malloc(4096);
957 memset(name, 0, 256);
959 stonewall = stonewall_flag;
961 p = fgets(string, 4095, f);
964 if (is_empty_or_comment(p))
966 if (sscanf(p, "[%255s]", name) != 1)
969 global = !strncmp(name, "global", 6);
971 name[strlen(name) - 1] = '\0';
973 td = get_new_job(global, &def_thread);
980 * Seperate multiple job files by a stonewall
982 if (!global && stonewall) {
983 td->stonewall = stonewall;
988 while ((p = fgets(string, 4096, f)) != NULL) {
989 if (is_empty_or_comment(p))
992 strip_blank_front(&p);
1002 * Don't break here, continue parsing options so we
1003 * dump all the bad ones. Makes trial/error fixups
1004 * easier on the user.
1006 ret |= parse_option(p, options, td);
1011 ret = add_job(td, name, 0);
1013 log_err("fio: job %s dropped\n", name);
1024 static int fill_def_thread(void)
1026 memset(&def_thread, 0, sizeof(def_thread));
1028 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1029 perror("sched_getaffinity");
1036 def_thread.ddir = DDIR_READ;
1037 def_thread.iomix = 0;
1038 def_thread.bs[DDIR_READ] = DEF_BS;
1039 def_thread.bs[DDIR_WRITE] = DEF_BS;
1040 def_thread.min_bs[DDIR_READ] = def_thread.min_bs[DDIR_WRITE] = 0;
1041 def_thread.max_bs[DDIR_READ] = def_thread.max_bs[DDIR_WRITE] = 0;
1042 def_thread.odirect = DEF_ODIRECT;
1043 def_thread.ratecycle = DEF_RATE_CYCLE;
1044 def_thread.sequential = DEF_SEQUENTIAL;
1045 def_thread.timeout = def_timeout;
1046 def_thread.overwrite = DEF_OVERWRITE;
1047 def_thread.invalidate_cache = DEF_INVALIDATE;
1048 def_thread.sync_io = DEF_SYNCIO;
1049 def_thread.mem_type = MEM_MALLOC;
1050 def_thread.bw_avg_time = DEF_BWAVGTIME;
1051 def_thread.create_serialize = DEF_CREATE_SER;
1052 def_thread.create_fsync = DEF_CREATE_FSYNC;
1053 def_thread.loops = DEF_LOOPS;
1054 def_thread.verify = DEF_VERIFY;
1055 def_thread.stonewall = DEF_STONEWALL;
1056 def_thread.numjobs = DEF_NUMJOBS;
1057 def_thread.use_thread = DEF_USE_THREAD;
1058 def_thread.rwmixcycle = DEF_RWMIX_CYCLE;
1059 def_thread.rwmixread = DEF_RWMIX_READ;
1060 def_thread.nice = DEF_NICE;
1061 def_thread.rand_repeatable = DEF_RAND_REPEAT;
1062 def_thread.nr_files = DEF_NR_FILES;
1063 def_thread.unlink = DEF_UNLINK;
1064 def_thread.write_bw_log = write_bw_log;
1065 def_thread.write_lat_log = write_lat_log;
1066 def_thread.norandommap = DEF_NO_RAND_MAP;
1067 def_thread.hugepage_size = DEF_HUGEPAGE_SIZE;
1068 #ifdef FIO_HAVE_DISK_UTIL
1069 def_thread.do_disk_util = 1;
1075 static void usage(void)
1077 printf("%s\n", fio_version_string);
1078 printf("\t--output\tWrite output to file\n");
1079 printf("\t--timeout\tRuntime in seconds\n");
1080 printf("\t--latency-log\tGenerate per-job latency logs\n");
1081 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1082 printf("\t--minimal\tMinimal (terse) output\n");
1083 printf("\t--version\tPrint version info and exit\n");
1086 static int parse_cmd_line(int argc, char *argv[])
1088 struct thread_data *td = NULL;
1089 int c, ini_idx = 0, lidx, ret;
1091 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1094 def_timeout = atoi(optarg);
1103 f_out = fopen(optarg, "w+");
1105 perror("fopen output");
1117 printf("%s\n", fio_version_string);
1119 case FIO_GETOPT_JOB: {
1120 const char *opt = long_options[lidx].name;
1123 if (!strncmp(opt, "name", 4) && td) {
1124 ret = add_job(td, td->name ?: "fio", 0);
1132 int global = !strncmp(val, "global", 6);
1134 td = get_new_job(global, &def_thread);
1139 ret = parse_cmd_option(opt, val, options, td);
1141 log_err("fio: job dropped\n");
1148 printf("optarg <<%s>>\n", argv[optind]);
1154 ret = add_job(td, td->name ?: "fio", 0);
1159 while (optind < argc) {
1161 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1162 ini_file[ini_idx - 1] = strdup(argv[optind]);
1169 static void free_shm(void)
1171 struct shmid_ds sbuf;
1174 shmdt((void *) threads);
1176 shmctl(shm_id, IPC_RMID, &sbuf);
1181 * The thread area is shared between the main process and the job
1182 * threads/processes. So setup a shared memory segment that will hold
1185 static int setup_thread_area(void)
1188 * 1024 is too much on some machines, scale max_jobs if
1189 * we get a failure that looks like too large a shm segment
1192 size_t size = max_jobs * sizeof(struct thread_data);
1194 shm_id = shmget(0, size, IPC_CREAT | 0600);
1197 if (errno != EINVAL) {
1208 threads = shmat(shm_id, NULL, 0);
1209 if (threads == (void *) -1) {
1219 * Copy the fio options into the long options map, so we mirror
1220 * job and cmd line options.
1222 static void dupe_job_options(void)
1224 struct fio_option *o;
1228 while (long_options[i].name)
1233 long_options[i].name = o->name;
1234 long_options[i].val = FIO_GETOPT_JOB;
1235 if (o->type == FIO_OPT_STR_SET)
1236 long_options[i].has_arg = no_argument;
1238 long_options[i].has_arg = required_argument;
1242 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1246 int parse_options(int argc, char *argv[])
1255 if (setup_thread_area())
1257 if (fill_def_thread())
1260 job_files = parse_cmd_line(argc, argv);
1262 for (i = 0; i < job_files; i++) {
1263 if (fill_def_thread())
1265 if (parse_jobs_ini(ini_file[i], i))
1272 if (!thread_number) {
1273 log_err("No jobs defined(s)\n");