blob: ba932bf369ce2ab3ffe3b838d18f09c4cf4b4f47 [file] [log] [blame]
Jens Axboe906c8d72006-06-13 09:37:56 +02001/*
Jens Axboecb2c86f2006-10-26 13:48:34 +02002 * This file contains job initialization and setup functions.
Jens Axboe906c8d72006-06-13 09:37:56 +02003 */
Jens Axboeebac4652005-12-08 15:25:21 +01004#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <ctype.h>
9#include <string.h>
10#include <errno.h>
Jens Axboeb4692822006-10-27 13:43:22 +020011#include <getopt.h>
12#include <assert.h>
Jens Axboeebac4652005-12-08 15:25:21 +010013#include <sys/ipc.h>
14#include <sys/shm.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17
18#include "fio.h"
Jens Axboecb2c86f2006-10-26 13:48:34 +020019#include "parse.h"
Jens Axboeebac4652005-12-08 15:25:21 +010020
Jens Axboeee738492007-01-10 11:23:16 +010021#define FIO_RANDSEED (0xb1899bedUL)
Jens Axboeebac4652005-12-08 15:25:21 +010022
Jens Axboee1f36502006-10-27 10:54:08 +020023#define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
24
Jens Axboeb4692822006-10-27 13:43:22 +020025static int str_mem_cb(void *, const char *);
Jens Axboee1f36502006-10-27 10:54:08 +020026static int str_lockmem_cb(void *, unsigned long *);
Jens Axboe34cfcda2006-11-03 14:00:45 +010027#ifdef FIO_HAVE_IOPRIO
Jens Axboee1f36502006-10-27 10:54:08 +020028static int str_prio_cb(void *, unsigned int *);
29static int str_prioclass_cb(void *, unsigned int *);
Jens Axboe34cfcda2006-11-03 14:00:45 +010030#endif
Jens Axboee1f36502006-10-27 10:54:08 +020031static int str_exitall_cb(void);
32static int str_cpumask_cb(void *, unsigned int *);
Jens Axboe1907dbc2007-03-12 11:44:28 +010033static int str_fst_cb(void *, const char *);
Jens Axboeaf52b342007-03-13 10:07:47 +010034static int str_filename_cb(void *, const char *);
35static int str_directory_cb(void *, const char *);
Jens Axboee1f36502006-10-27 10:54:08 +020036
Jens Axboeee738492007-01-10 11:23:16 +010037#define __stringify_1(x) #x
38#define __stringify(x) __stringify_1(x)
39
Jens Axboee1f36502006-10-27 10:54:08 +020040/*
41 * Map of job/command line options
42 */
43static struct fio_option options[] = {
44 {
Jens Axboe61697c32007-02-05 15:04:46 +010045 .name = "description",
46 .type = FIO_OPT_STR_STORE,
47 .off1 = td_var_offset(description),
48 .help = "Text job description",
49 },
50 {
Jens Axboee1f36502006-10-27 10:54:08 +020051 .name = "name",
52 .type = FIO_OPT_STR_STORE,
53 .off1 = td_var_offset(name),
Jens Axboefd28ca42007-01-09 21:20:13 +010054 .help = "Name of this job",
Jens Axboee1f36502006-10-27 10:54:08 +020055 },
56 {
57 .name = "directory",
58 .type = FIO_OPT_STR_STORE,
59 .off1 = td_var_offset(directory),
Jens Axboeaf52b342007-03-13 10:07:47 +010060 .cb = str_directory_cb,
Jens Axboefd28ca42007-01-09 21:20:13 +010061 .help = "Directory to store files in",
Jens Axboee1f36502006-10-27 10:54:08 +020062 },
63 {
64 .name = "filename",
65 .type = FIO_OPT_STR_STORE,
66 .off1 = td_var_offset(filename),
Jens Axboeaf52b342007-03-13 10:07:47 +010067 .cb = str_filename_cb,
68 .help = "File(s) to use for the workload",
Jens Axboee1f36502006-10-27 10:54:08 +020069 },
70 {
71 .name = "rw",
72 .type = FIO_OPT_STR,
Jens Axboeb1ec1da2007-02-23 10:29:16 +010073 .off1 = td_var_offset(td_ddir),
Jens Axboe15f79182007-01-10 12:26:18 +010074 .help = "IO direction",
Jens Axboeee738492007-01-10 11:23:16 +010075 .def = "read",
Jens Axboeb1ec1da2007-02-23 10:29:16 +010076 .posval = {
77 { .ival = "read", .oval = TD_DDIR_READ },
78 { .ival = "write", .oval = TD_DDIR_WRITE },
79 { .ival = "randread", .oval = TD_DDIR_RANDREAD },
80 { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE },
81 { .ival = "rw", .oval = TD_DDIR_RW },
82 { .ival = "randrw", .oval = TD_DDIR_RANDRW },
83 },
Jens Axboee1f36502006-10-27 10:54:08 +020084 },
85 {
86 .name = "ioengine",
Jens Axboe09629a92007-03-09 09:00:06 +010087 .type = FIO_OPT_STR_STORE,
88 .off1 = td_var_offset(ioengine),
Jens Axboe15f79182007-01-10 12:26:18 +010089 .help = "IO engine to use",
Jens Axboeee738492007-01-10 11:23:16 +010090 .def = "sync",
Jens Axboeb1ec1da2007-02-23 10:29:16 +010091 .posval = {
Jens Axboe10cad1a2007-02-23 11:23:03 +010092 { .ival = "sync", },
93#ifdef FIO_HAVE_LIBAIO
94 { .ival = "libaio", },
95#endif
96#ifdef FIO_HAVE_POSIXAIO
97 { .ival = "posixaio", },
98#endif
99 { .ival = "mmap", },
100#ifdef FIO_HAVE_SPLICE
101 { .ival = "splice", },
102#endif
103#ifdef FIO_HAVE_SGIO
104 { .ival = "sg", },
105#endif
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100106 { .ival = "null", }, { .ival = "net", },
Jens Axboe10cad1a2007-02-23 11:23:03 +0100107#ifdef FIO_HAVE_SYSLET
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100108 { .ival = "syslet-rw", },
Jens Axboe10cad1a2007-02-23 11:23:03 +0100109#endif
Jens Axboeba0fbe12007-03-09 14:34:23 +0100110 { .ival = "cpuio", },
Joel Becker7b395ca2007-02-28 11:10:58 +0100111 { .ival = "external", },
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100112 },
Jens Axboee1f36502006-10-27 10:54:08 +0200113 },
114 {
Jens Axboe03b74b32007-01-11 11:04:31 +0100115 .name = "iodepth",
116 .type = FIO_OPT_INT,
117 .off1 = td_var_offset(iodepth),
118 .help = "Amount of IO buffers to keep in flight",
119 .def = "1",
120 },
121 {
Jens Axboecb5ab512007-02-26 12:57:09 +0100122 .name = "iodepth_batch",
123 .type = FIO_OPT_INT,
124 .off1 = td_var_offset(iodepth_batch),
125 .help = "Number of IO to submit in one go",
126 },
127 {
Jens Axboee916b392007-02-20 14:37:26 +0100128 .name = "iodepth_low",
129 .type = FIO_OPT_INT,
130 .off1 = td_var_offset(iodepth_low),
131 .help = "Low water mark for queuing depth",
132 },
133 {
Jens Axboe03b74b32007-01-11 11:04:31 +0100134 .name = "size",
135 .type = FIO_OPT_STR_VAL,
136 .off1 = td_var_offset(total_file_size),
137 .help = "Size of device or file",
138 },
139 {
140 .name = "bs",
141 .type = FIO_OPT_STR_VAL_INT,
142 .off1 = td_var_offset(bs[DDIR_READ]),
143 .off2 = td_var_offset(bs[DDIR_WRITE]),
144 .help = "Block size unit",
145 .def = "4k",
146 },
147 {
148 .name = "bsrange",
149 .type = FIO_OPT_RANGE,
150 .off1 = td_var_offset(min_bs[DDIR_READ]),
151 .off2 = td_var_offset(max_bs[DDIR_READ]),
152 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
153 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
154 .help = "Set block size range (in more detail than bs)",
155 },
156 {
157 .name = "bs_unaligned",
158 .type = FIO_OPT_STR_SET,
159 .off1 = td_var_offset(bs_unaligned),
160 .help = "Don't sector align IO buffer sizes",
161 },
162 {
163 .name = "offset",
164 .type = FIO_OPT_STR_VAL,
165 .off1 = td_var_offset(start_offset),
166 .help = "Start IO from this offset",
167 .def = "0",
168 },
169 {
170 .name = "randrepeat",
171 .type = FIO_OPT_BOOL,
172 .off1 = td_var_offset(rand_repeatable),
173 .help = "Use repeatable random IO pattern",
174 .def = "1",
175 },
176 {
177 .name = "norandommap",
178 .type = FIO_OPT_STR_SET,
179 .off1 = td_var_offset(norandommap),
180 .help = "Accept potential duplicate random blocks",
181 },
182 {
183 .name = "nrfiles",
184 .type = FIO_OPT_INT,
185 .off1 = td_var_offset(nr_files),
186 .help = "Split job workload between this number of files",
187 .def = "1",
188 },
189 {
Jens Axboeb5af8292007-03-08 12:43:13 +0100190 .name = "openfiles",
191 .type = FIO_OPT_INT,
192 .off1 = td_var_offset(open_files),
193 .help = "Number of files to keep open at the same time",
194 },
195 {
Jens Axboe0aabe162007-02-23 08:45:55 +0100196 .name = "file_service_type",
197 .type = FIO_OPT_STR,
Jens Axboe1907dbc2007-03-12 11:44:28 +0100198 .cb = str_fst_cb,
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100199 .off1 = td_var_offset(file_service_type),
Jens Axboe0aabe162007-02-23 08:45:55 +0100200 .help = "How to select which file to service next",
201 .def = "roundrobin",
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100202 .posval = {
203 { .ival = "random", .oval = FIO_FSERVICE_RANDOM },
204 { .ival = "roundrobin", .oval = FIO_FSERVICE_RR },
205 },
Jens Axboe0aabe162007-02-23 08:45:55 +0100206 },
207 {
Jens Axboe03b74b32007-01-11 11:04:31 +0100208 .name = "fsync",
209 .type = FIO_OPT_INT,
210 .off1 = td_var_offset(fsync_blocks),
211 .help = "Issue fsync for writes every given number of blocks",
212 .def = "0",
213 },
214 {
215 .name = "direct",
216 .type = FIO_OPT_BOOL,
217 .off1 = td_var_offset(odirect),
Jens Axboe76a43db2007-01-11 13:24:44 +0100218 .help = "Use O_DIRECT IO (negates buffered)",
219 .def = "0",
220 },
221 {
222 .name = "buffered",
223 .type = FIO_OPT_BOOL,
224 .off1 = td_var_offset(odirect),
225 .neg = 1,
226 .help = "Use buffered IO (negates direct)",
Jens Axboe03b74b32007-01-11 11:04:31 +0100227 .def = "1",
228 },
229 {
230 .name = "overwrite",
231 .type = FIO_OPT_BOOL,
232 .off1 = td_var_offset(overwrite),
233 .help = "When writing, set whether to overwrite current data",
234 .def = "0",
235 },
236 {
237 .name = "loops",
238 .type = FIO_OPT_INT,
239 .off1 = td_var_offset(loops),
240 .help = "Number of times to run the job",
241 .def = "1",
242 },
243 {
244 .name = "numjobs",
245 .type = FIO_OPT_INT,
246 .off1 = td_var_offset(numjobs),
247 .help = "Duplicate this job this many times",
248 .def = "1",
249 },
250 {
251 .name = "startdelay",
252 .type = FIO_OPT_INT,
253 .off1 = td_var_offset(start_delay),
254 .help = "Only start job when this period has passed",
255 .def = "0",
256 },
257 {
258 .name = "runtime",
259 .alias = "timeout",
260 .type = FIO_OPT_STR_VAL_TIME,
261 .off1 = td_var_offset(timeout),
262 .help = "Stop workload when this amount of time has passed",
263 .def = "0",
264 },
265 {
Jens Axboee1f36502006-10-27 10:54:08 +0200266 .name = "mem",
267 .type = FIO_OPT_STR,
268 .cb = str_mem_cb,
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100269 .off1 = td_var_offset(mem_type),
Jens Axboe15f79182007-01-10 12:26:18 +0100270 .help = "Backing type for IO buffers",
Jens Axboeee738492007-01-10 11:23:16 +0100271 .def = "malloc",
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100272 .posval = {
273 { .ival = "malloc", .oval = MEM_MALLOC },
274 { .ival = "shm", .oval = MEM_SHM },
275#ifdef FIO_HAVE_HUGETLB
276 { .ival = "shmhuge", .oval = MEM_SHMHUGE },
277#endif
278 { .ival = "mmap", .oval = MEM_MMAP },
279#ifdef FIO_HAVE_HUGETLB
280 { .ival = "mmaphuge", .oval = MEM_MMAPHUGE },
281#endif
282 },
Jens Axboee1f36502006-10-27 10:54:08 +0200283 },
284 {
285 .name = "verify",
286 .type = FIO_OPT_STR,
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100287 .off1 = td_var_offset(verify),
Jens Axboe15f79182007-01-10 12:26:18 +0100288 .help = "Verify sum function",
Jens Axboeee738492007-01-10 11:23:16 +0100289 .def = "0",
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100290 .posval = {
291 { .ival = "0", .oval = VERIFY_NONE },
292 { .ival = "crc32", .oval = VERIFY_CRC32 },
293 { .ival = "md5", .oval = VERIFY_MD5 },
294 },
Jens Axboee1f36502006-10-27 10:54:08 +0200295 },
296 {
297 .name = "write_iolog",
Jens Axboe076efc72006-10-27 11:24:25 +0200298 .type = FIO_OPT_STR_STORE,
299 .off1 = td_var_offset(write_iolog_file),
Jens Axboefd28ca42007-01-09 21:20:13 +0100300 .help = "Store IO pattern to file",
Jens Axboee1f36502006-10-27 10:54:08 +0200301 },
302 {
Jens Axboe076efc72006-10-27 11:24:25 +0200303 .name = "read_iolog",
Jens Axboee1f36502006-10-27 10:54:08 +0200304 .type = FIO_OPT_STR_STORE,
Jens Axboe076efc72006-10-27 11:24:25 +0200305 .off1 = td_var_offset(read_iolog_file),
Jens Axboefd28ca42007-01-09 21:20:13 +0100306 .help = "Playback IO pattern from file",
Jens Axboee1f36502006-10-27 10:54:08 +0200307 },
308 {
309 .name = "exec_prerun",
310 .type = FIO_OPT_STR_STORE,
311 .off1 = td_var_offset(exec_prerun),
Jens Axboefd28ca42007-01-09 21:20:13 +0100312 .help = "Execute this file prior to running job",
Jens Axboee1f36502006-10-27 10:54:08 +0200313 },
314 {
315 .name = "exec_postrun",
316 .type = FIO_OPT_STR_STORE,
317 .off1 = td_var_offset(exec_postrun),
Jens Axboefd28ca42007-01-09 21:20:13 +0100318 .help = "Execute this file after running job",
Jens Axboee1f36502006-10-27 10:54:08 +0200319 },
320#ifdef FIO_HAVE_IOSCHED_SWITCH
321 {
322 .name = "ioscheduler",
323 .type = FIO_OPT_STR_STORE,
324 .off1 = td_var_offset(ioscheduler),
Jens Axboefd28ca42007-01-09 21:20:13 +0100325 .help = "Use this IO scheduler on the backing device",
Jens Axboee1f36502006-10-27 10:54:08 +0200326 },
327#endif
328 {
Jens Axboee1f36502006-10-27 10:54:08 +0200329 .name = "zonesize",
330 .type = FIO_OPT_STR_VAL,
331 .off1 = td_var_offset(zone_size),
Jens Axboefd28ca42007-01-09 21:20:13 +0100332 .help = "Give size of an IO zone",
Jens Axboeee738492007-01-10 11:23:16 +0100333 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200334 },
335 {
336 .name = "zoneskip",
337 .type = FIO_OPT_STR_VAL,
338 .off1 = td_var_offset(zone_skip),
Jens Axboefd28ca42007-01-09 21:20:13 +0100339 .help = "Space between IO zones",
Jens Axboeee738492007-01-10 11:23:16 +0100340 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200341 },
342 {
343 .name = "lockmem",
344 .type = FIO_OPT_STR_VAL,
345 .cb = str_lockmem_cb,
Jens Axboefd28ca42007-01-09 21:20:13 +0100346 .help = "Lock down this amount of memory",
Jens Axboeee738492007-01-10 11:23:16 +0100347 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200348 },
349 {
Jens Axboee1f36502006-10-27 10:54:08 +0200350 .name = "rwmixcycle",
351 .type = FIO_OPT_INT,
352 .off1 = td_var_offset(rwmixcycle),
Jens Axboeee738492007-01-10 11:23:16 +0100353 .help = "Cycle period for mixed read/write workloads (msec)",
354 .def = "500",
Jens Axboee1f36502006-10-27 10:54:08 +0200355 },
356 {
357 .name = "rwmixread",
358 .type = FIO_OPT_INT,
359 .off1 = td_var_offset(rwmixread),
Jens Axboeee738492007-01-10 11:23:16 +0100360 .maxval = 100,
Jens Axboefd28ca42007-01-09 21:20:13 +0100361 .help = "Percentage of mixed workload that is reads",
Jens Axboeee738492007-01-10 11:23:16 +0100362 .def = "50",
Jens Axboee1f36502006-10-27 10:54:08 +0200363 },
364 {
365 .name = "rwmixwrite",
366 .type = FIO_OPT_INT,
367 .off1 = td_var_offset(rwmixwrite),
Jens Axboeee738492007-01-10 11:23:16 +0100368 .maxval = 100,
Jens Axboefd28ca42007-01-09 21:20:13 +0100369 .help = "Percentage of mixed workload that is writes",
Jens Axboeee738492007-01-10 11:23:16 +0100370 .def = "50",
Jens Axboee1f36502006-10-27 10:54:08 +0200371 },
372 {
373 .name = "nice",
374 .type = FIO_OPT_INT,
375 .off1 = td_var_offset(nice),
Jens Axboefd28ca42007-01-09 21:20:13 +0100376 .help = "Set job CPU nice value",
Jens Axboe15f79182007-01-10 12:26:18 +0100377 .minval = -19,
Jens Axboeee738492007-01-10 11:23:16 +0100378 .maxval = 20,
379 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200380 },
381#ifdef FIO_HAVE_IOPRIO
382 {
383 .name = "prio",
384 .type = FIO_OPT_INT,
385 .cb = str_prio_cb,
Jens Axboefd28ca42007-01-09 21:20:13 +0100386 .help = "Set job IO priority value",
Jens Axboe15f79182007-01-10 12:26:18 +0100387 .minval = 0,
388 .maxval = 7,
Jens Axboee1f36502006-10-27 10:54:08 +0200389 },
390 {
391 .name = "prioclass",
392 .type = FIO_OPT_INT,
393 .cb = str_prioclass_cb,
Jens Axboefd28ca42007-01-09 21:20:13 +0100394 .help = "Set job IO priority class",
Jens Axboe15f79182007-01-10 12:26:18 +0100395 .minval = 0,
396 .maxval = 3,
Jens Axboee1f36502006-10-27 10:54:08 +0200397 },
398#endif
399 {
400 .name = "thinktime",
401 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100402 .off1 = td_var_offset(thinktime),
Jens Axboe5fa0f812007-01-11 14:06:35 +0100403 .help = "Idle time between IO buffers (usec)",
Jens Axboeee738492007-01-10 11:23:16 +0100404 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200405 },
406 {
Jens Axboe48097d52007-02-17 06:30:44 +0100407 .name = "thinktime_spin",
408 .type = FIO_OPT_INT,
409 .off1 = td_var_offset(thinktime_spin),
Jens Axboe34403fb2007-03-02 21:43:25 +0100410 .help = "Start think time by spinning this amount (usec)",
Jens Axboe48097d52007-02-17 06:30:44 +0100411 .def = "0",
412 },
413 {
Jens Axboe9c1f7432007-01-03 20:43:19 +0100414 .name = "thinktime_blocks",
415 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100416 .off1 = td_var_offset(thinktime_blocks),
Jens Axboefd28ca42007-01-09 21:20:13 +0100417 .help = "IO buffer period between 'thinktime'",
Jens Axboeee738492007-01-10 11:23:16 +0100418 .def = "1",
Jens Axboe9c1f7432007-01-03 20:43:19 +0100419 },
420 {
Jens Axboee1f36502006-10-27 10:54:08 +0200421 .name = "rate",
422 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100423 .off1 = td_var_offset(rate),
Jens Axboefd28ca42007-01-09 21:20:13 +0100424 .help = "Set bandwidth rate",
Jens Axboee1f36502006-10-27 10:54:08 +0200425 },
426 {
427 .name = "ratemin",
428 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100429 .off1 = td_var_offset(ratemin),
Jens Axboefd28ca42007-01-09 21:20:13 +0100430 .help = "The bottom limit accepted",
Jens Axboee1f36502006-10-27 10:54:08 +0200431 },
432 {
433 .name = "ratecycle",
434 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100435 .off1 = td_var_offset(ratecycle),
Jens Axboe6da1fa72007-01-10 11:27:48 +0100436 .help = "Window average for rate limits (msec)",
Jens Axboeee738492007-01-10 11:23:16 +0100437 .def = "1000",
Jens Axboee1f36502006-10-27 10:54:08 +0200438 },
439 {
Jens Axboee1f36502006-10-27 10:54:08 +0200440 .name = "invalidate",
Jens Axboe13335dd2007-01-10 13:14:02 +0100441 .type = FIO_OPT_BOOL,
Jens Axboe13049232007-01-03 20:45:09 +0100442 .off1 = td_var_offset(invalidate_cache),
Jens Axboefd28ca42007-01-09 21:20:13 +0100443 .help = "Invalidate buffer/page cache prior to running job",
Jens Axboeee738492007-01-10 11:23:16 +0100444 .def = "1",
Jens Axboee1f36502006-10-27 10:54:08 +0200445 },
446 {
447 .name = "sync",
Jens Axboe13335dd2007-01-10 13:14:02 +0100448 .type = FIO_OPT_BOOL,
Jens Axboe13049232007-01-03 20:45:09 +0100449 .off1 = td_var_offset(sync_io),
Jens Axboefd28ca42007-01-09 21:20:13 +0100450 .help = "Use O_SYNC for buffered writes",
Jens Axboeee738492007-01-10 11:23:16 +0100451 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200452 },
453 {
454 .name = "bwavgtime",
455 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100456 .off1 = td_var_offset(bw_avg_time),
Jens Axboeee738492007-01-10 11:23:16 +0100457 .help = "Time window over which to calculate bandwidth (msec)",
458 .def = "500",
Jens Axboee1f36502006-10-27 10:54:08 +0200459 },
460 {
461 .name = "create_serialize",
Jens Axboe13335dd2007-01-10 13:14:02 +0100462 .type = FIO_OPT_BOOL,
Jens Axboe13049232007-01-03 20:45:09 +0100463 .off1 = td_var_offset(create_serialize),
Jens Axboefd28ca42007-01-09 21:20:13 +0100464 .help = "Serialize creating of job files",
Jens Axboeee738492007-01-10 11:23:16 +0100465 .def = "1",
Jens Axboee1f36502006-10-27 10:54:08 +0200466 },
467 {
468 .name = "create_fsync",
Jens Axboe13335dd2007-01-10 13:14:02 +0100469 .type = FIO_OPT_BOOL,
Jens Axboe13049232007-01-03 20:45:09 +0100470 .off1 = td_var_offset(create_fsync),
Jens Axboefd28ca42007-01-09 21:20:13 +0100471 .help = "Fsync file after creation",
Jens Axboeee738492007-01-10 11:23:16 +0100472 .def = "1",
Jens Axboee1f36502006-10-27 10:54:08 +0200473 },
474 {
Jens Axboee1f36502006-10-27 10:54:08 +0200475 .name = "cpuload",
476 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100477 .off1 = td_var_offset(cpuload),
Jens Axboefd28ca42007-01-09 21:20:13 +0100478 .help = "Use this percentage of CPU",
Jens Axboee1f36502006-10-27 10:54:08 +0200479 },
480 {
481 .name = "cpuchunks",
482 .type = FIO_OPT_INT,
Jens Axboe13049232007-01-03 20:45:09 +0100483 .off1 = td_var_offset(cpucycle),
Jens Axboeba0fbe12007-03-09 14:34:23 +0100484 .help = "Length of the CPU burn cycles (usecs)",
485 .def = "50000",
Jens Axboee1f36502006-10-27 10:54:08 +0200486 },
Jens Axboee1f36502006-10-27 10:54:08 +0200487#ifdef FIO_HAVE_CPU_AFFINITY
488 {
489 .name = "cpumask",
490 .type = FIO_OPT_INT,
491 .cb = str_cpumask_cb,
Jens Axboefd28ca42007-01-09 21:20:13 +0100492 .help = "CPU affinity mask",
Jens Axboee1f36502006-10-27 10:54:08 +0200493 },
494#endif
495 {
496 .name = "end_fsync",
Jens Axboe13335dd2007-01-10 13:14:02 +0100497 .type = FIO_OPT_BOOL,
Jens Axboe13049232007-01-03 20:45:09 +0100498 .off1 = td_var_offset(end_fsync),
Jens Axboefd28ca42007-01-09 21:20:13 +0100499 .help = "Include fsync at the end of job",
Jens Axboeee738492007-01-10 11:23:16 +0100500 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200501 },
502 {
503 .name = "unlink",
Jens Axboe13335dd2007-01-10 13:14:02 +0100504 .type = FIO_OPT_BOOL,
Jens Axboee1f36502006-10-27 10:54:08 +0200505 .off1 = td_var_offset(unlink),
Jens Axboeee738492007-01-10 11:23:16 +0100506 .help = "Unlink created files after job has completed",
Jens Axboee545a6c2007-01-14 00:00:29 +0100507 .def = "0",
Jens Axboee1f36502006-10-27 10:54:08 +0200508 },
509 {
510 .name = "exitall",
511 .type = FIO_OPT_STR_SET,
512 .cb = str_exitall_cb,
Jens Axboefd28ca42007-01-09 21:20:13 +0100513 .help = "Terminate all jobs when one exits",
Jens Axboee1f36502006-10-27 10:54:08 +0200514 },
515 {
516 .name = "stonewall",
517 .type = FIO_OPT_STR_SET,
518 .off1 = td_var_offset(stonewall),
Jens Axboefd28ca42007-01-09 21:20:13 +0100519 .help = "Insert a hard barrier between this job and previous",
Jens Axboee1f36502006-10-27 10:54:08 +0200520 },
521 {
522 .name = "thread",
523 .type = FIO_OPT_STR_SET,
Jens Axboed9bb3b82007-01-10 20:30:53 +0100524 .off1 = td_var_offset(use_thread),
Jens Axboefd28ca42007-01-09 21:20:13 +0100525 .help = "Use threads instead of forks",
Jens Axboee1f36502006-10-27 10:54:08 +0200526 },
527 {
528 .name = "write_bw_log",
529 .type = FIO_OPT_STR_SET,
530 .off1 = td_var_offset(write_bw_log),
Jens Axboefd28ca42007-01-09 21:20:13 +0100531 .help = "Write log of bandwidth during run",
Jens Axboee1f36502006-10-27 10:54:08 +0200532 },
533 {
534 .name = "write_lat_log",
535 .type = FIO_OPT_STR_SET,
536 .off1 = td_var_offset(write_lat_log),
Jens Axboefd28ca42007-01-09 21:20:13 +0100537 .help = "Write log of latency during run",
Jens Axboee1f36502006-10-27 10:54:08 +0200538 },
539 {
Jens Axboe56bb17f2006-12-20 20:27:36 +0100540 .name = "hugepage-size",
541 .type = FIO_OPT_STR_VAL,
542 .off1 = td_var_offset(hugepage_size),
Jens Axboefd28ca42007-01-09 21:20:13 +0100543 .help = "When using hugepages, specify size of each page",
Jens Axboeee738492007-01-10 11:23:16 +0100544 .def = __stringify(FIO_HUGE_PAGE),
Jens Axboe56bb17f2006-12-20 20:27:36 +0100545 },
546 {
Jens Axboeb2560f32007-03-06 12:43:03 +0100547 .name = "group_reporting",
548 .type = FIO_OPT_STR_SET,
549 .off1 = td_var_offset(group_reporting),
550 .help = "Do reporting on a per-group basis",
551 },
552 {
Jens Axboee1f36502006-10-27 10:54:08 +0200553 .name = NULL,
554 },
555};
556
Jens Axboeb4692822006-10-27 13:43:22 +0200557#define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
558#define FIO_CMD_OPTS (16)
559#define FIO_GETOPT_JOB (0x89988998)
560
561/*
562 * Command line options. These will contain the above, plus a few
563 * extra that only pertain to fio itself and not jobs.
564 */
565static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
566 {
567 .name = "output",
568 .has_arg = required_argument,
569 .val = 'o',
570 },
571 {
572 .name = "timeout",
573 .has_arg = required_argument,
574 .val = 't',
575 },
576 {
577 .name = "latency-log",
578 .has_arg = required_argument,
579 .val = 'l',
580 },
581 {
582 .name = "bandwidth-log",
583 .has_arg = required_argument,
584 .val = 'b',
585 },
586 {
587 .name = "minimal",
588 .has_arg = optional_argument,
589 .val = 'm',
590 },
591 {
592 .name = "version",
593 .has_arg = no_argument,
594 .val = 'v',
595 },
596 {
Jens Axboefd28ca42007-01-09 21:20:13 +0100597 .name = "help",
598 .has_arg = no_argument,
599 .val = 'h',
600 },
601 {
602 .name = "cmdhelp",
Jens Axboe320beef2007-03-01 10:44:12 +0100603 .has_arg = optional_argument,
Jens Axboefd28ca42007-01-09 21:20:13 +0100604 .val = 'c',
605 },
606 {
Jens Axboeb4692822006-10-27 13:43:22 +0200607 .name = NULL,
608 },
609};
610
Jens Axboeee738492007-01-10 11:23:16 +0100611static int def_timeout = 0;
Jens Axboe972cfd22006-06-09 11:08:56 +0200612
Jens Axboefdf3de22007-03-03 12:21:34 +0100613static char fio_version_string[] = "fio 1.13";
Jens Axboeebac4652005-12-08 15:25:21 +0100614
Jens Axboe972cfd22006-06-09 11:08:56 +0200615static char **ini_file;
Jens Axboeebac4652005-12-08 15:25:21 +0100616static int max_jobs = MAX_JOBS;
617
618struct thread_data def_thread;
619struct thread_data *threads = NULL;
620
Jens Axboeebac4652005-12-08 15:25:21 +0100621int exitall_on_terminate = 0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200622int terse_output = 0;
Jens Axboec04f7ec2006-05-31 10:13:16 +0200623unsigned long long mlock_size = 0;
Jens Axboeeb8bbf42006-06-08 21:40:11 +0200624FILE *f_out = NULL;
625FILE *f_err = NULL;
Jens Axboeebac4652005-12-08 15:25:21 +0100626
Jens Axboeee738492007-01-10 11:23:16 +0100627static int write_lat_log = 0;
Jens Axboebb3884d2007-01-17 17:23:11 +1100628int write_bw_log = 0;
Jens Axboeec94ec52006-10-20 10:59:19 +0200629
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100630static int prev_group_jobs;
631
Joel Becker9728ce32007-03-01 08:24:39 +0100632FILE *get_f_out()
633{
634 return f_out;
635}
636
637FILE *get_f_err()
638{
639 return f_err;
640}
641
Jens Axboe906c8d72006-06-13 09:37:56 +0200642/*
643 * Return a free job structure.
644 */
Jens Axboeebac4652005-12-08 15:25:21 +0100645static struct thread_data *get_new_job(int global, struct thread_data *parent)
646{
647 struct thread_data *td;
648
649 if (global)
650 return &def_thread;
651 if (thread_number >= max_jobs)
652 return NULL;
653
654 td = &threads[thread_number++];
Jens Axboeddaeaa52006-06-08 11:00:58 +0200655 *td = *parent;
Jens Axboeebac4652005-12-08 15:25:21 +0100656
Jens Axboeebac4652005-12-08 15:25:21 +0100657 td->thread_number = thread_number;
Jens Axboeebac4652005-12-08 15:25:21 +0100658 return td;
659}
660
661static void put_job(struct thread_data *td)
662{
Jens Axboe549577a2006-10-30 12:23:41 +0100663 if (td == &def_thread)
664 return;
665
Jens Axboe16edf252007-02-10 14:59:22 +0100666 if (td->error)
667 fprintf(f_out, "fio: %s\n", td->verror);
668
Jens Axboeebac4652005-12-08 15:25:21 +0100669 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
670 thread_number--;
671}
672
Jens Axboedad915e2006-10-27 11:10:18 +0200673/*
674 * Lazy way of fixing up options that depend on each other. We could also
675 * define option callback handlers, but this is easier.
676 */
Jens Axboee1f36502006-10-27 10:54:08 +0200677static void fixup_options(struct thread_data *td)
678{
Jens Axboee1f36502006-10-27 10:54:08 +0200679 if (!td->rwmixread && td->rwmixwrite)
680 td->rwmixread = 100 - td->rwmixwrite;
Jens Axboedad915e2006-10-27 11:10:18 +0200681
Jens Axboe076efc72006-10-27 11:24:25 +0200682 if (td->write_iolog_file && td->read_iolog_file) {
683 log_err("fio: read iolog overrides write_iolog\n");
684 free(td->write_iolog_file);
685 td->write_iolog_file = NULL;
686 }
Jens Axboe16b462a2006-10-30 12:35:18 +0100687
688 if (td->io_ops->flags & FIO_SYNCIO)
689 td->iodepth = 1;
690 else {
691 if (!td->iodepth)
Jens Axboeb5af8292007-03-08 12:43:13 +0100692 td->iodepth = td->open_files;
Jens Axboe16b462a2006-10-30 12:35:18 +0100693 }
694
695 /*
696 * only really works for sequential io for now, and with 1 file
697 */
Jens Axboeb5af8292007-03-08 12:43:13 +0100698 if (td->zone_size && td_random(td) && td->open_files == 1)
Jens Axboe16b462a2006-10-30 12:35:18 +0100699 td->zone_size = 0;
700
701 /*
702 * Reads can do overwrites, we always need to pre-create the file
703 */
704 if (td_read(td) || td_rw(td))
705 td->overwrite = 1;
706
Jens Axboea00735e2006-11-03 08:58:08 +0100707 if (!td->min_bs[DDIR_READ])
708 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
709 if (!td->max_bs[DDIR_READ])
710 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
711 if (!td->min_bs[DDIR_WRITE])
Jens Axboe75e6f362006-11-03 08:17:09 +0100712 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
Jens Axboea00735e2006-11-03 08:58:08 +0100713 if (!td->max_bs[DDIR_WRITE])
Jens Axboe75e6f362006-11-03 08:17:09 +0100714 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
Jens Axboea00735e2006-11-03 08:58:08 +0100715
716 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
717
Jens Axboe16b462a2006-10-30 12:35:18 +0100718 if (td_read(td) && !td_rw(td))
719 td->verify = 0;
Jens Axboebb8895e2006-10-30 15:14:48 +0100720
721 if (td->norandommap && td->verify != VERIFY_NONE) {
722 log_err("fio: norandommap given, verify disabled\n");
723 td->verify = VERIFY_NONE;
724 }
Jens Axboe690adba2006-10-30 15:25:09 +0100725 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
726 log_err("fio: bs_unaligned may not work with raw io\n");
Jens Axboee0a22332006-12-20 12:54:25 +0100727
728 /*
Jens Axboe48097d52007-02-17 06:30:44 +0100729 * thinktime_spin must be less than thinktime
730 */
731 if (td->thinktime_spin > td->thinktime)
732 td->thinktime_spin = td->thinktime;
Jens Axboee916b392007-02-20 14:37:26 +0100733
734 /*
735 * The low water mark cannot be bigger than the iodepth
736 */
Jens Axboe9467b772007-02-27 19:56:43 +0100737 if (td->iodepth_low > td->iodepth || !td->iodepth_low) {
738 /*
739 * syslet work around - if the workload is sequential,
740 * we want to let the queue drain all the way down to
741 * avoid seeking between async threads
742 */
743 if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
744 td->iodepth_low = 1;
745 else
746 td->iodepth_low = td->iodepth;
747 }
Jens Axboecb5ab512007-02-26 12:57:09 +0100748
749 /*
750 * If batch number isn't set, default to the same as iodepth
751 */
752 if (td->iodepth_batch > td->iodepth || !td->iodepth_batch)
753 td->iodepth_batch = td->iodepth;
Jens Axboeb5af8292007-03-08 12:43:13 +0100754
Jens Axboe0ad920e2007-03-13 11:06:45 +0100755 if (!td->nr_files)
756 td->nr_files = td->open_files;
757 else if (td->open_files > td->nr_files || !td->open_files)
Jens Axboeb5af8292007-03-08 12:43:13 +0100758 td->open_files = td->nr_files;
Jens Axboee1f36502006-10-27 10:54:08 +0200759}
760
Jens Axboe906c8d72006-06-13 09:37:56 +0200761/*
Jens Axboef8977ee2006-11-06 14:03:03 +0100762 * This function leaks the buffer
763 */
764static char *to_kmg(unsigned int val)
765{
766 char *buf = malloc(32);
Jens Axboef3502ba2007-02-14 01:27:09 +0100767 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
Jens Axboef8977ee2006-11-06 14:03:03 +0100768 char *p = post;
769
Jens Axboe245142f2006-11-08 12:49:21 +0100770 do {
Jens Axboef8977ee2006-11-06 14:03:03 +0100771 if (val & 1023)
772 break;
773
774 val >>= 10;
775 p++;
Jens Axboe245142f2006-11-08 12:49:21 +0100776 } while (*p);
Jens Axboef8977ee2006-11-06 14:03:03 +0100777
778 snprintf(buf, 31, "%u%c", val, *p);
779 return buf;
780}
781
Jens Axboe09629a92007-03-09 09:00:06 +0100782/* External engines are specified by "external:name.o") */
783static const char *get_engine_name(const char *str)
784{
785 char *p = strstr(str, ":");
786
787 if (!p)
788 return str;
789
790 p++;
791 strip_blank_front(&p);
792 strip_blank_end(p);
793 return p;
794}
795
Jens Axboef8977ee2006-11-06 14:03:03 +0100796/*
Jens Axboe906c8d72006-06-13 09:37:56 +0200797 * Adds a job to the list of things todo. Sanitizes the various options
798 * to make sure we don't have conflicts, and initializes various
799 * members of td.
800 */
Jens Axboe75154842006-06-01 13:56:09 +0200801static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
Jens Axboeebac4652005-12-08 15:25:21 +0100802{
Jens Axboe413dd452007-02-23 09:26:09 +0100803 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
804 "randread", "randwrite", "randrw" };
Jens Axboeaf52b342007-03-13 10:07:47 +0100805 unsigned int i;
Jens Axboe53cdc682006-10-18 11:50:58 +0200806 struct fio_file *f;
Jens Axboe09629a92007-03-09 09:00:06 +0100807 const char *engine;
Jens Axboeaf52b342007-03-13 10:07:47 +0100808 char fname[PATH_MAX];
809 int numjobs;
Jens Axboeebac4652005-12-08 15:25:21 +0100810
Jens Axboeebac4652005-12-08 15:25:21 +0100811 /*
812 * the def_thread is just for options, it's not a real job
813 */
814 if (td == &def_thread)
815 return 0;
816
Jens Axboe09629a92007-03-09 09:00:06 +0100817 engine = get_engine_name(td->ioengine);
818 td->io_ops = load_ioengine(td, engine);
819 if (!td->io_ops) {
820 log_err("fio: failed to load engine %s\n", engine);
821 return 1;
822 }
Jens Axboedf641192006-10-12 07:55:41 +0200823
Jens Axboe9cedf162007-03-12 11:29:30 +0100824 if (td->use_thread)
825 nr_thread++;
826 else
827 nr_process++;
828
Jens Axboe690adba2006-10-30 15:25:09 +0100829 if (td->odirect)
830 td->io_ops->flags |= FIO_RAWIO;
831
Jens Axboeaf52b342007-03-13 10:07:47 +0100832 if (!td->filename) {
Jens Axboe80be24f2007-03-12 11:01:25 +0100833 td->filename = strdup(jobname);
834
Jens Axboe7b05a212007-03-13 11:17:07 +0100835 if (td->nr_files == 1)
836 add_file(td, td->filename);
837 else {
838 for (i = 0; i < td->nr_files; i++) {
839 sprintf(fname, "%s.%d.%d", td->filename, td->thread_number, i);
840 add_file(td, fname);
841 }
Jens Axboeaf52b342007-03-13 10:07:47 +0100842 }
Jens Axboe0af7b542006-02-17 10:10:12 +0100843 }
Jens Axboeebac4652005-12-08 15:25:21 +0100844
Jens Axboee0a22332006-12-20 12:54:25 +0100845 fixup_options(td);
846
Jens Axboe53cdc682006-10-18 11:50:58 +0200847 for_each_file(td, f, i) {
Jens Axboeaf52b342007-03-13 10:07:47 +0100848 if (td->directory && f->filetype == FIO_TYPE_FILE) {
849 sprintf(fname, "%s/%s", td->directory, f->file_name);
850 f->file_name = strdup(fname);
851 }
852
Jens Axboe53cdc682006-10-18 11:50:58 +0200853 f->file_size = td->total_file_size / td->nr_files;
854 f->file_offset = td->start_offset;
855 }
856
Jens Axboe07739b52007-03-08 20:25:46 +0100857 td->mutex = fio_sem_init(0);
Jens Axboeebac4652005-12-08 15:25:21 +0100858
Jens Axboe756867b2007-03-06 15:19:24 +0100859 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
860 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
861 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
Jens Axboeebac4652005-12-08 15:25:21 +0100862
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100863 if ((td->stonewall || td->numjobs > 1) && prev_group_jobs) {
864 prev_group_jobs = 0;
Jens Axboeebac4652005-12-08 15:25:21 +0100865 groupid++;
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100866 }
Jens Axboeebac4652005-12-08 15:25:21 +0100867
868 td->groupid = groupid;
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100869 prev_group_jobs++;
Jens Axboeebac4652005-12-08 15:25:21 +0100870
871 if (setup_rate(td))
872 goto err;
873
Jens Axboeec94ec52006-10-20 10:59:19 +0200874 if (td->write_lat_log) {
Jens Axboe756867b2007-03-06 15:19:24 +0100875 setup_log(&td->ts.slat_log);
876 setup_log(&td->ts.clat_log);
Jens Axboeebac4652005-12-08 15:25:21 +0100877 }
Jens Axboeec94ec52006-10-20 10:59:19 +0200878 if (td->write_bw_log)
Jens Axboe756867b2007-03-06 15:19:24 +0100879 setup_log(&td->ts.bw_log);
Jens Axboeebac4652005-12-08 15:25:21 +0100880
Jens Axboeb4692822006-10-27 13:43:22 +0200881 if (!td->name)
882 td->name = strdup(jobname);
Jens Axboe01452052006-06-07 10:29:47 +0200883
Jens Axboec6ae0a52006-06-12 11:04:44 +0200884 if (!terse_output) {
Jens Axboeb990b5c2006-09-14 09:48:22 +0200885 if (!job_add_num) {
Jens Axboeba0fbe12007-03-09 14:34:23 +0100886 if (!strcmp(td->io_ops->name, "cpuio"))
Jens Axboeb990b5c2006-09-14 09:48:22 +0200887 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
Jens Axboef8977ee2006-11-06 14:03:03 +0100888 else {
889 char *c1, *c2, *c3, *c4;
890
891 c1 = to_kmg(td->min_bs[DDIR_READ]);
892 c2 = to_kmg(td->max_bs[DDIR_READ]);
893 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
894 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
895
Jens Axboe413dd452007-02-23 09:26:09 +0100896 fprintf(f_out, "%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth);
Jens Axboef8977ee2006-11-06 14:03:03 +0100897
898 free(c1);
899 free(c2);
900 free(c3);
901 free(c4);
902 }
Jens Axboeb990b5c2006-09-14 09:48:22 +0200903 } else if (job_add_num == 1)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200904 fprintf(f_out, "...\n");
905 }
Jens Axboeebac4652005-12-08 15:25:21 +0100906
907 /*
908 * recurse add identical jobs, clear numjobs and stonewall options
909 * as they don't apply to sub-jobs
910 */
911 numjobs = td->numjobs;
912 while (--numjobs) {
913 struct thread_data *td_new = get_new_job(0, td);
914
915 if (!td_new)
916 goto err;
917
918 td_new->numjobs = 1;
919 td_new->stonewall = 0;
Jens Axboe75154842006-06-01 13:56:09 +0200920 job_add_num = numjobs - 1;
Jens Axboeebac4652005-12-08 15:25:21 +0100921
Jens Axboe75154842006-06-01 13:56:09 +0200922 if (add_job(td_new, jobname, job_add_num))
Jens Axboeebac4652005-12-08 15:25:21 +0100923 goto err;
924 }
Jens Axboe3c5df6f2007-03-12 15:09:24 +0100925
926 if (td->numjobs > 1) {
927 groupid++;
928 prev_group_jobs = 0;
929 }
930
Jens Axboeebac4652005-12-08 15:25:21 +0100931 return 0;
932err:
933 put_job(td);
934 return -1;
935}
936
Jens Axboe906c8d72006-06-13 09:37:56 +0200937/*
938 * Initialize the various random states we need (random io, block size ranges,
939 * read/write mix, etc).
940 */
Jens Axboeebac4652005-12-08 15:25:21 +0100941int init_random_state(struct thread_data *td)
942{
Jens Axboe0aabe162007-02-23 08:45:55 +0100943 unsigned long seeds[5];
Jens Axboeaf52b342007-03-13 10:07:47 +0100944 int fd, num_maps, blocks;
Jens Axboe0ab8db82006-10-18 17:16:23 +0200945 struct fio_file *f;
Jens Axboeaf52b342007-03-13 10:07:47 +0100946 unsigned int i;
Jens Axboeebac4652005-12-08 15:25:21 +0100947
Jens Axboeba0fbe12007-03-09 14:34:23 +0100948 if (td->io_ops->flags & FIO_DISKLESSIO)
Jens Axboef48b4672006-10-27 11:30:07 +0200949 return 0;
950
Jens Axboe1ac267b2006-05-31 20:29:00 +0200951 fd = open("/dev/urandom", O_RDONLY);
Jens Axboeebac4652005-12-08 15:25:21 +0100952 if (fd == -1) {
Jens Axboee1161c32007-02-22 19:36:48 +0100953 td_verror(td, errno, "open");
Jens Axboeebac4652005-12-08 15:25:21 +0100954 return 1;
955 }
956
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200957 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
Jens Axboee1161c32007-02-22 19:36:48 +0100958 td_verror(td, EIO, "read");
Jens Axboeebac4652005-12-08 15:25:21 +0100959 close(fd);
960 return 1;
961 }
962
963 close(fd);
964
Jens Axboe6dfd46b2006-06-07 13:57:06 +0200965 os_random_seed(seeds[0], &td->bsrange_state);
966 os_random_seed(seeds[1], &td->verify_state);
967 os_random_seed(seeds[2], &td->rwmix_state);
Jens Axboeebac4652005-12-08 15:25:21 +0100968
Jens Axboe413dd452007-02-23 09:26:09 +0100969 if (td->file_service_type == FIO_FSERVICE_RANDOM)
970 os_random_seed(seeds[3], &td->next_file_state);
971
972 if (!td_random(td))
Jens Axboeebac4652005-12-08 15:25:21 +0100973 return 0;
974
Jens Axboe9ebc27e2006-06-12 10:21:50 +0200975 if (td->rand_repeatable)
Jens Axboe0aabe162007-02-23 08:45:55 +0100976 seeds[4] = FIO_RANDSEED * td->thread_number;
Jens Axboeebac4652005-12-08 15:25:21 +0100977
Jens Axboebb8895e2006-10-30 15:14:48 +0100978 if (!td->norandommap) {
979 for_each_file(td, f, i) {
Jens Axboea4a81712007-02-13 20:07:26 +0100980 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
Jens Axboec7c280e2006-11-02 20:10:33 +0100981 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
Jens Axboebb8895e2006-10-30 15:14:48 +0100982 f->file_map = malloc(num_maps * sizeof(long));
Jens Axboebda4fd92007-03-12 11:21:48 +0100983 if (!f->file_map) {
984 log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n");
985 return 1;
986 }
Jens Axboebb8895e2006-10-30 15:14:48 +0100987 f->num_maps = num_maps;
988 memset(f->file_map, 0, num_maps * sizeof(long));
989 }
Jens Axboe53cdc682006-10-18 11:50:58 +0200990 }
Jens Axboeebac4652005-12-08 15:25:21 +0100991
Jens Axboe0aabe162007-02-23 08:45:55 +0100992 os_random_seed(seeds[4], &td->random_state);
Jens Axboeebac4652005-12-08 15:25:21 +0100993 return 0;
994}
995
996static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
997{
998#ifdef FIO_HAVE_CPU_AFFINITY
999 unsigned int i;
1000
1001 CPU_ZERO(&cpumask);
1002
1003 for (i = 0; i < sizeof(int) * 8; i++) {
1004 if ((1 << i) & cpu)
1005 CPU_SET(i, &cpumask);
1006 }
1007#endif
1008}
1009
Jens Axboeebac4652005-12-08 15:25:21 +01001010static int is_empty_or_comment(char *line)
1011{
1012 unsigned int i;
1013
1014 for (i = 0; i < strlen(line); i++) {
1015 if (line[i] == ';')
1016 return 1;
Ingo Molnar5cc2da32007-02-20 10:19:44 +01001017 if (line[i] == '#')
1018 return 1;
Jens Axboeebac4652005-12-08 15:25:21 +01001019 if (!isspace(line[i]) && !iscntrl(line[i]))
1020 return 0;
1021 }
1022
1023 return 1;
1024}
1025
Jens Axboe313cb202006-12-21 09:50:00 +01001026/*
1027 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
1028 */
Jens Axboe1907dbc2007-03-12 11:44:28 +01001029static char *get_opt_postfix(const char *str)
Jens Axboe313cb202006-12-21 09:50:00 +01001030{
1031 char *p = strstr(str, ":");
1032
1033 if (!p)
1034 return NULL;
1035
1036 p++;
1037 strip_blank_front(&p);
1038 strip_blank_end(p);
1039 return strdup(p);
1040}
1041
Jens Axboeb4692822006-10-27 13:43:22 +02001042static int str_mem_cb(void *data, const char *mem)
Jens Axboeebac4652005-12-08 15:25:21 +01001043{
Jens Axboecb2c86f2006-10-26 13:48:34 +02001044 struct thread_data *td = data;
1045
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001046 if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
Jens Axboe1907dbc2007-03-12 11:44:28 +01001047 td->mmapfile = get_opt_postfix(mem);
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001048 if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboed0bdaf42006-12-20 14:40:44 +01001049 log_err("fio: mmaphuge:/path/to/file\n");
1050 return 1;
1051 }
Jens Axboeebac4652005-12-08 15:25:21 +01001052 }
1053
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001054 return 0;
Jens Axboeebac4652005-12-08 15:25:21 +01001055}
1056
Jens Axboee1f36502006-10-27 10:54:08 +02001057static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1058{
1059 mlock_size = *val;
1060 return 0;
1061}
1062
Jens Axboe34cfcda2006-11-03 14:00:45 +01001063#ifdef FIO_HAVE_IOPRIO
Jens Axboee1f36502006-10-27 10:54:08 +02001064static int str_prioclass_cb(void *data, unsigned int *val)
1065{
1066 struct thread_data *td = data;
1067
1068 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1069 return 0;
1070}
1071
1072static int str_prio_cb(void *data, unsigned int *val)
1073{
1074 struct thread_data *td = data;
1075
1076 td->ioprio |= *val;
1077 return 0;
1078}
Jens Axboe34cfcda2006-11-03 14:00:45 +01001079#endif
Jens Axboee1f36502006-10-27 10:54:08 +02001080
1081static int str_exitall_cb(void)
1082{
1083 exitall_on_terminate = 1;
1084 return 0;
1085}
1086
1087static int str_cpumask_cb(void *data, unsigned int *val)
1088{
1089 struct thread_data *td = data;
1090
1091 fill_cpu_mask(td->cpumask, *val);
1092 return 0;
1093}
1094
Jens Axboe1907dbc2007-03-12 11:44:28 +01001095static int str_fst_cb(void *data, const char *str)
1096{
1097 struct thread_data *td = data;
1098 char *nr = get_opt_postfix(str);
1099
1100 td->file_service_nr = 1;
1101 if (nr)
1102 td->file_service_nr = atoi(nr);
1103
1104 return 0;
1105}
1106
Jens Axboeaf52b342007-03-13 10:07:47 +01001107static int str_filename_cb(void *data, const char *input)
1108{
1109 struct thread_data *td = data;
Jens Axboecae61952007-03-13 11:12:14 +01001110 char *fname, *str, *p;
Jens Axboeaf52b342007-03-13 10:07:47 +01001111
Jens Axboe0ad920e2007-03-13 11:06:45 +01001112 td->nr_files = 0;
Jens Axboecae61952007-03-13 11:12:14 +01001113 p = str = strdup(input);
Jens Axboe0ad920e2007-03-13 11:06:45 +01001114 while ((fname = strsep(&str, ":")) != NULL) {
Jens Axboeaf52b342007-03-13 10:07:47 +01001115 add_file(td, fname);
Jens Axboe0ad920e2007-03-13 11:06:45 +01001116 td->nr_files++;
1117 }
Jens Axboeaf52b342007-03-13 10:07:47 +01001118
Jens Axboecae61952007-03-13 11:12:14 +01001119 free(p);
Jens Axboeaf52b342007-03-13 10:07:47 +01001120 return 0;
1121}
1122
1123static int str_directory_cb(void *data, const char fio_unused *str)
1124{
1125 struct thread_data *td = data;
1126 struct stat sb;
1127
1128 if (lstat(td->directory, &sb) < 0) {
1129 log_err("fio: %s is not a directory\n", td->directory);
1130 td_verror(td, errno, "lstat");
1131 return 1;
1132 }
1133 if (!S_ISDIR(sb.st_mode)) {
1134 log_err("fio: %s is not a directory\n", td->directory);
1135 return 1;
1136 }
1137
1138 return 0;
1139}
1140
Jens Axboe07261982006-06-07 10:51:12 +02001141/*
1142 * This is our [ini] type file parser.
1143 */
Jens Axboe1e97cce2006-12-05 11:44:16 +01001144static int parse_jobs_ini(char *file, int stonewall_flag)
Jens Axboeebac4652005-12-08 15:25:21 +01001145{
Jens Axboee1f36502006-10-27 10:54:08 +02001146 unsigned int global;
Jens Axboeebac4652005-12-08 15:25:21 +01001147 struct thread_data *td;
Jens Axboefee3bb42006-10-30 13:32:08 +01001148 char *string, *name;
Jens Axboeebac4652005-12-08 15:25:21 +01001149 fpos_t off;
1150 FILE *f;
1151 char *p;
Jens Axboe0c7e37a2006-06-13 14:53:38 +02001152 int ret = 0, stonewall;
Jens Axboeebac4652005-12-08 15:25:21 +01001153
1154 f = fopen(file, "r");
1155 if (!f) {
Jens Axboeaea47d42006-05-26 19:27:29 +02001156 perror("fopen job file");
Jens Axboeebac4652005-12-08 15:25:21 +01001157 return 1;
1158 }
1159
1160 string = malloc(4096);
1161 name = malloc(256);
Jens Axboefee3bb42006-10-30 13:32:08 +01001162 memset(name, 0, 256);
Jens Axboeebac4652005-12-08 15:25:21 +01001163
Jens Axboe0c7e37a2006-06-13 14:53:38 +02001164 stonewall = stonewall_flag;
Jens Axboe7c124ac2006-10-30 13:36:52 +01001165 do {
1166 p = fgets(string, 4095, f);
1167 if (!p)
Jens Axboe45410ac2006-06-07 11:10:39 +02001168 break;
Jens Axboeebac4652005-12-08 15:25:21 +01001169 if (is_empty_or_comment(p))
1170 continue;
Jens Axboefee3bb42006-10-30 13:32:08 +01001171 if (sscanf(p, "[%255s]", name) != 1)
Jens Axboeebac4652005-12-08 15:25:21 +01001172 continue;
1173
1174 global = !strncmp(name, "global", 6);
1175
1176 name[strlen(name) - 1] = '\0';
1177
1178 td = get_new_job(global, &def_thread);
Jens Axboe45410ac2006-06-07 11:10:39 +02001179 if (!td) {
1180 ret = 1;
1181 break;
1182 }
Jens Axboeebac4652005-12-08 15:25:21 +01001183
Jens Axboe972cfd22006-06-09 11:08:56 +02001184 /*
1185 * Seperate multiple job files by a stonewall
1186 */
Jens Axboef9481912006-06-09 11:37:28 +02001187 if (!global && stonewall) {
Jens Axboe972cfd22006-06-09 11:08:56 +02001188 td->stonewall = stonewall;
1189 stonewall = 0;
1190 }
1191
Jens Axboeebac4652005-12-08 15:25:21 +01001192 fgetpos(f, &off);
1193 while ((p = fgets(string, 4096, f)) != NULL) {
1194 if (is_empty_or_comment(p))
1195 continue;
Jens Axboee1f36502006-10-27 10:54:08 +02001196
Jens Axboeb6754f92006-05-30 14:29:32 +02001197 strip_blank_front(&p);
Jens Axboe7c124ac2006-10-30 13:36:52 +01001198
1199 if (p[0] == '[')
1200 break;
1201
Jens Axboe4ae3f762006-05-30 13:35:14 +02001202 strip_blank_end(p);
Jens Axboeaea47d42006-05-26 19:27:29 +02001203
Jens Axboee1f36502006-10-27 10:54:08 +02001204 fgetpos(f, &off);
Jens Axboeebac4652005-12-08 15:25:21 +01001205
Jens Axboe45410ac2006-06-07 11:10:39 +02001206 /*
1207 * Don't break here, continue parsing options so we
1208 * dump all the bad ones. Makes trial/error fixups
1209 * easier on the user.
1210 */
Jens Axboe7c124ac2006-10-30 13:36:52 +01001211 ret |= parse_option(p, options, td);
Jens Axboeebac4652005-12-08 15:25:21 +01001212 }
Jens Axboeebac4652005-12-08 15:25:21 +01001213
Jens Axboe45410ac2006-06-07 11:10:39 +02001214 if (!ret) {
1215 fsetpos(f, &off);
1216 ret = add_job(td, name, 0);
Jens Axboeb1508cf2006-11-02 09:12:40 +01001217 } else {
1218 log_err("fio: job %s dropped\n", name);
1219 put_job(td);
Jens Axboe45410ac2006-06-07 11:10:39 +02001220 }
Jens Axboe7c124ac2006-10-30 13:36:52 +01001221 } while (!ret);
Jens Axboeebac4652005-12-08 15:25:21 +01001222
1223 free(string);
1224 free(name);
1225 fclose(f);
Jens Axboe45410ac2006-06-07 11:10:39 +02001226 return ret;
Jens Axboeebac4652005-12-08 15:25:21 +01001227}
1228
1229static int fill_def_thread(void)
1230{
1231 memset(&def_thread, 0, sizeof(def_thread));
1232
1233 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1234 perror("sched_getaffinity");
1235 return 1;
1236 }
1237
1238 /*
Jens Axboeee738492007-01-10 11:23:16 +01001239 * fill default options
Jens Axboeebac4652005-12-08 15:25:21 +01001240 */
Jens Axboeee738492007-01-10 11:23:16 +01001241 fill_default_options(&def_thread, options);
1242
Jens Axboe972cfd22006-06-09 11:08:56 +02001243 def_thread.timeout = def_timeout;
Jens Axboeec94ec52006-10-20 10:59:19 +02001244 def_thread.write_bw_log = write_bw_log;
1245 def_thread.write_lat_log = write_lat_log;
Jens Axboeee738492007-01-10 11:23:16 +01001246
Jens Axboeebac4652005-12-08 15:25:21 +01001247#ifdef FIO_HAVE_DISK_UTIL
1248 def_thread.do_disk_util = 1;
1249#endif
1250
1251 return 0;
1252}
1253
Jens Axboe0ab8db82006-10-18 17:16:23 +02001254static void usage(void)
Jens Axboe4785f992006-05-26 03:59:10 +02001255{
1256 printf("%s\n", fio_version_string);
Jens Axboeb4692822006-10-27 13:43:22 +02001257 printf("\t--output\tWrite output to file\n");
1258 printf("\t--timeout\tRuntime in seconds\n");
1259 printf("\t--latency-log\tGenerate per-job latency logs\n");
1260 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1261 printf("\t--minimal\tMinimal (terse) output\n");
1262 printf("\t--version\tPrint version info and exit\n");
Jens Axboefd28ca42007-01-09 21:20:13 +01001263 printf("\t--help\t\tPrint this page\n");
1264 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
Jens Axboe4785f992006-05-26 03:59:10 +02001265}
1266
Jens Axboe972cfd22006-06-09 11:08:56 +02001267static int parse_cmd_line(int argc, char *argv[])
Jens Axboeebac4652005-12-08 15:25:21 +01001268{
Jens Axboeb4692822006-10-27 13:43:22 +02001269 struct thread_data *td = NULL;
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001270 int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
Jens Axboeebac4652005-12-08 15:25:21 +01001271
Jens Axboe0be06ea2007-03-01 14:23:28 +01001272 while ((c = getopt_long_only(argc, argv, "", long_options, &lidx)) != -1) {
Jens Axboeebac4652005-12-08 15:25:21 +01001273 switch (c) {
Jens Axboeb4692822006-10-27 13:43:22 +02001274 case 't':
1275 def_timeout = atoi(optarg);
1276 break;
1277 case 'l':
1278 write_lat_log = 1;
1279 break;
1280 case 'w':
1281 write_bw_log = 1;
1282 break;
1283 case 'o':
1284 f_out = fopen(optarg, "w+");
1285 if (!f_out) {
1286 perror("fopen output");
1287 exit(1);
1288 }
1289 f_err = f_out;
1290 break;
1291 case 'm':
1292 terse_output = 1;
1293 break;
1294 case 'h':
1295 usage();
1296 exit(0);
Jens Axboefd28ca42007-01-09 21:20:13 +01001297 case 'c':
Jens Axboe29fc6af2007-01-09 21:22:02 +01001298 ret = show_cmd_help(options, optarg);
1299 exit(ret);
Jens Axboeb4692822006-10-27 13:43:22 +02001300 case 'v':
1301 printf("%s\n", fio_version_string);
1302 exit(0);
1303 case FIO_GETOPT_JOB: {
1304 const char *opt = long_options[lidx].name;
1305 char *val = optarg;
1306
Jens Axboec2b1e752006-10-30 09:03:13 +01001307 if (!strncmp(opt, "name", 4) && td) {
1308 ret = add_job(td, td->name ?: "fio", 0);
1309 if (ret) {
1310 put_job(td);
1311 return 0;
1312 }
1313 td = NULL;
1314 }
Jens Axboeb4692822006-10-27 13:43:22 +02001315 if (!td) {
Jens Axboe38d0adb2006-10-30 12:21:25 +01001316 int global = !strncmp(val, "global", 6);
Jens Axboec2b1e752006-10-30 09:03:13 +01001317
1318 td = get_new_job(global, &def_thread);
Jens Axboeb4692822006-10-27 13:43:22 +02001319 if (!td)
1320 return 0;
1321 }
Jens Axboe38d0adb2006-10-30 12:21:25 +01001322
Jens Axboeb1508cf2006-11-02 09:12:40 +01001323 ret = parse_cmd_option(opt, val, options, td);
Jens Axboe78217df2007-02-23 11:18:30 +01001324 if (ret)
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001325 dont_add_job = 1;
Jens Axboeb4692822006-10-27 13:43:22 +02001326 break;
1327 }
1328 default:
Jens Axboeb4692822006-10-27 13:43:22 +02001329 break;
Jens Axboeebac4652005-12-08 15:25:21 +01001330 }
1331 }
Jens Axboec9fad892006-05-27 17:26:50 +02001332
Jens Axboeb4692822006-10-27 13:43:22 +02001333 if (td) {
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001334 if (dont_add_job)
Jens Axboeb4692822006-10-27 13:43:22 +02001335 put_job(td);
Jens Axboeb1ec1da2007-02-23 10:29:16 +01001336 else {
1337 ret = add_job(td, td->name ?: "fio", 0);
1338 if (ret)
1339 put_job(td);
1340 }
Jens Axboe972cfd22006-06-09 11:08:56 +02001341 }
Jens Axboe774a6172006-08-24 08:44:26 +02001342
Jens Axboeb4692822006-10-27 13:43:22 +02001343 while (optind < argc) {
1344 ini_idx++;
1345 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1346 ini_file[ini_idx - 1] = strdup(argv[optind]);
1347 optind++;
Jens Axboeeb8bbf42006-06-08 21:40:11 +02001348 }
Jens Axboe972cfd22006-06-09 11:08:56 +02001349
1350 return ini_idx;
Jens Axboeebac4652005-12-08 15:25:21 +01001351}
1352
1353static void free_shm(void)
1354{
1355 struct shmid_ds sbuf;
1356
1357 if (threads) {
Jens Axboe2c0ecd22006-06-08 13:25:41 +02001358 shmdt((void *) threads);
Jens Axboeebac4652005-12-08 15:25:21 +01001359 threads = NULL;
1360 shmctl(shm_id, IPC_RMID, &sbuf);
1361 }
1362}
1363
Jens Axboe906c8d72006-06-13 09:37:56 +02001364/*
1365 * The thread area is shared between the main process and the job
1366 * threads/processes. So setup a shared memory segment that will hold
1367 * all the job info.
1368 */
Jens Axboeebac4652005-12-08 15:25:21 +01001369static int setup_thread_area(void)
1370{
1371 /*
1372 * 1024 is too much on some machines, scale max_jobs if
1373 * we get a failure that looks like too large a shm segment
1374 */
1375 do {
Jens Axboe906c8d72006-06-13 09:37:56 +02001376 size_t size = max_jobs * sizeof(struct thread_data);
Jens Axboeebac4652005-12-08 15:25:21 +01001377
Jens Axboe906c8d72006-06-13 09:37:56 +02001378 shm_id = shmget(0, size, IPC_CREAT | 0600);
Jens Axboeebac4652005-12-08 15:25:21 +01001379 if (shm_id != -1)
1380 break;
1381 if (errno != EINVAL) {
1382 perror("shmget");
1383 break;
1384 }
1385
1386 max_jobs >>= 1;
1387 } while (max_jobs);
1388
1389 if (shm_id == -1)
1390 return 1;
1391
1392 threads = shmat(shm_id, NULL, 0);
1393 if (threads == (void *) -1) {
1394 perror("shmat");
1395 return 1;
1396 }
1397
1398 atexit(free_shm);
1399 return 0;
1400}
1401
Jens Axboeb4692822006-10-27 13:43:22 +02001402/*
1403 * Copy the fio options into the long options map, so we mirror
1404 * job and cmd line options.
1405 */
1406static void dupe_job_options(void)
1407{
1408 struct fio_option *o;
1409 unsigned int i;
1410
1411 i = 0;
1412 while (long_options[i].name)
1413 i++;
1414
1415 o = &options[0];
1416 while (o->name) {
1417 long_options[i].name = o->name;
1418 long_options[i].val = FIO_GETOPT_JOB;
1419 if (o->type == FIO_OPT_STR_SET)
1420 long_options[i].has_arg = no_argument;
1421 else
1422 long_options[i].has_arg = required_argument;
1423
1424 i++;
1425 o++;
1426 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1427 }
1428}
1429
Jens Axboeebac4652005-12-08 15:25:21 +01001430int parse_options(int argc, char *argv[])
1431{
Jens Axboe972cfd22006-06-09 11:08:56 +02001432 int job_files, i;
1433
Jens Axboeb4692822006-10-27 13:43:22 +02001434 f_out = stdout;
1435 f_err = stderr;
1436
Jens Axboe13335dd2007-01-10 13:14:02 +01001437 options_init(options);
1438
Jens Axboeb4692822006-10-27 13:43:22 +02001439 dupe_job_options();
1440
Jens Axboeebac4652005-12-08 15:25:21 +01001441 if (setup_thread_area())
1442 return 1;
1443 if (fill_def_thread())
1444 return 1;
1445
Jens Axboe972cfd22006-06-09 11:08:56 +02001446 job_files = parse_cmd_line(argc, argv);
Jens Axboeebac4652005-12-08 15:25:21 +01001447
Jens Axboe972cfd22006-06-09 11:08:56 +02001448 for (i = 0; i < job_files; i++) {
1449 if (fill_def_thread())
1450 return 1;
Jens Axboe0c7e37a2006-06-13 14:53:38 +02001451 if (parse_jobs_ini(ini_file[i], i))
Jens Axboe972cfd22006-06-09 11:08:56 +02001452 return 1;
Jens Axboe88c6ed82006-06-09 11:28:10 +02001453 free(ini_file[i]);
Jens Axboe972cfd22006-06-09 11:08:56 +02001454 }
Jens Axboeebac4652005-12-08 15:25:21 +01001455
Jens Axboe88c6ed82006-06-09 11:28:10 +02001456 free(ini_file);
Jens Axboeb4692822006-10-27 13:43:22 +02001457
1458 if (!thread_number) {
1459 log_err("No jobs defined(s)\n");
Jens Axboeb4692822006-10-27 13:43:22 +02001460 return 1;
1461 }
1462
Jens Axboeebac4652005-12-08 15:25:21 +01001463 return 0;
1464}