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