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