Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1 | /* |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 2 | * This file contains job initialization and setup functions. |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 3 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 4 | #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> |
| 11 | #include <sys/ipc.h> |
| 12 | #include <sys/shm.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <sys/stat.h> |
| 15 | |
| 16 | #include "fio.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 17 | #include "parse.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 18 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 19 | /* |
| 20 | * The default options |
| 21 | */ |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 22 | #define DEF_BS (4096) |
| 23 | #define DEF_TIMEOUT (0) |
| 24 | #define DEF_RATE_CYCLE (1000) |
| 25 | #define DEF_ODIRECT (1) |
| 26 | #define DEF_IO_ENGINE (FIO_SYNCIO) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 27 | #define DEF_IO_ENGINE_NAME "sync" |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 28 | #define DEF_SEQUENTIAL (1) |
| 29 | #define DEF_RAND_REPEAT (1) |
| 30 | #define DEF_OVERWRITE (1) |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 31 | #define DEF_INVALIDATE (1) |
| 32 | #define DEF_SYNCIO (0) |
| 33 | #define DEF_RANDSEED (0xb1899bedUL) |
| 34 | #define DEF_BWAVGTIME (500) |
| 35 | #define DEF_CREATE_SER (1) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 36 | #define DEF_CREATE_FSYNC (1) |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 37 | #define DEF_LOOPS (1) |
| 38 | #define DEF_VERIFY (0) |
| 39 | #define DEF_STONEWALL (0) |
| 40 | #define DEF_NUMJOBS (1) |
| 41 | #define DEF_USE_THREAD (0) |
| 42 | #define DEF_FILE_SIZE (1024 * 1024 * 1024UL) |
| 43 | #define DEF_ZONE_SIZE (0) |
| 44 | #define DEF_ZONE_SKIP (0) |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 45 | #define DEF_RWMIX_CYCLE (500) |
| 46 | #define DEF_RWMIX_READ (50) |
Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 47 | #define DEF_NICE (0) |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 48 | #define DEF_NR_FILES (1) |
Jens Axboe | f6cbb26 | 2006-10-18 14:16:42 +0200 | [diff] [blame] | 49 | #define DEF_UNLINK (0) |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 50 | #define DEF_WRITE_BW_LOG (0) |
| 51 | #define DEF_WRITE_LAT_LOG (0) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 52 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 53 | #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var) |
| 54 | |
| 55 | static int str_rw_cb(void *, char *); |
| 56 | static int str_ioengine_cb(void *, char *); |
| 57 | static int str_mem_cb(void *, char *); |
| 58 | static int str_verify_cb(void *, char *); |
| 59 | static int str_lockmem_cb(void *, unsigned long *); |
| 60 | static int str_prio_cb(void *, unsigned int *); |
| 61 | static int str_prioclass_cb(void *, unsigned int *); |
| 62 | static int str_exitall_cb(void); |
| 63 | static int str_cpumask_cb(void *, unsigned int *); |
| 64 | |
| 65 | /* |
| 66 | * Map of job/command line options |
| 67 | */ |
| 68 | static struct fio_option options[] = { |
| 69 | { |
| 70 | .name = "name", |
| 71 | .type = FIO_OPT_STR_STORE, |
| 72 | .off1 = td_var_offset(name), |
| 73 | }, |
| 74 | { |
| 75 | .name = "directory", |
| 76 | .type = FIO_OPT_STR_STORE, |
| 77 | .off1 = td_var_offset(directory), |
| 78 | }, |
| 79 | { |
| 80 | .name = "filename", |
| 81 | .type = FIO_OPT_STR_STORE, |
| 82 | .off1 = td_var_offset(filename), |
| 83 | }, |
| 84 | { |
| 85 | .name = "rw", |
| 86 | .type = FIO_OPT_STR, |
| 87 | .cb = str_rw_cb, |
| 88 | }, |
| 89 | { |
| 90 | .name = "ioengine", |
| 91 | .type = FIO_OPT_STR, |
| 92 | .cb = str_ioengine_cb, |
| 93 | }, |
| 94 | { |
| 95 | .name = "mem", |
| 96 | .type = FIO_OPT_STR, |
| 97 | .cb = str_mem_cb, |
| 98 | }, |
| 99 | { |
| 100 | .name = "verify", |
| 101 | .type = FIO_OPT_STR, |
| 102 | .cb = str_verify_cb, |
| 103 | }, |
| 104 | { |
| 105 | .name = "write_iolog", |
| 106 | .type = FIO_OPT_STR_STORE, |
| 107 | .off1 = td_var_offset(write_iolog), |
| 108 | }, |
| 109 | { |
| 110 | .name = "iolog", |
| 111 | .type = FIO_OPT_STR_STORE, |
| 112 | .off1 = td_var_offset(iolog), |
| 113 | }, |
| 114 | { |
| 115 | .name = "exec_prerun", |
| 116 | .type = FIO_OPT_STR_STORE, |
| 117 | .off1 = td_var_offset(exec_prerun), |
| 118 | }, |
| 119 | { |
| 120 | .name = "exec_postrun", |
| 121 | .type = FIO_OPT_STR_STORE, |
| 122 | .off1 = td_var_offset(exec_postrun), |
| 123 | }, |
| 124 | #ifdef FIO_HAVE_IOSCHED_SWITCH |
| 125 | { |
| 126 | .name = "ioscheduler", |
| 127 | .type = FIO_OPT_STR_STORE, |
| 128 | .off1 = td_var_offset(ioscheduler), |
| 129 | }, |
| 130 | #endif |
| 131 | { |
| 132 | .name = "size", |
| 133 | .type = FIO_OPT_STR_VAL, |
| 134 | .off1 = td_var_offset(total_file_size), |
| 135 | }, |
| 136 | { |
| 137 | .name = "bs", |
| 138 | .type = FIO_OPT_STR_VAL, |
| 139 | .off1 = td_var_offset(bs), |
| 140 | }, |
| 141 | { |
| 142 | .name = "offset", |
| 143 | .type = FIO_OPT_STR_VAL, |
| 144 | .off1 = td_var_offset(start_offset), |
| 145 | }, |
| 146 | { |
| 147 | .name = "zonesize", |
| 148 | .type = FIO_OPT_STR_VAL, |
| 149 | .off1 = td_var_offset(zone_size), |
| 150 | }, |
| 151 | { |
| 152 | .name = "zoneskip", |
| 153 | .type = FIO_OPT_STR_VAL, |
| 154 | .off1 = td_var_offset(zone_skip), |
| 155 | }, |
| 156 | { |
| 157 | .name = "lockmem", |
| 158 | .type = FIO_OPT_STR_VAL, |
| 159 | .cb = str_lockmem_cb, |
| 160 | }, |
| 161 | { |
| 162 | .name = "bsrange", |
| 163 | .type = FIO_OPT_RANGE, |
| 164 | .off1 = td_var_offset(min_bs), |
| 165 | .off2 = td_var_offset(max_bs), |
| 166 | }, |
| 167 | { |
| 168 | .name = "nrfiles", |
| 169 | .type = FIO_OPT_INT, |
| 170 | .off1 = td_var_offset(nr_files), |
| 171 | }, |
| 172 | { |
| 173 | .name = "iodepth", |
| 174 | .type = FIO_OPT_INT, |
| 175 | .off1 = td_var_offset(iodepth), |
| 176 | }, |
| 177 | { |
| 178 | .name = "fsync", |
| 179 | .type = FIO_OPT_INT, |
| 180 | .off1 = td_var_offset(fsync_blocks), |
| 181 | }, |
| 182 | { |
| 183 | .name = "rwmixcycle", |
| 184 | .type = FIO_OPT_INT, |
| 185 | .off1 = td_var_offset(rwmixcycle), |
| 186 | }, |
| 187 | { |
| 188 | .name = "rwmixread", |
| 189 | .type = FIO_OPT_INT, |
| 190 | .off1 = td_var_offset(rwmixread), |
| 191 | .max_val= 100, |
| 192 | }, |
| 193 | { |
| 194 | .name = "rwmixwrite", |
| 195 | .type = FIO_OPT_INT, |
| 196 | .off1 = td_var_offset(rwmixwrite), |
| 197 | .max_val= 100, |
| 198 | }, |
| 199 | { |
| 200 | .name = "nice", |
| 201 | .type = FIO_OPT_INT, |
| 202 | .off1 = td_var_offset(nice), |
| 203 | }, |
| 204 | #ifdef FIO_HAVE_IOPRIO |
| 205 | { |
| 206 | .name = "prio", |
| 207 | .type = FIO_OPT_INT, |
| 208 | .cb = str_prio_cb, |
| 209 | }, |
| 210 | { |
| 211 | .name = "prioclass", |
| 212 | .type = FIO_OPT_INT, |
| 213 | .cb = str_prioclass_cb, |
| 214 | }, |
| 215 | #endif |
| 216 | { |
| 217 | .name = "thinktime", |
| 218 | .type = FIO_OPT_INT, |
| 219 | .off1 = td_var_offset(thinktime) |
| 220 | }, |
| 221 | { |
| 222 | .name = "rate", |
| 223 | .type = FIO_OPT_INT, |
| 224 | .off1 = td_var_offset(rate) |
| 225 | }, |
| 226 | { |
| 227 | .name = "ratemin", |
| 228 | .type = FIO_OPT_INT, |
| 229 | .off1 = td_var_offset(ratemin) |
| 230 | }, |
| 231 | { |
| 232 | .name = "ratecycle", |
| 233 | .type = FIO_OPT_INT, |
| 234 | .off1 = td_var_offset(ratecycle) |
| 235 | }, |
| 236 | { |
| 237 | .name = "startdelay", |
| 238 | .type = FIO_OPT_INT, |
| 239 | .off1 = td_var_offset(start_delay) |
| 240 | }, |
| 241 | { |
| 242 | .name = "timeout", |
| 243 | .type = FIO_OPT_STR_VAL_TIME, |
| 244 | .off1 = td_var_offset(timeout) |
| 245 | }, |
| 246 | { |
| 247 | .name = "invalidate", |
| 248 | .type = FIO_OPT_INT, |
| 249 | .off1 = td_var_offset(invalidate_cache) |
| 250 | }, |
| 251 | { |
| 252 | .name = "sync", |
| 253 | .type = FIO_OPT_INT, |
| 254 | .off1 = td_var_offset(sync_io) |
| 255 | }, |
| 256 | { |
| 257 | .name = "bwavgtime", |
| 258 | .type = FIO_OPT_INT, |
| 259 | .off1 = td_var_offset(bw_avg_time) |
| 260 | }, |
| 261 | { |
| 262 | .name = "create_serialize", |
| 263 | .type = FIO_OPT_INT, |
| 264 | .off1 = td_var_offset(create_serialize) |
| 265 | }, |
| 266 | { |
| 267 | .name = "create_fsync", |
| 268 | .type = FIO_OPT_INT, |
| 269 | .off1 = td_var_offset(create_fsync) |
| 270 | }, |
| 271 | { |
| 272 | .name = "loops", |
| 273 | .type = FIO_OPT_INT, |
| 274 | .off1 = td_var_offset(loops) |
| 275 | }, |
| 276 | { |
| 277 | .name = "numjobs", |
| 278 | .type = FIO_OPT_INT, |
| 279 | .off1 = td_var_offset(numjobs) |
| 280 | }, |
| 281 | { |
| 282 | .name = "cpuload", |
| 283 | .type = FIO_OPT_INT, |
| 284 | .off1 = td_var_offset(cpuload) |
| 285 | }, |
| 286 | { |
| 287 | .name = "cpuchunks", |
| 288 | .type = FIO_OPT_INT, |
| 289 | .off1 = td_var_offset(cpucycle) |
| 290 | }, |
| 291 | { |
| 292 | .name = "direct", |
| 293 | .type = FIO_OPT_INT, |
| 294 | .off1 = td_var_offset(odirect) |
| 295 | }, |
| 296 | { |
| 297 | .name = "overwrite", |
| 298 | .type = FIO_OPT_INT, |
| 299 | .off1 = td_var_offset(overwrite) |
| 300 | }, |
| 301 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 302 | { |
| 303 | .name = "cpumask", |
| 304 | .type = FIO_OPT_INT, |
| 305 | .cb = str_cpumask_cb, |
| 306 | }, |
| 307 | #endif |
| 308 | { |
| 309 | .name = "end_fsync", |
| 310 | .type = FIO_OPT_INT, |
| 311 | .off1 = td_var_offset(end_fsync) |
| 312 | }, |
| 313 | { |
| 314 | .name = "unlink", |
| 315 | .type = FIO_OPT_STR_SET, |
| 316 | .off1 = td_var_offset(unlink), |
| 317 | }, |
| 318 | { |
| 319 | .name = "exitall", |
| 320 | .type = FIO_OPT_STR_SET, |
| 321 | .cb = str_exitall_cb, |
| 322 | }, |
| 323 | { |
| 324 | .name = "stonewall", |
| 325 | .type = FIO_OPT_STR_SET, |
| 326 | .off1 = td_var_offset(stonewall), |
| 327 | }, |
| 328 | { |
| 329 | .name = "thread", |
| 330 | .type = FIO_OPT_STR_SET, |
| 331 | .off1 = td_var_offset(thread), |
| 332 | }, |
| 333 | { |
| 334 | .name = "write_bw_log", |
| 335 | .type = FIO_OPT_STR_SET, |
| 336 | .off1 = td_var_offset(write_bw_log), |
| 337 | }, |
| 338 | { |
| 339 | .name = "write_lat_log", |
| 340 | .type = FIO_OPT_STR_SET, |
| 341 | .off1 = td_var_offset(write_lat_log), |
| 342 | }, |
| 343 | { |
| 344 | .name = NULL, |
| 345 | }, |
| 346 | }; |
| 347 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 348 | static int def_timeout = DEF_TIMEOUT; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 349 | |
Jens Axboe | f4866ec | 2006-06-13 09:38:36 +0200 | [diff] [blame] | 350 | static char fio_version_string[] = "fio 1.5"; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 351 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 352 | static char **ini_file; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 353 | static int max_jobs = MAX_JOBS; |
| 354 | |
| 355 | struct thread_data def_thread; |
| 356 | struct thread_data *threads = NULL; |
| 357 | |
| 358 | int rate_quit = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 359 | int exitall_on_terminate = 0; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 360 | int terse_output = 0; |
Jens Axboe | c04f7ec | 2006-05-31 10:13:16 +0200 | [diff] [blame] | 361 | unsigned long long mlock_size = 0; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 362 | FILE *f_out = NULL; |
| 363 | FILE *f_err = NULL; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 364 | |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 365 | static int write_lat_log = DEF_WRITE_LAT_LOG; |
| 366 | static int write_bw_log = DEF_WRITE_BW_LOG; |
| 367 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 368 | /* |
| 369 | * Return a free job structure. |
| 370 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 371 | static struct thread_data *get_new_job(int global, struct thread_data *parent) |
| 372 | { |
| 373 | struct thread_data *td; |
| 374 | |
| 375 | if (global) |
| 376 | return &def_thread; |
| 377 | if (thread_number >= max_jobs) |
| 378 | return NULL; |
| 379 | |
| 380 | td = &threads[thread_number++]; |
Jens Axboe | ddaeaa5 | 2006-06-08 11:00:58 +0200 | [diff] [blame] | 381 | *td = *parent; |
| 382 | td->name[0] = '\0'; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 383 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 384 | td->thread_number = thread_number; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 385 | return td; |
| 386 | } |
| 387 | |
| 388 | static void put_job(struct thread_data *td) |
| 389 | { |
| 390 | memset(&threads[td->thread_number - 1], 0, sizeof(*td)); |
| 391 | thread_number--; |
| 392 | } |
| 393 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 394 | static void fixup_options(struct thread_data *td) |
| 395 | { |
| 396 | if (!td->min_bs) |
| 397 | td->min_bs = td->bs; |
| 398 | if (!td->max_bs) |
| 399 | td->max_bs = td->bs; |
| 400 | |
| 401 | if (!td->rwmixread && td->rwmixwrite) |
| 402 | td->rwmixread = 100 - td->rwmixwrite; |
| 403 | } |
| 404 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 405 | /* |
| 406 | * Adds a job to the list of things todo. Sanitizes the various options |
| 407 | * to make sure we don't have conflicts, and initializes various |
| 408 | * members of td. |
| 409 | */ |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 410 | static int add_job(struct thread_data *td, const char *jobname, int job_add_num) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 411 | { |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 412 | char *ddir_str[] = { "read", "write", "randread", "randwrite", |
| 413 | "rw", NULL, "randrw" }; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 414 | struct stat sb; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 415 | int numjobs, ddir, i; |
| 416 | struct fio_file *f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 417 | |
| 418 | #ifndef FIO_HAVE_LIBAIO |
| 419 | if (td->io_engine == FIO_LIBAIO) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 420 | log_err("Linux libaio not available\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 421 | return 1; |
| 422 | } |
| 423 | #endif |
| 424 | #ifndef FIO_HAVE_POSIXAIO |
| 425 | if (td->io_engine == FIO_POSIXAIO) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 426 | log_err("posix aio not available\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 427 | return 1; |
| 428 | } |
| 429 | #endif |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 430 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 431 | fixup_options(td); |
| 432 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 433 | /* |
| 434 | * the def_thread is just for options, it's not a real job |
| 435 | */ |
| 436 | if (td == &def_thread) |
| 437 | return 0; |
| 438 | |
Jens Axboe | df64119 | 2006-10-12 07:55:41 +0200 | [diff] [blame] | 439 | /* |
| 440 | * Set default io engine, if none set |
| 441 | */ |
| 442 | if (!td->io_ops) { |
| 443 | td->io_ops = load_ioengine(td, DEF_IO_ENGINE_NAME); |
| 444 | if (!td->io_ops) { |
| 445 | log_err("default engine %s not there?\n", DEF_IO_ENGINE_NAME); |
| 446 | return 1; |
| 447 | } |
| 448 | } |
| 449 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 450 | if (td->io_ops->flags & FIO_SYNCIO) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 451 | td->iodepth = 1; |
| 452 | else { |
| 453 | if (!td->iodepth) |
Jens Axboe | 841ddd1 | 2006-10-20 09:07:46 +0200 | [diff] [blame] | 454 | td->iodepth = td->nr_files; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 457 | /* |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 458 | * only really works for sequential io for now, and with 1 file |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 459 | */ |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 460 | if (td->zone_size && !td->sequential && td->nr_files == 1) |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 461 | td->zone_size = 0; |
| 462 | |
Jens Axboe | 9cc935a | 2006-06-13 09:11:18 +0200 | [diff] [blame] | 463 | /* |
| 464 | * Reads can do overwrites, we always need to pre-create the file |
| 465 | */ |
| 466 | if (td_read(td) || td_rw(td)) |
| 467 | td->overwrite = 1; |
| 468 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 469 | td->filetype = FIO_TYPE_FILE; |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 470 | if (!stat(jobname, &sb)) { |
| 471 | if (S_ISBLK(sb.st_mode)) |
| 472 | td->filetype = FIO_TYPE_BD; |
| 473 | else if (S_ISCHR(sb.st_mode)) |
| 474 | td->filetype = FIO_TYPE_CHAR; |
| 475 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 476 | |
Jens Axboe | b2a1519 | 2006-10-18 14:10:42 +0200 | [diff] [blame] | 477 | if (td->odirect) |
| 478 | td->io_ops->flags |= FIO_RAWIO; |
| 479 | |
Jens Axboe | 13f8e2d | 2006-10-24 09:29:45 +0200 | [diff] [blame] | 480 | if (td->filename) |
| 481 | td->nr_uniq_files = 1; |
| 482 | else |
| 483 | td->nr_uniq_files = td->nr_files; |
| 484 | |
| 485 | if (td->filetype == FIO_TYPE_FILE || td->filename) { |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 486 | char tmp[PATH_MAX]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 487 | int len = 0; |
| 488 | int i; |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 489 | |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 490 | if (td->directory && td->directory[0] != '\0') |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 491 | sprintf(tmp, "%s/", td->directory); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 492 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 493 | td->files = malloc(sizeof(struct fio_file) * td->nr_files); |
| 494 | |
| 495 | for_each_file(td, f, i) { |
| 496 | memset(f, 0, sizeof(*f)); |
| 497 | f->fd = -1; |
| 498 | |
Jens Axboe | 13f8e2d | 2006-10-24 09:29:45 +0200 | [diff] [blame] | 499 | if (td->filename) |
| 500 | sprintf(tmp + len, "%s", td->filename); |
| 501 | else |
| 502 | sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 503 | f->file_name = strdup(tmp); |
| 504 | } |
| 505 | } else { |
| 506 | td->nr_files = 1; |
| 507 | td->files = malloc(sizeof(struct fio_file)); |
| 508 | f = &td->files[0]; |
| 509 | |
| 510 | memset(f, 0, sizeof(*f)); |
| 511 | f->fd = -1; |
| 512 | f->file_name = strdup(jobname); |
| 513 | } |
| 514 | |
| 515 | for_each_file(td, f, i) { |
| 516 | f->file_size = td->total_file_size / td->nr_files; |
| 517 | f->file_offset = td->start_offset; |
| 518 | } |
| 519 | |
Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 520 | fio_sem_init(&td->mutex, 0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 521 | |
| 522 | td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX; |
| 523 | td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX; |
| 524 | td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX; |
| 525 | |
| 526 | if (td->min_bs == -1U) |
| 527 | td->min_bs = td->bs; |
| 528 | if (td->max_bs == -1U) |
| 529 | td->max_bs = td->bs; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 530 | if (td_read(td) && !td_rw(td)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 531 | td->verify = 0; |
| 532 | |
| 533 | if (td->stonewall && td->thread_number > 1) |
| 534 | groupid++; |
| 535 | |
| 536 | td->groupid = groupid; |
| 537 | |
| 538 | if (setup_rate(td)) |
| 539 | goto err; |
| 540 | |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 541 | if (td->write_lat_log) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 542 | setup_log(&td->slat_log); |
| 543 | setup_log(&td->clat_log); |
| 544 | } |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 545 | if (td->write_bw_log) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 546 | setup_log(&td->bw_log); |
| 547 | |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 548 | if (td->name[0] == '\0') |
| 549 | snprintf(td->name, sizeof(td->name)-1, "client%d", td->thread_number); |
| 550 | |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 551 | ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2); |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 552 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 553 | if (!terse_output) { |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 554 | if (!job_add_num) { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 555 | if (td->io_ops->flags & FIO_CPUIO) |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 556 | fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); |
| 557 | else |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 558 | fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_ops->name, td->iodepth); |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 559 | } else if (job_add_num == 1) |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 560 | fprintf(f_out, "...\n"); |
| 561 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 562 | |
| 563 | /* |
| 564 | * recurse add identical jobs, clear numjobs and stonewall options |
| 565 | * as they don't apply to sub-jobs |
| 566 | */ |
| 567 | numjobs = td->numjobs; |
| 568 | while (--numjobs) { |
| 569 | struct thread_data *td_new = get_new_job(0, td); |
| 570 | |
| 571 | if (!td_new) |
| 572 | goto err; |
| 573 | |
| 574 | td_new->numjobs = 1; |
| 575 | td_new->stonewall = 0; |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 576 | job_add_num = numjobs - 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 577 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 578 | if (add_job(td_new, jobname, job_add_num)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 579 | goto err; |
| 580 | } |
| 581 | return 0; |
| 582 | err: |
| 583 | put_job(td); |
| 584 | return -1; |
| 585 | } |
| 586 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 587 | /* |
| 588 | * Initialize the various random states we need (random io, block size ranges, |
| 589 | * read/write mix, etc). |
| 590 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 591 | int init_random_state(struct thread_data *td) |
| 592 | { |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 593 | unsigned long seeds[4]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 594 | int fd, num_maps, blocks, i; |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 595 | struct fio_file *f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 596 | |
Jens Axboe | 1ac267b | 2006-05-31 20:29:00 +0200 | [diff] [blame] | 597 | fd = open("/dev/urandom", O_RDONLY); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 598 | if (fd == -1) { |
| 599 | td_verror(td, errno); |
| 600 | return 1; |
| 601 | } |
| 602 | |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 603 | if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 604 | td_verror(td, EIO); |
| 605 | close(fd); |
| 606 | return 1; |
| 607 | } |
| 608 | |
| 609 | close(fd); |
| 610 | |
Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 611 | os_random_seed(seeds[0], &td->bsrange_state); |
| 612 | os_random_seed(seeds[1], &td->verify_state); |
| 613 | os_random_seed(seeds[2], &td->rwmix_state); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 614 | |
| 615 | if (td->sequential) |
| 616 | return 0; |
| 617 | |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 618 | if (td->rand_repeatable) |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 619 | seeds[3] = DEF_RANDSEED; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 620 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 621 | for_each_file(td, f, i) { |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 622 | blocks = (f->file_size + td->min_bs - 1) / td->min_bs; |
| 623 | num_maps = blocks / BLOCKS_PER_MAP; |
| 624 | f->file_map = malloc(num_maps * sizeof(long)); |
| 625 | f->num_maps = num_maps; |
| 626 | memset(f->file_map, 0, num_maps * sizeof(long)); |
| 627 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 628 | |
Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 629 | os_random_seed(seeds[3], &td->random_state); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) |
| 634 | { |
| 635 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 636 | unsigned int i; |
| 637 | |
| 638 | CPU_ZERO(&cpumask); |
| 639 | |
| 640 | for (i = 0; i < sizeof(int) * 8; i++) { |
| 641 | if ((1 << i) & cpu) |
| 642 | CPU_SET(i, &cpumask); |
| 643 | } |
| 644 | #endif |
| 645 | } |
| 646 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 647 | static int is_empty_or_comment(char *line) |
| 648 | { |
| 649 | unsigned int i; |
| 650 | |
| 651 | for (i = 0; i < strlen(line); i++) { |
| 652 | if (line[i] == ';') |
| 653 | return 1; |
| 654 | if (!isspace(line[i]) && !iscntrl(line[i])) |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | return 1; |
| 659 | } |
| 660 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 661 | static int str_rw_cb(void *data, char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 662 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 663 | struct thread_data *td = data; |
| 664 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 665 | if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) { |
| 666 | td->ddir = DDIR_READ; |
| 667 | td->sequential = 1; |
| 668 | return 0; |
| 669 | } else if (!strncmp(mem, "randread", 8)) { |
| 670 | td->ddir = DDIR_READ; |
| 671 | td->sequential = 0; |
| 672 | return 0; |
| 673 | } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) { |
| 674 | td->ddir = DDIR_WRITE; |
| 675 | td->sequential = 1; |
| 676 | return 0; |
| 677 | } else if (!strncmp(mem, "randwrite", 9)) { |
| 678 | td->ddir = DDIR_WRITE; |
| 679 | td->sequential = 0; |
| 680 | return 0; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 681 | } else if (!strncmp(mem, "rw", 2)) { |
| 682 | td->ddir = 0; |
| 683 | td->iomix = 1; |
| 684 | td->sequential = 1; |
| 685 | return 0; |
| 686 | } else if (!strncmp(mem, "randrw", 6)) { |
| 687 | td->ddir = 0; |
| 688 | td->iomix = 1; |
| 689 | td->sequential = 0; |
| 690 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 691 | } |
| 692 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 693 | log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 694 | return 1; |
| 695 | } |
| 696 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 697 | static int str_verify_cb(void *data, char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 698 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 699 | struct thread_data *td = data; |
| 700 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 701 | if (!strncmp(mem, "0", 1)) { |
| 702 | td->verify = VERIFY_NONE; |
| 703 | return 0; |
| 704 | } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) { |
| 705 | td->verify = VERIFY_MD5; |
| 706 | return 0; |
| 707 | } else if (!strncmp(mem, "crc32", 5)) { |
| 708 | td->verify = VERIFY_CRC32; |
| 709 | return 0; |
| 710 | } |
| 711 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 712 | log_err("fio: verify types: md5, crc32\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 713 | return 1; |
| 714 | } |
| 715 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 716 | static int str_mem_cb(void *data, char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 717 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 718 | struct thread_data *td = data; |
| 719 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 720 | if (!strncmp(mem, "malloc", 6)) { |
| 721 | td->mem_type = MEM_MALLOC; |
| 722 | return 0; |
| 723 | } else if (!strncmp(mem, "shm", 3)) { |
| 724 | td->mem_type = MEM_SHM; |
| 725 | return 0; |
| 726 | } else if (!strncmp(mem, "mmap", 4)) { |
| 727 | td->mem_type = MEM_MMAP; |
| 728 | return 0; |
| 729 | } |
| 730 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 731 | log_err("fio: mem type: malloc, shm, mmap\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 732 | return 1; |
| 733 | } |
| 734 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 735 | static int str_ioengine_cb(void *data, char *str) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 736 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 737 | struct thread_data *td = data; |
| 738 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 739 | td->io_ops = load_ioengine(td, str); |
| 740 | if (td->io_ops) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 741 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 742 | |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 743 | log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice, cpu\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 744 | return 1; |
| 745 | } |
| 746 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 747 | static int str_lockmem_cb(void fio_unused *data, unsigned long *val) |
| 748 | { |
| 749 | mlock_size = *val; |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static int str_prioclass_cb(void *data, unsigned int *val) |
| 754 | { |
| 755 | struct thread_data *td = data; |
| 756 | |
| 757 | td->ioprio |= *val << IOPRIO_CLASS_SHIFT; |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | static int str_prio_cb(void *data, unsigned int *val) |
| 762 | { |
| 763 | struct thread_data *td = data; |
| 764 | |
| 765 | td->ioprio |= *val; |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static int str_exitall_cb(void) |
| 770 | { |
| 771 | exitall_on_terminate = 1; |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static int str_cpumask_cb(void *data, unsigned int *val) |
| 776 | { |
| 777 | struct thread_data *td = data; |
| 778 | |
| 779 | fill_cpu_mask(td->cpumask, *val); |
| 780 | return 0; |
| 781 | } |
| 782 | |
Jens Axboe | 0726198 | 2006-06-07 10:51:12 +0200 | [diff] [blame] | 783 | /* |
| 784 | * This is our [ini] type file parser. |
| 785 | */ |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 786 | int parse_jobs_ini(char *file, int stonewall_flag) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 787 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 788 | unsigned int global; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 789 | struct thread_data *td; |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 790 | char *string, *name, *tmpbuf; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 791 | fpos_t off; |
| 792 | FILE *f; |
| 793 | char *p; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 794 | int ret = 0, stonewall; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 795 | |
| 796 | f = fopen(file, "r"); |
| 797 | if (!f) { |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 798 | perror("fopen job file"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 799 | return 1; |
| 800 | } |
| 801 | |
| 802 | string = malloc(4096); |
| 803 | name = malloc(256); |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 804 | tmpbuf = malloc(4096); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 805 | |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 806 | stonewall = stonewall_flag; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 807 | while ((p = fgets(string, 4096, f)) != NULL) { |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 808 | if (ret) |
| 809 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 810 | if (is_empty_or_comment(p)) |
| 811 | continue; |
| 812 | if (sscanf(p, "[%s]", name) != 1) |
| 813 | continue; |
| 814 | |
| 815 | global = !strncmp(name, "global", 6); |
| 816 | |
| 817 | name[strlen(name) - 1] = '\0'; |
| 818 | |
| 819 | td = get_new_job(global, &def_thread); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 820 | if (!td) { |
| 821 | ret = 1; |
| 822 | break; |
| 823 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 824 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 825 | /* |
| 826 | * Seperate multiple job files by a stonewall |
| 827 | */ |
Jens Axboe | f948191 | 2006-06-09 11:37:28 +0200 | [diff] [blame] | 828 | if (!global && stonewall) { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 829 | td->stonewall = stonewall; |
| 830 | stonewall = 0; |
| 831 | } |
| 832 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 833 | fgetpos(f, &off); |
| 834 | while ((p = fgets(string, 4096, f)) != NULL) { |
| 835 | if (is_empty_or_comment(p)) |
| 836 | continue; |
| 837 | if (strstr(p, "[")) |
| 838 | break; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 839 | |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 840 | strip_blank_front(&p); |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 841 | strip_blank_end(p); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 842 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 843 | fgetpos(f, &off); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 844 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 845 | /* |
| 846 | * Don't break here, continue parsing options so we |
| 847 | * dump all the bad ones. Makes trial/error fixups |
| 848 | * easier on the user. |
| 849 | */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame^] | 850 | ret = parse_option(p, options, td); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 851 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 852 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 853 | if (!ret) { |
| 854 | fsetpos(f, &off); |
| 855 | ret = add_job(td, name, 0); |
| 856 | } |
| 857 | if (ret) |
| 858 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | free(string); |
| 862 | free(name); |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 863 | free(tmpbuf); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 864 | fclose(f); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 865 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | static int fill_def_thread(void) |
| 869 | { |
| 870 | memset(&def_thread, 0, sizeof(def_thread)); |
| 871 | |
| 872 | if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) { |
| 873 | perror("sched_getaffinity"); |
| 874 | return 1; |
| 875 | } |
| 876 | |
| 877 | /* |
| 878 | * fill globals |
| 879 | */ |
| 880 | def_thread.ddir = DDIR_READ; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 881 | def_thread.iomix = 0; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 882 | def_thread.bs = DEF_BS; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 883 | def_thread.min_bs = -1; |
| 884 | def_thread.max_bs = -1; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 885 | def_thread.odirect = DEF_ODIRECT; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 886 | def_thread.ratecycle = DEF_RATE_CYCLE; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 887 | def_thread.sequential = DEF_SEQUENTIAL; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 888 | def_thread.timeout = def_timeout; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 889 | def_thread.overwrite = DEF_OVERWRITE; |
| 890 | def_thread.invalidate_cache = DEF_INVALIDATE; |
| 891 | def_thread.sync_io = DEF_SYNCIO; |
| 892 | def_thread.mem_type = MEM_MALLOC; |
| 893 | def_thread.bw_avg_time = DEF_BWAVGTIME; |
| 894 | def_thread.create_serialize = DEF_CREATE_SER; |
| 895 | def_thread.create_fsync = DEF_CREATE_FSYNC; |
| 896 | def_thread.loops = DEF_LOOPS; |
| 897 | def_thread.verify = DEF_VERIFY; |
| 898 | def_thread.stonewall = DEF_STONEWALL; |
| 899 | def_thread.numjobs = DEF_NUMJOBS; |
| 900 | def_thread.use_thread = DEF_USE_THREAD; |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 901 | def_thread.rwmixcycle = DEF_RWMIX_CYCLE; |
| 902 | def_thread.rwmixread = DEF_RWMIX_READ; |
Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 903 | def_thread.nice = DEF_NICE; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 904 | def_thread.rand_repeatable = DEF_RAND_REPEAT; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 905 | def_thread.nr_files = DEF_NR_FILES; |
Jens Axboe | f6cbb26 | 2006-10-18 14:16:42 +0200 | [diff] [blame] | 906 | def_thread.unlink = DEF_UNLINK; |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 907 | def_thread.write_bw_log = write_bw_log; |
| 908 | def_thread.write_lat_log = write_lat_log; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 909 | #ifdef FIO_HAVE_DISK_UTIL |
| 910 | def_thread.do_disk_util = 1; |
| 911 | #endif |
| 912 | |
| 913 | return 0; |
| 914 | } |
| 915 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 916 | static void usage(void) |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 917 | { |
| 918 | printf("%s\n", fio_version_string); |
Jens Axboe | 47623c7 | 2006-06-12 10:23:28 +0200 | [diff] [blame] | 919 | printf("\t-o Write output to file\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 920 | printf("\t-t Runtime in seconds\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 921 | printf("\t-l Generate per-job latency logs\n"); |
| 922 | printf("\t-w Generate per-job bandwidth logs\n"); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 923 | printf("\t-m Minimal (terse) output\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 924 | printf("\t-v Print version info and exit\n"); |
| 925 | } |
| 926 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 927 | static int parse_cmd_line(int argc, char *argv[]) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 928 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 929 | int c, idx = 1, ini_idx = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 930 | |
Jens Axboe | 2e77841 | 2006-06-16 10:00:50 +0200 | [diff] [blame] | 931 | while ((c = getopt(argc, argv, "t:o:lwvhm")) != EOF) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 932 | switch (c) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 933 | case 't': |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 934 | def_timeout = atoi(optarg); |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 935 | idx = optind; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 936 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 937 | case 'l': |
| 938 | write_lat_log = 1; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 939 | idx = optind; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 940 | break; |
| 941 | case 'w': |
| 942 | write_bw_log = 1; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 943 | idx = optind; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 944 | break; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 945 | case 'o': |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 946 | f_out = fopen(optarg, "w+"); |
| 947 | if (!f_out) { |
| 948 | perror("fopen output"); |
| 949 | exit(1); |
| 950 | } |
| 951 | f_err = f_out; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 952 | idx = optind; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 953 | break; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 954 | case 'm': |
| 955 | terse_output = 1; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 956 | idx = optind; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 957 | break; |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 958 | case 'h': |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 959 | usage(); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 960 | exit(0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 961 | case 'v': |
| 962 | printf("%s\n", fio_version_string); |
| 963 | exit(0); |
| 964 | } |
| 965 | } |
Jens Axboe | c9fad89 | 2006-05-27 17:26:50 +0200 | [diff] [blame] | 966 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 967 | while (idx < argc) { |
| 968 | ini_idx++; |
| 969 | ini_file = realloc(ini_file, ini_idx * sizeof(char *)); |
| 970 | ini_file[ini_idx - 1] = strdup(argv[idx]); |
| 971 | idx++; |
| 972 | } |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 973 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 974 | if (!f_out) { |
| 975 | f_out = stdout; |
| 976 | f_err = stderr; |
| 977 | } |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 978 | |
| 979 | return ini_idx; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static void free_shm(void) |
| 983 | { |
| 984 | struct shmid_ds sbuf; |
| 985 | |
| 986 | if (threads) { |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 987 | shmdt((void *) threads); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 988 | threads = NULL; |
| 989 | shmctl(shm_id, IPC_RMID, &sbuf); |
| 990 | } |
| 991 | } |
| 992 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 993 | /* |
| 994 | * The thread area is shared between the main process and the job |
| 995 | * threads/processes. So setup a shared memory segment that will hold |
| 996 | * all the job info. |
| 997 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 998 | static int setup_thread_area(void) |
| 999 | { |
| 1000 | /* |
| 1001 | * 1024 is too much on some machines, scale max_jobs if |
| 1002 | * we get a failure that looks like too large a shm segment |
| 1003 | */ |
| 1004 | do { |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1005 | size_t size = max_jobs * sizeof(struct thread_data); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1006 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1007 | shm_id = shmget(0, size, IPC_CREAT | 0600); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1008 | if (shm_id != -1) |
| 1009 | break; |
| 1010 | if (errno != EINVAL) { |
| 1011 | perror("shmget"); |
| 1012 | break; |
| 1013 | } |
| 1014 | |
| 1015 | max_jobs >>= 1; |
| 1016 | } while (max_jobs); |
| 1017 | |
| 1018 | if (shm_id == -1) |
| 1019 | return 1; |
| 1020 | |
| 1021 | threads = shmat(shm_id, NULL, 0); |
| 1022 | if (threads == (void *) -1) { |
| 1023 | perror("shmat"); |
| 1024 | return 1; |
| 1025 | } |
| 1026 | |
| 1027 | atexit(free_shm); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | int parse_options(int argc, char *argv[]) |
| 1032 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1033 | int job_files, i; |
| 1034 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1035 | if (setup_thread_area()) |
| 1036 | return 1; |
| 1037 | if (fill_def_thread()) |
| 1038 | return 1; |
| 1039 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1040 | job_files = parse_cmd_line(argc, argv); |
| 1041 | if (!job_files) { |
| 1042 | log_err("Need job file(s)\n"); |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 1043 | usage(); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1044 | return 1; |
| 1045 | } |
| 1046 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1047 | for (i = 0; i < job_files; i++) { |
| 1048 | if (fill_def_thread()) |
| 1049 | return 1; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1050 | if (parse_jobs_ini(ini_file[i], i)) |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1051 | return 1; |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1052 | free(ini_file[i]); |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1053 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1054 | |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1055 | free(ini_file); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1056 | return 0; |
| 1057 | } |