Fix bad latency reporting for rated IO jobs
[fio.git] / options.c
CommitLineData
214e1eca
JA
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <string.h>
214e1eca 6#include <assert.h>
921c766f 7#include <libgen.h>
5921e80c
JA
8#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
214e1eca
JA
11
12#include "fio.h"
4f5af7b2 13#include "verify.h"
214e1eca 14#include "parse.h"
eef32359 15#include "lib/fls.h"
9f988e2e 16#include "options.h"
214e1eca 17
5d7c5d34
JA
18#include "crc/crc32c.h"
19
214e1eca
JA
20/*
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 */
23static char *get_opt_postfix(const char *str)
24{
25 char *p = strstr(str, ":");
26
27 if (!p)
28 return NULL;
29
30 p++;
31 strip_blank_front(&p);
32 strip_blank_end(p);
33 return strdup(p);
34}
35
0e92f873
RR
36static int converthexchartoint(char a)
37{
38 int base;
39
40 switch(a) {
41 case '0'...'9':
42 base = '0';
43 break;
44 case 'A'...'F':
45 base = 'A' - 10;
46 break;
47 case 'a'...'f':
48 base = 'a' - 10;
49 break;
50 default:
51 base = 0;
52 }
53 return (a - base);
54}
55
564ca972
JA
56static int bs_cmp(const void *p1, const void *p2)
57{
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
60
61 return bsp1->perc < bsp2->perc;
62}
63
720e84ad 64static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
564ca972 65{
720e84ad 66 struct bssplit *bssplit;
564ca972
JA
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
720e84ad 70 char *fname;
564ca972 71
720e84ad
JA
72 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
564ca972
JA
74
75 i = 0;
76 max_bs = 0;
77 min_bs = -1;
78 while ((fname = strsep(&str, ":")) != NULL) {
79 char *perc_str;
80
81 if (!strlen(fname))
82 break;
83
84 /*
85 * grow struct buffer, if needed
86 */
720e84ad
JA
87 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
5ec10eaa 90 * sizeof(struct bssplit));
564ca972
JA
91 }
92
93 perc_str = strstr(fname, "/");
94 if (perc_str) {
95 *perc_str = '\0';
96 perc_str++;
97 perc = atoi(perc_str);
98 if (perc > 100)
99 perc = 100;
100 else if (!perc)
101 perc = -1;
102 } else
103 perc = -1;
104
df9cf928 105 if (str_to_decimal(fname, &val, 1, td)) {
564ca972
JA
106 log_err("fio: bssplit conversion failed\n");
107 free(td->o.bssplit);
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
720e84ad
JA
116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
564ca972
JA
118 i++;
119 }
120
720e84ad 121 td->o.bssplit_nr[ddir] = i;
564ca972
JA
122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
720e84ad
JA
127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
564ca972
JA
129
130 if (bsp->perc == (unsigned char) -1)
131 perc_missing++;
132 else
133 perc += bsp->perc;
134 }
135
136 if (perc > 100) {
137 log_err("fio: bssplit percentages add to more than 100%%\n");
720e84ad 138 free(bssplit);
564ca972
JA
139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
720e84ad
JA
146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
564ca972
JA
148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
720e84ad
JA
154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
564ca972
JA
156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
720e84ad
JA
160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
162 return 0;
163
164}
165
166static int str_bssplit_cb(void *data, const char *input)
167{
168 struct thread_data *td = data;
169 char *str, *p, *odir;
170 int ret = 0;
171
172 p = str = strdup(input);
173
174 strip_blank_front(&str);
175 strip_blank_end(str);
176
177 odir = strchr(str, ',');
178 if (odir) {
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
180 if (!ret) {
181 *odir = '\0';
182 ret = bssplit_ddir(td, DDIR_READ, str);
183 }
184 } else {
185 char *op;
186
187 op = strdup(str);
188
189 ret = bssplit_ddir(td, DDIR_READ, str);
190 if (!ret)
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
192
193 free(op);
194 }
564ca972
JA
195
196 free(p);
720e84ad 197 return ret;
564ca972
JA
198}
199
211097b2
JA
200static int str_rw_cb(void *data, const char *str)
201{
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
204
5736c10d 205 td->o.ddir_seq_nr = 1;
059b0802
JA
206 td->o.ddir_seq_add = 0;
207
208 if (!nr)
209 return 0;
210
211 if (td_random(td))
5736c10d 212 td->o.ddir_seq_nr = atoi(nr);
059b0802
JA
213 else {
214 long long val;
215
216 if (str_to_decimal(nr, &val, 1, td)) {
217 log_err("fio: rw postfix parsing failed\n");
218 free(nr);
219 return 1;
220 }
221
222 td->o.ddir_seq_add = val;
182ec6ee 223 }
211097b2 224
059b0802 225 free(nr);
211097b2
JA
226 return 0;
227}
228
214e1eca
JA
229static int str_mem_cb(void *data, const char *mem)
230{
231 struct thread_data *td = data;
232
2dc1bbeb 233 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
214e1eca 234 td->mmapfile = get_opt_postfix(mem);
2dc1bbeb 235 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
214e1eca
JA
236 log_err("fio: mmaphuge:/path/to/file\n");
237 return 1;
238 }
239 }
240
241 return 0;
242}
243
5d7c5d34
JA
244static int str_verify_cb(void *data, const char *mem)
245{
246 struct thread_data *td = data;
247
248 if (td->o.verify != VERIFY_CRC32C_INTEL)
249 return 0;
250
251 if (!crc32c_intel_works()) {
252 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
253 td->o.verify = VERIFY_CRC32C;
254 }
255
256 return 0;
257}
258
c223da83
JA
259static int fio_clock_source_cb(void *data, const char *str)
260{
261 struct thread_data *td = data;
262
263 fio_clock_source = td->o.clocksource;
264 fio_time_init();
265 return 0;
266}
267
85bc833b 268static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
214e1eca
JA
269{
270 mlock_size = *val;
271 return 0;
272}
273
85bc833b 274static int str_rwmix_read_cb(void *data, unsigned long long *val)
cb499fc4
JA
275{
276 struct thread_data *td = data;
277
278 td->o.rwmix[DDIR_READ] = *val;
279 td->o.rwmix[DDIR_WRITE] = 100 - *val;
280 return 0;
281}
282
85bc833b 283static int str_rwmix_write_cb(void *data, unsigned long long *val)
cb499fc4
JA
284{
285 struct thread_data *td = data;
286
287 td->o.rwmix[DDIR_WRITE] = *val;
288 td->o.rwmix[DDIR_READ] = 100 - *val;
289 return 0;
290}
291
214e1eca 292#ifdef FIO_HAVE_IOPRIO
85bc833b 293static int str_prioclass_cb(void *data, unsigned long long *val)
214e1eca
JA
294{
295 struct thread_data *td = data;
6cefbe33
JA
296 unsigned short mask;
297
298 /*
299 * mask off old class bits, str_prio_cb() may have set a default class
300 */
301 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
302 td->ioprio &= mask;
214e1eca
JA
303
304 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
ac684785 305 td->ioprio_set = 1;
214e1eca
JA
306 return 0;
307}
308
85bc833b 309static int str_prio_cb(void *data, unsigned long long *val)
214e1eca
JA
310{
311 struct thread_data *td = data;
312
313 td->ioprio |= *val;
6cefbe33
JA
314
315 /*
316 * If no class is set, assume BE
317 */
318 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
319 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
320
ac684785 321 td->ioprio_set = 1;
214e1eca
JA
322 return 0;
323}
324#endif
325
326static int str_exitall_cb(void)
327{
328 exitall_on_terminate = 1;
329 return 0;
330}
331
214e1eca 332#ifdef FIO_HAVE_CPU_AFFINITY
85bc833b 333static int str_cpumask_cb(void *data, unsigned long long *val)
d2e268b0
JA
334{
335 struct thread_data *td = data;
214e1eca 336 unsigned int i;
b03daafb 337 long max_cpu;
d2ce18b5
JA
338 int ret;
339
340 ret = fio_cpuset_init(&td->o.cpumask);
341 if (ret < 0) {
342 log_err("fio: cpuset_init failed\n");
343 td_verror(td, ret, "fio_cpuset_init");
344 return 1;
345 }
214e1eca 346
c00a2289 347 max_cpu = cpus_online();
214e1eca 348
62a7273d
JA
349 for (i = 0; i < sizeof(int) * 8; i++) {
350 if ((1 << i) & *val) {
b03daafb
JA
351 if (i > max_cpu) {
352 log_err("fio: CPU %d too large (max=%ld)\n", i,
353 max_cpu);
354 return 1;
355 }
62a7273d 356 dprint(FD_PARSE, "set cpu allowed %d\n", i);
6d459ee7 357 fio_cpu_set(&td->o.cpumask, i);
62a7273d
JA
358 }
359 }
d2e268b0
JA
360
361 td->o.cpumask_set = 1;
362 return 0;
214e1eca
JA
363}
364
e8462bd8
JA
365static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
366 const char *input)
214e1eca 367{
d2e268b0 368 char *cpu, *str, *p;
b03daafb 369 long max_cpu;
19608d6c 370 int ret = 0;
d2e268b0 371
e8462bd8 372 ret = fio_cpuset_init(mask);
d2ce18b5
JA
373 if (ret < 0) {
374 log_err("fio: cpuset_init failed\n");
375 td_verror(td, ret, "fio_cpuset_init");
376 return 1;
377 }
d2e268b0
JA
378
379 p = str = strdup(input);
214e1eca 380
d2e268b0
JA
381 strip_blank_front(&str);
382 strip_blank_end(str);
383
c00a2289 384 max_cpu = cpus_online();
b03daafb 385
d2e268b0 386 while ((cpu = strsep(&str, ",")) != NULL) {
62a7273d
JA
387 char *str2, *cpu2;
388 int icpu, icpu2;
389
d2e268b0
JA
390 if (!strlen(cpu))
391 break;
62a7273d
JA
392
393 str2 = cpu;
394 icpu2 = -1;
395 while ((cpu2 = strsep(&str2, "-")) != NULL) {
396 if (!strlen(cpu2))
397 break;
398
399 icpu2 = atoi(cpu2);
400 }
401
402 icpu = atoi(cpu);
403 if (icpu2 == -1)
404 icpu2 = icpu;
405 while (icpu <= icpu2) {
6d459ee7 406 if (icpu >= FIO_MAX_CPUS) {
19608d6c 407 log_err("fio: your OS only supports up to"
6d459ee7 408 " %d CPUs\n", (int) FIO_MAX_CPUS);
19608d6c
JA
409 ret = 1;
410 break;
411 }
b03daafb
JA
412 if (icpu > max_cpu) {
413 log_err("fio: CPU %d too large (max=%ld)\n",
414 icpu, max_cpu);
415 ret = 1;
416 break;
417 }
0b9d69ec 418
62a7273d 419 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
e8462bd8 420 fio_cpu_set(mask, icpu);
62a7273d
JA
421 icpu++;
422 }
19608d6c
JA
423 if (ret)
424 break;
d2e268b0
JA
425 }
426
427 free(p);
19608d6c
JA
428 if (!ret)
429 td->o.cpumask_set = 1;
430 return ret;
214e1eca 431}
e8462bd8
JA
432
433static int str_cpus_allowed_cb(void *data, const char *input)
434{
435 struct thread_data *td = data;
436 int ret;
437
438 ret = set_cpus_allowed(td, &td->o.cpumask, input);
439 if (!ret)
440 td->o.cpumask_set = 1;
441
442 return ret;
443}
444
445static int str_verify_cpus_allowed_cb(void *data, const char *input)
446{
447 struct thread_data *td = data;
448 int ret;
449
450 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
451 if (!ret)
452 td->o.verify_cpumask_set = 1;
453
454 return ret;
455}
d2e268b0 456#endif
214e1eca 457
0d29de83
JA
458#ifdef FIO_HAVE_TRIM
459static int str_verify_trim_cb(void *data, unsigned long long *val)
460{
461 struct thread_data *td = data;
462
463 td->o.trim_percentage = *val;
464 return 0;
465}
466#endif
467
214e1eca
JA
468static int str_fst_cb(void *data, const char *str)
469{
470 struct thread_data *td = data;
471 char *nr = get_opt_postfix(str);
472
473 td->file_service_nr = 1;
182ec6ee 474 if (nr) {
214e1eca 475 td->file_service_nr = atoi(nr);
182ec6ee
JA
476 free(nr);
477 }
214e1eca
JA
478
479 return 0;
480}
481
3ae06371 482#ifdef FIO_HAVE_SYNC_FILE_RANGE
44f29692
JA
483static int str_sfr_cb(void *data, const char *str)
484{
485 struct thread_data *td = data;
486 char *nr = get_opt_postfix(str);
487
488 td->sync_file_range_nr = 1;
489 if (nr) {
490 td->sync_file_range_nr = atoi(nr);
491 free(nr);
492 }
493
494 return 0;
495}
3ae06371 496#endif
44f29692 497
921c766f
JA
498static int check_dir(struct thread_data *td, char *fname)
499{
3f0ca9b9 500#if 0
921c766f 501 char file[PATH_MAX], *dir;
bc838919 502 int elen = 0;
921c766f 503
bc838919
JA
504 if (td->o.directory) {
505 strcpy(file, td->o.directory);
fcef0b35 506 strcat(file, "/");
bc838919
JA
507 elen = strlen(file);
508 }
509
fcef0b35 510 sprintf(file + elen, "%s", fname);
921c766f
JA
511 dir = dirname(file);
512
fcef0b35
JA
513 {
514 struct stat sb;
515 /*
516 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
517 * yet, so we can't do this check right here...
518 */
921c766f
JA
519 if (lstat(dir, &sb) < 0) {
520 int ret = errno;
521
522 log_err("fio: %s is not a directory\n", dir);
523 td_verror(td, ret, "lstat");
524 return 1;
525 }
526
527 if (!S_ISDIR(sb.st_mode)) {
528 log_err("fio: %s is not a directory\n", dir);
529 return 1;
530 }
fcef0b35
JA
531 }
532#endif
921c766f
JA
533
534 return 0;
535}
536
8e827d35
JA
537/*
538 * Return next file in the string. Files are separated with ':'. If the ':'
539 * is escaped with a '\', then that ':' is part of the filename and does not
540 * indicate a new file.
541 */
542static char *get_next_file_name(char **ptr)
543{
544 char *str = *ptr;
545 char *p, *start;
546
547 if (!str || !strlen(str))
548 return NULL;
549
550 start = str;
551 do {
552 /*
553 * No colon, we are done
554 */
555 p = strchr(str, ':');
556 if (!p) {
557 *ptr = NULL;
558 break;
559 }
560
561 /*
562 * We got a colon, but it's the first character. Skip and
563 * continue
564 */
565 if (p == start) {
566 str = ++start;
567 continue;
568 }
569
570 if (*(p - 1) != '\\') {
571 *p = '\0';
572 *ptr = p + 1;
573 break;
574 }
575
576 memmove(p - 1, p, strlen(p) + 1);
577 str = p;
578 } while (1);
579
580 return start;
581}
582
214e1eca
JA
583static int str_filename_cb(void *data, const char *input)
584{
585 struct thread_data *td = data;
586 char *fname, *str, *p;
587
588 p = str = strdup(input);
589
590 strip_blank_front(&str);
591 strip_blank_end(str);
592
593 if (!td->files_index)
2dc1bbeb 594 td->o.nr_files = 0;
214e1eca 595
8e827d35 596 while ((fname = get_next_file_name(&str)) != NULL) {
214e1eca
JA
597 if (!strlen(fname))
598 break;
921c766f
JA
599 if (check_dir(td, fname)) {
600 free(p);
601 return 1;
602 }
214e1eca 603 add_file(td, fname);
2dc1bbeb 604 td->o.nr_files++;
214e1eca
JA
605 }
606
607 free(p);
608 return 0;
609}
610
611static int str_directory_cb(void *data, const char fio_unused *str)
612{
613 struct thread_data *td = data;
614 struct stat sb;
615
2dc1bbeb 616 if (lstat(td->o.directory, &sb) < 0) {
921c766f
JA
617 int ret = errno;
618
2dc1bbeb 619 log_err("fio: %s is not a directory\n", td->o.directory);
921c766f 620 td_verror(td, ret, "lstat");
214e1eca
JA
621 return 1;
622 }
623 if (!S_ISDIR(sb.st_mode)) {
2dc1bbeb 624 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
625 return 1;
626 }
627
628 return 0;
629}
630
631static int str_opendir_cb(void *data, const char fio_unused *str)
632{
633 struct thread_data *td = data;
634
635 if (!td->files_index)
2dc1bbeb 636 td->o.nr_files = 0;
214e1eca 637
2dc1bbeb 638 return add_dir_files(td, td->o.opendir);
214e1eca
JA
639}
640
85bc833b 641static int str_verify_offset_cb(void *data, unsigned long long *off)
546a9142
SL
642{
643 struct thread_data *td = data;
a59e170d 644
546a9142 645 if (*off && *off < sizeof(struct verify_header)) {
a59e170d 646 log_err("fio: verify_offset too small\n");
546a9142
SL
647 return 1;
648 }
a59e170d
JA
649
650 td->o.verify_offset = *off;
546a9142
SL
651 return 0;
652}
653
0e92f873 654static int str_verify_pattern_cb(void *data, const char *input)
90059d65
JA
655{
656 struct thread_data *td = data;
0e92f873
RR
657 long off;
658 int i = 0, j = 0, len, k, base = 10;
659 char* loc1, * loc2;
660
661 loc1 = strstr(input, "0x");
662 loc2 = strstr(input, "0X");
663 if (loc1 || loc2)
664 base = 16;
665 off = strtol(input, NULL, base);
666 if (off != LONG_MAX || errno != ERANGE) {
667 while (off) {
668 td->o.verify_pattern[i] = off & 0xff;
669 off >>= 8;
670 i++;
671 }
672 } else {
673 len = strlen(input);
674 k = len - 1;
675 if (base == 16) {
676 if (loc1)
677 j = loc1 - input + 2;
678 else
679 j = loc2 - input + 2;
680 } else
681 return 1;
682 if (len - j < MAX_PATTERN_SIZE * 2) {
683 while (k >= j) {
684 off = converthexchartoint(input[k--]);
685 if (k >= j)
686 off += (converthexchartoint(input[k--])
687 * 16);
688 td->o.verify_pattern[i++] = (char) off;
689 }
690 }
691 }
692 td->o.verify_pattern_bytes = i;
92bf48d5
JA
693 /*
694 * VERIFY_META could already be set
695 */
696 if (td->o.verify == VERIFY_NONE)
697 td->o.verify = VERIFY_PATTERN;
90059d65
JA
698 return 0;
699}
214e1eca 700
4d4e80f2
JA
701static int str_lockfile_cb(void *data, const char *str)
702{
703 struct thread_data *td = data;
704 char *nr = get_opt_postfix(str);
705
706 td->o.lockfile_batch = 1;
182ec6ee 707 if (nr) {
4d4e80f2 708 td->o.lockfile_batch = atoi(nr);
182ec6ee
JA
709 free(nr);
710 }
4d4e80f2
JA
711
712 return 0;
713}
714
e3cedca7
JA
715static int str_write_bw_log_cb(void *data, const char *str)
716{
717 struct thread_data *td = data;
718
719 if (str)
720 td->o.bw_log_file = strdup(str);
721
722 td->o.write_bw_log = 1;
723 return 0;
724}
725
726static int str_write_lat_log_cb(void *data, const char *str)
727{
728 struct thread_data *td = data;
729
730 if (str)
731 td->o.lat_log_file = strdup(str);
732
733 td->o.write_lat_log = 1;
734 return 0;
735}
736
993bf48b
JA
737static int str_gtod_reduce_cb(void *data, int *il)
738{
739 struct thread_data *td = data;
740 int val = *il;
741
02af0988 742 td->o.disable_lat = !!val;
993bf48b
JA
743 td->o.disable_clat = !!val;
744 td->o.disable_slat = !!val;
745 td->o.disable_bw = !!val;
746 if (val)
747 td->tv_cache_mask = 63;
748
749 return 0;
750}
751
85bc833b 752static int str_gtod_cpu_cb(void *data, long long *il)
be4ecfdf
JA
753{
754 struct thread_data *td = data;
755 int val = *il;
756
757 td->o.gtod_cpu = val;
758 td->o.gtod_offload = 1;
759 return 0;
760}
761
7bb59102
JA
762static int str_size_cb(void *data, unsigned long long *__val)
763{
764 struct thread_data *td = data;
765 unsigned long long v = *__val;
766
767 if (parse_is_percent(v)) {
768 td->o.size = 0;
769 td->o.size_percent = -1ULL - v;
770 } else
771 td->o.size = v;
772
773 return 0;
774}
775
896cac2a
JA
776static int rw_verify(struct fio_option *o, void *data)
777{
778 struct thread_data *td = data;
779
780 if (read_only && td_write(td)) {
781 log_err("fio: job <%s> has write bit set, but fio is in"
782 " read-only mode\n", td->o.name);
783 return 1;
784 }
785
786 return 0;
787}
788
276ca4f7 789static int gtod_cpu_verify(struct fio_option *o, void *data)
29d43ff9 790{
276ca4f7 791#ifndef FIO_HAVE_CPU_AFFINITY
29d43ff9
JA
792 struct thread_data *td = data;
793
29d43ff9
JA
794 if (td->o.gtod_cpu) {
795 log_err("fio: platform must support CPU affinity for"
796 "gettimeofday() offloading\n");
797 return 1;
798 }
799#endif
800
801 return 0;
802}
803
90fef2d1
JA
804static int kb_base_verify(struct fio_option *o, void *data)
805{
806 struct thread_data *td = data;
807
808 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
809 log_err("fio: kb_base set to nonsensical value: %u\n",
810 td->o.kb_base);
811 return 1;
812 }
813
814 return 0;
815}
816
214e1eca
JA
817#define __stringify_1(x) #x
818#define __stringify(x) __stringify_1(x)
819
820/*
821 * Map of job/command line options
822 */
07b3232d 823static struct fio_option options[FIO_MAX_OPTS] = {
214e1eca
JA
824 {
825 .name = "description",
826 .type = FIO_OPT_STR_STORE,
827 .off1 = td_var_offset(description),
828 .help = "Text job description",
829 },
830 {
831 .name = "name",
832 .type = FIO_OPT_STR_STORE,
833 .off1 = td_var_offset(name),
834 .help = "Name of this job",
835 },
836 {
837 .name = "directory",
838 .type = FIO_OPT_STR_STORE,
839 .off1 = td_var_offset(directory),
840 .cb = str_directory_cb,
841 .help = "Directory to store files in",
842 },
843 {
844 .name = "filename",
845 .type = FIO_OPT_STR_STORE,
846 .off1 = td_var_offset(filename),
847 .cb = str_filename_cb,
f0d524b0 848 .prio = -1, /* must come after "directory" */
214e1eca
JA
849 .help = "File(s) to use for the workload",
850 },
90fef2d1
JA
851 {
852 .name = "kb_base",
853 .type = FIO_OPT_INT,
854 .off1 = td_var_offset(kb_base),
90fef2d1 855 .verify = kb_base_verify,
a639f0bb 856 .prio = 1,
90fef2d1 857 .def = "1024",
a639f0bb 858 .help = "How many bytes per KB for reporting (1000 or 1024)",
90fef2d1 859 },
29c1349f
JA
860 {
861 .name = "lockfile",
4d4e80f2
JA
862 .type = FIO_OPT_STR,
863 .cb = str_lockfile_cb,
864 .off1 = td_var_offset(file_lock_mode),
29c1349f
JA
865 .help = "Lock file when doing IO to it",
866 .parent = "filename",
4d4e80f2
JA
867 .def = "none",
868 .posval = {
869 { .ival = "none",
870 .oval = FILE_LOCK_NONE,
871 .help = "No file locking",
872 },
873 { .ival = "exclusive",
874 .oval = FILE_LOCK_EXCLUSIVE,
875 .help = "Exclusive file lock",
876 },
877 {
878 .ival = "readwrite",
879 .oval = FILE_LOCK_READWRITE,
880 .help = "Read vs write lock",
881 },
882 },
29c1349f 883 },
214e1eca
JA
884 {
885 .name = "opendir",
886 .type = FIO_OPT_STR_STORE,
887 .off1 = td_var_offset(opendir),
888 .cb = str_opendir_cb,
889 .help = "Recursively add files from this directory and down",
890 },
891 {
892 .name = "rw",
d3aad8f2 893 .alias = "readwrite",
214e1eca 894 .type = FIO_OPT_STR,
211097b2 895 .cb = str_rw_cb,
214e1eca
JA
896 .off1 = td_var_offset(td_ddir),
897 .help = "IO direction",
898 .def = "read",
896cac2a 899 .verify = rw_verify,
214e1eca
JA
900 .posval = {
901 { .ival = "read",
902 .oval = TD_DDIR_READ,
903 .help = "Sequential read",
904 },
905 { .ival = "write",
906 .oval = TD_DDIR_WRITE,
907 .help = "Sequential write",
908 },
909 { .ival = "randread",
910 .oval = TD_DDIR_RANDREAD,
911 .help = "Random read",
912 },
913 { .ival = "randwrite",
914 .oval = TD_DDIR_RANDWRITE,
915 .help = "Random write",
916 },
917 { .ival = "rw",
918 .oval = TD_DDIR_RW,
919 .help = "Sequential read and write mix",
920 },
921 { .ival = "randrw",
922 .oval = TD_DDIR_RANDRW,
923 .help = "Random read and write mix"
924 },
925 },
926 },
38dad62d
JA
927 {
928 .name = "rw_sequencer",
929 .type = FIO_OPT_STR,
930 .off1 = td_var_offset(rw_seq),
931 .help = "IO offset generator modifier",
932 .def = "sequential",
933 .posval = {
934 { .ival = "sequential",
935 .oval = RW_SEQ_SEQ,
936 .help = "Generate sequential offsets",
937 },
938 { .ival = "identical",
939 .oval = RW_SEQ_IDENT,
940 .help = "Generate identical offsets",
941 },
942 },
943 },
944
214e1eca
JA
945 {
946 .name = "ioengine",
947 .type = FIO_OPT_STR_STORE,
948 .off1 = td_var_offset(ioengine),
949 .help = "IO engine to use",
58483fa4 950 .def = FIO_PREFERRED_ENGINE,
214e1eca
JA
951 .posval = {
952 { .ival = "sync",
953 .help = "Use read/write",
954 },
a31041ea 955 { .ival = "psync",
956 .help = "Use pread/pwrite",
957 },
1d2af02a 958 { .ival = "vsync",
03e20d68 959 .help = "Use readv/writev",
1d2af02a 960 },
214e1eca
JA
961#ifdef FIO_HAVE_LIBAIO
962 { .ival = "libaio",
963 .help = "Linux native asynchronous IO",
964 },
965#endif
966#ifdef FIO_HAVE_POSIXAIO
967 { .ival = "posixaio",
968 .help = "POSIX asynchronous IO",
969 },
417f0068
JA
970#endif
971#ifdef FIO_HAVE_SOLARISAIO
972 { .ival = "solarisaio",
973 .help = "Solaris native asynchronous IO",
974 },
214e1eca 975#endif
03e20d68
BC
976#ifdef FIO_HAVE_WINDOWSAIO
977 { .ival = "windowsaio",
3be80071 978 .help = "Windows native asynchronous IO"
03e20d68 979 },
3be80071 980#endif
214e1eca 981 { .ival = "mmap",
03e20d68 982 .help = "Memory mapped IO"
214e1eca
JA
983 },
984#ifdef FIO_HAVE_SPLICE
985 { .ival = "splice",
986 .help = "splice/vmsplice based IO",
987 },
9cce02e8
JA
988 { .ival = "netsplice",
989 .help = "splice/vmsplice to/from the network",
990 },
214e1eca
JA
991#endif
992#ifdef FIO_HAVE_SGIO
993 { .ival = "sg",
994 .help = "SCSI generic v3 IO",
995 },
996#endif
997 { .ival = "null",
998 .help = "Testing engine (no data transfer)",
999 },
1000 { .ival = "net",
1001 .help = "Network IO",
1002 },
1003#ifdef FIO_HAVE_SYSLET
1004 { .ival = "syslet-rw",
1005 .help = "syslet enabled async pread/pwrite IO",
1006 },
1007#endif
1008 { .ival = "cpuio",
03e20d68 1009 .help = "CPU cycle burner engine",
214e1eca 1010 },
b8c82a46
JA
1011#ifdef FIO_HAVE_GUASI
1012 { .ival = "guasi",
1013 .help = "GUASI IO engine",
1014 },
79a43187
JA
1015#endif
1016#ifdef FIO_HAVE_BINJECT
1017 { .ival = "binject",
1018 .help = "binject direct inject block engine",
1019 },
21b8aee8 1020#endif
1021#ifdef FIO_HAVE_RDMA
1022 { .ival = "rdma",
1023 .help = "RDMA IO engine",
1024 },
b8c82a46 1025#endif
214e1eca
JA
1026 { .ival = "external",
1027 .help = "Load external engine (append name)",
1028 },
1029 },
1030 },
1031 {
1032 .name = "iodepth",
1033 .type = FIO_OPT_INT,
1034 .off1 = td_var_offset(iodepth),
03e20d68 1035 .help = "Number of IO buffers to keep in flight",
757aff4f 1036 .minval = 1,
214e1eca
JA
1037 .def = "1",
1038 },
1039 {
1040 .name = "iodepth_batch",
4950421a 1041 .alias = "iodepth_batch_submit",
214e1eca
JA
1042 .type = FIO_OPT_INT,
1043 .off1 = td_var_offset(iodepth_batch),
d65db441 1044 .help = "Number of IO buffers to submit in one go",
afdf9352 1045 .parent = "iodepth",
a2e6f8ac
JA
1046 .minval = 1,
1047 .def = "1",
4950421a
JA
1048 },
1049 {
1050 .name = "iodepth_batch_complete",
1051 .type = FIO_OPT_INT,
1052 .off1 = td_var_offset(iodepth_batch_complete),
d65db441 1053 .help = "Number of IO buffers to retrieve in one go",
4950421a
JA
1054 .parent = "iodepth",
1055 .minval = 0,
1056 .def = "1",
214e1eca
JA
1057 },
1058 {
1059 .name = "iodepth_low",
1060 .type = FIO_OPT_INT,
1061 .off1 = td_var_offset(iodepth_low),
1062 .help = "Low water mark for queuing depth",
afdf9352 1063 .parent = "iodepth",
214e1eca
JA
1064 },
1065 {
1066 .name = "size",
1067 .type = FIO_OPT_STR_VAL,
7bb59102 1068 .cb = str_size_cb,
214e1eca
JA
1069 .help = "Total size of device or files",
1070 },
aa31f1f1
SL
1071 {
1072 .name = "fill_device",
74586c1e 1073 .alias = "fill_fs",
aa31f1f1
SL
1074 .type = FIO_OPT_BOOL,
1075 .off1 = td_var_offset(fill_device),
1076 .help = "Write until an ENOSPC error occurs",
1077 .def = "0",
1078 },
214e1eca
JA
1079 {
1080 .name = "filesize",
1081 .type = FIO_OPT_STR_VAL,
1082 .off1 = td_var_offset(file_size_low),
1083 .off2 = td_var_offset(file_size_high),
c3edbdba 1084 .minval = 1,
214e1eca
JA
1085 .help = "Size of individual files",
1086 },
67a1000f
JA
1087 {
1088 .name = "offset",
1089 .alias = "fileoffset",
1090 .type = FIO_OPT_STR_VAL,
1091 .off1 = td_var_offset(start_offset),
1092 .help = "Start IO from this offset",
1093 .def = "0",
1094 },
214e1eca
JA
1095 {
1096 .name = "bs",
d3aad8f2 1097 .alias = "blocksize",
e01b22b8 1098 .type = FIO_OPT_INT,
214e1eca
JA
1099 .off1 = td_var_offset(bs[DDIR_READ]),
1100 .off2 = td_var_offset(bs[DDIR_WRITE]),
c3edbdba 1101 .minval = 1,
214e1eca
JA
1102 .help = "Block size unit",
1103 .def = "4k",
67a1000f 1104 .parent = "rw",
214e1eca 1105 },
2b7a01d0
JA
1106 {
1107 .name = "ba",
1108 .alias = "blockalign",
e01b22b8 1109 .type = FIO_OPT_INT,
2b7a01d0
JA
1110 .off1 = td_var_offset(ba[DDIR_READ]),
1111 .off2 = td_var_offset(ba[DDIR_WRITE]),
1112 .minval = 1,
1113 .help = "IO block offset alignment",
1114 .parent = "rw",
1115 },
214e1eca
JA
1116 {
1117 .name = "bsrange",
d3aad8f2 1118 .alias = "blocksize_range",
214e1eca
JA
1119 .type = FIO_OPT_RANGE,
1120 .off1 = td_var_offset(min_bs[DDIR_READ]),
1121 .off2 = td_var_offset(max_bs[DDIR_READ]),
1122 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1123 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
c3edbdba 1124 .minval = 1,
214e1eca 1125 .help = "Set block size range (in more detail than bs)",
67a1000f 1126 .parent = "rw",
214e1eca 1127 },
564ca972
JA
1128 {
1129 .name = "bssplit",
1130 .type = FIO_OPT_STR,
1131 .cb = str_bssplit_cb,
1132 .help = "Set a specific mix of block sizes",
1133 .parent = "rw",
1134 },
214e1eca
JA
1135 {
1136 .name = "bs_unaligned",
d3aad8f2 1137 .alias = "blocksize_unaligned",
214e1eca
JA
1138 .type = FIO_OPT_STR_SET,
1139 .off1 = td_var_offset(bs_unaligned),
1140 .help = "Don't sector align IO buffer sizes",
67a1000f 1141 .parent = "rw",
214e1eca
JA
1142 },
1143 {
1144 .name = "randrepeat",
1145 .type = FIO_OPT_BOOL,
1146 .off1 = td_var_offset(rand_repeatable),
1147 .help = "Use repeatable random IO pattern",
1148 .def = "1",
67a1000f 1149 .parent = "rw",
214e1eca 1150 },
2615cc4b
JA
1151 {
1152 .name = "use_os_rand",
1153 .type = FIO_OPT_BOOL,
1154 .off1 = td_var_offset(use_os_rand),
1155 .help = "Set to use OS random generator",
1156 .def = "0",
1157 .parent = "rw",
1158 },
214e1eca
JA
1159 {
1160 .name = "norandommap",
1161 .type = FIO_OPT_STR_SET,
1162 .off1 = td_var_offset(norandommap),
1163 .help = "Accept potential duplicate random blocks",
67a1000f 1164 .parent = "rw",
214e1eca 1165 },
2b386d25
JA
1166 {
1167 .name = "softrandommap",
1168 .type = FIO_OPT_BOOL,
1169 .off1 = td_var_offset(softrandommap),
f66ab3c8 1170 .help = "Set norandommap if randommap allocation fails",
2b386d25
JA
1171 .parent = "norandommap",
1172 .def = "0",
1173 },
214e1eca
JA
1174 {
1175 .name = "nrfiles",
d7c8be03 1176 .alias = "nr_files",
214e1eca
JA
1177 .type = FIO_OPT_INT,
1178 .off1 = td_var_offset(nr_files),
1179 .help = "Split job workload between this number of files",
1180 .def = "1",
1181 },
1182 {
1183 .name = "openfiles",
1184 .type = FIO_OPT_INT,
1185 .off1 = td_var_offset(open_files),
1186 .help = "Number of files to keep open at the same time",
1187 },
1188 {
1189 .name = "file_service_type",
1190 .type = FIO_OPT_STR,
1191 .cb = str_fst_cb,
1192 .off1 = td_var_offset(file_service_type),
1193 .help = "How to select which file to service next",
1194 .def = "roundrobin",
1195 .posval = {
1196 { .ival = "random",
1197 .oval = FIO_FSERVICE_RANDOM,
1198 .help = "Choose a file at random",
1199 },
1200 { .ival = "roundrobin",
1201 .oval = FIO_FSERVICE_RR,
1202 .help = "Round robin select files",
1203 },
a086c257
JA
1204 { .ival = "sequential",
1205 .oval = FIO_FSERVICE_SEQ,
1206 .help = "Finish one file before moving to the next",
1207 },
214e1eca 1208 },
67a1000f
JA
1209 .parent = "nrfiles",
1210 },
7bc8c2cf
JA
1211#ifdef FIO_HAVE_FALLOCATE
1212 {
1213 .name = "fallocate",
a596f047
EG
1214 .type = FIO_OPT_STR,
1215 .off1 = td_var_offset(fallocate_mode),
1216 .help = "Whether pre-allocation is performed when laying out files",
1217 .def = "posix",
1218 .posval = {
1219 { .ival = "none",
1220 .oval = FIO_FALLOCATE_NONE,
1221 .help = "Do not pre-allocate space",
1222 },
1223 { .ival = "posix",
1224 .oval = FIO_FALLOCATE_POSIX,
1225 .help = "Use posix_fallocate()",
1226 },
1227#ifdef FIO_HAVE_LINUX_FALLOCATE
1228 { .ival = "keep",
1229 .oval = FIO_FALLOCATE_KEEP_SIZE,
1230 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1231 },
7bc8c2cf 1232#endif
a596f047
EG
1233 /* Compatibility with former boolean values */
1234 { .ival = "0",
1235 .oval = FIO_FALLOCATE_NONE,
1236 .help = "Alias for 'none'",
1237 },
1238 { .ival = "1",
1239 .oval = FIO_FALLOCATE_POSIX,
1240 .help = "Alias for 'posix'",
1241 },
1242 },
1243 },
1244#endif /* FIO_HAVE_FALLOCATE */
67a1000f
JA
1245 {
1246 .name = "fadvise_hint",
1247 .type = FIO_OPT_BOOL,
1248 .off1 = td_var_offset(fadvise_hint),
1249 .help = "Use fadvise() to advise the kernel on IO pattern",
1250 .def = "1",
214e1eca
JA
1251 },
1252 {
1253 .name = "fsync",
1254 .type = FIO_OPT_INT,
1255 .off1 = td_var_offset(fsync_blocks),
1256 .help = "Issue fsync for writes every given number of blocks",
1257 .def = "0",
1258 },
5f9099ea
JA
1259 {
1260 .name = "fdatasync",
1261 .type = FIO_OPT_INT,
1262 .off1 = td_var_offset(fdatasync_blocks),
1263 .help = "Issue fdatasync for writes every given number of blocks",
1264 .def = "0",
1265 },
1ef2b6be
JA
1266 {
1267 .name = "write_barrier",
1268 .type = FIO_OPT_INT,
1269 .off1 = td_var_offset(barrier_blocks),
1270 .help = "Make every Nth write a barrier write",
1271 .def = "0",
1272 },
44f29692
JA
1273#ifdef FIO_HAVE_SYNC_FILE_RANGE
1274 {
1275 .name = "sync_file_range",
1276 .posval = {
1277 { .ival = "wait_before",
1278 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1279 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
3843deb3 1280 .or = 1,
44f29692
JA
1281 },
1282 { .ival = "write",
1283 .oval = SYNC_FILE_RANGE_WRITE,
1284 .help = "SYNC_FILE_RANGE_WRITE",
3843deb3 1285 .or = 1,
44f29692
JA
1286 },
1287 {
1288 .ival = "wait_after",
1289 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1290 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
3843deb3 1291 .or = 1,
44f29692
JA
1292 },
1293 },
3843deb3 1294 .type = FIO_OPT_STR_MULTI,
44f29692
JA
1295 .cb = str_sfr_cb,
1296 .off1 = td_var_offset(sync_file_range),
1297 .help = "Use sync_file_range()",
1298 },
1299#endif
214e1eca
JA
1300 {
1301 .name = "direct",
1302 .type = FIO_OPT_BOOL,
1303 .off1 = td_var_offset(odirect),
1304 .help = "Use O_DIRECT IO (negates buffered)",
1305 .def = "0",
1306 },
1307 {
1308 .name = "buffered",
1309 .type = FIO_OPT_BOOL,
1310 .off1 = td_var_offset(odirect),
1311 .neg = 1,
1312 .help = "Use buffered IO (negates direct)",
1313 .def = "1",
1314 },
1315 {
1316 .name = "overwrite",
1317 .type = FIO_OPT_BOOL,
1318 .off1 = td_var_offset(overwrite),
1319 .help = "When writing, set whether to overwrite current data",
1320 .def = "0",
1321 },
1322 {
1323 .name = "loops",
1324 .type = FIO_OPT_INT,
1325 .off1 = td_var_offset(loops),
1326 .help = "Number of times to run the job",
1327 .def = "1",
1328 },
1329 {
1330 .name = "numjobs",
1331 .type = FIO_OPT_INT,
1332 .off1 = td_var_offset(numjobs),
1333 .help = "Duplicate this job this many times",
1334 .def = "1",
1335 },
1336 {
1337 .name = "startdelay",
a5737c93 1338 .type = FIO_OPT_STR_VAL_TIME,
214e1eca
JA
1339 .off1 = td_var_offset(start_delay),
1340 .help = "Only start job when this period has passed",
1341 .def = "0",
1342 },
1343 {
1344 .name = "runtime",
1345 .alias = "timeout",
1346 .type = FIO_OPT_STR_VAL_TIME,
1347 .off1 = td_var_offset(timeout),
1348 .help = "Stop workload when this amount of time has passed",
1349 .def = "0",
1350 },
cf4464ca
JA
1351 {
1352 .name = "time_based",
1353 .type = FIO_OPT_STR_SET,
1354 .off1 = td_var_offset(time_based),
1355 .help = "Keep running until runtime/timeout is met",
1356 },
721938ae
JA
1357 {
1358 .name = "ramp_time",
1359 .type = FIO_OPT_STR_VAL_TIME,
1360 .off1 = td_var_offset(ramp_time),
1361 .help = "Ramp up time before measuring performance",
1362 },
c223da83
JA
1363 {
1364 .name = "clocksource",
1365 .type = FIO_OPT_STR,
1366 .cb = fio_clock_source_cb,
1367 .off1 = td_var_offset(clocksource),
1368 .help = "What type of timing source to use",
c223da83
JA
1369 .posval = {
1370 { .ival = "gettimeofday",
1371 .oval = CS_GTOD,
1372 .help = "Use gettimeofday(2) for timing",
1373 },
1374 { .ival = "clock_gettime",
1375 .oval = CS_CGETTIME,
1376 .help = "Use clock_gettime(2) for timing",
1377 },
1378#ifdef ARCH_HAVE_CPU_CLOCK
1379 { .ival = "cpu",
1380 .oval = CS_CPUCLOCK,
1381 .help = "Use CPU private clock",
1382 },
1383#endif
1384 },
1385 },
214e1eca
JA
1386 {
1387 .name = "mem",
d3aad8f2 1388 .alias = "iomem",
214e1eca
JA
1389 .type = FIO_OPT_STR,
1390 .cb = str_mem_cb,
1391 .off1 = td_var_offset(mem_type),
1392 .help = "Backing type for IO buffers",
1393 .def = "malloc",
1394 .posval = {
1395 { .ival = "malloc",
1396 .oval = MEM_MALLOC,
1397 .help = "Use malloc(3) for IO buffers",
1398 },
37c8cdfe
JA
1399 { .ival = "shm",
1400 .oval = MEM_SHM,
1401 .help = "Use shared memory segments for IO buffers",
1402 },
214e1eca
JA
1403#ifdef FIO_HAVE_HUGETLB
1404 { .ival = "shmhuge",
1405 .oval = MEM_SHMHUGE,
1406 .help = "Like shm, but use huge pages",
1407 },
b370e46a 1408#endif
37c8cdfe
JA
1409 { .ival = "mmap",
1410 .oval = MEM_MMAP,
1411 .help = "Use mmap(2) (file or anon) for IO buffers",
1412 },
214e1eca
JA
1413#ifdef FIO_HAVE_HUGETLB
1414 { .ival = "mmaphuge",
1415 .oval = MEM_MMAPHUGE,
1416 .help = "Like mmap, but use huge pages",
1417 },
1418#endif
1419 },
1420 },
d529ee19
JA
1421 {
1422 .name = "iomem_align",
1423 .alias = "mem_align",
1424 .type = FIO_OPT_INT,
1425 .off1 = td_var_offset(mem_align),
1426 .minval = 0,
1427 .help = "IO memory buffer offset alignment",
1428 .def = "0",
1429 .parent = "iomem",
1430 },
214e1eca
JA
1431 {
1432 .name = "verify",
1433 .type = FIO_OPT_STR,
1434 .off1 = td_var_offset(verify),
1435 .help = "Verify data written",
5d7c5d34 1436 .cb = str_verify_cb,
214e1eca
JA
1437 .def = "0",
1438 .posval = {
1439 { .ival = "0",
1440 .oval = VERIFY_NONE,
1441 .help = "Don't do IO verification",
1442 },
fcca4b58
JA
1443 { .ival = "md5",
1444 .oval = VERIFY_MD5,
1445 .help = "Use md5 checksums for verification",
1446 },
d77a7af3
JA
1447 { .ival = "crc64",
1448 .oval = VERIFY_CRC64,
1449 .help = "Use crc64 checksums for verification",
1450 },
214e1eca
JA
1451 { .ival = "crc32",
1452 .oval = VERIFY_CRC32,
1453 .help = "Use crc32 checksums for verification",
1454 },
af497e6a
JA
1455 { .ival = "crc32c-intel",
1456 .oval = VERIFY_CRC32C_INTEL,
1457 .help = "Use hw crc32c checksums for verification",
1458 },
bac39e0e
JA
1459 { .ival = "crc32c",
1460 .oval = VERIFY_CRC32C,
1461 .help = "Use crc32c checksums for verification",
1462 },
969f7ed3
JA
1463 { .ival = "crc16",
1464 .oval = VERIFY_CRC16,
1465 .help = "Use crc16 checksums for verification",
1466 },
1e154bdb
JA
1467 { .ival = "crc7",
1468 .oval = VERIFY_CRC7,
1469 .help = "Use crc7 checksums for verification",
1470 },
7c353ceb
JA
1471 { .ival = "sha1",
1472 .oval = VERIFY_SHA1,
1473 .help = "Use sha1 checksums for verification",
1474 },
cd14cc10
JA
1475 { .ival = "sha256",
1476 .oval = VERIFY_SHA256,
1477 .help = "Use sha256 checksums for verification",
1478 },
1479 { .ival = "sha512",
1480 .oval = VERIFY_SHA512,
1481 .help = "Use sha512 checksums for verification",
1482 },
7437ee87
SL
1483 { .ival = "meta",
1484 .oval = VERIFY_META,
1485 .help = "Use io information",
1486 },
36690c9b
JA
1487 {
1488 .ival = "null",
1489 .oval = VERIFY_NULL,
1490 .help = "Pretend to verify",
1491 },
214e1eca
JA
1492 },
1493 },
005c565a
JA
1494 {
1495 .name = "do_verify",
68e1f29a 1496 .type = FIO_OPT_BOOL,
005c565a
JA
1497 .off1 = td_var_offset(do_verify),
1498 .help = "Run verification stage after write",
1499 .def = "1",
1500 .parent = "verify",
1501 },
160b966d
JA
1502 {
1503 .name = "verifysort",
1504 .type = FIO_OPT_BOOL,
1505 .off1 = td_var_offset(verifysort),
1506 .help = "Sort written verify blocks for read back",
1507 .def = "1",
c83f2df1 1508 .parent = "verify",
160b966d 1509 },
3f9f4e26 1510 {
a59e170d 1511 .name = "verify_interval",
e01b22b8 1512 .type = FIO_OPT_INT,
a59e170d 1513 .off1 = td_var_offset(verify_interval),
819a9680 1514 .minval = 2 * sizeof(struct verify_header),
a59e170d 1515 .help = "Store verify buffer header every N bytes",
afdf9352 1516 .parent = "verify",
3f9f4e26 1517 },
546a9142 1518 {
a59e170d 1519 .name = "verify_offset",
e01b22b8 1520 .type = FIO_OPT_INT,
a59e170d 1521 .help = "Offset verify header location by N bytes",
546a9142 1522 .def = "0",
5ec10eaa 1523 .cb = str_verify_offset_cb,
afdf9352 1524 .parent = "verify",
546a9142 1525 },
e28218f3
SL
1526 {
1527 .name = "verify_pattern",
0e92f873 1528 .type = FIO_OPT_STR,
e28218f3
SL
1529 .cb = str_verify_pattern_cb,
1530 .help = "Fill pattern for IO buffers",
1531 .parent = "verify",
1532 },
a12a3b4d
JA
1533 {
1534 .name = "verify_fatal",
68e1f29a 1535 .type = FIO_OPT_BOOL,
a12a3b4d
JA
1536 .off1 = td_var_offset(verify_fatal),
1537 .def = "0",
1538 .help = "Exit on a single verify failure, don't continue",
1539 .parent = "verify",
1540 },
b463e936
JA
1541 {
1542 .name = "verify_dump",
1543 .type = FIO_OPT_BOOL,
1544 .off1 = td_var_offset(verify_dump),
1545 .def = "1",
1546 .help = "Dump contents of good and bad blocks on failure",
1547 .parent = "verify",
1548 },
e8462bd8
JA
1549 {
1550 .name = "verify_async",
1551 .type = FIO_OPT_INT,
1552 .off1 = td_var_offset(verify_async),
1553 .def = "0",
1554 .help = "Number of async verifier threads to use",
1555 .parent = "verify",
1556 },
9e144189
JA
1557 {
1558 .name = "verify_backlog",
1559 .type = FIO_OPT_STR_VAL,
1560 .off1 = td_var_offset(verify_backlog),
1561 .help = "Verify after this number of blocks are written",
1562 .parent = "verify",
1563 },
1564 {
1565 .name = "verify_backlog_batch",
1566 .type = FIO_OPT_INT,
1567 .off1 = td_var_offset(verify_batch),
1568 .help = "Verify this number of IO blocks",
0d29de83 1569 .parent = "verify",
9e144189 1570 },
e8462bd8
JA
1571#ifdef FIO_HAVE_CPU_AFFINITY
1572 {
1573 .name = "verify_async_cpus",
1574 .type = FIO_OPT_STR,
1575 .cb = str_verify_cpus_allowed_cb,
1576 .help = "Set CPUs allowed for async verify threads",
1577 .parent = "verify_async",
1578 },
0d29de83
JA
1579#endif
1580#ifdef FIO_HAVE_TRIM
1581 {
1582 .name = "trim_percentage",
1583 .type = FIO_OPT_INT,
1584 .cb = str_verify_trim_cb,
1585 .maxval = 100,
1586 .help = "Number of verify blocks to discard/trim",
1587 .parent = "verify",
1588 .def = "0",
1589 },
1590 {
1591 .name = "trim_verify_zero",
1592 .type = FIO_OPT_INT,
1593 .help = "Verify that trim/discarded blocks are returned as zeroes",
1594 .off1 = td_var_offset(trim_zero),
1595 .parent = "trim_percentage",
1596 .def = "1",
1597 },
1598 {
1599 .name = "trim_backlog",
1600 .type = FIO_OPT_STR_VAL,
1601 .off1 = td_var_offset(trim_backlog),
1602 .help = "Trim after this number of blocks are written",
1603 .parent = "trim_percentage",
1604 },
1605 {
1606 .name = "trim_backlog_batch",
1607 .type = FIO_OPT_INT,
1608 .off1 = td_var_offset(trim_batch),
1609 .help = "Trim this number of IO blocks",
1610 .parent = "trim_percentage",
1611 },
e8462bd8 1612#endif
214e1eca
JA
1613 {
1614 .name = "write_iolog",
1615 .type = FIO_OPT_STR_STORE,
1616 .off1 = td_var_offset(write_iolog_file),
1617 .help = "Store IO pattern to file",
1618 },
1619 {
1620 .name = "read_iolog",
1621 .type = FIO_OPT_STR_STORE,
1622 .off1 = td_var_offset(read_iolog_file),
1623 .help = "Playback IO pattern from file",
1624 },
64bbb865
DN
1625 {
1626 .name = "replay_no_stall",
1627 .type = FIO_OPT_INT,
1628 .off1 = td_var_offset(no_stall),
1629 .def = "0",
87e7a972 1630 .parent = "read_iolog",
64bbb865
DN
1631 .help = "Playback IO pattern file as fast as possible without stalls",
1632 },
d1c46c04
DN
1633 {
1634 .name = "replay_redirect",
1635 .type = FIO_OPT_STR_STORE,
1636 .off1 = td_var_offset(replay_redirect),
1637 .parent = "read_iolog",
1638 .help = "Replay all I/O onto this device, regardless of trace device",
1639 },
214e1eca
JA
1640 {
1641 .name = "exec_prerun",
1642 .type = FIO_OPT_STR_STORE,
1643 .off1 = td_var_offset(exec_prerun),
1644 .help = "Execute this file prior to running job",
1645 },
1646 {
1647 .name = "exec_postrun",
1648 .type = FIO_OPT_STR_STORE,
1649 .off1 = td_var_offset(exec_postrun),
1650 .help = "Execute this file after running job",
1651 },
1652#ifdef FIO_HAVE_IOSCHED_SWITCH
1653 {
1654 .name = "ioscheduler",
1655 .type = FIO_OPT_STR_STORE,
1656 .off1 = td_var_offset(ioscheduler),
1657 .help = "Use this IO scheduler on the backing device",
1658 },
1659#endif
1660 {
1661 .name = "zonesize",
1662 .type = FIO_OPT_STR_VAL,
1663 .off1 = td_var_offset(zone_size),
1664 .help = "Give size of an IO zone",
1665 .def = "0",
1666 },
1667 {
1668 .name = "zoneskip",
1669 .type = FIO_OPT_STR_VAL,
1670 .off1 = td_var_offset(zone_skip),
1671 .help = "Space between IO zones",
1672 .def = "0",
1673 },
1674 {
1675 .name = "lockmem",
1676 .type = FIO_OPT_STR_VAL,
1677 .cb = str_lockmem_cb,
1678 .help = "Lock down this amount of memory",
1679 .def = "0",
1680 },
214e1eca
JA
1681 {
1682 .name = "rwmixread",
1683 .type = FIO_OPT_INT,
cb499fc4 1684 .cb = str_rwmix_read_cb,
214e1eca
JA
1685 .maxval = 100,
1686 .help = "Percentage of mixed workload that is reads",
1687 .def = "50",
1688 },
1689 {
1690 .name = "rwmixwrite",
1691 .type = FIO_OPT_INT,
cb499fc4 1692 .cb = str_rwmix_write_cb,
214e1eca
JA
1693 .maxval = 100,
1694 .help = "Percentage of mixed workload that is writes",
1695 .def = "50",
1696 },
afdf9352
JA
1697 {
1698 .name = "rwmixcycle",
15ca150e 1699 .type = FIO_OPT_DEPRECATED,
afdf9352 1700 },
214e1eca
JA
1701 {
1702 .name = "nice",
1703 .type = FIO_OPT_INT,
1704 .off1 = td_var_offset(nice),
1705 .help = "Set job CPU nice value",
1706 .minval = -19,
1707 .maxval = 20,
1708 .def = "0",
1709 },
1710#ifdef FIO_HAVE_IOPRIO
1711 {
1712 .name = "prio",
1713 .type = FIO_OPT_INT,
1714 .cb = str_prio_cb,
1715 .help = "Set job IO priority value",
1716 .minval = 0,
1717 .maxval = 7,
1718 },
1719 {
1720 .name = "prioclass",
1721 .type = FIO_OPT_INT,
1722 .cb = str_prioclass_cb,
1723 .help = "Set job IO priority class",
1724 .minval = 0,
1725 .maxval = 3,
1726 },
1727#endif
1728 {
1729 .name = "thinktime",
1730 .type = FIO_OPT_INT,
1731 .off1 = td_var_offset(thinktime),
1732 .help = "Idle time between IO buffers (usec)",
1733 .def = "0",
1734 },
1735 {
1736 .name = "thinktime_spin",
1737 .type = FIO_OPT_INT,
1738 .off1 = td_var_offset(thinktime_spin),
1739 .help = "Start think time by spinning this amount (usec)",
1740 .def = "0",
afdf9352 1741 .parent = "thinktime",
214e1eca
JA
1742 },
1743 {
1744 .name = "thinktime_blocks",
1745 .type = FIO_OPT_INT,
1746 .off1 = td_var_offset(thinktime_blocks),
1747 .help = "IO buffer period between 'thinktime'",
1748 .def = "1",
afdf9352 1749 .parent = "thinktime",
214e1eca
JA
1750 },
1751 {
1752 .name = "rate",
e01b22b8 1753 .type = FIO_OPT_INT,
581e7141
JA
1754 .off1 = td_var_offset(rate[0]),
1755 .off2 = td_var_offset(rate[1]),
214e1eca
JA
1756 .help = "Set bandwidth rate",
1757 },
1758 {
1759 .name = "ratemin",
e01b22b8 1760 .type = FIO_OPT_INT,
581e7141
JA
1761 .off1 = td_var_offset(ratemin[0]),
1762 .off2 = td_var_offset(ratemin[1]),
4e991c23 1763 .help = "Job must meet this rate or it will be shutdown",
afdf9352 1764 .parent = "rate",
4e991c23
JA
1765 },
1766 {
1767 .name = "rate_iops",
e01b22b8 1768 .type = FIO_OPT_INT,
581e7141
JA
1769 .off1 = td_var_offset(rate_iops[0]),
1770 .off2 = td_var_offset(rate_iops[1]),
4e991c23
JA
1771 .help = "Limit IO used to this number of IO operations/sec",
1772 },
1773 {
1774 .name = "rate_iops_min",
e01b22b8 1775 .type = FIO_OPT_INT,
581e7141
JA
1776 .off1 = td_var_offset(rate_iops_min[0]),
1777 .off2 = td_var_offset(rate_iops_min[1]),
03e20d68 1778 .help = "Job must meet this rate or it will be shut down",
afdf9352 1779 .parent = "rate_iops",
214e1eca
JA
1780 },
1781 {
1782 .name = "ratecycle",
1783 .type = FIO_OPT_INT,
1784 .off1 = td_var_offset(ratecycle),
1785 .help = "Window average for rate limits (msec)",
1786 .def = "1000",
afdf9352 1787 .parent = "rate",
214e1eca
JA
1788 },
1789 {
1790 .name = "invalidate",
1791 .type = FIO_OPT_BOOL,
1792 .off1 = td_var_offset(invalidate_cache),
1793 .help = "Invalidate buffer/page cache prior to running job",
1794 .def = "1",
1795 },
1796 {
1797 .name = "sync",
1798 .type = FIO_OPT_BOOL,
1799 .off1 = td_var_offset(sync_io),
1800 .help = "Use O_SYNC for buffered writes",
1801 .def = "0",
67a1000f 1802 .parent = "buffered",
214e1eca
JA
1803 },
1804 {
1805 .name = "bwavgtime",
1806 .type = FIO_OPT_INT,
1807 .off1 = td_var_offset(bw_avg_time),
5ec10eaa
JA
1808 .help = "Time window over which to calculate bandwidth"
1809 " (msec)",
214e1eca
JA
1810 .def = "500",
1811 },
1812 {
1813 .name = "create_serialize",
1814 .type = FIO_OPT_BOOL,
1815 .off1 = td_var_offset(create_serialize),
1816 .help = "Serialize creating of job files",
1817 .def = "1",
1818 },
1819 {
1820 .name = "create_fsync",
1821 .type = FIO_OPT_BOOL,
1822 .off1 = td_var_offset(create_fsync),
03e20d68 1823 .help = "fsync file after creation",
214e1eca
JA
1824 .def = "1",
1825 },
814452bd
JA
1826 {
1827 .name = "create_on_open",
1828 .type = FIO_OPT_BOOL,
1829 .off1 = td_var_offset(create_on_open),
1830 .help = "Create files when they are opened for IO",
1831 .def = "0",
1832 },
0b9d69ec 1833 {
afad68f7
ZY
1834 .name = "pre_read",
1835 .type = FIO_OPT_BOOL,
1836 .off1 = td_var_offset(pre_read),
03e20d68 1837 .help = "Pre-read files before starting official testing",
afad68f7
ZY
1838 .def = "0",
1839 },
214e1eca
JA
1840 {
1841 .name = "cpuload",
1842 .type = FIO_OPT_INT,
1843 .off1 = td_var_offset(cpuload),
1844 .help = "Use this percentage of CPU",
1845 },
1846 {
1847 .name = "cpuchunks",
1848 .type = FIO_OPT_INT,
1849 .off1 = td_var_offset(cpucycle),
1850 .help = "Length of the CPU burn cycles (usecs)",
1851 .def = "50000",
67a1000f 1852 .parent = "cpuload",
214e1eca
JA
1853 },
1854#ifdef FIO_HAVE_CPU_AFFINITY
1855 {
1856 .name = "cpumask",
1857 .type = FIO_OPT_INT,
1858 .cb = str_cpumask_cb,
1859 .help = "CPU affinity mask",
1860 },
d2e268b0
JA
1861 {
1862 .name = "cpus_allowed",
1863 .type = FIO_OPT_STR,
1864 .cb = str_cpus_allowed_cb,
1865 .help = "Set CPUs allowed",
1866 },
214e1eca
JA
1867#endif
1868 {
1869 .name = "end_fsync",
1870 .type = FIO_OPT_BOOL,
1871 .off1 = td_var_offset(end_fsync),
1872 .help = "Include fsync at the end of job",
1873 .def = "0",
1874 },
1875 {
1876 .name = "fsync_on_close",
1877 .type = FIO_OPT_BOOL,
1878 .off1 = td_var_offset(fsync_on_close),
1879 .help = "fsync files on close",
1880 .def = "0",
1881 },
1882 {
1883 .name = "unlink",
1884 .type = FIO_OPT_BOOL,
1885 .off1 = td_var_offset(unlink),
1886 .help = "Unlink created files after job has completed",
1887 .def = "0",
1888 },
1889 {
1890 .name = "exitall",
1891 .type = FIO_OPT_STR_SET,
1892 .cb = str_exitall_cb,
1893 .help = "Terminate all jobs when one exits",
1894 },
1895 {
1896 .name = "stonewall",
d392365e 1897 .alias = "wait_for_previous",
214e1eca
JA
1898 .type = FIO_OPT_STR_SET,
1899 .off1 = td_var_offset(stonewall),
1900 .help = "Insert a hard barrier between this job and previous",
1901 },
b3d62a75
JA
1902 {
1903 .name = "new_group",
1904 .type = FIO_OPT_STR_SET,
1905 .off1 = td_var_offset(new_group),
1906 .help = "Mark the start of a new group (for reporting)",
1907 },
214e1eca
JA
1908 {
1909 .name = "thread",
1910 .type = FIO_OPT_STR_SET,
1911 .off1 = td_var_offset(use_thread),
1912 .help = "Use threads instead of forks",
1913 },
1914 {
1915 .name = "write_bw_log",
e3cedca7 1916 .type = FIO_OPT_STR,
214e1eca 1917 .off1 = td_var_offset(write_bw_log),
e3cedca7 1918 .cb = str_write_bw_log_cb,
214e1eca
JA
1919 .help = "Write log of bandwidth during run",
1920 },
1921 {
1922 .name = "write_lat_log",
e3cedca7 1923 .type = FIO_OPT_STR,
214e1eca 1924 .off1 = td_var_offset(write_lat_log),
e3cedca7 1925 .cb = str_write_lat_log_cb,
214e1eca
JA
1926 .help = "Write log of latency during run",
1927 },
1928 {
1929 .name = "hugepage-size",
e01b22b8 1930 .type = FIO_OPT_INT,
214e1eca
JA
1931 .off1 = td_var_offset(hugepage_size),
1932 .help = "When using hugepages, specify size of each page",
1933 .def = __stringify(FIO_HUGE_PAGE),
1934 },
1935 {
1936 .name = "group_reporting",
1937 .type = FIO_OPT_STR_SET,
1938 .off1 = td_var_offset(group_reporting),
1939 .help = "Do reporting on a per-group basis",
1940 },
e9459e5a
JA
1941 {
1942 .name = "zero_buffers",
1943 .type = FIO_OPT_STR_SET,
1944 .off1 = td_var_offset(zero_buffers),
1945 .help = "Init IO buffers to all zeroes",
1946 },
5973cafb
JA
1947 {
1948 .name = "refill_buffers",
1949 .type = FIO_OPT_STR_SET,
1950 .off1 = td_var_offset(refill_buffers),
1951 .help = "Refill IO buffers on every IO submit",
1952 },
83349190
YH
1953 {
1954 .name = "clat_percentiles",
1955 .type = FIO_OPT_BOOL,
1956 .off1 = td_var_offset(clat_percentiles),
1957 .help = "Enable the reporting of completion latency percentiles",
1958 .def = "0",
1959 },
1960 {
1961 .name = "percentile_list",
1962 .type = FIO_OPT_FLOAT_LIST,
1963 .off1 = td_var_offset(percentile_list),
1964 .off2 = td_var_offset(overwrite_plist),
1965 .help = "Specify a custom list of percentiles to report",
1966 .maxlen = FIO_IO_U_LIST_MAX_LEN,
1967 .minfp = 0.0,
1968 .maxfp = 100.0,
1969 },
1970
0a839f30
JA
1971#ifdef FIO_HAVE_DISK_UTIL
1972 {
1973 .name = "disk_util",
1974 .type = FIO_OPT_BOOL,
1975 .off1 = td_var_offset(do_disk_util),
f66ab3c8 1976 .help = "Log disk utilization statistics",
0a839f30
JA
1977 .def = "1",
1978 },
1979#endif
993bf48b
JA
1980 {
1981 .name = "gtod_reduce",
1982 .type = FIO_OPT_BOOL,
1983 .help = "Greatly reduce number of gettimeofday() calls",
1984 .cb = str_gtod_reduce_cb,
1985 .def = "0",
1986 },
02af0988
JA
1987 {
1988 .name = "disable_lat",
1989 .type = FIO_OPT_BOOL,
1990 .off1 = td_var_offset(disable_lat),
1991 .help = "Disable latency numbers",
1992 .parent = "gtod_reduce",
1993 .def = "0",
1994 },
9520ebb9
JA
1995 {
1996 .name = "disable_clat",
1997 .type = FIO_OPT_BOOL,
1998 .off1 = td_var_offset(disable_clat),
1999 .help = "Disable completion latency numbers",
993bf48b 2000 .parent = "gtod_reduce",
9520ebb9
JA
2001 .def = "0",
2002 },
2003 {
2004 .name = "disable_slat",
2005 .type = FIO_OPT_BOOL,
2006 .off1 = td_var_offset(disable_slat),
03e20d68 2007 .help = "Disable submission latency numbers",
993bf48b 2008 .parent = "gtod_reduce",
9520ebb9
JA
2009 .def = "0",
2010 },
2011 {
2012 .name = "disable_bw_measurement",
2013 .type = FIO_OPT_BOOL,
2014 .off1 = td_var_offset(disable_bw),
2015 .help = "Disable bandwidth logging",
993bf48b 2016 .parent = "gtod_reduce",
9520ebb9
JA
2017 .def = "0",
2018 },
be4ecfdf
JA
2019 {
2020 .name = "gtod_cpu",
2021 .type = FIO_OPT_INT,
2022 .cb = str_gtod_cpu_cb,
03e20d68 2023 .help = "Set up dedicated gettimeofday() thread on this CPU",
29d43ff9 2024 .verify = gtod_cpu_verify,
be4ecfdf 2025 },
f2bba182
RR
2026 {
2027 .name = "continue_on_error",
2028 .type = FIO_OPT_BOOL,
2029 .off1 = td_var_offset(continue_on_error),
03e20d68 2030 .help = "Continue on non-fatal errors during IO",
f2bba182
RR
2031 .def = "0",
2032 },
9ac8a797
JA
2033 {
2034 .name = "profile",
79d16311 2035 .type = FIO_OPT_STR_STORE,
9ac8a797 2036 .off1 = td_var_offset(profile),
9ac8a797
JA
2037 .help = "Select a specific builtin performance test",
2038 },
a696fa2a
JA
2039 {
2040 .name = "cgroup",
2041 .type = FIO_OPT_STR_STORE,
2042 .off1 = td_var_offset(cgroup),
2043 .help = "Add job to cgroup of this name",
2044 },
2045 {
2046 .name = "cgroup_weight",
2047 .type = FIO_OPT_INT,
2048 .off1 = td_var_offset(cgroup_weight),
2049 .help = "Use given weight for cgroup",
2050 .minval = 100,
2051 .maxval = 1000,
a696fa2a 2052 },
7de87099
VG
2053 {
2054 .name = "cgroup_nodelete",
2055 .type = FIO_OPT_BOOL,
2056 .off1 = td_var_offset(cgroup_nodelete),
2057 .help = "Do not delete cgroups after job completion",
2058 .def = "0",
2059 },
e0b0d892
JA
2060 {
2061 .name = "uid",
2062 .type = FIO_OPT_INT,
2063 .off1 = td_var_offset(uid),
2064 .help = "Run job with this user ID",
2065 },
2066 {
2067 .name = "gid",
2068 .type = FIO_OPT_INT,
2069 .off1 = td_var_offset(gid),
2070 .help = "Run job with this group ID",
2071 },
214e1eca
JA
2072 {
2073 .name = NULL,
2074 },
2075};
2076
17af15d4
JA
2077static void add_to_lopt(struct option *lopt, struct fio_option *o,
2078 const char *name)
9f81736c 2079{
17af15d4 2080 lopt->name = (char *) name;
9f81736c
JA
2081 lopt->val = FIO_GETOPT_JOB;
2082 if (o->type == FIO_OPT_STR_SET)
2083 lopt->has_arg = no_argument;
2084 else
2085 lopt->has_arg = required_argument;
2086}
2087
214e1eca
JA
2088void fio_options_dup_and_init(struct option *long_options)
2089{
2090 struct fio_option *o;
2091 unsigned int i;
2092
2093 options_init(options);
2094
2095 i = 0;
2096 while (long_options[i].name)
2097 i++;
2098
2099 o = &options[0];
2100 while (o->name) {
17af15d4
JA
2101 add_to_lopt(&long_options[i], o, o->name);
2102 if (o->alias) {
2103 i++;
2104 add_to_lopt(&long_options[i], o, o->alias);
2105 }
214e1eca
JA
2106
2107 i++;
2108 o++;
2109 assert(i < FIO_NR_OPTIONS);
2110 }
2111}
2112
74929ac2
JA
2113struct fio_keyword {
2114 const char *word;
2115 const char *desc;
2116 char *replace;
2117};
2118
2119static struct fio_keyword fio_keywords[] = {
2120 {
2121 .word = "$pagesize",
2122 .desc = "Page size in the system",
2123 },
2124 {
2125 .word = "$mb_memory",
2126 .desc = "Megabytes of memory online",
2127 },
2128 {
2129 .word = "$ncpus",
2130 .desc = "Number of CPUs online in the system",
2131 },
2132 {
2133 .word = NULL,
2134 },
2135};
2136
2137void fio_keywords_init(void)
2138{
3b2e1464 2139 unsigned long long mb_memory;
74929ac2
JA
2140 char buf[128];
2141 long l;
2142
2143 sprintf(buf, "%lu", page_size);
2144 fio_keywords[0].replace = strdup(buf);
2145
8eb016d3 2146 mb_memory = os_phys_mem() / (1024 * 1024);
3b2e1464 2147 sprintf(buf, "%llu", mb_memory);
74929ac2
JA
2148 fio_keywords[1].replace = strdup(buf);
2149
c00a2289 2150 l = cpus_online();
74929ac2
JA
2151 sprintf(buf, "%lu", l);
2152 fio_keywords[2].replace = strdup(buf);
2153}
2154
892a6ffc
JA
2155#define BC_APP "bc"
2156
2157static char *bc_calc(char *str)
2158{
2159 char *buf, *tmp, opt[80];
2160 FILE *f;
2161 int ret;
2162
2163 /*
2164 * No math, just return string
2165 */
2166 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2167 !strchr(str, '/'))
2168 return str;
2169
2170 /*
2171 * Split option from value, we only need to calculate the value
2172 */
2173 tmp = strchr(str, '=');
2174 if (!tmp)
2175 return str;
2176
2177 tmp++;
9ac8a797 2178 memset(opt, 0, sizeof(opt));
892a6ffc
JA
2179 strncpy(opt, str, tmp - str);
2180
2181 buf = malloc(128);
2182
2183 sprintf(buf, "which %s > /dev/null", BC_APP);
2184 if (system(buf)) {
2185 log_err("fio: bc is needed for performing math\n");
2186 free(buf);
2187 return NULL;
2188 }
2189
2190 sprintf(buf, "echo %s | %s", tmp, BC_APP);
2191 f = popen(buf, "r");
2192 if (!f) {
2193 free(buf);
2194 return NULL;
2195 }
2196
2197 ret = fread(buf, 1, 128, f);
2198 if (ret <= 0) {
2199 free(buf);
2200 return NULL;
2201 }
2202
2203 buf[ret - 1] = '\0';
2204 strcat(opt, buf);
2205 strcpy(buf, opt);
2206 pclose(f);
2207 free(str);
2208 return buf;
2209}
2210
74929ac2
JA
2211/*
2212 * Look for reserved variable names and replace them with real values
2213 */
2214static char *fio_keyword_replace(char *opt)
2215{
2216 char *s;
2217 int i;
2218
2219 for (i = 0; fio_keywords[i].word != NULL; i++) {
2220 struct fio_keyword *kw = &fio_keywords[i];
2221
2222 while ((s = strstr(opt, kw->word)) != NULL) {
2223 char *new = malloc(strlen(opt) + 1);
2224 char *o_org = opt;
2225 int olen = s - opt;
2226 int len;
2227
2228 /*
2229 * Copy part of the string before the keyword and
2230 * sprintf() the replacement after it.
2231 */
2232 memcpy(new, opt, olen);
2233 len = sprintf(new + olen, "%s", kw->replace);
2234
2235 /*
2236 * If there's more in the original string, copy that
2237 * in too
2238 */
2239 opt += strlen(kw->word) + olen;
2240 if (strlen(opt))
2241 memcpy(new + olen + len, opt, opt - o_org - 1);
2242
2243 /*
2244 * replace opt and free the old opt
2245 */
2246 opt = new;
9ac8a797 2247 //free(o_org);
7a958bd5
JA
2248
2249 /*
2250 * Check for potential math and invoke bc, if possible
2251 */
2252 opt = bc_calc(opt);
74929ac2
JA
2253 }
2254 }
2255
7a958bd5 2256 return opt;
74929ac2
JA
2257}
2258
3b8b7135 2259int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
214e1eca 2260{
3b8b7135
JA
2261 int i, ret;
2262
2263 sort_options(opts, options, num_opts);
2264
74929ac2
JA
2265 for (ret = 0, i = 0; i < num_opts; i++) {
2266 opts[i] = fio_keyword_replace(opts[i]);
07b3232d 2267 ret |= parse_option(opts[i], options, td);
74929ac2 2268 }
3b8b7135
JA
2269
2270 return ret;
214e1eca
JA
2271}
2272
2273int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2274{
07b3232d 2275 return parse_cmd_option(opt, val, options, td);
214e1eca
JA
2276}
2277
2278void fio_fill_default_options(struct thread_data *td)
2279{
2280 fill_default_options(td, options);
2281}
2282
2283int fio_show_option_help(const char *opt)
2284{
07b3232d 2285 return show_cmd_help(options, opt);
214e1eca 2286}
d23bb327
JA
2287
2288static void __options_mem(struct thread_data *td, int alloc)
2289{
2290 struct thread_options *o = &td->o;
2291 struct fio_option *opt;
2292 char **ptr;
2293 int i;
2294
2295 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2296 if (opt->type != FIO_OPT_STR_STORE)
2297 continue;
2298
2299 ptr = (void *) o + opt->off1;
2300 if (*ptr) {
2301 if (alloc)
2302 *ptr = strdup(*ptr);
2303 else {
2304 free(*ptr);
2305 *ptr = NULL;
2306 }
2307 }
2308 }
2309}
2310
2311/*
2312 * dupe FIO_OPT_STR_STORE options
2313 */
2314void options_mem_dupe(struct thread_data *td)
2315{
2316 __options_mem(td, 1);
2317}
2318
22d66213 2319void options_mem_free(struct thread_data fio_unused *td)
d23bb327 2320{
22d66213 2321#if 0
d23bb327 2322 __options_mem(td, 0);
22d66213 2323#endif
d23bb327 2324}
d6978a32
JA
2325
2326unsigned int fio_get_kb_base(void *data)
2327{
2328 struct thread_data *td = data;
2329 unsigned int kb_base = 0;
2330
2331 if (td)
2332 kb_base = td->o.kb_base;
2333 if (!kb_base)
2334 kb_base = 1024;
2335
2336 return kb_base;
2337}
9f988e2e 2338
07b3232d 2339int add_option(struct fio_option *o)
9f988e2e 2340{
07b3232d
JA
2341 struct fio_option *__o;
2342 int opt_index = 0;
2343
2344 __o = options;
2345 while (__o->name) {
2346 opt_index++;
2347 __o++;
2348 }
2349
2350 memcpy(&options[opt_index], o, sizeof(*o));
2351 return 0;
9f988e2e 2352}
e2de69da 2353
07b3232d 2354void invalidate_profile_options(const char *prof_name)
e2de69da 2355{
07b3232d 2356 struct fio_option *o;
e2de69da 2357
07b3232d
JA
2358 o = options;
2359 while (o->name) {
2360 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2361 o->type = FIO_OPT_INVALID;
2362 o->prof_name = NULL;
2363 }
2364 o++;
e2de69da
JA
2365 }
2366}
f5b6bb85
JA
2367
2368void add_opt_posval(const char *optname, const char *ival, const char *help)
2369{
2370 struct fio_option *o;
2371 unsigned int i;
2372
2373 o = find_option(options, optname);
2374 if (!o)
2375 return;
2376
2377 for (i = 0; i < PARSE_MAX_VP; i++) {
2378 if (o->posval[i].ival)
2379 continue;
2380
2381 o->posval[i].ival = ival;
2382 o->posval[i].help = help;
2383 break;
2384 }
2385}
2386
2387void del_opt_posval(const char *optname, const char *ival)
2388{
2389 struct fio_option *o;
2390 unsigned int i;
2391
2392 o = find_option(options, optname);
2393 if (!o)
2394 return;
2395
2396 for (i = 0; i < PARSE_MAX_VP; i++) {
2397 if (!o->posval[i].ival)
2398 continue;
2399 if (strcmp(o->posval[i].ival, ival))
2400 continue;
2401
2402 o->posval[i].ival = NULL;
2403 o->posval[i].help = NULL;
2404 }
2405}