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