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