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