blob: a45d1af6b7d9f17c316def4b0bfa6d48b515763e [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"
14#include "parse.h"
Jens Axboeeef32352008-06-02 13:31:26 +020015#include "lib/fls.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010016
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010017#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
Jens Axboe214e1ec2007-03-15 10:48:13 +010018
19/*
20 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
21 */
22static char *get_opt_postfix(const char *str)
23{
24 char *p = strstr(str, ":");
25
26 if (!p)
27 return NULL;
28
29 p++;
30 strip_blank_front(&p);
31 strip_blank_end(p);
32 return strdup(p);
33}
34
Jens Axboe564ca972007-12-14 12:21:19 +010035static int bs_cmp(const void *p1, const void *p2)
36{
37 const struct bssplit *bsp1 = p1;
38 const struct bssplit *bsp2 = p2;
39
40 return bsp1->perc < bsp2->perc;
41}
42
Jens Axboe720e84a2009-04-21 08:29:55 +020043static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010044{
Jens Axboe720e84a2009-04-21 08:29:55 +020045 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010046 unsigned int i, perc, perc_missing;
47 unsigned int max_bs, min_bs;
48 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020049 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010050
Jens Axboe720e84a2009-04-21 08:29:55 +020051 td->o.bssplit_nr[ddir] = 4;
52 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010053
54 i = 0;
55 max_bs = 0;
56 min_bs = -1;
57 while ((fname = strsep(&str, ":")) != NULL) {
58 char *perc_str;
59
60 if (!strlen(fname))
61 break;
62
63 /*
64 * grow struct buffer, if needed
65 */
Jens Axboe720e84a2009-04-21 08:29:55 +020066 if (i == td->o.bssplit_nr[ddir]) {
67 td->o.bssplit_nr[ddir] <<= 1;
68 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010069 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010070 }
71
72 perc_str = strstr(fname, "/");
73 if (perc_str) {
74 *perc_str = '\0';
75 perc_str++;
76 perc = atoi(perc_str);
77 if (perc > 100)
78 perc = 100;
79 else if (!perc)
80 perc = -1;
81 } else
82 perc = -1;
83
84 if (str_to_decimal(fname, &val, 1)) {
85 log_err("fio: bssplit conversion failed\n");
86 free(td->o.bssplit);
87 return 1;
88 }
89
90 if (val > max_bs)
91 max_bs = val;
92 if (val < min_bs)
93 min_bs = val;
94
Jens Axboe720e84a2009-04-21 08:29:55 +020095 bssplit[i].bs = val;
96 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +010097 i++;
98 }
99
Jens Axboe720e84a2009-04-21 08:29:55 +0200100 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100101
102 /*
103 * Now check if the percentages add up, and how much is missing
104 */
105 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200106 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
107 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100108
109 if (bsp->perc == (unsigned char) -1)
110 perc_missing++;
111 else
112 perc += bsp->perc;
113 }
114
115 if (perc > 100) {
116 log_err("fio: bssplit percentages add to more than 100%%\n");
Jens Axboe720e84a2009-04-21 08:29:55 +0200117 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100118 return 1;
119 }
120 /*
121 * If values didn't have a percentage set, divide the remains between
122 * them.
123 */
124 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200125 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
126 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100127
128 if (bsp->perc == (unsigned char) -1)
129 bsp->perc = (100 - perc) / perc_missing;
130 }
131 }
132
Jens Axboe720e84a2009-04-21 08:29:55 +0200133 td->o.min_bs[ddir] = min_bs;
134 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100135
136 /*
137 * now sort based on percentages, for ease of lookup
138 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200139 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
140 td->o.bssplit[ddir] = bssplit;
141 return 0;
142
143}
144
145static int str_bssplit_cb(void *data, const char *input)
146{
147 struct thread_data *td = data;
148 char *str, *p, *odir;
149 int ret = 0;
150
151 p = str = strdup(input);
152
153 strip_blank_front(&str);
154 strip_blank_end(str);
155
156 odir = strchr(str, ',');
157 if (odir) {
158 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
159 if (!ret) {
160 *odir = '\0';
161 ret = bssplit_ddir(td, DDIR_READ, str);
162 }
163 } else {
164 char *op;
165
166 op = strdup(str);
167
168 ret = bssplit_ddir(td, DDIR_READ, str);
169 if (!ret)
170 ret = bssplit_ddir(td, DDIR_WRITE, op);
171
172 free(op);
173 }
Jens Axboe564ca972007-12-14 12:21:19 +0100174
175 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200176 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100177}
178
Jens Axboe211097b2007-03-22 18:56:45 +0100179static int str_rw_cb(void *data, const char *str)
180{
181 struct thread_data *td = data;
182 char *nr = get_opt_postfix(str);
183
Jens Axboefafdba32007-03-26 10:09:12 +0200184 td->o.ddir_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100185 if (nr) {
Jens Axboe211097b2007-03-22 18:56:45 +0100186 td->o.ddir_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100187 free(nr);
188 }
Jens Axboe211097b2007-03-22 18:56:45 +0100189
Jens Axboe211097b2007-03-22 18:56:45 +0100190 return 0;
191}
192
Jens Axboe214e1ec2007-03-15 10:48:13 +0100193static int str_mem_cb(void *data, const char *mem)
194{
195 struct thread_data *td = data;
196
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100197 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100198 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100199 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100200 log_err("fio: mmaphuge:/path/to/file\n");
201 return 1;
202 }
203 }
204
205 return 0;
206}
207
208static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
209{
210 mlock_size = *val;
211 return 0;
212}
213
Jens Axboecb499fc2008-05-28 10:33:32 +0200214static int str_rwmix_read_cb(void *data, unsigned int *val)
215{
216 struct thread_data *td = data;
217
218 td->o.rwmix[DDIR_READ] = *val;
219 td->o.rwmix[DDIR_WRITE] = 100 - *val;
220 return 0;
221}
222
223static int str_rwmix_write_cb(void *data, unsigned int *val)
224{
225 struct thread_data *td = data;
226
227 td->o.rwmix[DDIR_WRITE] = *val;
228 td->o.rwmix[DDIR_READ] = 100 - *val;
229 return 0;
230}
231
Jens Axboe214e1ec2007-03-15 10:48:13 +0100232#ifdef FIO_HAVE_IOPRIO
233static int str_prioclass_cb(void *data, unsigned int *val)
234{
235 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200236 unsigned short mask;
237
238 /*
239 * mask off old class bits, str_prio_cb() may have set a default class
240 */
241 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
242 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100243
244 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100245 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100246 return 0;
247}
248
249static int str_prio_cb(void *data, unsigned int *val)
250{
251 struct thread_data *td = data;
252
253 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200254
255 /*
256 * If no class is set, assume BE
257 */
258 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
259 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
260
Jens Axboeac684782007-11-08 08:29:07 +0100261 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100262 return 0;
263}
264#endif
265
266static int str_exitall_cb(void)
267{
268 exitall_on_terminate = 1;
269 return 0;
270}
271
Jens Axboe214e1ec2007-03-15 10:48:13 +0100272#ifdef FIO_HAVE_CPU_AFFINITY
Jens Axboe214e1ec2007-03-15 10:48:13 +0100273static int str_cpumask_cb(void *data, unsigned int *val)
274{
275 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200276 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100277 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100278 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100279
Jens Axboed2ce18b2008-12-12 20:51:40 +0100280 ret = fio_cpuset_init(&td->o.cpumask);
281 if (ret < 0) {
282 log_err("fio: cpuset_init failed\n");
283 td_verror(td, ret, "fio_cpuset_init");
284 return 1;
285 }
286
Jens Axboeb03daaf2008-12-08 20:31:43 +0100287 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
Jens Axboed2e268b2007-06-15 10:33:49 +0200288
Jens Axboe62a72732008-12-08 11:37:01 +0100289 for (i = 0; i < sizeof(int) * 8; i++) {
290 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100291 if (i > max_cpu) {
292 log_err("fio: CPU %d too large (max=%ld)\n", i,
293 max_cpu);
294 return 1;
295 }
Jens Axboe62a72732008-12-08 11:37:01 +0100296 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100297 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100298 }
299 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200300
Jens Axboe375b2692007-05-22 09:13:02 +0200301 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100302 return 0;
303}
304
Jens Axboed2e268b2007-06-15 10:33:49 +0200305static int str_cpus_allowed_cb(void *data, const char *input)
306{
307 struct thread_data *td = data;
308 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100309 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100310 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200311
Jens Axboed2ce18b2008-12-12 20:51:40 +0100312 ret = fio_cpuset_init(&td->o.cpumask);
313 if (ret < 0) {
314 log_err("fio: cpuset_init failed\n");
315 td_verror(td, ret, "fio_cpuset_init");
316 return 1;
317 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200318
319 p = str = strdup(input);
320
321 strip_blank_front(&str);
322 strip_blank_end(str);
323
Jens Axboeb03daaf2008-12-08 20:31:43 +0100324 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
325
Jens Axboed2e268b2007-06-15 10:33:49 +0200326 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100327 char *str2, *cpu2;
328 int icpu, icpu2;
329
Jens Axboed2e268b2007-06-15 10:33:49 +0200330 if (!strlen(cpu))
331 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100332
333 str2 = cpu;
334 icpu2 = -1;
335 while ((cpu2 = strsep(&str2, "-")) != NULL) {
336 if (!strlen(cpu2))
337 break;
338
339 icpu2 = atoi(cpu2);
340 }
341
342 icpu = atoi(cpu);
343 if (icpu2 == -1)
344 icpu2 = icpu;
345 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100346 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100347 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100348 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100349 ret = 1;
350 break;
351 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100352 if (icpu > max_cpu) {
353 log_err("fio: CPU %d too large (max=%ld)\n",
354 icpu, max_cpu);
355 ret = 1;
356 break;
357 }
358
Jens Axboe62a72732008-12-08 11:37:01 +0100359 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100360 fio_cpu_set(&td->o.cpumask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100361 icpu++;
362 }
Jens Axboe19608d62008-12-08 15:03:12 +0100363 if (ret)
364 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200365 }
366
367 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100368 if (!ret)
369 td->o.cpumask_set = 1;
370 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200371}
372#endif
373
Jens Axboe214e1ec2007-03-15 10:48:13 +0100374static int str_fst_cb(void *data, const char *str)
375{
376 struct thread_data *td = data;
377 char *nr = get_opt_postfix(str);
378
379 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100380 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100381 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100382 free(nr);
383 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100384
385 return 0;
386}
387
Jens Axboe921c7662008-03-26 09:17:55 +0100388static int check_dir(struct thread_data *td, char *fname)
389{
390 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200391 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100392
Jens Axboebc838912008-04-07 09:00:54 +0200393 if (td->o.directory) {
394 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200395 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200396 elen = strlen(file);
397 }
398
Jens Axboefcef0b32008-05-26 14:53:24 +0200399 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100400 dir = dirname(file);
401
Jens Axboefcef0b32008-05-26 14:53:24 +0200402#if 0
403 {
404 struct stat sb;
405 /*
406 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
407 * yet, so we can't do this check right here...
408 */
Jens Axboe921c7662008-03-26 09:17:55 +0100409 if (lstat(dir, &sb) < 0) {
410 int ret = errno;
411
412 log_err("fio: %s is not a directory\n", dir);
413 td_verror(td, ret, "lstat");
414 return 1;
415 }
416
417 if (!S_ISDIR(sb.st_mode)) {
418 log_err("fio: %s is not a directory\n", dir);
419 return 1;
420 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200421 }
422#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100423
424 return 0;
425}
426
Jens Axboe214e1ec2007-03-15 10:48:13 +0100427static int str_filename_cb(void *data, const char *input)
428{
429 struct thread_data *td = data;
430 char *fname, *str, *p;
431
432 p = str = strdup(input);
433
434 strip_blank_front(&str);
435 strip_blank_end(str);
436
437 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100438 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100439
440 while ((fname = strsep(&str, ":")) != NULL) {
441 if (!strlen(fname))
442 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100443 if (check_dir(td, fname)) {
444 free(p);
445 return 1;
446 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100447 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100448 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100449 }
450
451 free(p);
452 return 0;
453}
454
455static int str_directory_cb(void *data, const char fio_unused *str)
456{
457 struct thread_data *td = data;
458 struct stat sb;
459
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100460 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100461 int ret = errno;
462
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100463 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100464 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100465 return 1;
466 }
467 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100468 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100469 return 1;
470 }
471
472 return 0;
473}
474
475static int str_opendir_cb(void *data, const char fio_unused *str)
476{
477 struct thread_data *td = data;
478
479 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100480 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100481
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100482 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100483}
484
Jens Axboea59e1702007-07-30 08:53:27 +0200485static int str_verify_offset_cb(void *data, unsigned int *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200486{
487 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200488
Shawn Lewis546a9142007-07-28 21:11:37 +0200489 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200490 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200491 return 1;
492 }
Jens Axboea59e1702007-07-30 08:53:27 +0200493
494 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200495 return 0;
496}
497
Shawn Lewise28218f2008-01-16 11:01:33 +0100498static int str_verify_pattern_cb(void *data, unsigned int *off)
Jens Axboe90059d62007-07-30 09:33:12 +0200499{
500 struct thread_data *td = data;
Shawn Lewise28218f2008-01-16 11:01:33 +0100501 unsigned int msb;
Jens Axboe90059d62007-07-30 09:33:12 +0200502
Jens Axboe3c48c2c2008-06-02 12:22:30 +0200503 msb = __fls(*off);
Jens Axboe90059d62007-07-30 09:33:12 +0200504 if (msb <= 8)
505 td->o.verify_pattern_bytes = 1;
506 else if (msb <= 16)
507 td->o.verify_pattern_bytes = 2;
508 else if (msb <= 24)
509 td->o.verify_pattern_bytes = 3;
510 else
511 td->o.verify_pattern_bytes = 4;
512
Shawn Lewise28218f2008-01-16 11:01:33 +0100513 td->o.verify_pattern = *off;
Jens Axboe90059d62007-07-30 09:33:12 +0200514 return 0;
515}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100516
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100517static int str_lockfile_cb(void *data, const char *str)
518{
519 struct thread_data *td = data;
520 char *nr = get_opt_postfix(str);
521
522 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100523 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100524 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100525 free(nr);
526 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100527
528 return 0;
529}
530
Jens Axboee3cedca2008-11-19 19:57:52 +0100531static int str_write_bw_log_cb(void *data, const char *str)
532{
533 struct thread_data *td = data;
534
535 if (str)
536 td->o.bw_log_file = strdup(str);
537
538 td->o.write_bw_log = 1;
539 return 0;
540}
541
542static int str_write_lat_log_cb(void *data, const char *str)
543{
544 struct thread_data *td = data;
545
546 if (str)
547 td->o.lat_log_file = strdup(str);
548
549 td->o.write_lat_log = 1;
550 return 0;
551}
552
Jens Axboe993bf482008-11-14 13:04:53 +0100553static int str_gtod_reduce_cb(void *data, int *il)
554{
555 struct thread_data *td = data;
556 int val = *il;
557
558 td->o.disable_clat = !!val;
559 td->o.disable_slat = !!val;
560 td->o.disable_bw = !!val;
561 if (val)
562 td->tv_cache_mask = 63;
563
564 return 0;
565}
566
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100567static int str_gtod_cpu_cb(void *data, int *il)
568{
569 struct thread_data *td = data;
570 int val = *il;
571
572 td->o.gtod_cpu = val;
573 td->o.gtod_offload = 1;
574 return 0;
575}
576
Jens Axboe214e1ec2007-03-15 10:48:13 +0100577#define __stringify_1(x) #x
578#define __stringify(x) __stringify_1(x)
579
580/*
581 * Map of job/command line options
582 */
583static struct fio_option options[] = {
584 {
585 .name = "description",
586 .type = FIO_OPT_STR_STORE,
587 .off1 = td_var_offset(description),
588 .help = "Text job description",
589 },
590 {
591 .name = "name",
592 .type = FIO_OPT_STR_STORE,
593 .off1 = td_var_offset(name),
594 .help = "Name of this job",
595 },
596 {
597 .name = "directory",
598 .type = FIO_OPT_STR_STORE,
599 .off1 = td_var_offset(directory),
600 .cb = str_directory_cb,
601 .help = "Directory to store files in",
602 },
603 {
604 .name = "filename",
605 .type = FIO_OPT_STR_STORE,
606 .off1 = td_var_offset(filename),
607 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200608 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100609 .help = "File(s) to use for the workload",
610 },
611 {
Jens Axboe29c13492008-03-01 19:25:20 +0100612 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100613 .type = FIO_OPT_STR,
614 .cb = str_lockfile_cb,
615 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100616 .help = "Lock file when doing IO to it",
617 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100618 .def = "none",
619 .posval = {
620 { .ival = "none",
621 .oval = FILE_LOCK_NONE,
622 .help = "No file locking",
623 },
624 { .ival = "exclusive",
625 .oval = FILE_LOCK_EXCLUSIVE,
626 .help = "Exclusive file lock",
627 },
628 {
629 .ival = "readwrite",
630 .oval = FILE_LOCK_READWRITE,
631 .help = "Read vs write lock",
632 },
633 },
Jens Axboe29c13492008-03-01 19:25:20 +0100634 },
635 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100636 .name = "opendir",
637 .type = FIO_OPT_STR_STORE,
638 .off1 = td_var_offset(opendir),
639 .cb = str_opendir_cb,
640 .help = "Recursively add files from this directory and down",
641 },
642 {
643 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100644 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100645 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100646 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100647 .off1 = td_var_offset(td_ddir),
648 .help = "IO direction",
649 .def = "read",
650 .posval = {
651 { .ival = "read",
652 .oval = TD_DDIR_READ,
653 .help = "Sequential read",
654 },
655 { .ival = "write",
656 .oval = TD_DDIR_WRITE,
657 .help = "Sequential write",
658 },
659 { .ival = "randread",
660 .oval = TD_DDIR_RANDREAD,
661 .help = "Random read",
662 },
663 { .ival = "randwrite",
664 .oval = TD_DDIR_RANDWRITE,
665 .help = "Random write",
666 },
667 { .ival = "rw",
668 .oval = TD_DDIR_RW,
669 .help = "Sequential read and write mix",
670 },
671 { .ival = "randrw",
672 .oval = TD_DDIR_RANDRW,
673 .help = "Random read and write mix"
674 },
675 },
676 },
677 {
678 .name = "ioengine",
679 .type = FIO_OPT_STR_STORE,
680 .off1 = td_var_offset(ioengine),
681 .help = "IO engine to use",
682 .def = "sync",
683 .posval = {
684 { .ival = "sync",
685 .help = "Use read/write",
686 },
gurudas paia31041e2007-10-23 15:12:30 +0200687 { .ival = "psync",
688 .help = "Use pread/pwrite",
689 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100690 { .ival = "vsync",
691 .help = "Use readv/writev",
692 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100693#ifdef FIO_HAVE_LIBAIO
694 { .ival = "libaio",
695 .help = "Linux native asynchronous IO",
696 },
697#endif
698#ifdef FIO_HAVE_POSIXAIO
699 { .ival = "posixaio",
700 .help = "POSIX asynchronous IO",
701 },
702#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200703#ifdef FIO_HAVE_SOLARISAIO
704 { .ival = "solarisaio",
705 .help = "Solaris native asynchronous IO",
706 },
707#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100708 { .ival = "mmap",
709 .help = "Memory mapped IO",
710 },
711#ifdef FIO_HAVE_SPLICE
712 { .ival = "splice",
713 .help = "splice/vmsplice based IO",
714 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200715 { .ival = "netsplice",
716 .help = "splice/vmsplice to/from the network",
717 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100718#endif
719#ifdef FIO_HAVE_SGIO
720 { .ival = "sg",
721 .help = "SCSI generic v3 IO",
722 },
723#endif
724 { .ival = "null",
725 .help = "Testing engine (no data transfer)",
726 },
727 { .ival = "net",
728 .help = "Network IO",
729 },
730#ifdef FIO_HAVE_SYSLET
731 { .ival = "syslet-rw",
732 .help = "syslet enabled async pread/pwrite IO",
733 },
734#endif
735 { .ival = "cpuio",
736 .help = "CPU cycler burner engine",
737 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100738#ifdef FIO_HAVE_GUASI
739 { .ival = "guasi",
740 .help = "GUASI IO engine",
741 },
742#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100743 { .ival = "external",
744 .help = "Load external engine (append name)",
745 },
746 },
747 },
748 {
749 .name = "iodepth",
750 .type = FIO_OPT_INT,
751 .off1 = td_var_offset(iodepth),
752 .help = "Amount of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +0100753 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100754 .def = "1",
755 },
756 {
757 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +0200758 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100759 .type = FIO_OPT_INT,
760 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +0100761 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +0200762 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +0100763 .minval = 1,
764 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100765 },
766 {
Jens Axboe49504212008-06-05 09:03:30 +0200767 .name = "iodepth_batch_complete",
768 .type = FIO_OPT_INT,
769 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +0100770 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +0200771 .parent = "iodepth",
772 .minval = 0,
773 .def = "1",
774 },
775 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100776 .name = "iodepth_low",
777 .type = FIO_OPT_INT,
778 .off1 = td_var_offset(iodepth_low),
779 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +0200780 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100781 },
782 {
783 .name = "size",
784 .type = FIO_OPT_STR_VAL,
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100785 .off1 = td_var_offset(size),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200786 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100787 .help = "Total size of device or files",
788 },
789 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100790 .name = "fill_device",
791 .type = FIO_OPT_BOOL,
792 .off1 = td_var_offset(fill_device),
793 .help = "Write until an ENOSPC error occurs",
794 .def = "0",
795 },
796 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100797 .name = "filesize",
798 .type = FIO_OPT_STR_VAL,
799 .off1 = td_var_offset(file_size_low),
800 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200801 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100802 .help = "Size of individual files",
803 },
804 {
Jens Axboe67a10002007-07-31 23:12:16 +0200805 .name = "offset",
806 .alias = "fileoffset",
807 .type = FIO_OPT_STR_VAL,
808 .off1 = td_var_offset(start_offset),
809 .help = "Start IO from this offset",
810 .def = "0",
811 },
812 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100813 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100814 .alias = "blocksize",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100815 .type = FIO_OPT_STR_VAL_INT,
816 .off1 = td_var_offset(bs[DDIR_READ]),
817 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200818 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100819 .help = "Block size unit",
820 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +0200821 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100822 },
823 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100824 .name = "ba",
825 .alias = "blockalign",
826 .type = FIO_OPT_STR_VAL_INT,
827 .off1 = td_var_offset(ba[DDIR_READ]),
828 .off2 = td_var_offset(ba[DDIR_WRITE]),
829 .minval = 1,
830 .help = "IO block offset alignment",
831 .parent = "rw",
832 },
833 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100834 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100835 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100836 .type = FIO_OPT_RANGE,
837 .off1 = td_var_offset(min_bs[DDIR_READ]),
838 .off2 = td_var_offset(max_bs[DDIR_READ]),
839 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
840 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200841 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100842 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +0200843 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100844 },
845 {
Jens Axboe564ca972007-12-14 12:21:19 +0100846 .name = "bssplit",
847 .type = FIO_OPT_STR,
848 .cb = str_bssplit_cb,
849 .help = "Set a specific mix of block sizes",
850 .parent = "rw",
851 },
852 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100853 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100854 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100855 .type = FIO_OPT_STR_SET,
856 .off1 = td_var_offset(bs_unaligned),
857 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +0200858 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100859 },
860 {
861 .name = "randrepeat",
862 .type = FIO_OPT_BOOL,
863 .off1 = td_var_offset(rand_repeatable),
864 .help = "Use repeatable random IO pattern",
865 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +0200866 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100867 },
868 {
869 .name = "norandommap",
870 .type = FIO_OPT_STR_SET,
871 .off1 = td_var_offset(norandommap),
872 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +0200873 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100874 },
875 {
Jens Axboe2b386d22008-03-26 10:32:57 +0100876 .name = "softrandommap",
877 .type = FIO_OPT_BOOL,
878 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +0200879 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +0100880 .parent = "norandommap",
881 .def = "0",
882 },
883 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100884 .name = "nrfiles",
885 .type = FIO_OPT_INT,
886 .off1 = td_var_offset(nr_files),
887 .help = "Split job workload between this number of files",
888 .def = "1",
889 },
890 {
891 .name = "openfiles",
892 .type = FIO_OPT_INT,
893 .off1 = td_var_offset(open_files),
894 .help = "Number of files to keep open at the same time",
895 },
896 {
897 .name = "file_service_type",
898 .type = FIO_OPT_STR,
899 .cb = str_fst_cb,
900 .off1 = td_var_offset(file_service_type),
901 .help = "How to select which file to service next",
902 .def = "roundrobin",
903 .posval = {
904 { .ival = "random",
905 .oval = FIO_FSERVICE_RANDOM,
906 .help = "Choose a file at random",
907 },
908 { .ival = "roundrobin",
909 .oval = FIO_FSERVICE_RR,
910 .help = "Round robin select files",
911 },
Jens Axboea086c252009-03-04 08:27:37 +0100912 { .ival = "sequential",
913 .oval = FIO_FSERVICE_SEQ,
914 .help = "Finish one file before moving to the next",
915 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100916 },
Jens Axboe67a10002007-07-31 23:12:16 +0200917 .parent = "nrfiles",
918 },
919 {
920 .name = "fadvise_hint",
921 .type = FIO_OPT_BOOL,
922 .off1 = td_var_offset(fadvise_hint),
923 .help = "Use fadvise() to advise the kernel on IO pattern",
924 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100925 },
926 {
927 .name = "fsync",
928 .type = FIO_OPT_INT,
929 .off1 = td_var_offset(fsync_blocks),
930 .help = "Issue fsync for writes every given number of blocks",
931 .def = "0",
932 },
933 {
934 .name = "direct",
935 .type = FIO_OPT_BOOL,
936 .off1 = td_var_offset(odirect),
937 .help = "Use O_DIRECT IO (negates buffered)",
938 .def = "0",
939 },
940 {
941 .name = "buffered",
942 .type = FIO_OPT_BOOL,
943 .off1 = td_var_offset(odirect),
944 .neg = 1,
945 .help = "Use buffered IO (negates direct)",
946 .def = "1",
947 },
948 {
949 .name = "overwrite",
950 .type = FIO_OPT_BOOL,
951 .off1 = td_var_offset(overwrite),
952 .help = "When writing, set whether to overwrite current data",
953 .def = "0",
954 },
955 {
956 .name = "loops",
957 .type = FIO_OPT_INT,
958 .off1 = td_var_offset(loops),
959 .help = "Number of times to run the job",
960 .def = "1",
961 },
962 {
963 .name = "numjobs",
964 .type = FIO_OPT_INT,
965 .off1 = td_var_offset(numjobs),
966 .help = "Duplicate this job this many times",
967 .def = "1",
968 },
969 {
970 .name = "startdelay",
971 .type = FIO_OPT_INT,
972 .off1 = td_var_offset(start_delay),
973 .help = "Only start job when this period has passed",
974 .def = "0",
975 },
976 {
977 .name = "runtime",
978 .alias = "timeout",
979 .type = FIO_OPT_STR_VAL_TIME,
980 .off1 = td_var_offset(timeout),
981 .help = "Stop workload when this amount of time has passed",
982 .def = "0",
983 },
984 {
Jens Axboecf4464c2007-04-17 20:14:42 +0200985 .name = "time_based",
986 .type = FIO_OPT_STR_SET,
987 .off1 = td_var_offset(time_based),
988 .help = "Keep running until runtime/timeout is met",
989 },
990 {
Jens Axboe721938a2008-09-10 09:46:16 +0200991 .name = "ramp_time",
992 .type = FIO_OPT_STR_VAL_TIME,
993 .off1 = td_var_offset(ramp_time),
994 .help = "Ramp up time before measuring performance",
995 },
996 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100997 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100998 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100999 .type = FIO_OPT_STR,
1000 .cb = str_mem_cb,
1001 .off1 = td_var_offset(mem_type),
1002 .help = "Backing type for IO buffers",
1003 .def = "malloc",
1004 .posval = {
1005 { .ival = "malloc",
1006 .oval = MEM_MALLOC,
1007 .help = "Use malloc(3) for IO buffers",
1008 },
Jens Axboeb370e462007-03-19 10:51:49 +01001009 { .ival = "shm",
1010 .oval = MEM_SHM,
1011 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001012 },
1013#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001014 { .ival = "shmhuge",
1015 .oval = MEM_SHMHUGE,
1016 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001017 },
1018#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001019 { .ival = "mmap",
1020 .oval = MEM_MMAP,
1021 .help = "Use mmap(2) (file or anon) for IO buffers",
1022 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001023#ifdef FIO_HAVE_HUGETLB
1024 { .ival = "mmaphuge",
1025 .oval = MEM_MMAPHUGE,
1026 .help = "Like mmap, but use huge pages",
1027 },
1028#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001029 },
1030 },
1031 {
1032 .name = "verify",
1033 .type = FIO_OPT_STR,
1034 .off1 = td_var_offset(verify),
1035 .help = "Verify data written",
1036 .def = "0",
1037 .posval = {
1038 { .ival = "0",
1039 .oval = VERIFY_NONE,
1040 .help = "Don't do IO verification",
1041 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001042 { .ival = "md5",
1043 .oval = VERIFY_MD5,
1044 .help = "Use md5 checksums for verification",
1045 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001046 { .ival = "crc64",
1047 .oval = VERIFY_CRC64,
1048 .help = "Use crc64 checksums for verification",
1049 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001050 { .ival = "crc32",
1051 .oval = VERIFY_CRC32,
1052 .help = "Use crc32 checksums for verification",
1053 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001054 { .ival = "crc32c-intel",
1055 .oval = VERIFY_CRC32C_INTEL,
1056 .help = "Use hw crc32c checksums for verification",
1057 },
Jens Axboebac39e02008-06-11 20:46:19 +02001058 { .ival = "crc32c",
1059 .oval = VERIFY_CRC32C,
1060 .help = "Use crc32c checksums for verification",
1061 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001062 { .ival = "crc16",
1063 .oval = VERIFY_CRC16,
1064 .help = "Use crc16 checksums for verification",
1065 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001066 { .ival = "crc7",
1067 .oval = VERIFY_CRC7,
1068 .help = "Use crc7 checksums for verification",
1069 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001070 { .ival = "sha256",
1071 .oval = VERIFY_SHA256,
1072 .help = "Use sha256 checksums for verification",
1073 },
1074 { .ival = "sha512",
1075 .oval = VERIFY_SHA512,
1076 .help = "Use sha512 checksums for verification",
1077 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001078 { .ival = "meta",
1079 .oval = VERIFY_META,
1080 .help = "Use io information",
1081 },
Jens Axboe36690c92007-03-26 10:23:34 +02001082 {
1083 .ival = "null",
1084 .oval = VERIFY_NULL,
1085 .help = "Pretend to verify",
1086 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001087 },
1088 },
1089 {
Jens Axboe005c5652007-08-02 22:21:36 +02001090 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001091 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001092 .off1 = td_var_offset(do_verify),
1093 .help = "Run verification stage after write",
1094 .def = "1",
1095 .parent = "verify",
1096 },
1097 {
Jens Axboe160b9662007-03-27 10:59:49 +02001098 .name = "verifysort",
1099 .type = FIO_OPT_BOOL,
1100 .off1 = td_var_offset(verifysort),
1101 .help = "Sort written verify blocks for read back",
1102 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001103 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001104 },
1105 {
Jens Axboea59e1702007-07-30 08:53:27 +02001106 .name = "verify_interval",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001107 .type = FIO_OPT_STR_VAL_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001108 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001109 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001110 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001111 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001112 },
1113 {
Jens Axboea59e1702007-07-30 08:53:27 +02001114 .name = "verify_offset",
Shawn Lewis546a9142007-07-28 21:11:37 +02001115 .type = FIO_OPT_STR_VAL_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001116 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001117 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001118 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001119 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001120 },
1121 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001122 .name = "verify_pattern",
1123 .type = FIO_OPT_INT,
1124 .cb = str_verify_pattern_cb,
1125 .help = "Fill pattern for IO buffers",
1126 .parent = "verify",
1127 },
1128 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001129 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001130 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001131 .off1 = td_var_offset(verify_fatal),
1132 .def = "0",
1133 .help = "Exit on a single verify failure, don't continue",
1134 .parent = "verify",
1135 },
1136 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001137 .name = "write_iolog",
1138 .type = FIO_OPT_STR_STORE,
1139 .off1 = td_var_offset(write_iolog_file),
1140 .help = "Store IO pattern to file",
1141 },
1142 {
1143 .name = "read_iolog",
1144 .type = FIO_OPT_STR_STORE,
1145 .off1 = td_var_offset(read_iolog_file),
1146 .help = "Playback IO pattern from file",
1147 },
1148 {
1149 .name = "exec_prerun",
1150 .type = FIO_OPT_STR_STORE,
1151 .off1 = td_var_offset(exec_prerun),
1152 .help = "Execute this file prior to running job",
1153 },
1154 {
1155 .name = "exec_postrun",
1156 .type = FIO_OPT_STR_STORE,
1157 .off1 = td_var_offset(exec_postrun),
1158 .help = "Execute this file after running job",
1159 },
1160#ifdef FIO_HAVE_IOSCHED_SWITCH
1161 {
1162 .name = "ioscheduler",
1163 .type = FIO_OPT_STR_STORE,
1164 .off1 = td_var_offset(ioscheduler),
1165 .help = "Use this IO scheduler on the backing device",
1166 },
1167#endif
1168 {
1169 .name = "zonesize",
1170 .type = FIO_OPT_STR_VAL,
1171 .off1 = td_var_offset(zone_size),
1172 .help = "Give size of an IO zone",
1173 .def = "0",
1174 },
1175 {
1176 .name = "zoneskip",
1177 .type = FIO_OPT_STR_VAL,
1178 .off1 = td_var_offset(zone_skip),
1179 .help = "Space between IO zones",
1180 .def = "0",
1181 },
1182 {
1183 .name = "lockmem",
1184 .type = FIO_OPT_STR_VAL,
1185 .cb = str_lockmem_cb,
1186 .help = "Lock down this amount of memory",
1187 .def = "0",
1188 },
1189 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001190 .name = "rwmixread",
1191 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001192 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001193 .maxval = 100,
1194 .help = "Percentage of mixed workload that is reads",
1195 .def = "50",
1196 },
1197 {
1198 .name = "rwmixwrite",
1199 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001200 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001201 .maxval = 100,
1202 .help = "Percentage of mixed workload that is writes",
1203 .def = "50",
1204 },
1205 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001206 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001207 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001208 },
1209 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001210 .name = "nice",
1211 .type = FIO_OPT_INT,
1212 .off1 = td_var_offset(nice),
1213 .help = "Set job CPU nice value",
1214 .minval = -19,
1215 .maxval = 20,
1216 .def = "0",
1217 },
1218#ifdef FIO_HAVE_IOPRIO
1219 {
1220 .name = "prio",
1221 .type = FIO_OPT_INT,
1222 .cb = str_prio_cb,
1223 .help = "Set job IO priority value",
1224 .minval = 0,
1225 .maxval = 7,
1226 },
1227 {
1228 .name = "prioclass",
1229 .type = FIO_OPT_INT,
1230 .cb = str_prioclass_cb,
1231 .help = "Set job IO priority class",
1232 .minval = 0,
1233 .maxval = 3,
1234 },
1235#endif
1236 {
1237 .name = "thinktime",
1238 .type = FIO_OPT_INT,
1239 .off1 = td_var_offset(thinktime),
1240 .help = "Idle time between IO buffers (usec)",
1241 .def = "0",
1242 },
1243 {
1244 .name = "thinktime_spin",
1245 .type = FIO_OPT_INT,
1246 .off1 = td_var_offset(thinktime_spin),
1247 .help = "Start think time by spinning this amount (usec)",
1248 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001249 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001250 },
1251 {
1252 .name = "thinktime_blocks",
1253 .type = FIO_OPT_INT,
1254 .off1 = td_var_offset(thinktime_blocks),
1255 .help = "IO buffer period between 'thinktime'",
1256 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001257 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001258 },
1259 {
1260 .name = "rate",
1261 .type = FIO_OPT_INT,
1262 .off1 = td_var_offset(rate),
1263 .help = "Set bandwidth rate",
1264 },
1265 {
1266 .name = "ratemin",
1267 .type = FIO_OPT_INT,
1268 .off1 = td_var_offset(ratemin),
Jens Axboe4e991c22007-03-15 11:41:11 +01001269 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001270 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001271 },
1272 {
1273 .name = "rate_iops",
1274 .type = FIO_OPT_INT,
1275 .off1 = td_var_offset(rate_iops),
1276 .help = "Limit IO used to this number of IO operations/sec",
1277 },
1278 {
1279 .name = "rate_iops_min",
1280 .type = FIO_OPT_INT,
1281 .off1 = td_var_offset(rate_iops_min),
1282 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001283 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001284 },
1285 {
1286 .name = "ratecycle",
1287 .type = FIO_OPT_INT,
1288 .off1 = td_var_offset(ratecycle),
1289 .help = "Window average for rate limits (msec)",
1290 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001291 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001292 },
1293 {
1294 .name = "invalidate",
1295 .type = FIO_OPT_BOOL,
1296 .off1 = td_var_offset(invalidate_cache),
1297 .help = "Invalidate buffer/page cache prior to running job",
1298 .def = "1",
1299 },
1300 {
1301 .name = "sync",
1302 .type = FIO_OPT_BOOL,
1303 .off1 = td_var_offset(sync_io),
1304 .help = "Use O_SYNC for buffered writes",
1305 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001306 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001307 },
1308 {
1309 .name = "bwavgtime",
1310 .type = FIO_OPT_INT,
1311 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001312 .help = "Time window over which to calculate bandwidth"
1313 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001314 .def = "500",
1315 },
1316 {
1317 .name = "create_serialize",
1318 .type = FIO_OPT_BOOL,
1319 .off1 = td_var_offset(create_serialize),
1320 .help = "Serialize creating of job files",
1321 .def = "1",
1322 },
1323 {
1324 .name = "create_fsync",
1325 .type = FIO_OPT_BOOL,
1326 .off1 = td_var_offset(create_fsync),
1327 .help = "Fsync file after creation",
1328 .def = "1",
1329 },
1330 {
Jens Axboe814452b2009-03-04 12:53:13 +01001331 .name = "create_on_open",
1332 .type = FIO_OPT_BOOL,
1333 .off1 = td_var_offset(create_on_open),
1334 .help = "Create files when they are opened for IO",
1335 .def = "0",
1336 },
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001337 {
1338 .name = "pre_read",
1339 .type = FIO_OPT_BOOL,
1340 .off1 = td_var_offset(pre_read),
1341 .help = "Preread files before starting official testing",
1342 .def = "0",
1343 },
Jens Axboe814452b2009-03-04 12:53:13 +01001344 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001345 .name = "cpuload",
1346 .type = FIO_OPT_INT,
1347 .off1 = td_var_offset(cpuload),
1348 .help = "Use this percentage of CPU",
1349 },
1350 {
1351 .name = "cpuchunks",
1352 .type = FIO_OPT_INT,
1353 .off1 = td_var_offset(cpucycle),
1354 .help = "Length of the CPU burn cycles (usecs)",
1355 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001356 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001357 },
1358#ifdef FIO_HAVE_CPU_AFFINITY
1359 {
1360 .name = "cpumask",
1361 .type = FIO_OPT_INT,
1362 .cb = str_cpumask_cb,
1363 .help = "CPU affinity mask",
1364 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001365 {
1366 .name = "cpus_allowed",
1367 .type = FIO_OPT_STR,
1368 .cb = str_cpus_allowed_cb,
1369 .help = "Set CPUs allowed",
1370 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001371#endif
1372 {
1373 .name = "end_fsync",
1374 .type = FIO_OPT_BOOL,
1375 .off1 = td_var_offset(end_fsync),
1376 .help = "Include fsync at the end of job",
1377 .def = "0",
1378 },
1379 {
1380 .name = "fsync_on_close",
1381 .type = FIO_OPT_BOOL,
1382 .off1 = td_var_offset(fsync_on_close),
1383 .help = "fsync files on close",
1384 .def = "0",
1385 },
1386 {
1387 .name = "unlink",
1388 .type = FIO_OPT_BOOL,
1389 .off1 = td_var_offset(unlink),
1390 .help = "Unlink created files after job has completed",
1391 .def = "0",
1392 },
1393 {
1394 .name = "exitall",
1395 .type = FIO_OPT_STR_SET,
1396 .cb = str_exitall_cb,
1397 .help = "Terminate all jobs when one exits",
1398 },
1399 {
1400 .name = "stonewall",
1401 .type = FIO_OPT_STR_SET,
1402 .off1 = td_var_offset(stonewall),
1403 .help = "Insert a hard barrier between this job and previous",
1404 },
1405 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001406 .name = "new_group",
1407 .type = FIO_OPT_STR_SET,
1408 .off1 = td_var_offset(new_group),
1409 .help = "Mark the start of a new group (for reporting)",
1410 },
1411 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001412 .name = "thread",
1413 .type = FIO_OPT_STR_SET,
1414 .off1 = td_var_offset(use_thread),
1415 .help = "Use threads instead of forks",
1416 },
1417 {
1418 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001419 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001420 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001421 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001422 .help = "Write log of bandwidth during run",
1423 },
1424 {
1425 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001426 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001427 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001428 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001429 .help = "Write log of latency during run",
1430 },
1431 {
1432 .name = "hugepage-size",
Aaron Carroll357f6182008-02-20 09:14:13 +01001433 .type = FIO_OPT_STR_VAL_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001434 .off1 = td_var_offset(hugepage_size),
1435 .help = "When using hugepages, specify size of each page",
1436 .def = __stringify(FIO_HUGE_PAGE),
1437 },
1438 {
1439 .name = "group_reporting",
1440 .type = FIO_OPT_STR_SET,
1441 .off1 = td_var_offset(group_reporting),
1442 .help = "Do reporting on a per-group basis",
1443 },
1444 {
Jens Axboee9459e52007-04-17 15:46:32 +02001445 .name = "zero_buffers",
1446 .type = FIO_OPT_STR_SET,
1447 .off1 = td_var_offset(zero_buffers),
1448 .help = "Init IO buffers to all zeroes",
1449 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001450 {
1451 .name = "refill_buffers",
1452 .type = FIO_OPT_STR_SET,
1453 .off1 = td_var_offset(refill_buffers),
1454 .help = "Refill IO buffers on every IO submit",
1455 },
Jens Axboe0a839f32007-04-26 09:02:34 +02001456#ifdef FIO_HAVE_DISK_UTIL
1457 {
1458 .name = "disk_util",
1459 .type = FIO_OPT_BOOL,
1460 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001461 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02001462 .def = "1",
1463 },
1464#endif
Jens Axboee9459e52007-04-17 15:46:32 +02001465 {
Jens Axboe993bf482008-11-14 13:04:53 +01001466 .name = "gtod_reduce",
1467 .type = FIO_OPT_BOOL,
1468 .help = "Greatly reduce number of gettimeofday() calls",
1469 .cb = str_gtod_reduce_cb,
1470 .def = "0",
1471 },
1472 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02001473 .name = "disable_clat",
1474 .type = FIO_OPT_BOOL,
1475 .off1 = td_var_offset(disable_clat),
1476 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001477 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001478 .def = "0",
1479 },
1480 {
1481 .name = "disable_slat",
1482 .type = FIO_OPT_BOOL,
1483 .off1 = td_var_offset(disable_slat),
1484 .help = "Disable submissionn latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001485 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001486 .def = "0",
1487 },
1488 {
1489 .name = "disable_bw_measurement",
1490 .type = FIO_OPT_BOOL,
1491 .off1 = td_var_offset(disable_bw),
1492 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01001493 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001494 .def = "0",
1495 },
1496 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001497 .name = "gtod_cpu",
1498 .type = FIO_OPT_INT,
1499 .cb = str_gtod_cpu_cb,
1500 .help = "Setup dedicated gettimeofday() thread on this CPU",
1501 },
1502 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001503 .name = NULL,
1504 },
1505};
1506
1507void fio_options_dup_and_init(struct option *long_options)
1508{
1509 struct fio_option *o;
1510 unsigned int i;
1511
1512 options_init(options);
1513
1514 i = 0;
1515 while (long_options[i].name)
1516 i++;
1517
1518 o = &options[0];
1519 while (o->name) {
Jens Axboe5921e802008-05-30 15:02:38 +02001520 long_options[i].name = (char *) o->name;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001521 long_options[i].val = FIO_GETOPT_JOB;
1522 if (o->type == FIO_OPT_STR_SET)
1523 long_options[i].has_arg = no_argument;
1524 else
1525 long_options[i].has_arg = required_argument;
1526
1527 i++;
1528 o++;
1529 assert(i < FIO_NR_OPTIONS);
1530 }
1531}
1532
Jens Axboe3b8b7132008-06-10 19:46:23 +02001533int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01001534{
Jens Axboe3b8b7132008-06-10 19:46:23 +02001535 int i, ret;
1536
1537 sort_options(opts, options, num_opts);
1538
1539 for (ret = 0, i = 0; i < num_opts; i++)
1540 ret |= parse_option(opts[i], options, td);
1541
1542 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001543}
1544
1545int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1546{
1547 return parse_cmd_option(opt, val, options, td);
1548}
1549
1550void fio_fill_default_options(struct thread_data *td)
1551{
1552 fill_default_options(td, options);
1553}
1554
1555int fio_show_option_help(const char *opt)
1556{
1557 return show_cmd_help(options, opt);
1558}
Jens Axboed23bb322007-03-23 15:57:56 +01001559
1560static void __options_mem(struct thread_data *td, int alloc)
1561{
1562 struct thread_options *o = &td->o;
1563 struct fio_option *opt;
1564 char **ptr;
1565 int i;
1566
1567 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1568 if (opt->type != FIO_OPT_STR_STORE)
1569 continue;
1570
1571 ptr = (void *) o + opt->off1;
1572 if (*ptr) {
1573 if (alloc)
1574 *ptr = strdup(*ptr);
1575 else {
1576 free(*ptr);
1577 *ptr = NULL;
1578 }
1579 }
1580 }
1581}
1582
1583/*
1584 * dupe FIO_OPT_STR_STORE options
1585 */
1586void options_mem_dupe(struct thread_data *td)
1587{
1588 __options_mem(td, 1);
1589}
1590
Jens Axboe22d66212007-03-27 20:06:25 +02001591void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01001592{
Jens Axboe22d66212007-03-27 20:06:25 +02001593#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01001594 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02001595#endif
Jens Axboed23bb322007-03-23 15:57:56 +01001596}