blob: 2f38b4ae75edddd208d16b2624dac3cf40b4203a [file] [log] [blame]
Jens Axboe214e1ec2007-03-15 10:48:13 +01001#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>
Jens Axboe921c7662008-03-26 09:17:55 +01008#include <libgen.h>
Jens Axboe5921e802008-05-30 15:02:38 +02009#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/stat.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +010012
13#include "fio.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020014#include "verify.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010015#include "parse.h"
Jens Axboeeef32352008-06-02 13:31:26 +020016#include "lib/fls.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010017#include "options.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010018
Jens Axboe9f988e22010-03-04 10:42:38 +010019static FLIST_HEAD(ext_opt_list);
Jens Axboe214e1ec2007-03-15 10:48:13 +010020
21/*
22 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
23 */
24static 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
Radha Ramachandran0e92f872009-10-27 20:14:27 +010037static 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
Jens Axboe564ca972007-12-14 12:21:19 +010057static 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
Jens Axboe720e84a2009-04-21 08:29:55 +020065static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010066{
Jens Axboe720e84a2009-04-21 08:29:55 +020067 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010068 unsigned int i, perc, perc_missing;
69 unsigned int max_bs, min_bs;
70 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020071 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010072
Jens Axboe720e84a2009-04-21 08:29:55 +020073 td->o.bssplit_nr[ddir] = 4;
74 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010075
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 */
Jens Axboe720e84a2009-04-21 08:29:55 +020088 if (i == td->o.bssplit_nr[ddir]) {
89 td->o.bssplit_nr[ddir] <<= 1;
90 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010091 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010092 }
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
Kenneth Watersdf9cf922009-10-15 07:08:48 +0200106 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100107 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
Jens Axboe720e84a2009-04-21 08:29:55 +0200117 bssplit[i].bs = val;
118 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100119 i++;
120 }
121
Jens Axboe720e84a2009-04-21 08:29:55 +0200122 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100123
124 /*
125 * Now check if the percentages add up, and how much is missing
126 */
127 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200128 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
129 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100130
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");
Jens Axboe720e84a2009-04-21 08:29:55 +0200139 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100140 return 1;
141 }
142 /*
143 * If values didn't have a percentage set, divide the remains between
144 * them.
145 */
146 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200147 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
148 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100149
150 if (bsp->perc == (unsigned char) -1)
151 bsp->perc = (100 - perc) / perc_missing;
152 }
153 }
154
Jens Axboe720e84a2009-04-21 08:29:55 +0200155 td->o.min_bs[ddir] = min_bs;
156 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100157
158 /*
159 * now sort based on percentages, for ease of lookup
160 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200161 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
162 td->o.bssplit[ddir] = bssplit;
163 return 0;
164
165}
166
167static 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 }
Jens Axboe564ca972007-12-14 12:21:19 +0100196
197 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200198 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100199}
200
Jens Axboe211097b2007-03-22 18:56:45 +0100201static int str_rw_cb(void *data, const char *str)
202{
203 struct thread_data *td = data;
204 char *nr = get_opt_postfix(str);
205
Jens Axboefafdba32007-03-26 10:09:12 +0200206 td->o.ddir_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100207 if (nr) {
Jens Axboe211097b2007-03-22 18:56:45 +0100208 td->o.ddir_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100209 free(nr);
210 }
Jens Axboe211097b2007-03-22 18:56:45 +0100211
Jens Axboe211097b2007-03-22 18:56:45 +0100212 return 0;
213}
214
Jens Axboe214e1ec2007-03-15 10:48:13 +0100215static int str_mem_cb(void *data, const char *mem)
216{
217 struct thread_data *td = data;
218
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100219 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100220 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100221 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100222 log_err("fio: mmaphuge:/path/to/file\n");
223 return 1;
224 }
225 }
226
227 return 0;
228}
229
230static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
231{
232 mlock_size = *val;
233 return 0;
234}
235
Jens Axboecb499fc2008-05-28 10:33:32 +0200236static int str_rwmix_read_cb(void *data, unsigned int *val)
237{
238 struct thread_data *td = data;
239
240 td->o.rwmix[DDIR_READ] = *val;
241 td->o.rwmix[DDIR_WRITE] = 100 - *val;
242 return 0;
243}
244
245static int str_rwmix_write_cb(void *data, unsigned int *val)
246{
247 struct thread_data *td = data;
248
249 td->o.rwmix[DDIR_WRITE] = *val;
250 td->o.rwmix[DDIR_READ] = 100 - *val;
251 return 0;
252}
253
Jens Axboe214e1ec2007-03-15 10:48:13 +0100254#ifdef FIO_HAVE_IOPRIO
255static int str_prioclass_cb(void *data, unsigned int *val)
256{
257 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200258 unsigned short mask;
259
260 /*
261 * mask off old class bits, str_prio_cb() may have set a default class
262 */
263 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
264 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100265
266 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100267 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100268 return 0;
269}
270
271static int str_prio_cb(void *data, unsigned int *val)
272{
273 struct thread_data *td = data;
274
275 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200276
277 /*
278 * If no class is set, assume BE
279 */
280 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
281 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
282
Jens Axboeac684782007-11-08 08:29:07 +0100283 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100284 return 0;
285}
286#endif
287
288static int str_exitall_cb(void)
289{
290 exitall_on_terminate = 1;
291 return 0;
292}
293
Jens Axboe214e1ec2007-03-15 10:48:13 +0100294#ifdef FIO_HAVE_CPU_AFFINITY
Jens Axboe214e1ec2007-03-15 10:48:13 +0100295static int str_cpumask_cb(void *data, unsigned int *val)
296{
297 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200298 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100299 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100300 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100301
Jens Axboed2ce18b2008-12-12 20:51:40 +0100302 ret = fio_cpuset_init(&td->o.cpumask);
303 if (ret < 0) {
304 log_err("fio: cpuset_init failed\n");
305 td_verror(td, ret, "fio_cpuset_init");
306 return 1;
307 }
308
Jens Axboeb03daaf2008-12-08 20:31:43 +0100309 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
Jens Axboed2e268b2007-06-15 10:33:49 +0200310
Jens Axboe62a72732008-12-08 11:37:01 +0100311 for (i = 0; i < sizeof(int) * 8; i++) {
312 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100313 if (i > max_cpu) {
314 log_err("fio: CPU %d too large (max=%ld)\n", i,
315 max_cpu);
316 return 1;
317 }
Jens Axboe62a72732008-12-08 11:37:01 +0100318 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100319 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100320 }
321 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200322
Jens Axboe375b2692007-05-22 09:13:02 +0200323 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100324 return 0;
325}
326
Jens Axboee8462bd2009-07-06 12:59:04 +0200327static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
328 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200329{
Jens Axboed2e268b2007-06-15 10:33:49 +0200330 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100331 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100332 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200333
Jens Axboee8462bd2009-07-06 12:59:04 +0200334 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100335 if (ret < 0) {
336 log_err("fio: cpuset_init failed\n");
337 td_verror(td, ret, "fio_cpuset_init");
338 return 1;
339 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200340
341 p = str = strdup(input);
342
343 strip_blank_front(&str);
344 strip_blank_end(str);
345
Jens Axboeb03daaf2008-12-08 20:31:43 +0100346 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
347
Jens Axboed2e268b2007-06-15 10:33:49 +0200348 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100349 char *str2, *cpu2;
350 int icpu, icpu2;
351
Jens Axboed2e268b2007-06-15 10:33:49 +0200352 if (!strlen(cpu))
353 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100354
355 str2 = cpu;
356 icpu2 = -1;
357 while ((cpu2 = strsep(&str2, "-")) != NULL) {
358 if (!strlen(cpu2))
359 break;
360
361 icpu2 = atoi(cpu2);
362 }
363
364 icpu = atoi(cpu);
365 if (icpu2 == -1)
366 icpu2 = icpu;
367 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100368 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100369 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100370 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100371 ret = 1;
372 break;
373 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100374 if (icpu > max_cpu) {
375 log_err("fio: CPU %d too large (max=%ld)\n",
376 icpu, max_cpu);
377 ret = 1;
378 break;
379 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200380
Jens Axboe62a72732008-12-08 11:37:01 +0100381 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200382 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100383 icpu++;
384 }
Jens Axboe19608d62008-12-08 15:03:12 +0100385 if (ret)
386 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200387 }
388
389 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100390 if (!ret)
391 td->o.cpumask_set = 1;
392 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200393}
Jens Axboee8462bd2009-07-06 12:59:04 +0200394
395static int str_cpus_allowed_cb(void *data, const char *input)
396{
397 struct thread_data *td = data;
398 int ret;
399
400 ret = set_cpus_allowed(td, &td->o.cpumask, input);
401 if (!ret)
402 td->o.cpumask_set = 1;
403
404 return ret;
405}
406
407static int str_verify_cpus_allowed_cb(void *data, const char *input)
408{
409 struct thread_data *td = data;
410 int ret;
411
412 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
413 if (!ret)
414 td->o.verify_cpumask_set = 1;
415
416 return ret;
417}
Jens Axboed2e268b2007-06-15 10:33:49 +0200418#endif
419
Jens Axboe214e1ec2007-03-15 10:48:13 +0100420static int str_fst_cb(void *data, const char *str)
421{
422 struct thread_data *td = data;
423 char *nr = get_opt_postfix(str);
424
425 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100426 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100427 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100428 free(nr);
429 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100430
431 return 0;
432}
433
Jens Axboe921c7662008-03-26 09:17:55 +0100434static int check_dir(struct thread_data *td, char *fname)
435{
436 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200437 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100438
Jens Axboebc838912008-04-07 09:00:54 +0200439 if (td->o.directory) {
440 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200441 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200442 elen = strlen(file);
443 }
444
Jens Axboefcef0b32008-05-26 14:53:24 +0200445 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100446 dir = dirname(file);
447
Jens Axboefcef0b32008-05-26 14:53:24 +0200448#if 0
449 {
450 struct stat sb;
451 /*
452 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
453 * yet, so we can't do this check right here...
454 */
Jens Axboe921c7662008-03-26 09:17:55 +0100455 if (lstat(dir, &sb) < 0) {
456 int ret = errno;
457
458 log_err("fio: %s is not a directory\n", dir);
459 td_verror(td, ret, "lstat");
460 return 1;
461 }
462
463 if (!S_ISDIR(sb.st_mode)) {
464 log_err("fio: %s is not a directory\n", dir);
465 return 1;
466 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200467 }
468#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100469
470 return 0;
471}
472
Jens Axboe8e827d32009-08-04 09:51:48 +0200473/*
474 * Return next file in the string. Files are separated with ':'. If the ':'
475 * is escaped with a '\', then that ':' is part of the filename and does not
476 * indicate a new file.
477 */
478static char *get_next_file_name(char **ptr)
479{
480 char *str = *ptr;
481 char *p, *start;
482
483 if (!str || !strlen(str))
484 return NULL;
485
486 start = str;
487 do {
488 /*
489 * No colon, we are done
490 */
491 p = strchr(str, ':');
492 if (!p) {
493 *ptr = NULL;
494 break;
495 }
496
497 /*
498 * We got a colon, but it's the first character. Skip and
499 * continue
500 */
501 if (p == start) {
502 str = ++start;
503 continue;
504 }
505
506 if (*(p - 1) != '\\') {
507 *p = '\0';
508 *ptr = p + 1;
509 break;
510 }
511
512 memmove(p - 1, p, strlen(p) + 1);
513 str = p;
514 } while (1);
515
516 return start;
517}
518
Jens Axboe214e1ec2007-03-15 10:48:13 +0100519static int str_filename_cb(void *data, const char *input)
520{
521 struct thread_data *td = data;
522 char *fname, *str, *p;
523
524 p = str = strdup(input);
525
526 strip_blank_front(&str);
527 strip_blank_end(str);
528
529 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100530 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100531
Jens Axboe8e827d32009-08-04 09:51:48 +0200532 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100533 if (!strlen(fname))
534 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100535 if (check_dir(td, fname)) {
536 free(p);
537 return 1;
538 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100539 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100540 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100541 }
542
543 free(p);
544 return 0;
545}
546
547static int str_directory_cb(void *data, const char fio_unused *str)
548{
549 struct thread_data *td = data;
550 struct stat sb;
551
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100552 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100553 int ret = errno;
554
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100555 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100556 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100557 return 1;
558 }
559 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100560 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100561 return 1;
562 }
563
564 return 0;
565}
566
567static int str_opendir_cb(void *data, const char fio_unused *str)
568{
569 struct thread_data *td = data;
570
571 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100572 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100573
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100574 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100575}
576
Jens Axboea59e1702007-07-30 08:53:27 +0200577static int str_verify_offset_cb(void *data, unsigned int *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200578{
579 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200580
Shawn Lewis546a9142007-07-28 21:11:37 +0200581 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200582 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200583 return 1;
584 }
Jens Axboea59e1702007-07-30 08:53:27 +0200585
586 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200587 return 0;
588}
589
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100590static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200591{
592 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100593 long off;
594 int i = 0, j = 0, len, k, base = 10;
595 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200596
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100597 loc1 = strstr(input, "0x");
598 loc2 = strstr(input, "0X");
599 if (loc1 || loc2)
600 base = 16;
601 off = strtol(input, NULL, base);
602 if (off != LONG_MAX || errno != ERANGE) {
603 while (off) {
604 td->o.verify_pattern[i] = off & 0xff;
605 off >>= 8;
606 i++;
607 }
608 } else {
609 len = strlen(input);
610 k = len - 1;
611 if (base == 16) {
612 if (loc1)
613 j = loc1 - input + 2;
614 else
615 j = loc2 - input + 2;
616 } else
617 return 1;
618 if (len - j < MAX_PATTERN_SIZE * 2) {
619 while (k >= j) {
620 off = converthexchartoint(input[k--]);
621 if (k >= j)
622 off += (converthexchartoint(input[k--])
623 * 16);
624 td->o.verify_pattern[i++] = (char) off;
625 }
626 }
627 }
628 td->o.verify_pattern_bytes = i;
Jens Axboe90059d62007-07-30 09:33:12 +0200629 return 0;
630}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100631
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100632static int str_lockfile_cb(void *data, const char *str)
633{
634 struct thread_data *td = data;
635 char *nr = get_opt_postfix(str);
636
637 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100638 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100639 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100640 free(nr);
641 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100642
643 return 0;
644}
645
Jens Axboee3cedca2008-11-19 19:57:52 +0100646static int str_write_bw_log_cb(void *data, const char *str)
647{
648 struct thread_data *td = data;
649
650 if (str)
651 td->o.bw_log_file = strdup(str);
652
653 td->o.write_bw_log = 1;
654 return 0;
655}
656
657static int str_write_lat_log_cb(void *data, const char *str)
658{
659 struct thread_data *td = data;
660
661 if (str)
662 td->o.lat_log_file = strdup(str);
663
664 td->o.write_lat_log = 1;
665 return 0;
666}
667
Jens Axboe993bf482008-11-14 13:04:53 +0100668static int str_gtod_reduce_cb(void *data, int *il)
669{
670 struct thread_data *td = data;
671 int val = *il;
672
673 td->o.disable_clat = !!val;
674 td->o.disable_slat = !!val;
675 td->o.disable_bw = !!val;
676 if (val)
677 td->tv_cache_mask = 63;
678
679 return 0;
680}
681
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100682static int str_gtod_cpu_cb(void *data, int *il)
683{
684 struct thread_data *td = data;
685 int val = *il;
686
687 td->o.gtod_cpu = val;
688 td->o.gtod_offload = 1;
689 return 0;
690}
691
Jens Axboe896cac22009-07-01 10:38:35 +0200692static int rw_verify(struct fio_option *o, void *data)
693{
694 struct thread_data *td = data;
695
696 if (read_only && td_write(td)) {
697 log_err("fio: job <%s> has write bit set, but fio is in"
698 " read-only mode\n", td->o.name);
699 return 1;
700 }
701
702 return 0;
703}
704
Jens Axboe276ca4f2009-07-01 10:43:05 +0200705static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200706{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200707#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200708 struct thread_data *td = data;
709
Jens Axboe29d43ff2009-07-01 10:42:18 +0200710 if (td->o.gtod_cpu) {
711 log_err("fio: platform must support CPU affinity for"
712 "gettimeofday() offloading\n");
713 return 1;
714 }
715#endif
716
717 return 0;
718}
719
Jens Axboe90fef2d2009-07-17 22:33:32 +0200720static int kb_base_verify(struct fio_option *o, void *data)
721{
722 struct thread_data *td = data;
723
724 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
725 log_err("fio: kb_base set to nonsensical value: %u\n",
726 td->o.kb_base);
727 return 1;
728 }
729
730 return 0;
731}
732
Jens Axboe214e1ec2007-03-15 10:48:13 +0100733#define __stringify_1(x) #x
734#define __stringify(x) __stringify_1(x)
735
736/*
737 * Map of job/command line options
738 */
739static struct fio_option options[] = {
740 {
741 .name = "description",
742 .type = FIO_OPT_STR_STORE,
743 .off1 = td_var_offset(description),
744 .help = "Text job description",
745 },
746 {
747 .name = "name",
748 .type = FIO_OPT_STR_STORE,
749 .off1 = td_var_offset(name),
750 .help = "Name of this job",
751 },
752 {
753 .name = "directory",
754 .type = FIO_OPT_STR_STORE,
755 .off1 = td_var_offset(directory),
756 .cb = str_directory_cb,
757 .help = "Directory to store files in",
758 },
759 {
760 .name = "filename",
761 .type = FIO_OPT_STR_STORE,
762 .off1 = td_var_offset(filename),
763 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200764 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100765 .help = "File(s) to use for the workload",
766 },
767 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200768 .name = "kb_base",
769 .type = FIO_OPT_INT,
770 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200771 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200772 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200773 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200774 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200775 },
776 {
Jens Axboe29c13492008-03-01 19:25:20 +0100777 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100778 .type = FIO_OPT_STR,
779 .cb = str_lockfile_cb,
780 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100781 .help = "Lock file when doing IO to it",
782 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100783 .def = "none",
784 .posval = {
785 { .ival = "none",
786 .oval = FILE_LOCK_NONE,
787 .help = "No file locking",
788 },
789 { .ival = "exclusive",
790 .oval = FILE_LOCK_EXCLUSIVE,
791 .help = "Exclusive file lock",
792 },
793 {
794 .ival = "readwrite",
795 .oval = FILE_LOCK_READWRITE,
796 .help = "Read vs write lock",
797 },
798 },
Jens Axboe29c13492008-03-01 19:25:20 +0100799 },
800 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100801 .name = "opendir",
802 .type = FIO_OPT_STR_STORE,
803 .off1 = td_var_offset(opendir),
804 .cb = str_opendir_cb,
805 .help = "Recursively add files from this directory and down",
806 },
807 {
808 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100809 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100810 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100811 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100812 .off1 = td_var_offset(td_ddir),
813 .help = "IO direction",
814 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200815 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100816 .posval = {
817 { .ival = "read",
818 .oval = TD_DDIR_READ,
819 .help = "Sequential read",
820 },
821 { .ival = "write",
822 .oval = TD_DDIR_WRITE,
823 .help = "Sequential write",
824 },
825 { .ival = "randread",
826 .oval = TD_DDIR_RANDREAD,
827 .help = "Random read",
828 },
829 { .ival = "randwrite",
830 .oval = TD_DDIR_RANDWRITE,
831 .help = "Random write",
832 },
833 { .ival = "rw",
834 .oval = TD_DDIR_RW,
835 .help = "Sequential read and write mix",
836 },
837 { .ival = "randrw",
838 .oval = TD_DDIR_RANDRW,
839 .help = "Random read and write mix"
840 },
841 },
842 },
843 {
844 .name = "ioengine",
845 .type = FIO_OPT_STR_STORE,
846 .off1 = td_var_offset(ioengine),
847 .help = "IO engine to use",
848 .def = "sync",
849 .posval = {
850 { .ival = "sync",
851 .help = "Use read/write",
852 },
gurudas paia31041e2007-10-23 15:12:30 +0200853 { .ival = "psync",
854 .help = "Use pread/pwrite",
855 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100856 { .ival = "vsync",
857 .help = "Use readv/writev",
858 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100859#ifdef FIO_HAVE_LIBAIO
860 { .ival = "libaio",
861 .help = "Linux native asynchronous IO",
862 },
863#endif
864#ifdef FIO_HAVE_POSIXAIO
865 { .ival = "posixaio",
866 .help = "POSIX asynchronous IO",
867 },
868#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200869#ifdef FIO_HAVE_SOLARISAIO
870 { .ival = "solarisaio",
871 .help = "Solaris native asynchronous IO",
872 },
873#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100874 { .ival = "mmap",
875 .help = "Memory mapped IO",
876 },
877#ifdef FIO_HAVE_SPLICE
878 { .ival = "splice",
879 .help = "splice/vmsplice based IO",
880 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200881 { .ival = "netsplice",
882 .help = "splice/vmsplice to/from the network",
883 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100884#endif
885#ifdef FIO_HAVE_SGIO
886 { .ival = "sg",
887 .help = "SCSI generic v3 IO",
888 },
889#endif
890 { .ival = "null",
891 .help = "Testing engine (no data transfer)",
892 },
893 { .ival = "net",
894 .help = "Network IO",
895 },
896#ifdef FIO_HAVE_SYSLET
897 { .ival = "syslet-rw",
898 .help = "syslet enabled async pread/pwrite IO",
899 },
900#endif
901 { .ival = "cpuio",
902 .help = "CPU cycler burner engine",
903 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100904#ifdef FIO_HAVE_GUASI
905 { .ival = "guasi",
906 .help = "GUASI IO engine",
907 },
908#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100909 { .ival = "external",
910 .help = "Load external engine (append name)",
911 },
912 },
913 },
914 {
915 .name = "iodepth",
916 .type = FIO_OPT_INT,
917 .off1 = td_var_offset(iodepth),
918 .help = "Amount of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +0100919 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100920 .def = "1",
921 },
922 {
923 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +0200924 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100925 .type = FIO_OPT_INT,
926 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +0100927 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +0200928 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +0100929 .minval = 1,
930 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100931 },
932 {
Jens Axboe49504212008-06-05 09:03:30 +0200933 .name = "iodepth_batch_complete",
934 .type = FIO_OPT_INT,
935 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +0100936 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +0200937 .parent = "iodepth",
938 .minval = 0,
939 .def = "1",
940 },
941 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100942 .name = "iodepth_low",
943 .type = FIO_OPT_INT,
944 .off1 = td_var_offset(iodepth_low),
945 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +0200946 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100947 },
948 {
949 .name = "size",
950 .type = FIO_OPT_STR_VAL,
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100951 .off1 = td_var_offset(size),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200952 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100953 .help = "Total size of device or files",
954 },
955 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100956 .name = "fill_device",
957 .type = FIO_OPT_BOOL,
958 .off1 = td_var_offset(fill_device),
959 .help = "Write until an ENOSPC error occurs",
960 .def = "0",
961 },
962 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100963 .name = "filesize",
964 .type = FIO_OPT_STR_VAL,
965 .off1 = td_var_offset(file_size_low),
966 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200967 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100968 .help = "Size of individual files",
969 },
970 {
Jens Axboe67a10002007-07-31 23:12:16 +0200971 .name = "offset",
972 .alias = "fileoffset",
973 .type = FIO_OPT_STR_VAL,
974 .off1 = td_var_offset(start_offset),
975 .help = "Start IO from this offset",
976 .def = "0",
977 },
978 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100979 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100980 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +0200981 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100982 .off1 = td_var_offset(bs[DDIR_READ]),
983 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200984 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100985 .help = "Block size unit",
986 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +0200987 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100988 },
989 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100990 .name = "ba",
991 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +0200992 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100993 .off1 = td_var_offset(ba[DDIR_READ]),
994 .off2 = td_var_offset(ba[DDIR_WRITE]),
995 .minval = 1,
996 .help = "IO block offset alignment",
997 .parent = "rw",
998 },
999 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001000 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001001 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001002 .type = FIO_OPT_RANGE,
1003 .off1 = td_var_offset(min_bs[DDIR_READ]),
1004 .off2 = td_var_offset(max_bs[DDIR_READ]),
1005 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1006 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001007 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001008 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001009 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001010 },
1011 {
Jens Axboe564ca972007-12-14 12:21:19 +01001012 .name = "bssplit",
1013 .type = FIO_OPT_STR,
1014 .cb = str_bssplit_cb,
1015 .help = "Set a specific mix of block sizes",
1016 .parent = "rw",
1017 },
1018 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001019 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001020 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001021 .type = FIO_OPT_STR_SET,
1022 .off1 = td_var_offset(bs_unaligned),
1023 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001024 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001025 },
1026 {
1027 .name = "randrepeat",
1028 .type = FIO_OPT_BOOL,
1029 .off1 = td_var_offset(rand_repeatable),
1030 .help = "Use repeatable random IO pattern",
1031 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001032 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001033 },
1034 {
1035 .name = "norandommap",
1036 .type = FIO_OPT_STR_SET,
1037 .off1 = td_var_offset(norandommap),
1038 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001039 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001040 },
1041 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001042 .name = "softrandommap",
1043 .type = FIO_OPT_BOOL,
1044 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001045 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001046 .parent = "norandommap",
1047 .def = "0",
1048 },
1049 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001050 .name = "nrfiles",
1051 .type = FIO_OPT_INT,
1052 .off1 = td_var_offset(nr_files),
1053 .help = "Split job workload between this number of files",
1054 .def = "1",
1055 },
1056 {
1057 .name = "openfiles",
1058 .type = FIO_OPT_INT,
1059 .off1 = td_var_offset(open_files),
1060 .help = "Number of files to keep open at the same time",
1061 },
1062 {
1063 .name = "file_service_type",
1064 .type = FIO_OPT_STR,
1065 .cb = str_fst_cb,
1066 .off1 = td_var_offset(file_service_type),
1067 .help = "How to select which file to service next",
1068 .def = "roundrobin",
1069 .posval = {
1070 { .ival = "random",
1071 .oval = FIO_FSERVICE_RANDOM,
1072 .help = "Choose a file at random",
1073 },
1074 { .ival = "roundrobin",
1075 .oval = FIO_FSERVICE_RR,
1076 .help = "Round robin select files",
1077 },
Jens Axboea086c252009-03-04 08:27:37 +01001078 { .ival = "sequential",
1079 .oval = FIO_FSERVICE_SEQ,
1080 .help = "Finish one file before moving to the next",
1081 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001082 },
Jens Axboe67a10002007-07-31 23:12:16 +02001083 .parent = "nrfiles",
1084 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001085#ifdef FIO_HAVE_FALLOCATE
1086 {
1087 .name = "fallocate",
1088 .type = FIO_OPT_BOOL,
1089 .off1 = td_var_offset(fallocate),
1090 .help = "Use fallocate() when laying out files",
1091 .def = "1",
1092 },
1093#endif
Jens Axboe67a10002007-07-31 23:12:16 +02001094 {
1095 .name = "fadvise_hint",
1096 .type = FIO_OPT_BOOL,
1097 .off1 = td_var_offset(fadvise_hint),
1098 .help = "Use fadvise() to advise the kernel on IO pattern",
1099 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001100 },
1101 {
1102 .name = "fsync",
1103 .type = FIO_OPT_INT,
1104 .off1 = td_var_offset(fsync_blocks),
1105 .help = "Issue fsync for writes every given number of blocks",
1106 .def = "0",
1107 },
1108 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001109 .name = "fdatasync",
1110 .type = FIO_OPT_INT,
1111 .off1 = td_var_offset(fdatasync_blocks),
1112 .help = "Issue fdatasync for writes every given number of blocks",
1113 .def = "0",
1114 },
1115 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001116 .name = "direct",
1117 .type = FIO_OPT_BOOL,
1118 .off1 = td_var_offset(odirect),
1119 .help = "Use O_DIRECT IO (negates buffered)",
1120 .def = "0",
1121 },
1122 {
1123 .name = "buffered",
1124 .type = FIO_OPT_BOOL,
1125 .off1 = td_var_offset(odirect),
1126 .neg = 1,
1127 .help = "Use buffered IO (negates direct)",
1128 .def = "1",
1129 },
1130 {
1131 .name = "overwrite",
1132 .type = FIO_OPT_BOOL,
1133 .off1 = td_var_offset(overwrite),
1134 .help = "When writing, set whether to overwrite current data",
1135 .def = "0",
1136 },
1137 {
1138 .name = "loops",
1139 .type = FIO_OPT_INT,
1140 .off1 = td_var_offset(loops),
1141 .help = "Number of times to run the job",
1142 .def = "1",
1143 },
1144 {
1145 .name = "numjobs",
1146 .type = FIO_OPT_INT,
1147 .off1 = td_var_offset(numjobs),
1148 .help = "Duplicate this job this many times",
1149 .def = "1",
1150 },
1151 {
1152 .name = "startdelay",
1153 .type = FIO_OPT_INT,
1154 .off1 = td_var_offset(start_delay),
1155 .help = "Only start job when this period has passed",
1156 .def = "0",
1157 },
1158 {
1159 .name = "runtime",
1160 .alias = "timeout",
1161 .type = FIO_OPT_STR_VAL_TIME,
1162 .off1 = td_var_offset(timeout),
1163 .help = "Stop workload when this amount of time has passed",
1164 .def = "0",
1165 },
1166 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001167 .name = "time_based",
1168 .type = FIO_OPT_STR_SET,
1169 .off1 = td_var_offset(time_based),
1170 .help = "Keep running until runtime/timeout is met",
1171 },
1172 {
Jens Axboe721938a2008-09-10 09:46:16 +02001173 .name = "ramp_time",
1174 .type = FIO_OPT_STR_VAL_TIME,
1175 .off1 = td_var_offset(ramp_time),
1176 .help = "Ramp up time before measuring performance",
1177 },
1178 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001179 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001180 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001181 .type = FIO_OPT_STR,
1182 .cb = str_mem_cb,
1183 .off1 = td_var_offset(mem_type),
1184 .help = "Backing type for IO buffers",
1185 .def = "malloc",
1186 .posval = {
1187 { .ival = "malloc",
1188 .oval = MEM_MALLOC,
1189 .help = "Use malloc(3) for IO buffers",
1190 },
Jens Axboeb370e462007-03-19 10:51:49 +01001191 { .ival = "shm",
1192 .oval = MEM_SHM,
1193 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001194 },
1195#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001196 { .ival = "shmhuge",
1197 .oval = MEM_SHMHUGE,
1198 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001199 },
1200#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001201 { .ival = "mmap",
1202 .oval = MEM_MMAP,
1203 .help = "Use mmap(2) (file or anon) for IO buffers",
1204 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001205#ifdef FIO_HAVE_HUGETLB
1206 { .ival = "mmaphuge",
1207 .oval = MEM_MMAPHUGE,
1208 .help = "Like mmap, but use huge pages",
1209 },
1210#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001211 },
1212 },
1213 {
Jens Axboed529ee12009-07-01 10:33:03 +02001214 .name = "iomem_align",
1215 .alias = "mem_align",
1216 .type = FIO_OPT_INT,
1217 .off1 = td_var_offset(mem_align),
1218 .minval = 0,
1219 .help = "IO memory buffer offset alignment",
1220 .def = "0",
1221 .parent = "iomem",
1222 },
1223 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001224 .name = "verify",
1225 .type = FIO_OPT_STR,
1226 .off1 = td_var_offset(verify),
1227 .help = "Verify data written",
1228 .def = "0",
1229 .posval = {
1230 { .ival = "0",
1231 .oval = VERIFY_NONE,
1232 .help = "Don't do IO verification",
1233 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001234 { .ival = "md5",
1235 .oval = VERIFY_MD5,
1236 .help = "Use md5 checksums for verification",
1237 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001238 { .ival = "crc64",
1239 .oval = VERIFY_CRC64,
1240 .help = "Use crc64 checksums for verification",
1241 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001242 { .ival = "crc32",
1243 .oval = VERIFY_CRC32,
1244 .help = "Use crc32 checksums for verification",
1245 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001246 { .ival = "crc32c-intel",
1247 .oval = VERIFY_CRC32C_INTEL,
1248 .help = "Use hw crc32c checksums for verification",
1249 },
Jens Axboebac39e02008-06-11 20:46:19 +02001250 { .ival = "crc32c",
1251 .oval = VERIFY_CRC32C,
1252 .help = "Use crc32c checksums for verification",
1253 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001254 { .ival = "crc16",
1255 .oval = VERIFY_CRC16,
1256 .help = "Use crc16 checksums for verification",
1257 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001258 { .ival = "crc7",
1259 .oval = VERIFY_CRC7,
1260 .help = "Use crc7 checksums for verification",
1261 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001262 { .ival = "sha1",
1263 .oval = VERIFY_SHA1,
1264 .help = "Use sha1 checksums for verification",
1265 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001266 { .ival = "sha256",
1267 .oval = VERIFY_SHA256,
1268 .help = "Use sha256 checksums for verification",
1269 },
1270 { .ival = "sha512",
1271 .oval = VERIFY_SHA512,
1272 .help = "Use sha512 checksums for verification",
1273 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001274 { .ival = "meta",
1275 .oval = VERIFY_META,
1276 .help = "Use io information",
1277 },
Jens Axboe36690c92007-03-26 10:23:34 +02001278 {
1279 .ival = "null",
1280 .oval = VERIFY_NULL,
1281 .help = "Pretend to verify",
1282 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001283 },
1284 },
1285 {
Jens Axboe005c5652007-08-02 22:21:36 +02001286 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001287 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001288 .off1 = td_var_offset(do_verify),
1289 .help = "Run verification stage after write",
1290 .def = "1",
1291 .parent = "verify",
1292 },
1293 {
Jens Axboe160b9662007-03-27 10:59:49 +02001294 .name = "verifysort",
1295 .type = FIO_OPT_BOOL,
1296 .off1 = td_var_offset(verifysort),
1297 .help = "Sort written verify blocks for read back",
1298 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001299 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001300 },
1301 {
Jens Axboea59e1702007-07-30 08:53:27 +02001302 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001303 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001304 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001305 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001306 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001307 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001308 },
1309 {
Jens Axboea59e1702007-07-30 08:53:27 +02001310 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001311 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001312 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001313 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001314 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001315 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001316 },
1317 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001318 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001319 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001320 .cb = str_verify_pattern_cb,
1321 .help = "Fill pattern for IO buffers",
1322 .parent = "verify",
1323 },
1324 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001325 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001326 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001327 .off1 = td_var_offset(verify_fatal),
1328 .def = "0",
1329 .help = "Exit on a single verify failure, don't continue",
1330 .parent = "verify",
1331 },
1332 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001333 .name = "verify_async",
1334 .type = FIO_OPT_INT,
1335 .off1 = td_var_offset(verify_async),
1336 .def = "0",
1337 .help = "Number of async verifier threads to use",
1338 .parent = "verify",
1339 },
1340#ifdef FIO_HAVE_CPU_AFFINITY
1341 {
1342 .name = "verify_async_cpus",
1343 .type = FIO_OPT_STR,
1344 .cb = str_verify_cpus_allowed_cb,
1345 .help = "Set CPUs allowed for async verify threads",
1346 .parent = "verify_async",
1347 },
1348#endif
1349 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001350 .name = "write_iolog",
1351 .type = FIO_OPT_STR_STORE,
1352 .off1 = td_var_offset(write_iolog_file),
1353 .help = "Store IO pattern to file",
1354 },
1355 {
1356 .name = "read_iolog",
1357 .type = FIO_OPT_STR_STORE,
1358 .off1 = td_var_offset(read_iolog_file),
1359 .help = "Playback IO pattern from file",
1360 },
1361 {
1362 .name = "exec_prerun",
1363 .type = FIO_OPT_STR_STORE,
1364 .off1 = td_var_offset(exec_prerun),
1365 .help = "Execute this file prior to running job",
1366 },
1367 {
1368 .name = "exec_postrun",
1369 .type = FIO_OPT_STR_STORE,
1370 .off1 = td_var_offset(exec_postrun),
1371 .help = "Execute this file after running job",
1372 },
1373#ifdef FIO_HAVE_IOSCHED_SWITCH
1374 {
1375 .name = "ioscheduler",
1376 .type = FIO_OPT_STR_STORE,
1377 .off1 = td_var_offset(ioscheduler),
1378 .help = "Use this IO scheduler on the backing device",
1379 },
1380#endif
1381 {
1382 .name = "zonesize",
1383 .type = FIO_OPT_STR_VAL,
1384 .off1 = td_var_offset(zone_size),
1385 .help = "Give size of an IO zone",
1386 .def = "0",
1387 },
1388 {
1389 .name = "zoneskip",
1390 .type = FIO_OPT_STR_VAL,
1391 .off1 = td_var_offset(zone_skip),
1392 .help = "Space between IO zones",
1393 .def = "0",
1394 },
1395 {
1396 .name = "lockmem",
1397 .type = FIO_OPT_STR_VAL,
1398 .cb = str_lockmem_cb,
1399 .help = "Lock down this amount of memory",
1400 .def = "0",
1401 },
1402 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001403 .name = "rwmixread",
1404 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001405 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001406 .maxval = 100,
1407 .help = "Percentage of mixed workload that is reads",
1408 .def = "50",
1409 },
1410 {
1411 .name = "rwmixwrite",
1412 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001413 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001414 .maxval = 100,
1415 .help = "Percentage of mixed workload that is writes",
1416 .def = "50",
1417 },
1418 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001419 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001420 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001421 },
1422 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001423 .name = "nice",
1424 .type = FIO_OPT_INT,
1425 .off1 = td_var_offset(nice),
1426 .help = "Set job CPU nice value",
1427 .minval = -19,
1428 .maxval = 20,
1429 .def = "0",
1430 },
1431#ifdef FIO_HAVE_IOPRIO
1432 {
1433 .name = "prio",
1434 .type = FIO_OPT_INT,
1435 .cb = str_prio_cb,
1436 .help = "Set job IO priority value",
1437 .minval = 0,
1438 .maxval = 7,
1439 },
1440 {
1441 .name = "prioclass",
1442 .type = FIO_OPT_INT,
1443 .cb = str_prioclass_cb,
1444 .help = "Set job IO priority class",
1445 .minval = 0,
1446 .maxval = 3,
1447 },
1448#endif
1449 {
1450 .name = "thinktime",
1451 .type = FIO_OPT_INT,
1452 .off1 = td_var_offset(thinktime),
1453 .help = "Idle time between IO buffers (usec)",
1454 .def = "0",
1455 },
1456 {
1457 .name = "thinktime_spin",
1458 .type = FIO_OPT_INT,
1459 .off1 = td_var_offset(thinktime_spin),
1460 .help = "Start think time by spinning this amount (usec)",
1461 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001462 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001463 },
1464 {
1465 .name = "thinktime_blocks",
1466 .type = FIO_OPT_INT,
1467 .off1 = td_var_offset(thinktime_blocks),
1468 .help = "IO buffer period between 'thinktime'",
1469 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001470 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001471 },
1472 {
1473 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001474 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001475 .off1 = td_var_offset(rate[0]),
1476 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001477 .help = "Set bandwidth rate",
1478 },
1479 {
1480 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001481 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001482 .off1 = td_var_offset(ratemin[0]),
1483 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001484 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001485 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001486 },
1487 {
1488 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001489 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001490 .off1 = td_var_offset(rate_iops[0]),
1491 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001492 .help = "Limit IO used to this number of IO operations/sec",
1493 },
1494 {
1495 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001496 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001497 .off1 = td_var_offset(rate_iops_min[0]),
1498 .off2 = td_var_offset(rate_iops_min[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001499 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001500 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001501 },
1502 {
1503 .name = "ratecycle",
1504 .type = FIO_OPT_INT,
1505 .off1 = td_var_offset(ratecycle),
1506 .help = "Window average for rate limits (msec)",
1507 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001508 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001509 },
1510 {
1511 .name = "invalidate",
1512 .type = FIO_OPT_BOOL,
1513 .off1 = td_var_offset(invalidate_cache),
1514 .help = "Invalidate buffer/page cache prior to running job",
1515 .def = "1",
1516 },
1517 {
1518 .name = "sync",
1519 .type = FIO_OPT_BOOL,
1520 .off1 = td_var_offset(sync_io),
1521 .help = "Use O_SYNC for buffered writes",
1522 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001523 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001524 },
1525 {
1526 .name = "bwavgtime",
1527 .type = FIO_OPT_INT,
1528 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001529 .help = "Time window over which to calculate bandwidth"
1530 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001531 .def = "500",
1532 },
1533 {
1534 .name = "create_serialize",
1535 .type = FIO_OPT_BOOL,
1536 .off1 = td_var_offset(create_serialize),
1537 .help = "Serialize creating of job files",
1538 .def = "1",
1539 },
1540 {
1541 .name = "create_fsync",
1542 .type = FIO_OPT_BOOL,
1543 .off1 = td_var_offset(create_fsync),
1544 .help = "Fsync file after creation",
1545 .def = "1",
1546 },
1547 {
Jens Axboe814452b2009-03-04 12:53:13 +01001548 .name = "create_on_open",
1549 .type = FIO_OPT_BOOL,
1550 .off1 = td_var_offset(create_on_open),
1551 .help = "Create files when they are opened for IO",
1552 .def = "0",
1553 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001554 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001555 .name = "pre_read",
1556 .type = FIO_OPT_BOOL,
1557 .off1 = td_var_offset(pre_read),
1558 .help = "Preread files before starting official testing",
1559 .def = "0",
1560 },
Jens Axboe814452b2009-03-04 12:53:13 +01001561 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001562 .name = "cpuload",
1563 .type = FIO_OPT_INT,
1564 .off1 = td_var_offset(cpuload),
1565 .help = "Use this percentage of CPU",
1566 },
1567 {
1568 .name = "cpuchunks",
1569 .type = FIO_OPT_INT,
1570 .off1 = td_var_offset(cpucycle),
1571 .help = "Length of the CPU burn cycles (usecs)",
1572 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001573 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001574 },
1575#ifdef FIO_HAVE_CPU_AFFINITY
1576 {
1577 .name = "cpumask",
1578 .type = FIO_OPT_INT,
1579 .cb = str_cpumask_cb,
1580 .help = "CPU affinity mask",
1581 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001582 {
1583 .name = "cpus_allowed",
1584 .type = FIO_OPT_STR,
1585 .cb = str_cpus_allowed_cb,
1586 .help = "Set CPUs allowed",
1587 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001588#endif
1589 {
1590 .name = "end_fsync",
1591 .type = FIO_OPT_BOOL,
1592 .off1 = td_var_offset(end_fsync),
1593 .help = "Include fsync at the end of job",
1594 .def = "0",
1595 },
1596 {
1597 .name = "fsync_on_close",
1598 .type = FIO_OPT_BOOL,
1599 .off1 = td_var_offset(fsync_on_close),
1600 .help = "fsync files on close",
1601 .def = "0",
1602 },
1603 {
1604 .name = "unlink",
1605 .type = FIO_OPT_BOOL,
1606 .off1 = td_var_offset(unlink),
1607 .help = "Unlink created files after job has completed",
1608 .def = "0",
1609 },
1610 {
1611 .name = "exitall",
1612 .type = FIO_OPT_STR_SET,
1613 .cb = str_exitall_cb,
1614 .help = "Terminate all jobs when one exits",
1615 },
1616 {
1617 .name = "stonewall",
1618 .type = FIO_OPT_STR_SET,
1619 .off1 = td_var_offset(stonewall),
1620 .help = "Insert a hard barrier between this job and previous",
1621 },
1622 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001623 .name = "new_group",
1624 .type = FIO_OPT_STR_SET,
1625 .off1 = td_var_offset(new_group),
1626 .help = "Mark the start of a new group (for reporting)",
1627 },
1628 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001629 .name = "thread",
1630 .type = FIO_OPT_STR_SET,
1631 .off1 = td_var_offset(use_thread),
1632 .help = "Use threads instead of forks",
1633 },
1634 {
1635 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001636 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001637 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001638 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001639 .help = "Write log of bandwidth during run",
1640 },
1641 {
1642 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001643 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001644 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001645 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001646 .help = "Write log of latency during run",
1647 },
1648 {
1649 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001650 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001651 .off1 = td_var_offset(hugepage_size),
1652 .help = "When using hugepages, specify size of each page",
1653 .def = __stringify(FIO_HUGE_PAGE),
1654 },
1655 {
1656 .name = "group_reporting",
1657 .type = FIO_OPT_STR_SET,
1658 .off1 = td_var_offset(group_reporting),
1659 .help = "Do reporting on a per-group basis",
1660 },
1661 {
Jens Axboee9459e52007-04-17 15:46:32 +02001662 .name = "zero_buffers",
1663 .type = FIO_OPT_STR_SET,
1664 .off1 = td_var_offset(zero_buffers),
1665 .help = "Init IO buffers to all zeroes",
1666 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001667 {
1668 .name = "refill_buffers",
1669 .type = FIO_OPT_STR_SET,
1670 .off1 = td_var_offset(refill_buffers),
1671 .help = "Refill IO buffers on every IO submit",
1672 },
Jens Axboe0a839f32007-04-26 09:02:34 +02001673#ifdef FIO_HAVE_DISK_UTIL
1674 {
1675 .name = "disk_util",
1676 .type = FIO_OPT_BOOL,
1677 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001678 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02001679 .def = "1",
1680 },
1681#endif
Jens Axboee9459e52007-04-17 15:46:32 +02001682 {
Jens Axboe993bf482008-11-14 13:04:53 +01001683 .name = "gtod_reduce",
1684 .type = FIO_OPT_BOOL,
1685 .help = "Greatly reduce number of gettimeofday() calls",
1686 .cb = str_gtod_reduce_cb,
1687 .def = "0",
1688 },
1689 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02001690 .name = "disable_clat",
1691 .type = FIO_OPT_BOOL,
1692 .off1 = td_var_offset(disable_clat),
1693 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001694 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001695 .def = "0",
1696 },
1697 {
1698 .name = "disable_slat",
1699 .type = FIO_OPT_BOOL,
1700 .off1 = td_var_offset(disable_slat),
1701 .help = "Disable submissionn latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001702 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001703 .def = "0",
1704 },
1705 {
1706 .name = "disable_bw_measurement",
1707 .type = FIO_OPT_BOOL,
1708 .off1 = td_var_offset(disable_bw),
1709 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01001710 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001711 .def = "0",
1712 },
1713 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001714 .name = "gtod_cpu",
1715 .type = FIO_OPT_INT,
1716 .cb = str_gtod_cpu_cb,
1717 .help = "Setup dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02001718 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001719 },
1720 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001721 .name = "continue_on_error",
1722 .type = FIO_OPT_BOOL,
1723 .off1 = td_var_offset(continue_on_error),
1724 .help = "Continue on non-fatal errors during I/O",
1725 .def = "0",
1726 },
1727 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01001728 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01001729 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01001730 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01001731 .help = "Select a specific builtin performance test",
1732 },
1733 {
Jens Axboea696fa22009-12-04 10:05:02 +01001734 .name = "cgroup",
1735 .type = FIO_OPT_STR_STORE,
1736 .off1 = td_var_offset(cgroup),
1737 .help = "Add job to cgroup of this name",
1738 },
1739 {
1740 .name = "cgroup_weight",
1741 .type = FIO_OPT_INT,
1742 .off1 = td_var_offset(cgroup_weight),
1743 .help = "Use given weight for cgroup",
1744 .minval = 100,
1745 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01001746 },
1747 {
Jens Axboee0b0d892009-12-08 10:10:14 +01001748 .name = "uid",
1749 .type = FIO_OPT_INT,
1750 .off1 = td_var_offset(uid),
1751 .help = "Run job with this user ID",
1752 },
1753 {
1754 .name = "gid",
1755 .type = FIO_OPT_INT,
1756 .off1 = td_var_offset(gid),
1757 .help = "Run job with this group ID",
1758 },
1759 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001760 .name = NULL,
1761 },
1762};
1763
1764void fio_options_dup_and_init(struct option *long_options)
1765{
1766 struct fio_option *o;
1767 unsigned int i;
1768
1769 options_init(options);
1770
1771 i = 0;
1772 while (long_options[i].name)
1773 i++;
1774
1775 o = &options[0];
1776 while (o->name) {
Jens Axboe5921e802008-05-30 15:02:38 +02001777 long_options[i].name = (char *) o->name;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001778 long_options[i].val = FIO_GETOPT_JOB;
1779 if (o->type == FIO_OPT_STR_SET)
1780 long_options[i].has_arg = no_argument;
1781 else
1782 long_options[i].has_arg = required_argument;
1783
1784 i++;
1785 o++;
1786 assert(i < FIO_NR_OPTIONS);
1787 }
1788}
1789
Jens Axboe74929ac2009-08-05 11:42:37 +02001790struct fio_keyword {
1791 const char *word;
1792 const char *desc;
1793 char *replace;
1794};
1795
1796static struct fio_keyword fio_keywords[] = {
1797 {
1798 .word = "$pagesize",
1799 .desc = "Page size in the system",
1800 },
1801 {
1802 .word = "$mb_memory",
1803 .desc = "Megabytes of memory online",
1804 },
1805 {
1806 .word = "$ncpus",
1807 .desc = "Number of CPUs online in the system",
1808 },
1809 {
1810 .word = NULL,
1811 },
1812};
1813
1814void fio_keywords_init(void)
1815{
Jens Axboe3b2e1462009-12-15 08:58:10 +01001816 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02001817 char buf[128];
1818 long l;
1819
1820 sprintf(buf, "%lu", page_size);
1821 fio_keywords[0].replace = strdup(buf);
1822
Jens Axboe3b2e1462009-12-15 08:58:10 +01001823 mb_memory = os_phys_mem() / page_size;
1824 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02001825 fio_keywords[1].replace = strdup(buf);
1826
1827 l = sysconf(_SC_NPROCESSORS_ONLN);
1828 sprintf(buf, "%lu", l);
1829 fio_keywords[2].replace = strdup(buf);
1830}
1831
Jens Axboe892a6ff2009-11-13 12:19:49 +01001832#define BC_APP "bc"
1833
1834static char *bc_calc(char *str)
1835{
1836 char *buf, *tmp, opt[80];
1837 FILE *f;
1838 int ret;
1839
1840 /*
1841 * No math, just return string
1842 */
1843 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1844 !strchr(str, '/'))
1845 return str;
1846
1847 /*
1848 * Split option from value, we only need to calculate the value
1849 */
1850 tmp = strchr(str, '=');
1851 if (!tmp)
1852 return str;
1853
1854 tmp++;
Jens Axboe9ac8a792009-11-13 21:23:07 +01001855 memset(opt, 0, sizeof(opt));
Jens Axboe892a6ff2009-11-13 12:19:49 +01001856 strncpy(opt, str, tmp - str);
1857
1858 buf = malloc(128);
1859
1860 sprintf(buf, "which %s > /dev/null", BC_APP);
1861 if (system(buf)) {
1862 log_err("fio: bc is needed for performing math\n");
1863 free(buf);
1864 return NULL;
1865 }
1866
1867 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1868 f = popen(buf, "r");
1869 if (!f) {
1870 free(buf);
1871 return NULL;
1872 }
1873
1874 ret = fread(buf, 1, 128, f);
1875 if (ret <= 0) {
1876 free(buf);
1877 return NULL;
1878 }
1879
1880 buf[ret - 1] = '\0';
1881 strcat(opt, buf);
1882 strcpy(buf, opt);
1883 pclose(f);
1884 free(str);
1885 return buf;
1886}
1887
Jens Axboe74929ac2009-08-05 11:42:37 +02001888/*
1889 * Look for reserved variable names and replace them with real values
1890 */
1891static char *fio_keyword_replace(char *opt)
1892{
1893 char *s;
1894 int i;
1895
1896 for (i = 0; fio_keywords[i].word != NULL; i++) {
1897 struct fio_keyword *kw = &fio_keywords[i];
1898
1899 while ((s = strstr(opt, kw->word)) != NULL) {
1900 char *new = malloc(strlen(opt) + 1);
1901 char *o_org = opt;
1902 int olen = s - opt;
1903 int len;
1904
1905 /*
1906 * Copy part of the string before the keyword and
1907 * sprintf() the replacement after it.
1908 */
1909 memcpy(new, opt, olen);
1910 len = sprintf(new + olen, "%s", kw->replace);
1911
1912 /*
1913 * If there's more in the original string, copy that
1914 * in too
1915 */
1916 opt += strlen(kw->word) + olen;
1917 if (strlen(opt))
1918 memcpy(new + olen + len, opt, opt - o_org - 1);
1919
1920 /*
1921 * replace opt and free the old opt
1922 */
1923 opt = new;
Jens Axboe9ac8a792009-11-13 21:23:07 +01001924 //free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01001925
1926 /*
1927 * Check for potential math and invoke bc, if possible
1928 */
1929 opt = bc_calc(opt);
Jens Axboe74929ac2009-08-05 11:42:37 +02001930 }
1931 }
1932
Jens Axboe7a958bd2009-11-13 12:33:54 +01001933 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02001934}
1935
Jens Axboe3b8b7132008-06-10 19:46:23 +02001936int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01001937{
Jens Axboe3b8b7132008-06-10 19:46:23 +02001938 int i, ret;
1939
1940 sort_options(opts, options, num_opts);
1941
Jens Axboe74929ac2009-08-05 11:42:37 +02001942 for (ret = 0, i = 0; i < num_opts; i++) {
1943 opts[i] = fio_keyword_replace(opts[i]);
Jens Axboe9f988e22010-03-04 10:42:38 +01001944 ret |= parse_option(opts[i], options, &ext_opt_list, td);
Jens Axboe74929ac2009-08-05 11:42:37 +02001945 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02001946
1947 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001948}
1949
1950int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1951{
Jens Axboe9f988e22010-03-04 10:42:38 +01001952 return parse_cmd_option(opt, val, options, &ext_opt_list, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001953}
1954
1955void fio_fill_default_options(struct thread_data *td)
1956{
1957 fill_default_options(td, options);
1958}
1959
1960int fio_show_option_help(const char *opt)
1961{
Jens Axboee2de69d2010-03-04 14:05:48 +01001962 return show_cmd_help(options, &ext_opt_list, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001963}
Jens Axboed23bb322007-03-23 15:57:56 +01001964
1965static void __options_mem(struct thread_data *td, int alloc)
1966{
1967 struct thread_options *o = &td->o;
1968 struct fio_option *opt;
1969 char **ptr;
1970 int i;
1971
1972 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1973 if (opt->type != FIO_OPT_STR_STORE)
1974 continue;
1975
1976 ptr = (void *) o + opt->off1;
1977 if (*ptr) {
1978 if (alloc)
1979 *ptr = strdup(*ptr);
1980 else {
1981 free(*ptr);
1982 *ptr = NULL;
1983 }
1984 }
1985 }
1986}
1987
1988/*
1989 * dupe FIO_OPT_STR_STORE options
1990 */
1991void options_mem_dupe(struct thread_data *td)
1992{
1993 __options_mem(td, 1);
1994}
1995
Jens Axboe22d66212007-03-27 20:06:25 +02001996void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01001997{
Jens Axboe22d66212007-03-27 20:06:25 +02001998#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01001999 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02002000#endif
Jens Axboed23bb322007-03-23 15:57:56 +01002001}
Jens Axboed6978a32009-07-18 21:04:09 +02002002
2003unsigned int fio_get_kb_base(void *data)
2004{
2005 struct thread_data *td = data;
2006 unsigned int kb_base = 0;
2007
2008 if (td)
2009 kb_base = td->o.kb_base;
2010 if (!kb_base)
2011 kb_base = 1024;
2012
2013 return kb_base;
2014}
Jens Axboe9f988e22010-03-04 10:42:38 +01002015
2016void register_ext_option(struct ext_option *eopt)
2017{
2018 dprint(FD_PARSE, "register option '%s'\n", eopt->o.name);
2019 option_init(&eopt->o);
2020 flist_add_tail(&eopt->list, &ext_opt_list);
2021}
Jens Axboee2de69d2010-03-04 14:05:48 +01002022
2023void prune_profile_options(const char *prof_name)
2024{
2025 struct ext_option *eo;
2026 struct flist_head *n, *tmp;
2027
2028 flist_for_each_safe(n, tmp, &ext_opt_list) {
2029 eo = flist_entry(n, struct ext_option, list);
2030 if (strcmp(eo->prof_name, prof_name))
2031 continue;
2032 flist_del(&eo->list);
2033 free(eo);
2034 }
2035}