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 | ||
713 | td->o.disable_clat = !!val; | |
714 | td->o.disable_slat = !!val; | |
715 | td->o.disable_bw = !!val; | |
716 | if (val) | |
717 | td->tv_cache_mask = 63; | |
718 | ||
719 | return 0; | |
720 | } | |
721 | ||
be4ecfdf JA |
722 | static int str_gtod_cpu_cb(void *data, int *il) |
723 | { | |
724 | struct thread_data *td = data; | |
725 | int val = *il; | |
726 | ||
727 | td->o.gtod_cpu = val; | |
728 | td->o.gtod_offload = 1; | |
729 | return 0; | |
730 | } | |
731 | ||
896cac2a JA |
732 | static int rw_verify(struct fio_option *o, void *data) |
733 | { | |
734 | struct thread_data *td = data; | |
735 | ||
736 | if (read_only && td_write(td)) { | |
737 | log_err("fio: job <%s> has write bit set, but fio is in" | |
738 | " read-only mode\n", td->o.name); | |
739 | return 1; | |
740 | } | |
741 | ||
742 | return 0; | |
743 | } | |
744 | ||
276ca4f7 | 745 | static int gtod_cpu_verify(struct fio_option *o, void *data) |
29d43ff9 | 746 | { |
276ca4f7 | 747 | #ifndef FIO_HAVE_CPU_AFFINITY |
29d43ff9 JA |
748 | struct thread_data *td = data; |
749 | ||
29d43ff9 JA |
750 | if (td->o.gtod_cpu) { |
751 | log_err("fio: platform must support CPU affinity for" | |
752 | "gettimeofday() offloading\n"); | |
753 | return 1; | |
754 | } | |
755 | #endif | |
756 | ||
757 | return 0; | |
758 | } | |
759 | ||
90fef2d1 JA |
760 | static int kb_base_verify(struct fio_option *o, void *data) |
761 | { | |
762 | struct thread_data *td = data; | |
763 | ||
764 | if (td->o.kb_base != 1024 && td->o.kb_base != 1000) { | |
765 | log_err("fio: kb_base set to nonsensical value: %u\n", | |
766 | td->o.kb_base); | |
767 | return 1; | |
768 | } | |
769 | ||
770 | return 0; | |
771 | } | |
772 | ||
214e1eca JA |
773 | #define __stringify_1(x) #x |
774 | #define __stringify(x) __stringify_1(x) | |
775 | ||
776 | /* | |
777 | * Map of job/command line options | |
778 | */ | |
07b3232d | 779 | static struct fio_option options[FIO_MAX_OPTS] = { |
214e1eca JA |
780 | { |
781 | .name = "description", | |
782 | .type = FIO_OPT_STR_STORE, | |
783 | .off1 = td_var_offset(description), | |
784 | .help = "Text job description", | |
785 | }, | |
786 | { | |
787 | .name = "name", | |
788 | .type = FIO_OPT_STR_STORE, | |
789 | .off1 = td_var_offset(name), | |
790 | .help = "Name of this job", | |
791 | }, | |
792 | { | |
793 | .name = "directory", | |
794 | .type = FIO_OPT_STR_STORE, | |
795 | .off1 = td_var_offset(directory), | |
796 | .cb = str_directory_cb, | |
797 | .help = "Directory to store files in", | |
798 | }, | |
799 | { | |
800 | .name = "filename", | |
801 | .type = FIO_OPT_STR_STORE, | |
802 | .off1 = td_var_offset(filename), | |
803 | .cb = str_filename_cb, | |
f0d524b0 | 804 | .prio = -1, /* must come after "directory" */ |
214e1eca JA |
805 | .help = "File(s) to use for the workload", |
806 | }, | |
90fef2d1 JA |
807 | { |
808 | .name = "kb_base", | |
809 | .type = FIO_OPT_INT, | |
810 | .off1 = td_var_offset(kb_base), | |
90fef2d1 | 811 | .verify = kb_base_verify, |
a639f0bb | 812 | .prio = 1, |
90fef2d1 | 813 | .def = "1024", |
a639f0bb | 814 | .help = "How many bytes per KB for reporting (1000 or 1024)", |
90fef2d1 | 815 | }, |
29c1349f JA |
816 | { |
817 | .name = "lockfile", | |
4d4e80f2 JA |
818 | .type = FIO_OPT_STR, |
819 | .cb = str_lockfile_cb, | |
820 | .off1 = td_var_offset(file_lock_mode), | |
29c1349f JA |
821 | .help = "Lock file when doing IO to it", |
822 | .parent = "filename", | |
4d4e80f2 JA |
823 | .def = "none", |
824 | .posval = { | |
825 | { .ival = "none", | |
826 | .oval = FILE_LOCK_NONE, | |
827 | .help = "No file locking", | |
828 | }, | |
829 | { .ival = "exclusive", | |
830 | .oval = FILE_LOCK_EXCLUSIVE, | |
831 | .help = "Exclusive file lock", | |
832 | }, | |
833 | { | |
834 | .ival = "readwrite", | |
835 | .oval = FILE_LOCK_READWRITE, | |
836 | .help = "Read vs write lock", | |
837 | }, | |
838 | }, | |
29c1349f | 839 | }, |
214e1eca JA |
840 | { |
841 | .name = "opendir", | |
842 | .type = FIO_OPT_STR_STORE, | |
843 | .off1 = td_var_offset(opendir), | |
844 | .cb = str_opendir_cb, | |
845 | .help = "Recursively add files from this directory and down", | |
846 | }, | |
847 | { | |
848 | .name = "rw", | |
d3aad8f2 | 849 | .alias = "readwrite", |
214e1eca | 850 | .type = FIO_OPT_STR, |
211097b2 | 851 | .cb = str_rw_cb, |
214e1eca JA |
852 | .off1 = td_var_offset(td_ddir), |
853 | .help = "IO direction", | |
854 | .def = "read", | |
896cac2a | 855 | .verify = rw_verify, |
214e1eca JA |
856 | .posval = { |
857 | { .ival = "read", | |
858 | .oval = TD_DDIR_READ, | |
859 | .help = "Sequential read", | |
860 | }, | |
861 | { .ival = "write", | |
862 | .oval = TD_DDIR_WRITE, | |
863 | .help = "Sequential write", | |
864 | }, | |
865 | { .ival = "randread", | |
866 | .oval = TD_DDIR_RANDREAD, | |
867 | .help = "Random read", | |
868 | }, | |
869 | { .ival = "randwrite", | |
870 | .oval = TD_DDIR_RANDWRITE, | |
871 | .help = "Random write", | |
872 | }, | |
873 | { .ival = "rw", | |
874 | .oval = TD_DDIR_RW, | |
875 | .help = "Sequential read and write mix", | |
876 | }, | |
877 | { .ival = "randrw", | |
878 | .oval = TD_DDIR_RANDRW, | |
879 | .help = "Random read and write mix" | |
880 | }, | |
881 | }, | |
882 | }, | |
883 | { | |
884 | .name = "ioengine", | |
885 | .type = FIO_OPT_STR_STORE, | |
886 | .off1 = td_var_offset(ioengine), | |
887 | .help = "IO engine to use", | |
888 | .def = "sync", | |
889 | .posval = { | |
890 | { .ival = "sync", | |
891 | .help = "Use read/write", | |
892 | }, | |
a31041ea | 893 | { .ival = "psync", |
894 | .help = "Use pread/pwrite", | |
895 | }, | |
1d2af02a JA |
896 | { .ival = "vsync", |
897 | .help = "Use readv/writev", | |
898 | }, | |
214e1eca JA |
899 | #ifdef FIO_HAVE_LIBAIO |
900 | { .ival = "libaio", | |
901 | .help = "Linux native asynchronous IO", | |
902 | }, | |
903 | #endif | |
904 | #ifdef FIO_HAVE_POSIXAIO | |
905 | { .ival = "posixaio", | |
906 | .help = "POSIX asynchronous IO", | |
907 | }, | |
417f0068 JA |
908 | #endif |
909 | #ifdef FIO_HAVE_SOLARISAIO | |
910 | { .ival = "solarisaio", | |
911 | .help = "Solaris native asynchronous IO", | |
912 | }, | |
214e1eca JA |
913 | #endif |
914 | { .ival = "mmap", | |
915 | .help = "Memory mapped IO", | |
916 | }, | |
917 | #ifdef FIO_HAVE_SPLICE | |
918 | { .ival = "splice", | |
919 | .help = "splice/vmsplice based IO", | |
920 | }, | |
9cce02e8 JA |
921 | { .ival = "netsplice", |
922 | .help = "splice/vmsplice to/from the network", | |
923 | }, | |
214e1eca JA |
924 | #endif |
925 | #ifdef FIO_HAVE_SGIO | |
926 | { .ival = "sg", | |
927 | .help = "SCSI generic v3 IO", | |
928 | }, | |
929 | #endif | |
930 | { .ival = "null", | |
931 | .help = "Testing engine (no data transfer)", | |
932 | }, | |
933 | { .ival = "net", | |
934 | .help = "Network IO", | |
935 | }, | |
936 | #ifdef FIO_HAVE_SYSLET | |
937 | { .ival = "syslet-rw", | |
938 | .help = "syslet enabled async pread/pwrite IO", | |
939 | }, | |
940 | #endif | |
941 | { .ival = "cpuio", | |
942 | .help = "CPU cycler burner engine", | |
943 | }, | |
b8c82a46 JA |
944 | #ifdef FIO_HAVE_GUASI |
945 | { .ival = "guasi", | |
946 | .help = "GUASI IO engine", | |
947 | }, | |
948 | #endif | |
214e1eca JA |
949 | { .ival = "external", |
950 | .help = "Load external engine (append name)", | |
951 | }, | |
952 | }, | |
953 | }, | |
954 | { | |
955 | .name = "iodepth", | |
956 | .type = FIO_OPT_INT, | |
957 | .off1 = td_var_offset(iodepth), | |
958 | .help = "Amount of IO buffers to keep in flight", | |
757aff4f | 959 | .minval = 1, |
214e1eca JA |
960 | .def = "1", |
961 | }, | |
962 | { | |
963 | .name = "iodepth_batch", | |
4950421a | 964 | .alias = "iodepth_batch_submit", |
214e1eca JA |
965 | .type = FIO_OPT_INT, |
966 | .off1 = td_var_offset(iodepth_batch), | |
d65db441 | 967 | .help = "Number of IO buffers to submit in one go", |
afdf9352 | 968 | .parent = "iodepth", |
a2e6f8ac JA |
969 | .minval = 1, |
970 | .def = "1", | |
4950421a JA |
971 | }, |
972 | { | |
973 | .name = "iodepth_batch_complete", | |
974 | .type = FIO_OPT_INT, | |
975 | .off1 = td_var_offset(iodepth_batch_complete), | |
d65db441 | 976 | .help = "Number of IO buffers to retrieve in one go", |
4950421a JA |
977 | .parent = "iodepth", |
978 | .minval = 0, | |
979 | .def = "1", | |
214e1eca JA |
980 | }, |
981 | { | |
982 | .name = "iodepth_low", | |
983 | .type = FIO_OPT_INT, | |
984 | .off1 = td_var_offset(iodepth_low), | |
985 | .help = "Low water mark for queuing depth", | |
afdf9352 | 986 | .parent = "iodepth", |
214e1eca JA |
987 | }, |
988 | { | |
989 | .name = "size", | |
990 | .type = FIO_OPT_STR_VAL, | |
2dc1bbeb | 991 | .off1 = td_var_offset(size), |
c3edbdba | 992 | .minval = 1, |
214e1eca JA |
993 | .help = "Total size of device or files", |
994 | }, | |
aa31f1f1 SL |
995 | { |
996 | .name = "fill_device", | |
997 | .type = FIO_OPT_BOOL, | |
998 | .off1 = td_var_offset(fill_device), | |
999 | .help = "Write until an ENOSPC error occurs", | |
1000 | .def = "0", | |
1001 | }, | |
214e1eca JA |
1002 | { |
1003 | .name = "filesize", | |
1004 | .type = FIO_OPT_STR_VAL, | |
1005 | .off1 = td_var_offset(file_size_low), | |
1006 | .off2 = td_var_offset(file_size_high), | |
c3edbdba | 1007 | .minval = 1, |
214e1eca JA |
1008 | .help = "Size of individual files", |
1009 | }, | |
67a1000f JA |
1010 | { |
1011 | .name = "offset", | |
1012 | .alias = "fileoffset", | |
1013 | .type = FIO_OPT_STR_VAL, | |
1014 | .off1 = td_var_offset(start_offset), | |
1015 | .help = "Start IO from this offset", | |
1016 | .def = "0", | |
1017 | }, | |
214e1eca JA |
1018 | { |
1019 | .name = "bs", | |
d3aad8f2 | 1020 | .alias = "blocksize", |
e01b22b8 | 1021 | .type = FIO_OPT_INT, |
214e1eca JA |
1022 | .off1 = td_var_offset(bs[DDIR_READ]), |
1023 | .off2 = td_var_offset(bs[DDIR_WRITE]), | |
c3edbdba | 1024 | .minval = 1, |
214e1eca JA |
1025 | .help = "Block size unit", |
1026 | .def = "4k", | |
67a1000f | 1027 | .parent = "rw", |
214e1eca | 1028 | }, |
2b7a01d0 JA |
1029 | { |
1030 | .name = "ba", | |
1031 | .alias = "blockalign", | |
e01b22b8 | 1032 | .type = FIO_OPT_INT, |
2b7a01d0 JA |
1033 | .off1 = td_var_offset(ba[DDIR_READ]), |
1034 | .off2 = td_var_offset(ba[DDIR_WRITE]), | |
1035 | .minval = 1, | |
1036 | .help = "IO block offset alignment", | |
1037 | .parent = "rw", | |
1038 | }, | |
214e1eca JA |
1039 | { |
1040 | .name = "bsrange", | |
d3aad8f2 | 1041 | .alias = "blocksize_range", |
214e1eca JA |
1042 | .type = FIO_OPT_RANGE, |
1043 | .off1 = td_var_offset(min_bs[DDIR_READ]), | |
1044 | .off2 = td_var_offset(max_bs[DDIR_READ]), | |
1045 | .off3 = td_var_offset(min_bs[DDIR_WRITE]), | |
1046 | .off4 = td_var_offset(max_bs[DDIR_WRITE]), | |
c3edbdba | 1047 | .minval = 1, |
214e1eca | 1048 | .help = "Set block size range (in more detail than bs)", |
67a1000f | 1049 | .parent = "rw", |
214e1eca | 1050 | }, |
564ca972 JA |
1051 | { |
1052 | .name = "bssplit", | |
1053 | .type = FIO_OPT_STR, | |
1054 | .cb = str_bssplit_cb, | |
1055 | .help = "Set a specific mix of block sizes", | |
1056 | .parent = "rw", | |
1057 | }, | |
214e1eca JA |
1058 | { |
1059 | .name = "bs_unaligned", | |
d3aad8f2 | 1060 | .alias = "blocksize_unaligned", |
214e1eca JA |
1061 | .type = FIO_OPT_STR_SET, |
1062 | .off1 = td_var_offset(bs_unaligned), | |
1063 | .help = "Don't sector align IO buffer sizes", | |
67a1000f | 1064 | .parent = "rw", |
214e1eca JA |
1065 | }, |
1066 | { | |
1067 | .name = "randrepeat", | |
1068 | .type = FIO_OPT_BOOL, | |
1069 | .off1 = td_var_offset(rand_repeatable), | |
1070 | .help = "Use repeatable random IO pattern", | |
1071 | .def = "1", | |
67a1000f | 1072 | .parent = "rw", |
214e1eca JA |
1073 | }, |
1074 | { | |
1075 | .name = "norandommap", | |
1076 | .type = FIO_OPT_STR_SET, | |
1077 | .off1 = td_var_offset(norandommap), | |
1078 | .help = "Accept potential duplicate random blocks", | |
67a1000f | 1079 | .parent = "rw", |
214e1eca | 1080 | }, |
2b386d25 JA |
1081 | { |
1082 | .name = "softrandommap", | |
1083 | .type = FIO_OPT_BOOL, | |
1084 | .off1 = td_var_offset(softrandommap), | |
f66ab3c8 | 1085 | .help = "Set norandommap if randommap allocation fails", |
2b386d25 JA |
1086 | .parent = "norandommap", |
1087 | .def = "0", | |
1088 | }, | |
214e1eca JA |
1089 | { |
1090 | .name = "nrfiles", | |
1091 | .type = FIO_OPT_INT, | |
1092 | .off1 = td_var_offset(nr_files), | |
1093 | .help = "Split job workload between this number of files", | |
1094 | .def = "1", | |
1095 | }, | |
1096 | { | |
1097 | .name = "openfiles", | |
1098 | .type = FIO_OPT_INT, | |
1099 | .off1 = td_var_offset(open_files), | |
1100 | .help = "Number of files to keep open at the same time", | |
1101 | }, | |
1102 | { | |
1103 | .name = "file_service_type", | |
1104 | .type = FIO_OPT_STR, | |
1105 | .cb = str_fst_cb, | |
1106 | .off1 = td_var_offset(file_service_type), | |
1107 | .help = "How to select which file to service next", | |
1108 | .def = "roundrobin", | |
1109 | .posval = { | |
1110 | { .ival = "random", | |
1111 | .oval = FIO_FSERVICE_RANDOM, | |
1112 | .help = "Choose a file at random", | |
1113 | }, | |
1114 | { .ival = "roundrobin", | |
1115 | .oval = FIO_FSERVICE_RR, | |
1116 | .help = "Round robin select files", | |
1117 | }, | |
a086c257 JA |
1118 | { .ival = "sequential", |
1119 | .oval = FIO_FSERVICE_SEQ, | |
1120 | .help = "Finish one file before moving to the next", | |
1121 | }, | |
214e1eca | 1122 | }, |
67a1000f JA |
1123 | .parent = "nrfiles", |
1124 | }, | |
7bc8c2cf JA |
1125 | #ifdef FIO_HAVE_FALLOCATE |
1126 | { | |
1127 | .name = "fallocate", | |
1128 | .type = FIO_OPT_BOOL, | |
1129 | .off1 = td_var_offset(fallocate), | |
1130 | .help = "Use fallocate() when laying out files", | |
1131 | .def = "1", | |
1132 | }, | |
1133 | #endif | |
67a1000f JA |
1134 | { |
1135 | .name = "fadvise_hint", | |
1136 | .type = FIO_OPT_BOOL, | |
1137 | .off1 = td_var_offset(fadvise_hint), | |
1138 | .help = "Use fadvise() to advise the kernel on IO pattern", | |
1139 | .def = "1", | |
214e1eca JA |
1140 | }, |
1141 | { | |
1142 | .name = "fsync", | |
1143 | .type = FIO_OPT_INT, | |
1144 | .off1 = td_var_offset(fsync_blocks), | |
1145 | .help = "Issue fsync for writes every given number of blocks", | |
1146 | .def = "0", | |
1147 | }, | |
5f9099ea JA |
1148 | { |
1149 | .name = "fdatasync", | |
1150 | .type = FIO_OPT_INT, | |
1151 | .off1 = td_var_offset(fdatasync_blocks), | |
1152 | .help = "Issue fdatasync for writes every given number of blocks", | |
1153 | .def = "0", | |
1154 | }, | |
44f29692 JA |
1155 | #ifdef FIO_HAVE_SYNC_FILE_RANGE |
1156 | { | |
1157 | .name = "sync_file_range", | |
1158 | .posval = { | |
1159 | { .ival = "wait_before", | |
1160 | .oval = SYNC_FILE_RANGE_WAIT_BEFORE, | |
1161 | .help = "SYNC_FILE_RANGE_WAIT_BEFORE", | |
3843deb3 | 1162 | .or = 1, |
44f29692 JA |
1163 | }, |
1164 | { .ival = "write", | |
1165 | .oval = SYNC_FILE_RANGE_WRITE, | |
1166 | .help = "SYNC_FILE_RANGE_WRITE", | |
3843deb3 | 1167 | .or = 1, |
44f29692 JA |
1168 | }, |
1169 | { | |
1170 | .ival = "wait_after", | |
1171 | .oval = SYNC_FILE_RANGE_WAIT_AFTER, | |
1172 | .help = "SYNC_FILE_RANGE_WAIT_AFTER", | |
3843deb3 | 1173 | .or = 1, |
44f29692 JA |
1174 | }, |
1175 | }, | |
3843deb3 | 1176 | .type = FIO_OPT_STR_MULTI, |
44f29692 JA |
1177 | .cb = str_sfr_cb, |
1178 | .off1 = td_var_offset(sync_file_range), | |
1179 | .help = "Use sync_file_range()", | |
1180 | }, | |
1181 | #endif | |
214e1eca JA |
1182 | { |
1183 | .name = "direct", | |
1184 | .type = FIO_OPT_BOOL, | |
1185 | .off1 = td_var_offset(odirect), | |
1186 | .help = "Use O_DIRECT IO (negates buffered)", | |
1187 | .def = "0", | |
1188 | }, | |
1189 | { | |
1190 | .name = "buffered", | |
1191 | .type = FIO_OPT_BOOL, | |
1192 | .off1 = td_var_offset(odirect), | |
1193 | .neg = 1, | |
1194 | .help = "Use buffered IO (negates direct)", | |
1195 | .def = "1", | |
1196 | }, | |
1197 | { | |
1198 | .name = "overwrite", | |
1199 | .type = FIO_OPT_BOOL, | |
1200 | .off1 = td_var_offset(overwrite), | |
1201 | .help = "When writing, set whether to overwrite current data", | |
1202 | .def = "0", | |
1203 | }, | |
1204 | { | |
1205 | .name = "loops", | |
1206 | .type = FIO_OPT_INT, | |
1207 | .off1 = td_var_offset(loops), | |
1208 | .help = "Number of times to run the job", | |
1209 | .def = "1", | |
1210 | }, | |
1211 | { | |
1212 | .name = "numjobs", | |
1213 | .type = FIO_OPT_INT, | |
1214 | .off1 = td_var_offset(numjobs), | |
1215 | .help = "Duplicate this job this many times", | |
1216 | .def = "1", | |
1217 | }, | |
1218 | { | |
1219 | .name = "startdelay", | |
1220 | .type = FIO_OPT_INT, | |
1221 | .off1 = td_var_offset(start_delay), | |
1222 | .help = "Only start job when this period has passed", | |
1223 | .def = "0", | |
1224 | }, | |
1225 | { | |
1226 | .name = "runtime", | |
1227 | .alias = "timeout", | |
1228 | .type = FIO_OPT_STR_VAL_TIME, | |
1229 | .off1 = td_var_offset(timeout), | |
1230 | .help = "Stop workload when this amount of time has passed", | |
1231 | .def = "0", | |
1232 | }, | |
cf4464ca JA |
1233 | { |
1234 | .name = "time_based", | |
1235 | .type = FIO_OPT_STR_SET, | |
1236 | .off1 = td_var_offset(time_based), | |
1237 | .help = "Keep running until runtime/timeout is met", | |
1238 | }, | |
721938ae JA |
1239 | { |
1240 | .name = "ramp_time", | |
1241 | .type = FIO_OPT_STR_VAL_TIME, | |
1242 | .off1 = td_var_offset(ramp_time), | |
1243 | .help = "Ramp up time before measuring performance", | |
1244 | }, | |
c223da83 JA |
1245 | { |
1246 | .name = "clocksource", | |
1247 | .type = FIO_OPT_STR, | |
1248 | .cb = fio_clock_source_cb, | |
1249 | .off1 = td_var_offset(clocksource), | |
1250 | .help = "What type of timing source to use", | |
c223da83 JA |
1251 | .posval = { |
1252 | { .ival = "gettimeofday", | |
1253 | .oval = CS_GTOD, | |
1254 | .help = "Use gettimeofday(2) for timing", | |
1255 | }, | |
1256 | { .ival = "clock_gettime", | |
1257 | .oval = CS_CGETTIME, | |
1258 | .help = "Use clock_gettime(2) for timing", | |
1259 | }, | |
1260 | #ifdef ARCH_HAVE_CPU_CLOCK | |
1261 | { .ival = "cpu", | |
1262 | .oval = CS_CPUCLOCK, | |
1263 | .help = "Use CPU private clock", | |
1264 | }, | |
1265 | #endif | |
1266 | }, | |
1267 | }, | |
214e1eca JA |
1268 | { |
1269 | .name = "mem", | |
d3aad8f2 | 1270 | .alias = "iomem", |
214e1eca JA |
1271 | .type = FIO_OPT_STR, |
1272 | .cb = str_mem_cb, | |
1273 | .off1 = td_var_offset(mem_type), | |
1274 | .help = "Backing type for IO buffers", | |
1275 | .def = "malloc", | |
1276 | .posval = { | |
1277 | { .ival = "malloc", | |
1278 | .oval = MEM_MALLOC, | |
1279 | .help = "Use malloc(3) for IO buffers", | |
1280 | }, | |
37c8cdfe JA |
1281 | { .ival = "shm", |
1282 | .oval = MEM_SHM, | |
1283 | .help = "Use shared memory segments for IO buffers", | |
1284 | }, | |
214e1eca JA |
1285 | #ifdef FIO_HAVE_HUGETLB |
1286 | { .ival = "shmhuge", | |
1287 | .oval = MEM_SHMHUGE, | |
1288 | .help = "Like shm, but use huge pages", | |
1289 | }, | |
b370e46a | 1290 | #endif |
37c8cdfe JA |
1291 | { .ival = "mmap", |
1292 | .oval = MEM_MMAP, | |
1293 | .help = "Use mmap(2) (file or anon) for IO buffers", | |
1294 | }, | |
214e1eca JA |
1295 | #ifdef FIO_HAVE_HUGETLB |
1296 | { .ival = "mmaphuge", | |
1297 | .oval = MEM_MMAPHUGE, | |
1298 | .help = "Like mmap, but use huge pages", | |
1299 | }, | |
1300 | #endif | |
1301 | }, | |
1302 | }, | |
d529ee19 JA |
1303 | { |
1304 | .name = "iomem_align", | |
1305 | .alias = "mem_align", | |
1306 | .type = FIO_OPT_INT, | |
1307 | .off1 = td_var_offset(mem_align), | |
1308 | .minval = 0, | |
1309 | .help = "IO memory buffer offset alignment", | |
1310 | .def = "0", | |
1311 | .parent = "iomem", | |
1312 | }, | |
214e1eca JA |
1313 | { |
1314 | .name = "verify", | |
1315 | .type = FIO_OPT_STR, | |
1316 | .off1 = td_var_offset(verify), | |
1317 | .help = "Verify data written", | |
5d7c5d34 | 1318 | .cb = str_verify_cb, |
214e1eca JA |
1319 | .def = "0", |
1320 | .posval = { | |
1321 | { .ival = "0", | |
1322 | .oval = VERIFY_NONE, | |
1323 | .help = "Don't do IO verification", | |
1324 | }, | |
fcca4b58 JA |
1325 | { .ival = "md5", |
1326 | .oval = VERIFY_MD5, | |
1327 | .help = "Use md5 checksums for verification", | |
1328 | }, | |
d77a7af3 JA |
1329 | { .ival = "crc64", |
1330 | .oval = VERIFY_CRC64, | |
1331 | .help = "Use crc64 checksums for verification", | |
1332 | }, | |
214e1eca JA |
1333 | { .ival = "crc32", |
1334 | .oval = VERIFY_CRC32, | |
1335 | .help = "Use crc32 checksums for verification", | |
1336 | }, | |
af497e6a JA |
1337 | { .ival = "crc32c-intel", |
1338 | .oval = VERIFY_CRC32C_INTEL, | |
1339 | .help = "Use hw crc32c checksums for verification", | |
1340 | }, | |
bac39e0e JA |
1341 | { .ival = "crc32c", |
1342 | .oval = VERIFY_CRC32C, | |
1343 | .help = "Use crc32c checksums for verification", | |
1344 | }, | |
969f7ed3 JA |
1345 | { .ival = "crc16", |
1346 | .oval = VERIFY_CRC16, | |
1347 | .help = "Use crc16 checksums for verification", | |
1348 | }, | |
1e154bdb JA |
1349 | { .ival = "crc7", |
1350 | .oval = VERIFY_CRC7, | |
1351 | .help = "Use crc7 checksums for verification", | |
1352 | }, | |
7c353ceb JA |
1353 | { .ival = "sha1", |
1354 | .oval = VERIFY_SHA1, | |
1355 | .help = "Use sha1 checksums for verification", | |
1356 | }, | |
cd14cc10 JA |
1357 | { .ival = "sha256", |
1358 | .oval = VERIFY_SHA256, | |
1359 | .help = "Use sha256 checksums for verification", | |
1360 | }, | |
1361 | { .ival = "sha512", | |
1362 | .oval = VERIFY_SHA512, | |
1363 | .help = "Use sha512 checksums for verification", | |
1364 | }, | |
7437ee87 SL |
1365 | { .ival = "meta", |
1366 | .oval = VERIFY_META, | |
1367 | .help = "Use io information", | |
1368 | }, | |
36690c9b JA |
1369 | { |
1370 | .ival = "null", | |
1371 | .oval = VERIFY_NULL, | |
1372 | .help = "Pretend to verify", | |
1373 | }, | |
214e1eca JA |
1374 | }, |
1375 | }, | |
005c565a JA |
1376 | { |
1377 | .name = "do_verify", | |
68e1f29a | 1378 | .type = FIO_OPT_BOOL, |
005c565a JA |
1379 | .off1 = td_var_offset(do_verify), |
1380 | .help = "Run verification stage after write", | |
1381 | .def = "1", | |
1382 | .parent = "verify", | |
1383 | }, | |
160b966d JA |
1384 | { |
1385 | .name = "verifysort", | |
1386 | .type = FIO_OPT_BOOL, | |
1387 | .off1 = td_var_offset(verifysort), | |
1388 | .help = "Sort written verify blocks for read back", | |
1389 | .def = "1", | |
c83f2df1 | 1390 | .parent = "verify", |
160b966d | 1391 | }, |
3f9f4e26 | 1392 | { |
a59e170d | 1393 | .name = "verify_interval", |
e01b22b8 | 1394 | .type = FIO_OPT_INT, |
a59e170d | 1395 | .off1 = td_var_offset(verify_interval), |
819a9680 | 1396 | .minval = 2 * sizeof(struct verify_header), |
a59e170d | 1397 | .help = "Store verify buffer header every N bytes", |
afdf9352 | 1398 | .parent = "verify", |
3f9f4e26 | 1399 | }, |
546a9142 | 1400 | { |
a59e170d | 1401 | .name = "verify_offset", |
e01b22b8 | 1402 | .type = FIO_OPT_INT, |
a59e170d | 1403 | .help = "Offset verify header location by N bytes", |
546a9142 | 1404 | .def = "0", |
5ec10eaa | 1405 | .cb = str_verify_offset_cb, |
afdf9352 | 1406 | .parent = "verify", |
546a9142 | 1407 | }, |
e28218f3 SL |
1408 | { |
1409 | .name = "verify_pattern", | |
0e92f873 | 1410 | .type = FIO_OPT_STR, |
e28218f3 SL |
1411 | .cb = str_verify_pattern_cb, |
1412 | .help = "Fill pattern for IO buffers", | |
1413 | .parent = "verify", | |
1414 | }, | |
a12a3b4d JA |
1415 | { |
1416 | .name = "verify_fatal", | |
68e1f29a | 1417 | .type = FIO_OPT_BOOL, |
a12a3b4d JA |
1418 | .off1 = td_var_offset(verify_fatal), |
1419 | .def = "0", | |
1420 | .help = "Exit on a single verify failure, don't continue", | |
1421 | .parent = "verify", | |
1422 | }, | |
e8462bd8 JA |
1423 | { |
1424 | .name = "verify_async", | |
1425 | .type = FIO_OPT_INT, | |
1426 | .off1 = td_var_offset(verify_async), | |
1427 | .def = "0", | |
1428 | .help = "Number of async verifier threads to use", | |
1429 | .parent = "verify", | |
1430 | }, | |
9e144189 JA |
1431 | { |
1432 | .name = "verify_backlog", | |
1433 | .type = FIO_OPT_STR_VAL, | |
1434 | .off1 = td_var_offset(verify_backlog), | |
1435 | .help = "Verify after this number of blocks are written", | |
1436 | .parent = "verify", | |
1437 | }, | |
1438 | { | |
1439 | .name = "verify_backlog_batch", | |
1440 | .type = FIO_OPT_INT, | |
1441 | .off1 = td_var_offset(verify_batch), | |
1442 | .help = "Verify this number of IO blocks", | |
1443 | .parent = "verify_backlog", | |
1444 | }, | |
e8462bd8 JA |
1445 | #ifdef FIO_HAVE_CPU_AFFINITY |
1446 | { | |
1447 | .name = "verify_async_cpus", | |
1448 | .type = FIO_OPT_STR, | |
1449 | .cb = str_verify_cpus_allowed_cb, | |
1450 | .help = "Set CPUs allowed for async verify threads", | |
1451 | .parent = "verify_async", | |
1452 | }, | |
1453 | #endif | |
214e1eca JA |
1454 | { |
1455 | .name = "write_iolog", | |
1456 | .type = FIO_OPT_STR_STORE, | |
1457 | .off1 = td_var_offset(write_iolog_file), | |
1458 | .help = "Store IO pattern to file", | |
1459 | }, | |
1460 | { | |
1461 | .name = "read_iolog", | |
1462 | .type = FIO_OPT_STR_STORE, | |
1463 | .off1 = td_var_offset(read_iolog_file), | |
1464 | .help = "Playback IO pattern from file", | |
1465 | }, | |
1466 | { | |
1467 | .name = "exec_prerun", | |
1468 | .type = FIO_OPT_STR_STORE, | |
1469 | .off1 = td_var_offset(exec_prerun), | |
1470 | .help = "Execute this file prior to running job", | |
1471 | }, | |
1472 | { | |
1473 | .name = "exec_postrun", | |
1474 | .type = FIO_OPT_STR_STORE, | |
1475 | .off1 = td_var_offset(exec_postrun), | |
1476 | .help = "Execute this file after running job", | |
1477 | }, | |
1478 | #ifdef FIO_HAVE_IOSCHED_SWITCH | |
1479 | { | |
1480 | .name = "ioscheduler", | |
1481 | .type = FIO_OPT_STR_STORE, | |
1482 | .off1 = td_var_offset(ioscheduler), | |
1483 | .help = "Use this IO scheduler on the backing device", | |
1484 | }, | |
1485 | #endif | |
1486 | { | |
1487 | .name = "zonesize", | |
1488 | .type = FIO_OPT_STR_VAL, | |
1489 | .off1 = td_var_offset(zone_size), | |
1490 | .help = "Give size of an IO zone", | |
1491 | .def = "0", | |
1492 | }, | |
1493 | { | |
1494 | .name = "zoneskip", | |
1495 | .type = FIO_OPT_STR_VAL, | |
1496 | .off1 = td_var_offset(zone_skip), | |
1497 | .help = "Space between IO zones", | |
1498 | .def = "0", | |
1499 | }, | |
1500 | { | |
1501 | .name = "lockmem", | |
1502 | .type = FIO_OPT_STR_VAL, | |
1503 | .cb = str_lockmem_cb, | |
1504 | .help = "Lock down this amount of memory", | |
1505 | .def = "0", | |
1506 | }, | |
214e1eca JA |
1507 | { |
1508 | .name = "rwmixread", | |
1509 | .type = FIO_OPT_INT, | |
cb499fc4 | 1510 | .cb = str_rwmix_read_cb, |
214e1eca JA |
1511 | .maxval = 100, |
1512 | .help = "Percentage of mixed workload that is reads", | |
1513 | .def = "50", | |
1514 | }, | |
1515 | { | |
1516 | .name = "rwmixwrite", | |
1517 | .type = FIO_OPT_INT, | |
cb499fc4 | 1518 | .cb = str_rwmix_write_cb, |
214e1eca JA |
1519 | .maxval = 100, |
1520 | .help = "Percentage of mixed workload that is writes", | |
1521 | .def = "50", | |
1522 | }, | |
afdf9352 JA |
1523 | { |
1524 | .name = "rwmixcycle", | |
15ca150e | 1525 | .type = FIO_OPT_DEPRECATED, |
afdf9352 | 1526 | }, |
214e1eca JA |
1527 | { |
1528 | .name = "nice", | |
1529 | .type = FIO_OPT_INT, | |
1530 | .off1 = td_var_offset(nice), | |
1531 | .help = "Set job CPU nice value", | |
1532 | .minval = -19, | |
1533 | .maxval = 20, | |
1534 | .def = "0", | |
1535 | }, | |
1536 | #ifdef FIO_HAVE_IOPRIO | |
1537 | { | |
1538 | .name = "prio", | |
1539 | .type = FIO_OPT_INT, | |
1540 | .cb = str_prio_cb, | |
1541 | .help = "Set job IO priority value", | |
1542 | .minval = 0, | |
1543 | .maxval = 7, | |
1544 | }, | |
1545 | { | |
1546 | .name = "prioclass", | |
1547 | .type = FIO_OPT_INT, | |
1548 | .cb = str_prioclass_cb, | |
1549 | .help = "Set job IO priority class", | |
1550 | .minval = 0, | |
1551 | .maxval = 3, | |
1552 | }, | |
1553 | #endif | |
1554 | { | |
1555 | .name = "thinktime", | |
1556 | .type = FIO_OPT_INT, | |
1557 | .off1 = td_var_offset(thinktime), | |
1558 | .help = "Idle time between IO buffers (usec)", | |
1559 | .def = "0", | |
1560 | }, | |
1561 | { | |
1562 | .name = "thinktime_spin", | |
1563 | .type = FIO_OPT_INT, | |
1564 | .off1 = td_var_offset(thinktime_spin), | |
1565 | .help = "Start think time by spinning this amount (usec)", | |
1566 | .def = "0", | |
afdf9352 | 1567 | .parent = "thinktime", |
214e1eca JA |
1568 | }, |
1569 | { | |
1570 | .name = "thinktime_blocks", | |
1571 | .type = FIO_OPT_INT, | |
1572 | .off1 = td_var_offset(thinktime_blocks), | |
1573 | .help = "IO buffer period between 'thinktime'", | |
1574 | .def = "1", | |
afdf9352 | 1575 | .parent = "thinktime", |
214e1eca JA |
1576 | }, |
1577 | { | |
1578 | .name = "rate", | |
e01b22b8 | 1579 | .type = FIO_OPT_INT, |
581e7141 JA |
1580 | .off1 = td_var_offset(rate[0]), |
1581 | .off2 = td_var_offset(rate[1]), | |
214e1eca JA |
1582 | .help = "Set bandwidth rate", |
1583 | }, | |
1584 | { | |
1585 | .name = "ratemin", | |
e01b22b8 | 1586 | .type = FIO_OPT_INT, |
581e7141 JA |
1587 | .off1 = td_var_offset(ratemin[0]), |
1588 | .off2 = td_var_offset(ratemin[1]), | |
4e991c23 | 1589 | .help = "Job must meet this rate or it will be shutdown", |
afdf9352 | 1590 | .parent = "rate", |
4e991c23 JA |
1591 | }, |
1592 | { | |
1593 | .name = "rate_iops", | |
e01b22b8 | 1594 | .type = FIO_OPT_INT, |
581e7141 JA |
1595 | .off1 = td_var_offset(rate_iops[0]), |
1596 | .off2 = td_var_offset(rate_iops[1]), | |
4e991c23 JA |
1597 | .help = "Limit IO used to this number of IO operations/sec", |
1598 | }, | |
1599 | { | |
1600 | .name = "rate_iops_min", | |
e01b22b8 | 1601 | .type = FIO_OPT_INT, |
581e7141 JA |
1602 | .off1 = td_var_offset(rate_iops_min[0]), |
1603 | .off2 = td_var_offset(rate_iops_min[1]), | |
4e991c23 | 1604 | .help = "Job must meet this rate or it will be shutdown", |
afdf9352 | 1605 | .parent = "rate_iops", |
214e1eca JA |
1606 | }, |
1607 | { | |
1608 | .name = "ratecycle", | |
1609 | .type = FIO_OPT_INT, | |
1610 | .off1 = td_var_offset(ratecycle), | |
1611 | .help = "Window average for rate limits (msec)", | |
1612 | .def = "1000", | |
afdf9352 | 1613 | .parent = "rate", |
214e1eca JA |
1614 | }, |
1615 | { | |
1616 | .name = "invalidate", | |
1617 | .type = FIO_OPT_BOOL, | |
1618 | .off1 = td_var_offset(invalidate_cache), | |
1619 | .help = "Invalidate buffer/page cache prior to running job", | |
1620 | .def = "1", | |
1621 | }, | |
1622 | { | |
1623 | .name = "sync", | |
1624 | .type = FIO_OPT_BOOL, | |
1625 | .off1 = td_var_offset(sync_io), | |
1626 | .help = "Use O_SYNC for buffered writes", | |
1627 | .def = "0", | |
67a1000f | 1628 | .parent = "buffered", |
214e1eca JA |
1629 | }, |
1630 | { | |
1631 | .name = "bwavgtime", | |
1632 | .type = FIO_OPT_INT, | |
1633 | .off1 = td_var_offset(bw_avg_time), | |
5ec10eaa JA |
1634 | .help = "Time window over which to calculate bandwidth" |
1635 | " (msec)", | |
214e1eca JA |
1636 | .def = "500", |
1637 | }, | |
1638 | { | |
1639 | .name = "create_serialize", | |
1640 | .type = FIO_OPT_BOOL, | |
1641 | .off1 = td_var_offset(create_serialize), | |
1642 | .help = "Serialize creating of job files", | |
1643 | .def = "1", | |
1644 | }, | |
1645 | { | |
1646 | .name = "create_fsync", | |
1647 | .type = FIO_OPT_BOOL, | |
1648 | .off1 = td_var_offset(create_fsync), | |
1649 | .help = "Fsync file after creation", | |
1650 | .def = "1", | |
1651 | }, | |
814452bd JA |
1652 | { |
1653 | .name = "create_on_open", | |
1654 | .type = FIO_OPT_BOOL, | |
1655 | .off1 = td_var_offset(create_on_open), | |
1656 | .help = "Create files when they are opened for IO", | |
1657 | .def = "0", | |
1658 | }, | |
0b9d69ec | 1659 | { |
afad68f7 ZY |
1660 | .name = "pre_read", |
1661 | .type = FIO_OPT_BOOL, | |
1662 | .off1 = td_var_offset(pre_read), | |
1663 | .help = "Preread files before starting official testing", | |
1664 | .def = "0", | |
1665 | }, | |
214e1eca JA |
1666 | { |
1667 | .name = "cpuload", | |
1668 | .type = FIO_OPT_INT, | |
1669 | .off1 = td_var_offset(cpuload), | |
1670 | .help = "Use this percentage of CPU", | |
1671 | }, | |
1672 | { | |
1673 | .name = "cpuchunks", | |
1674 | .type = FIO_OPT_INT, | |
1675 | .off1 = td_var_offset(cpucycle), | |
1676 | .help = "Length of the CPU burn cycles (usecs)", | |
1677 | .def = "50000", | |
67a1000f | 1678 | .parent = "cpuload", |
214e1eca JA |
1679 | }, |
1680 | #ifdef FIO_HAVE_CPU_AFFINITY | |
1681 | { | |
1682 | .name = "cpumask", | |
1683 | .type = FIO_OPT_INT, | |
1684 | .cb = str_cpumask_cb, | |
1685 | .help = "CPU affinity mask", | |
1686 | }, | |
d2e268b0 JA |
1687 | { |
1688 | .name = "cpus_allowed", | |
1689 | .type = FIO_OPT_STR, | |
1690 | .cb = str_cpus_allowed_cb, | |
1691 | .help = "Set CPUs allowed", | |
1692 | }, | |
214e1eca JA |
1693 | #endif |
1694 | { | |
1695 | .name = "end_fsync", | |
1696 | .type = FIO_OPT_BOOL, | |
1697 | .off1 = td_var_offset(end_fsync), | |
1698 | .help = "Include fsync at the end of job", | |
1699 | .def = "0", | |
1700 | }, | |
1701 | { | |
1702 | .name = "fsync_on_close", | |
1703 | .type = FIO_OPT_BOOL, | |
1704 | .off1 = td_var_offset(fsync_on_close), | |
1705 | .help = "fsync files on close", | |
1706 | .def = "0", | |
1707 | }, | |
1708 | { | |
1709 | .name = "unlink", | |
1710 | .type = FIO_OPT_BOOL, | |
1711 | .off1 = td_var_offset(unlink), | |
1712 | .help = "Unlink created files after job has completed", | |
1713 | .def = "0", | |
1714 | }, | |
1715 | { | |
1716 | .name = "exitall", | |
1717 | .type = FIO_OPT_STR_SET, | |
1718 | .cb = str_exitall_cb, | |
1719 | .help = "Terminate all jobs when one exits", | |
1720 | }, | |
1721 | { | |
1722 | .name = "stonewall", | |
1723 | .type = FIO_OPT_STR_SET, | |
1724 | .off1 = td_var_offset(stonewall), | |
1725 | .help = "Insert a hard barrier between this job and previous", | |
1726 | }, | |
b3d62a75 JA |
1727 | { |
1728 | .name = "new_group", | |
1729 | .type = FIO_OPT_STR_SET, | |
1730 | .off1 = td_var_offset(new_group), | |
1731 | .help = "Mark the start of a new group (for reporting)", | |
1732 | }, | |
214e1eca JA |
1733 | { |
1734 | .name = "thread", | |
1735 | .type = FIO_OPT_STR_SET, | |
1736 | .off1 = td_var_offset(use_thread), | |
1737 | .help = "Use threads instead of forks", | |
1738 | }, | |
1739 | { | |
1740 | .name = "write_bw_log", | |
e3cedca7 | 1741 | .type = FIO_OPT_STR, |
214e1eca | 1742 | .off1 = td_var_offset(write_bw_log), |
e3cedca7 | 1743 | .cb = str_write_bw_log_cb, |
214e1eca JA |
1744 | .help = "Write log of bandwidth during run", |
1745 | }, | |
1746 | { | |
1747 | .name = "write_lat_log", | |
e3cedca7 | 1748 | .type = FIO_OPT_STR, |
214e1eca | 1749 | .off1 = td_var_offset(write_lat_log), |
e3cedca7 | 1750 | .cb = str_write_lat_log_cb, |
214e1eca JA |
1751 | .help = "Write log of latency during run", |
1752 | }, | |
1753 | { | |
1754 | .name = "hugepage-size", | |
e01b22b8 | 1755 | .type = FIO_OPT_INT, |
214e1eca JA |
1756 | .off1 = td_var_offset(hugepage_size), |
1757 | .help = "When using hugepages, specify size of each page", | |
1758 | .def = __stringify(FIO_HUGE_PAGE), | |
1759 | }, | |
1760 | { | |
1761 | .name = "group_reporting", | |
1762 | .type = FIO_OPT_STR_SET, | |
1763 | .off1 = td_var_offset(group_reporting), | |
1764 | .help = "Do reporting on a per-group basis", | |
1765 | }, | |
e9459e5a JA |
1766 | { |
1767 | .name = "zero_buffers", | |
1768 | .type = FIO_OPT_STR_SET, | |
1769 | .off1 = td_var_offset(zero_buffers), | |
1770 | .help = "Init IO buffers to all zeroes", | |
1771 | }, | |
5973cafb JA |
1772 | { |
1773 | .name = "refill_buffers", | |
1774 | .type = FIO_OPT_STR_SET, | |
1775 | .off1 = td_var_offset(refill_buffers), | |
1776 | .help = "Refill IO buffers on every IO submit", | |
1777 | }, | |
0a839f30 JA |
1778 | #ifdef FIO_HAVE_DISK_UTIL |
1779 | { | |
1780 | .name = "disk_util", | |
1781 | .type = FIO_OPT_BOOL, | |
1782 | .off1 = td_var_offset(do_disk_util), | |
f66ab3c8 | 1783 | .help = "Log disk utilization statistics", |
0a839f30 JA |
1784 | .def = "1", |
1785 | }, | |
1786 | #endif | |
993bf48b JA |
1787 | { |
1788 | .name = "gtod_reduce", | |
1789 | .type = FIO_OPT_BOOL, | |
1790 | .help = "Greatly reduce number of gettimeofday() calls", | |
1791 | .cb = str_gtod_reduce_cb, | |
1792 | .def = "0", | |
1793 | }, | |
9520ebb9 JA |
1794 | { |
1795 | .name = "disable_clat", | |
1796 | .type = FIO_OPT_BOOL, | |
1797 | .off1 = td_var_offset(disable_clat), | |
1798 | .help = "Disable completion latency numbers", | |
993bf48b | 1799 | .parent = "gtod_reduce", |
9520ebb9 JA |
1800 | .def = "0", |
1801 | }, | |
1802 | { | |
1803 | .name = "disable_slat", | |
1804 | .type = FIO_OPT_BOOL, | |
1805 | .off1 = td_var_offset(disable_slat), | |
1806 | .help = "Disable submissionn latency numbers", | |
993bf48b | 1807 | .parent = "gtod_reduce", |
9520ebb9 JA |
1808 | .def = "0", |
1809 | }, | |
1810 | { | |
1811 | .name = "disable_bw_measurement", | |
1812 | .type = FIO_OPT_BOOL, | |
1813 | .off1 = td_var_offset(disable_bw), | |
1814 | .help = "Disable bandwidth logging", | |
993bf48b | 1815 | .parent = "gtod_reduce", |
9520ebb9 JA |
1816 | .def = "0", |
1817 | }, | |
be4ecfdf JA |
1818 | { |
1819 | .name = "gtod_cpu", | |
1820 | .type = FIO_OPT_INT, | |
1821 | .cb = str_gtod_cpu_cb, | |
1822 | .help = "Setup dedicated gettimeofday() thread on this CPU", | |
29d43ff9 | 1823 | .verify = gtod_cpu_verify, |
be4ecfdf | 1824 | }, |
f2bba182 RR |
1825 | { |
1826 | .name = "continue_on_error", | |
1827 | .type = FIO_OPT_BOOL, | |
1828 | .off1 = td_var_offset(continue_on_error), | |
1829 | .help = "Continue on non-fatal errors during I/O", | |
1830 | .def = "0", | |
1831 | }, | |
9ac8a797 JA |
1832 | { |
1833 | .name = "profile", | |
79d16311 | 1834 | .type = FIO_OPT_STR_STORE, |
9ac8a797 | 1835 | .off1 = td_var_offset(profile), |
9ac8a797 JA |
1836 | .help = "Select a specific builtin performance test", |
1837 | }, | |
a696fa2a JA |
1838 | { |
1839 | .name = "cgroup", | |
1840 | .type = FIO_OPT_STR_STORE, | |
1841 | .off1 = td_var_offset(cgroup), | |
1842 | .help = "Add job to cgroup of this name", | |
1843 | }, | |
1844 | { | |
1845 | .name = "cgroup_weight", | |
1846 | .type = FIO_OPT_INT, | |
1847 | .off1 = td_var_offset(cgroup_weight), | |
1848 | .help = "Use given weight for cgroup", | |
1849 | .minval = 100, | |
1850 | .maxval = 1000, | |
a696fa2a | 1851 | }, |
7de87099 VG |
1852 | { |
1853 | .name = "cgroup_nodelete", | |
1854 | .type = FIO_OPT_BOOL, | |
1855 | .off1 = td_var_offset(cgroup_nodelete), | |
1856 | .help = "Do not delete cgroups after job completion", | |
1857 | .def = "0", | |
1858 | }, | |
e0b0d892 JA |
1859 | { |
1860 | .name = "uid", | |
1861 | .type = FIO_OPT_INT, | |
1862 | .off1 = td_var_offset(uid), | |
1863 | .help = "Run job with this user ID", | |
1864 | }, | |
1865 | { | |
1866 | .name = "gid", | |
1867 | .type = FIO_OPT_INT, | |
1868 | .off1 = td_var_offset(gid), | |
1869 | .help = "Run job with this group ID", | |
1870 | }, | |
214e1eca JA |
1871 | { |
1872 | .name = NULL, | |
1873 | }, | |
1874 | }; | |
1875 | ||
17af15d4 JA |
1876 | static void add_to_lopt(struct option *lopt, struct fio_option *o, |
1877 | const char *name) | |
9f81736c | 1878 | { |
17af15d4 | 1879 | lopt->name = (char *) name; |
9f81736c JA |
1880 | lopt->val = FIO_GETOPT_JOB; |
1881 | if (o->type == FIO_OPT_STR_SET) | |
1882 | lopt->has_arg = no_argument; | |
1883 | else | |
1884 | lopt->has_arg = required_argument; | |
1885 | } | |
1886 | ||
214e1eca JA |
1887 | void fio_options_dup_and_init(struct option *long_options) |
1888 | { | |
1889 | struct fio_option *o; | |
1890 | unsigned int i; | |
1891 | ||
1892 | options_init(options); | |
1893 | ||
1894 | i = 0; | |
1895 | while (long_options[i].name) | |
1896 | i++; | |
1897 | ||
1898 | o = &options[0]; | |
1899 | while (o->name) { | |
17af15d4 JA |
1900 | add_to_lopt(&long_options[i], o, o->name); |
1901 | if (o->alias) { | |
1902 | i++; | |
1903 | add_to_lopt(&long_options[i], o, o->alias); | |
1904 | } | |
214e1eca JA |
1905 | |
1906 | i++; | |
1907 | o++; | |
1908 | assert(i < FIO_NR_OPTIONS); | |
1909 | } | |
1910 | } | |
1911 | ||
74929ac2 JA |
1912 | struct fio_keyword { |
1913 | const char *word; | |
1914 | const char *desc; | |
1915 | char *replace; | |
1916 | }; | |
1917 | ||
1918 | static struct fio_keyword fio_keywords[] = { | |
1919 | { | |
1920 | .word = "$pagesize", | |
1921 | .desc = "Page size in the system", | |
1922 | }, | |
1923 | { | |
1924 | .word = "$mb_memory", | |
1925 | .desc = "Megabytes of memory online", | |
1926 | }, | |
1927 | { | |
1928 | .word = "$ncpus", | |
1929 | .desc = "Number of CPUs online in the system", | |
1930 | }, | |
1931 | { | |
1932 | .word = NULL, | |
1933 | }, | |
1934 | }; | |
1935 | ||
1936 | void fio_keywords_init(void) | |
1937 | { | |
3b2e1464 | 1938 | unsigned long long mb_memory; |
74929ac2 JA |
1939 | char buf[128]; |
1940 | long l; | |
1941 | ||
1942 | sprintf(buf, "%lu", page_size); | |
1943 | fio_keywords[0].replace = strdup(buf); | |
1944 | ||
3b2e1464 JA |
1945 | mb_memory = os_phys_mem() / page_size; |
1946 | sprintf(buf, "%llu", mb_memory); | |
74929ac2 JA |
1947 | fio_keywords[1].replace = strdup(buf); |
1948 | ||
1949 | l = sysconf(_SC_NPROCESSORS_ONLN); | |
1950 | sprintf(buf, "%lu", l); | |
1951 | fio_keywords[2].replace = strdup(buf); | |
1952 | } | |
1953 | ||
892a6ffc JA |
1954 | #define BC_APP "bc" |
1955 | ||
1956 | static char *bc_calc(char *str) | |
1957 | { | |
1958 | char *buf, *tmp, opt[80]; | |
1959 | FILE *f; | |
1960 | int ret; | |
1961 | ||
1962 | /* | |
1963 | * No math, just return string | |
1964 | */ | |
1965 | if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') && | |
1966 | !strchr(str, '/')) | |
1967 | return str; | |
1968 | ||
1969 | /* | |
1970 | * Split option from value, we only need to calculate the value | |
1971 | */ | |
1972 | tmp = strchr(str, '='); | |
1973 | if (!tmp) | |
1974 | return str; | |
1975 | ||
1976 | tmp++; | |
9ac8a797 | 1977 | memset(opt, 0, sizeof(opt)); |
892a6ffc JA |
1978 | strncpy(opt, str, tmp - str); |
1979 | ||
1980 | buf = malloc(128); | |
1981 | ||
1982 | sprintf(buf, "which %s > /dev/null", BC_APP); | |
1983 | if (system(buf)) { | |
1984 | log_err("fio: bc is needed for performing math\n"); | |
1985 | free(buf); | |
1986 | return NULL; | |
1987 | } | |
1988 | ||
1989 | sprintf(buf, "echo %s | %s", tmp, BC_APP); | |
1990 | f = popen(buf, "r"); | |
1991 | if (!f) { | |
1992 | free(buf); | |
1993 | return NULL; | |
1994 | } | |
1995 | ||
1996 | ret = fread(buf, 1, 128, f); | |
1997 | if (ret <= 0) { | |
1998 | free(buf); | |
1999 | return NULL; | |
2000 | } | |
2001 | ||
2002 | buf[ret - 1] = '\0'; | |
2003 | strcat(opt, buf); | |
2004 | strcpy(buf, opt); | |
2005 | pclose(f); | |
2006 | free(str); | |
2007 | return buf; | |
2008 | } | |
2009 | ||
74929ac2 JA |
2010 | /* |
2011 | * Look for reserved variable names and replace them with real values | |
2012 | */ | |
2013 | static char *fio_keyword_replace(char *opt) | |
2014 | { | |
2015 | char *s; | |
2016 | int i; | |
2017 | ||
2018 | for (i = 0; fio_keywords[i].word != NULL; i++) { | |
2019 | struct fio_keyword *kw = &fio_keywords[i]; | |
2020 | ||
2021 | while ((s = strstr(opt, kw->word)) != NULL) { | |
2022 | char *new = malloc(strlen(opt) + 1); | |
2023 | char *o_org = opt; | |
2024 | int olen = s - opt; | |
2025 | int len; | |
2026 | ||
2027 | /* | |
2028 | * Copy part of the string before the keyword and | |
2029 | * sprintf() the replacement after it. | |
2030 | */ | |
2031 | memcpy(new, opt, olen); | |
2032 | len = sprintf(new + olen, "%s", kw->replace); | |
2033 | ||
2034 | /* | |
2035 | * If there's more in the original string, copy that | |
2036 | * in too | |
2037 | */ | |
2038 | opt += strlen(kw->word) + olen; | |
2039 | if (strlen(opt)) | |
2040 | memcpy(new + olen + len, opt, opt - o_org - 1); | |
2041 | ||
2042 | /* | |
2043 | * replace opt and free the old opt | |
2044 | */ | |
2045 | opt = new; | |
9ac8a797 | 2046 | //free(o_org); |
7a958bd5 JA |
2047 | |
2048 | /* | |
2049 | * Check for potential math and invoke bc, if possible | |
2050 | */ | |
2051 | opt = bc_calc(opt); | |
74929ac2 JA |
2052 | } |
2053 | } | |
2054 | ||
7a958bd5 | 2055 | return opt; |
74929ac2 JA |
2056 | } |
2057 | ||
3b8b7135 | 2058 | int fio_options_parse(struct thread_data *td, char **opts, int num_opts) |
214e1eca | 2059 | { |
3b8b7135 JA |
2060 | int i, ret; |
2061 | ||
2062 | sort_options(opts, options, num_opts); | |
2063 | ||
74929ac2 JA |
2064 | for (ret = 0, i = 0; i < num_opts; i++) { |
2065 | opts[i] = fio_keyword_replace(opts[i]); | |
07b3232d | 2066 | ret |= parse_option(opts[i], options, td); |
74929ac2 | 2067 | } |
3b8b7135 JA |
2068 | |
2069 | return ret; | |
214e1eca JA |
2070 | } |
2071 | ||
2072 | int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val) | |
2073 | { | |
07b3232d | 2074 | return parse_cmd_option(opt, val, options, td); |
214e1eca JA |
2075 | } |
2076 | ||
2077 | void fio_fill_default_options(struct thread_data *td) | |
2078 | { | |
2079 | fill_default_options(td, options); | |
2080 | } | |
2081 | ||
2082 | int fio_show_option_help(const char *opt) | |
2083 | { | |
07b3232d | 2084 | return show_cmd_help(options, opt); |
214e1eca | 2085 | } |
d23bb327 JA |
2086 | |
2087 | static void __options_mem(struct thread_data *td, int alloc) | |
2088 | { | |
2089 | struct thread_options *o = &td->o; | |
2090 | struct fio_option *opt; | |
2091 | char **ptr; | |
2092 | int i; | |
2093 | ||
2094 | for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) { | |
2095 | if (opt->type != FIO_OPT_STR_STORE) | |
2096 | continue; | |
2097 | ||
2098 | ptr = (void *) o + opt->off1; | |
2099 | if (*ptr) { | |
2100 | if (alloc) | |
2101 | *ptr = strdup(*ptr); | |
2102 | else { | |
2103 | free(*ptr); | |
2104 | *ptr = NULL; | |
2105 | } | |
2106 | } | |
2107 | } | |
2108 | } | |
2109 | ||
2110 | /* | |
2111 | * dupe FIO_OPT_STR_STORE options | |
2112 | */ | |
2113 | void options_mem_dupe(struct thread_data *td) | |
2114 | { | |
2115 | __options_mem(td, 1); | |
2116 | } | |
2117 | ||
22d66213 | 2118 | void options_mem_free(struct thread_data fio_unused *td) |
d23bb327 | 2119 | { |
22d66213 | 2120 | #if 0 |
d23bb327 | 2121 | __options_mem(td, 0); |
22d66213 | 2122 | #endif |
d23bb327 | 2123 | } |
d6978a32 JA |
2124 | |
2125 | unsigned int fio_get_kb_base(void *data) | |
2126 | { | |
2127 | struct thread_data *td = data; | |
2128 | unsigned int kb_base = 0; | |
2129 | ||
2130 | if (td) | |
2131 | kb_base = td->o.kb_base; | |
2132 | if (!kb_base) | |
2133 | kb_base = 1024; | |
2134 | ||
2135 | return kb_base; | |
2136 | } | |
9f988e2e | 2137 | |
07b3232d | 2138 | int add_option(struct fio_option *o) |
9f988e2e | 2139 | { |
07b3232d JA |
2140 | struct fio_option *__o; |
2141 | int opt_index = 0; | |
2142 | ||
2143 | __o = options; | |
2144 | while (__o->name) { | |
2145 | opt_index++; | |
2146 | __o++; | |
2147 | } | |
2148 | ||
2149 | memcpy(&options[opt_index], o, sizeof(*o)); | |
2150 | return 0; | |
9f988e2e | 2151 | } |
e2de69da | 2152 | |
07b3232d | 2153 | void invalidate_profile_options(const char *prof_name) |
e2de69da | 2154 | { |
07b3232d | 2155 | struct fio_option *o; |
e2de69da | 2156 | |
07b3232d JA |
2157 | o = options; |
2158 | while (o->name) { | |
2159 | if (o->prof_name && !strcmp(o->prof_name, prof_name)) { | |
2160 | o->type = FIO_OPT_INVALID; | |
2161 | o->prof_name = NULL; | |
2162 | } | |
2163 | o++; | |
e2de69da JA |
2164 | } |
2165 | } | |
f5b6bb85 JA |
2166 | |
2167 | void add_opt_posval(const char *optname, const char *ival, const char *help) | |
2168 | { | |
2169 | struct fio_option *o; | |
2170 | unsigned int i; | |
2171 | ||
2172 | o = find_option(options, optname); | |
2173 | if (!o) | |
2174 | return; | |
2175 | ||
2176 | for (i = 0; i < PARSE_MAX_VP; i++) { | |
2177 | if (o->posval[i].ival) | |
2178 | continue; | |
2179 | ||
2180 | o->posval[i].ival = ival; | |
2181 | o->posval[i].help = help; | |
2182 | break; | |
2183 | } | |
2184 | } | |
2185 | ||
2186 | void del_opt_posval(const char *optname, const char *ival) | |
2187 | { | |
2188 | struct fio_option *o; | |
2189 | unsigned int i; | |
2190 | ||
2191 | o = find_option(options, optname); | |
2192 | if (!o) | |
2193 | return; | |
2194 | ||
2195 | for (i = 0; i < PARSE_MAX_VP; i++) { | |
2196 | if (!o->posval[i].ival) | |
2197 | continue; | |
2198 | if (strcmp(o->posval[i].ival, ival)) | |
2199 | continue; | |
2200 | ||
2201 | o->posval[i].ival = NULL; | |
2202 | o->posval[i].help = NULL; | |
2203 | } | |
2204 | } |