Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1 | #ifndef FIO_H |
| 2 | #define FIO_H |
| 3 | |
| 4 | #include <sched.h> |
| 5 | #include <limits.h> |
| 6 | #include <pthread.h> |
| 7 | #include <sys/time.h> |
| 8 | #include <sys/resource.h> |
| 9 | #include <semaphore.h> |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdio.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 13 | |
| 14 | #include "list.h" |
| 15 | #include "md5.h" |
| 16 | #include "crc32.h" |
| 17 | #include "arch.h" |
| 18 | #include "os.h" |
| 19 | |
| 20 | struct io_stat { |
| 21 | unsigned long val; |
| 22 | unsigned long val_sq; |
| 23 | unsigned long max_val; |
| 24 | unsigned long min_val; |
| 25 | unsigned long samples; |
| 26 | }; |
| 27 | |
| 28 | struct io_sample { |
| 29 | unsigned long time; |
| 30 | unsigned long val; |
| 31 | unsigned int ddir; |
| 32 | }; |
| 33 | |
| 34 | struct io_log { |
| 35 | unsigned long nr_samples; |
| 36 | unsigned long max_samples; |
| 37 | struct io_sample *log; |
| 38 | }; |
| 39 | |
| 40 | struct io_piece { |
| 41 | struct list_head list; |
| 42 | unsigned long long offset; |
| 43 | unsigned int len; |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 44 | int ddir; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * The io unit |
| 49 | */ |
| 50 | struct io_u { |
| 51 | union { |
| 52 | #ifdef FIO_HAVE_LIBAIO |
| 53 | struct iocb iocb; |
| 54 | #endif |
| 55 | #ifdef FIO_HAVE_POSIXAIO |
| 56 | struct aiocb aiocb; |
| 57 | #endif |
| 58 | #ifdef FIO_HAVE_SGIO |
| 59 | struct sg_io_hdr hdr; |
| 60 | #endif |
| 61 | }; |
| 62 | struct timeval start_time; |
| 63 | struct timeval issue_time; |
| 64 | |
| 65 | char *buf; |
| 66 | unsigned int buflen; |
| 67 | unsigned long long offset; |
Jens Axboe | b1ff340 | 2006-02-17 11:35:58 +0100 | [diff] [blame] | 68 | unsigned int index; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 69 | |
| 70 | unsigned int resid; |
| 71 | unsigned int error; |
| 72 | |
| 73 | unsigned char seen; |
| 74 | unsigned char ddir; |
| 75 | |
| 76 | struct list_head list; |
| 77 | }; |
| 78 | |
| 79 | #define FIO_HDR_MAGIC 0xf00baaef |
| 80 | |
| 81 | enum { |
| 82 | VERIFY_NONE = 0, |
| 83 | VERIFY_MD5, |
| 84 | VERIFY_CRC32, |
| 85 | }; |
| 86 | |
| 87 | struct verify_header { |
| 88 | unsigned int fio_magic; |
| 89 | unsigned int len; |
| 90 | unsigned int verify_type; |
| 91 | union { |
| 92 | char md5_digest[MD5_HASH_WORDS * 4]; |
| 93 | unsigned long crc32; |
| 94 | }; |
| 95 | }; |
| 96 | |
| 97 | struct group_run_stats { |
Jens Axboe | 9104f87 | 2005-12-28 23:50:45 +0100 | [diff] [blame] | 98 | unsigned long long max_run[2], min_run[2]; |
| 99 | unsigned long long max_bw[2], min_bw[2]; |
Jens Axboe | e9b2a3f | 2006-06-06 15:38:33 +0200 | [diff] [blame] | 100 | unsigned long long io_kb[2]; |
Jens Axboe | 9104f87 | 2005-12-28 23:50:45 +0100 | [diff] [blame] | 101 | unsigned long long agg[2]; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | struct thread_data { |
| 105 | char file_name[256]; |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 106 | char *directory; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 107 | char verror[80]; |
| 108 | pthread_t thread; |
| 109 | int thread_number; |
| 110 | int groupid; |
| 111 | int filetype; |
| 112 | int error; |
| 113 | int fd; |
| 114 | void *mmap; |
| 115 | pid_t pid; |
| 116 | char *orig_buffer; |
| 117 | size_t orig_buffer_size; |
| 118 | volatile int terminate; |
| 119 | volatile int runstate; |
| 120 | volatile int old_runstate; |
| 121 | unsigned int ddir; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 122 | unsigned int iomix; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 123 | unsigned int ioprio; |
| 124 | unsigned int sequential; |
| 125 | unsigned int bs; |
| 126 | unsigned int min_bs; |
| 127 | unsigned int max_bs; |
| 128 | unsigned int odirect; |
| 129 | unsigned int thinktime; |
| 130 | unsigned int fsync_blocks; |
| 131 | unsigned int start_delay; |
| 132 | unsigned int timeout; |
| 133 | unsigned int io_engine; |
| 134 | unsigned int create_file; |
| 135 | unsigned int overwrite; |
| 136 | unsigned int invalidate_cache; |
| 137 | unsigned int bw_avg_time; |
| 138 | unsigned int create_serialize; |
| 139 | unsigned int create_fsync; |
Jens Axboe | fc1a471 | 2006-05-30 13:04:05 +0200 | [diff] [blame] | 140 | unsigned int end_fsync; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 141 | unsigned int loops; |
| 142 | unsigned long long file_size; |
Jens Axboe | 838a3cd | 2006-01-20 12:38:29 +0100 | [diff] [blame] | 143 | unsigned long long real_file_size; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 144 | unsigned long long file_offset; |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 145 | unsigned long long zone_size; |
| 146 | unsigned long long zone_skip; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 147 | unsigned int sync_io; |
| 148 | unsigned int mem_type; |
| 149 | unsigned int verify; |
| 150 | unsigned int stonewall; |
| 151 | unsigned int numjobs; |
| 152 | unsigned int use_thread; |
| 153 | unsigned int iodepth; |
| 154 | os_cpu_mask_t cpumask; |
Jens Axboe | eba09dd | 2006-05-22 20:20:54 +0200 | [diff] [blame] | 155 | unsigned int jobnum; |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 156 | unsigned int iolog; |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 157 | unsigned int read_iolog; |
| 158 | unsigned int write_iolog; |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 159 | unsigned int rwmixcycle; |
| 160 | unsigned int rwmixread; |
Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 161 | unsigned int nice; |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 162 | |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 163 | char *iolog_file; |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 164 | void *iolog_buf; |
| 165 | FILE *iolog_f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 166 | |
Jens Axboe | da86774 | 2006-06-06 10:39:10 -0700 | [diff] [blame] | 167 | char *sysfs_root; |
| 168 | |
| 169 | char *ioscheduler; |
| 170 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 171 | struct drand48_data bsrange_state; |
| 172 | struct drand48_data verify_state; |
| 173 | |
| 174 | int shm_id; |
| 175 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 176 | void *io_data; |
| 177 | char io_engine_name[16]; |
| 178 | int (*io_prep)(struct thread_data *, struct io_u *); |
| 179 | int (*io_queue)(struct thread_data *, struct io_u *); |
| 180 | int (*io_getevents)(struct thread_data *, int, int, struct timespec *); |
| 181 | struct io_u *(*io_event)(struct thread_data *, int); |
| 182 | int (*io_cancel)(struct thread_data *, struct io_u *); |
| 183 | void (*io_cleanup)(struct thread_data *); |
| 184 | int (*io_sync)(struct thread_data *); |
| 185 | |
| 186 | unsigned int cur_depth; |
| 187 | struct list_head io_u_freelist; |
| 188 | struct list_head io_u_busylist; |
| 189 | |
| 190 | unsigned int rate; |
| 191 | unsigned int ratemin; |
| 192 | unsigned int ratecycle; |
| 193 | unsigned long rate_usec_cycle; |
| 194 | long rate_pending_usleep; |
| 195 | unsigned long rate_bytes; |
| 196 | struct timeval lastrate; |
| 197 | |
| 198 | unsigned long runtime[2]; /* msec */ |
| 199 | unsigned long long io_size; |
| 200 | unsigned long long total_io_size; |
| 201 | |
Jens Axboe | 9104f87 | 2005-12-28 23:50:45 +0100 | [diff] [blame] | 202 | unsigned long long io_blocks[2]; |
| 203 | unsigned long long io_bytes[2]; |
| 204 | unsigned long long zone_bytes; |
| 205 | unsigned long long this_io_bytes[2]; |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 206 | unsigned long long last_pos; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 207 | sem_t mutex; |
| 208 | |
| 209 | struct drand48_data random_state; |
| 210 | unsigned long *file_map; |
| 211 | unsigned int num_maps; |
| 212 | |
| 213 | /* |
| 214 | * bandwidth and latency stats |
| 215 | */ |
| 216 | struct io_stat clat_stat[2]; /* completion latency */ |
| 217 | struct io_stat slat_stat[2]; /* submission latency */ |
| 218 | struct io_stat bw_stat[2]; /* bandwidth stats */ |
| 219 | |
Jens Axboe | 9104f87 | 2005-12-28 23:50:45 +0100 | [diff] [blame] | 220 | unsigned long long stat_io_bytes[2]; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 221 | struct timeval stat_sample_time[2]; |
| 222 | |
| 223 | struct io_log *slat_log; |
| 224 | struct io_log *clat_log; |
| 225 | struct io_log *bw_log; |
| 226 | |
| 227 | struct timeval start; /* start of this loop */ |
| 228 | struct timeval epoch; /* time job was started */ |
| 229 | |
| 230 | struct rusage ru_start; |
| 231 | struct rusage ru_end; |
| 232 | unsigned long usr_time; |
| 233 | unsigned long sys_time; |
| 234 | unsigned long ctx; |
| 235 | |
| 236 | unsigned int do_disk_util; |
| 237 | unsigned int override_sync; |
| 238 | |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 239 | struct drand48_data rwmix_state; |
| 240 | struct timeval rwmix_switch; |
| 241 | int rwmix_ddir; |
| 242 | |
Jens Axboe | 4e0ba8a | 2006-06-06 09:36:28 +0200 | [diff] [blame] | 243 | /* |
| 244 | * Pre-run and post-run shell |
| 245 | */ |
| 246 | char *exec_prerun; |
| 247 | char *exec_postrun; |
| 248 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 249 | struct list_head io_hist_list; |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 250 | struct list_head io_log_list; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | #define td_verror(td, err) \ |
| 254 | do { \ |
| 255 | int e = (err); \ |
| 256 | (td)->error = e; \ |
| 257 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \ |
| 258 | } while (0) |
| 259 | |
| 260 | extern int parse_jobs_ini(char *); |
| 261 | extern int parse_options(int, char **); |
| 262 | extern void finish_log(struct thread_data *, struct io_log *, const char *); |
| 263 | extern int init_random_state(struct thread_data *); |
Jens Axboe | b1ff340 | 2006-02-17 11:35:58 +0100 | [diff] [blame] | 264 | extern struct io_u *__get_io_u(struct thread_data *); |
| 265 | extern void put_io_u(struct thread_data *, struct io_u *); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 266 | |
| 267 | extern int rate_quit; |
| 268 | extern int write_lat_log; |
| 269 | extern int write_bw_log; |
| 270 | extern int exitall_on_terminate; |
| 271 | extern int thread_number; |
| 272 | extern int shm_id; |
| 273 | extern int groupid; |
| 274 | |
| 275 | extern struct thread_data *threads; |
| 276 | |
| 277 | enum { |
| 278 | DDIR_READ = 0, |
| 279 | DDIR_WRITE, |
| 280 | }; |
| 281 | |
| 282 | /* |
| 283 | * What type of allocation to use for io buffers |
| 284 | */ |
| 285 | enum { |
| 286 | MEM_MALLOC, /* ordinary malloc */ |
| 287 | MEM_SHM, /* use shared memory segments */ |
| 288 | MEM_MMAP, /* use anonynomous mmap */ |
| 289 | }; |
| 290 | |
| 291 | /* |
| 292 | * The type of object we are working on |
| 293 | */ |
| 294 | enum { |
| 295 | FIO_TYPE_FILE = 1, |
| 296 | FIO_TYPE_BD, |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 297 | FIO_TYPE_CHAR, |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | enum { |
| 301 | FIO_SYNCIO = 1 << 0, |
| 302 | FIO_MMAPIO = 1 << 1 | FIO_SYNCIO, |
| 303 | FIO_LIBAIO = 1 << 2, |
| 304 | FIO_POSIXAIO = 1 << 3, |
| 305 | FIO_SGIO = 1 << 4, |
Jens Axboe | 8756e4d | 2006-05-27 20:24:53 +0200 | [diff] [blame] | 306 | FIO_SPLICEIO = 1 << 5 | FIO_SYNCIO, |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | #define td_read(td) ((td)->ddir == DDIR_READ) |
| 310 | #define td_write(td) ((td)->ddir == DDIR_WRITE) |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 311 | #define td_rw(td) ((td)->iomix != 0) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 312 | |
| 313 | #define BLOCKS_PER_MAP (8 * sizeof(long)) |
| 314 | #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs)) |
| 315 | #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP) |
| 316 | #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1)) |
| 317 | |
| 318 | #define MAX_JOBS (1024) |
| 319 | |
| 320 | struct disk_util_stat { |
| 321 | unsigned ios[2]; |
| 322 | unsigned merges[2]; |
| 323 | unsigned long long sectors[2]; |
| 324 | unsigned ticks[2]; |
| 325 | unsigned io_ticks; |
| 326 | unsigned time_in_queue; |
| 327 | }; |
| 328 | |
| 329 | struct disk_util { |
| 330 | struct list_head list; |
| 331 | |
| 332 | char *name; |
| 333 | char path[256]; |
| 334 | dev_t dev; |
| 335 | |
| 336 | struct disk_util_stat dus; |
| 337 | struct disk_util_stat last_dus; |
| 338 | |
| 339 | unsigned long msec; |
| 340 | struct timeval time; |
| 341 | }; |
| 342 | |
| 343 | struct io_completion_data { |
| 344 | int nr; /* input */ |
| 345 | |
| 346 | int error; /* output */ |
| 347 | unsigned long bytes_done[2]; /* output */ |
| 348 | }; |
| 349 | |
| 350 | #define DISK_UTIL_MSEC (250) |
| 351 | |
Jens Axboe | 6a0106a | 2006-05-05 10:34:43 +0200 | [diff] [blame] | 352 | #ifndef min |
| 353 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 354 | #endif |
| 355 | |
Jens Axboe | 6796209 | 2006-06-07 08:45:01 +0200 | [diff] [blame^] | 356 | /* |
| 357 | * Log exports |
| 358 | */ |
| 359 | extern int read_iolog_get(struct thread_data *, struct io_u *); |
| 360 | extern void write_iolog_put(struct thread_data *, struct io_u *); |
| 361 | extern int init_iolog(struct thread_data *td); |
| 362 | extern void log_io_piece(struct thread_data *, struct io_u *); |
| 363 | extern void prune_io_piece_log(struct thread_data *); |
| 364 | extern void write_iolog_close(struct thread_data *); |
| 365 | |
| 366 | /* |
| 367 | * Logging |
| 368 | */ |
| 369 | extern void add_clat_sample(struct thread_data *, int, unsigned long); |
| 370 | extern void add_slat_sample(struct thread_data *, int, unsigned long); |
| 371 | extern void add_bw_sample(struct thread_data *, int); |
| 372 | extern void show_run_stats(void); |
| 373 | extern void init_disk_util(struct thread_data *); |
| 374 | extern void update_rusage_stat(struct thread_data *); |
| 375 | extern void update_io_ticks(void); |
| 376 | extern void disk_util_timer_arm(void); |
| 377 | |
| 378 | /* |
| 379 | * Time functions |
| 380 | */ |
| 381 | extern unsigned long utime_since(struct timeval *, struct timeval *); |
| 382 | extern unsigned long mtime_since(struct timeval *, struct timeval *); |
| 383 | extern unsigned long mtime_since_now(struct timeval *); |
| 384 | extern unsigned long time_since_now(struct timeval *); |
| 385 | extern void usec_sleep(struct thread_data *, unsigned long); |
| 386 | extern void rate_throttle(struct thread_data *, unsigned long, unsigned int); |
| 387 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 388 | #endif |