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> |
| 10 | |
| 11 | #include "list.h" |
| 12 | #include "md5.h" |
| 13 | #include "crc32.h" |
| 14 | #include "arch.h" |
| 15 | #include "os.h" |
| 16 | |
| 17 | struct io_stat { |
| 18 | unsigned long val; |
| 19 | unsigned long val_sq; |
| 20 | unsigned long max_val; |
| 21 | unsigned long min_val; |
| 22 | unsigned long samples; |
| 23 | }; |
| 24 | |
| 25 | struct io_sample { |
| 26 | unsigned long time; |
| 27 | unsigned long val; |
| 28 | unsigned int ddir; |
| 29 | }; |
| 30 | |
| 31 | struct io_log { |
| 32 | unsigned long nr_samples; |
| 33 | unsigned long max_samples; |
| 34 | struct io_sample *log; |
| 35 | }; |
| 36 | |
| 37 | struct io_piece { |
| 38 | struct list_head list; |
| 39 | unsigned long long offset; |
| 40 | unsigned int len; |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * The io unit |
| 45 | */ |
| 46 | struct io_u { |
| 47 | union { |
| 48 | #ifdef FIO_HAVE_LIBAIO |
| 49 | struct iocb iocb; |
| 50 | #endif |
| 51 | #ifdef FIO_HAVE_POSIXAIO |
| 52 | struct aiocb aiocb; |
| 53 | #endif |
| 54 | #ifdef FIO_HAVE_SGIO |
| 55 | struct sg_io_hdr hdr; |
| 56 | #endif |
| 57 | }; |
| 58 | struct timeval start_time; |
| 59 | struct timeval issue_time; |
| 60 | |
| 61 | char *buf; |
| 62 | unsigned int buflen; |
| 63 | unsigned long long offset; |
| 64 | |
| 65 | unsigned int resid; |
| 66 | unsigned int error; |
| 67 | |
| 68 | unsigned char seen; |
| 69 | unsigned char ddir; |
| 70 | |
| 71 | struct list_head list; |
| 72 | }; |
| 73 | |
| 74 | #define FIO_HDR_MAGIC 0xf00baaef |
| 75 | |
| 76 | enum { |
| 77 | VERIFY_NONE = 0, |
| 78 | VERIFY_MD5, |
| 79 | VERIFY_CRC32, |
| 80 | }; |
| 81 | |
| 82 | struct verify_header { |
| 83 | unsigned int fio_magic; |
| 84 | unsigned int len; |
| 85 | unsigned int verify_type; |
| 86 | union { |
| 87 | char md5_digest[MD5_HASH_WORDS * 4]; |
| 88 | unsigned long crc32; |
| 89 | }; |
| 90 | }; |
| 91 | |
| 92 | struct group_run_stats { |
| 93 | unsigned long max_run[2], min_run[2]; |
| 94 | unsigned long max_bw[2], min_bw[2]; |
| 95 | unsigned long io_mb[2]; |
| 96 | unsigned long agg[2]; |
| 97 | }; |
| 98 | |
| 99 | struct thread_data { |
| 100 | char file_name[256]; |
| 101 | char directory[256]; |
| 102 | char verror[80]; |
| 103 | pthread_t thread; |
| 104 | int thread_number; |
| 105 | int groupid; |
| 106 | int filetype; |
| 107 | int error; |
| 108 | int fd; |
| 109 | void *mmap; |
| 110 | pid_t pid; |
| 111 | char *orig_buffer; |
| 112 | size_t orig_buffer_size; |
| 113 | volatile int terminate; |
| 114 | volatile int runstate; |
| 115 | volatile int old_runstate; |
| 116 | unsigned int ddir; |
| 117 | unsigned int ioprio; |
| 118 | unsigned int sequential; |
| 119 | unsigned int bs; |
| 120 | unsigned int min_bs; |
| 121 | unsigned int max_bs; |
| 122 | unsigned int odirect; |
| 123 | unsigned int thinktime; |
| 124 | unsigned int fsync_blocks; |
| 125 | unsigned int start_delay; |
| 126 | unsigned int timeout; |
| 127 | unsigned int io_engine; |
| 128 | unsigned int create_file; |
| 129 | unsigned int overwrite; |
| 130 | unsigned int invalidate_cache; |
| 131 | unsigned int bw_avg_time; |
| 132 | unsigned int create_serialize; |
| 133 | unsigned int create_fsync; |
| 134 | unsigned int loops; |
| 135 | unsigned long long file_size; |
| 136 | unsigned long long file_offset; |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame^] | 137 | unsigned long long zone_size; |
| 138 | unsigned long long zone_skip; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 139 | unsigned int sync_io; |
| 140 | unsigned int mem_type; |
| 141 | unsigned int verify; |
| 142 | unsigned int stonewall; |
| 143 | unsigned int numjobs; |
| 144 | unsigned int use_thread; |
| 145 | unsigned int iodepth; |
| 146 | os_cpu_mask_t cpumask; |
| 147 | |
| 148 | struct drand48_data bsrange_state; |
| 149 | struct drand48_data verify_state; |
| 150 | |
| 151 | int shm_id; |
| 152 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 153 | void *io_data; |
| 154 | char io_engine_name[16]; |
| 155 | int (*io_prep)(struct thread_data *, struct io_u *); |
| 156 | int (*io_queue)(struct thread_data *, struct io_u *); |
| 157 | int (*io_getevents)(struct thread_data *, int, int, struct timespec *); |
| 158 | struct io_u *(*io_event)(struct thread_data *, int); |
| 159 | int (*io_cancel)(struct thread_data *, struct io_u *); |
| 160 | void (*io_cleanup)(struct thread_data *); |
| 161 | int (*io_sync)(struct thread_data *); |
| 162 | |
| 163 | unsigned int cur_depth; |
| 164 | struct list_head io_u_freelist; |
| 165 | struct list_head io_u_busylist; |
| 166 | |
| 167 | unsigned int rate; |
| 168 | unsigned int ratemin; |
| 169 | unsigned int ratecycle; |
| 170 | unsigned long rate_usec_cycle; |
| 171 | long rate_pending_usleep; |
| 172 | unsigned long rate_bytes; |
| 173 | struct timeval lastrate; |
| 174 | |
| 175 | unsigned long runtime[2]; /* msec */ |
| 176 | unsigned long long io_size; |
| 177 | unsigned long long total_io_size; |
| 178 | |
| 179 | unsigned long io_blocks[2]; |
| 180 | unsigned long io_bytes[2]; |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame^] | 181 | unsigned long zone_bytes; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 182 | unsigned long this_io_bytes[2]; |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame^] | 183 | unsigned long long last_pos; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 184 | sem_t mutex; |
| 185 | |
| 186 | struct drand48_data random_state; |
| 187 | unsigned long *file_map; |
| 188 | unsigned int num_maps; |
| 189 | |
| 190 | /* |
| 191 | * bandwidth and latency stats |
| 192 | */ |
| 193 | struct io_stat clat_stat[2]; /* completion latency */ |
| 194 | struct io_stat slat_stat[2]; /* submission latency */ |
| 195 | struct io_stat bw_stat[2]; /* bandwidth stats */ |
| 196 | |
| 197 | unsigned long stat_io_bytes[2]; |
| 198 | struct timeval stat_sample_time[2]; |
| 199 | |
| 200 | struct io_log *slat_log; |
| 201 | struct io_log *clat_log; |
| 202 | struct io_log *bw_log; |
| 203 | |
| 204 | struct timeval start; /* start of this loop */ |
| 205 | struct timeval epoch; /* time job was started */ |
| 206 | |
| 207 | struct rusage ru_start; |
| 208 | struct rusage ru_end; |
| 209 | unsigned long usr_time; |
| 210 | unsigned long sys_time; |
| 211 | unsigned long ctx; |
| 212 | |
| 213 | unsigned int do_disk_util; |
| 214 | unsigned int override_sync; |
| 215 | |
| 216 | struct list_head io_hist_list; |
| 217 | }; |
| 218 | |
| 219 | #define td_verror(td, err) \ |
| 220 | do { \ |
| 221 | int e = (err); \ |
| 222 | (td)->error = e; \ |
| 223 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \ |
| 224 | } while (0) |
| 225 | |
| 226 | extern int parse_jobs_ini(char *); |
| 227 | extern int parse_options(int, char **); |
| 228 | extern void finish_log(struct thread_data *, struct io_log *, const char *); |
| 229 | extern int init_random_state(struct thread_data *); |
| 230 | |
| 231 | extern int rate_quit; |
| 232 | extern int write_lat_log; |
| 233 | extern int write_bw_log; |
| 234 | extern int exitall_on_terminate; |
| 235 | extern int thread_number; |
| 236 | extern int shm_id; |
| 237 | extern int groupid; |
| 238 | |
| 239 | extern struct thread_data *threads; |
| 240 | |
| 241 | enum { |
| 242 | DDIR_READ = 0, |
| 243 | DDIR_WRITE, |
| 244 | }; |
| 245 | |
| 246 | /* |
| 247 | * What type of allocation to use for io buffers |
| 248 | */ |
| 249 | enum { |
| 250 | MEM_MALLOC, /* ordinary malloc */ |
| 251 | MEM_SHM, /* use shared memory segments */ |
| 252 | MEM_MMAP, /* use anonynomous mmap */ |
| 253 | }; |
| 254 | |
| 255 | /* |
| 256 | * The type of object we are working on |
| 257 | */ |
| 258 | enum { |
| 259 | FIO_TYPE_FILE = 1, |
| 260 | FIO_TYPE_BD, |
| 261 | }; |
| 262 | |
| 263 | enum { |
| 264 | FIO_SYNCIO = 1 << 0, |
| 265 | FIO_MMAPIO = 1 << 1 | FIO_SYNCIO, |
| 266 | FIO_LIBAIO = 1 << 2, |
| 267 | FIO_POSIXAIO = 1 << 3, |
| 268 | FIO_SGIO = 1 << 4, |
| 269 | }; |
| 270 | |
| 271 | #define td_read(td) ((td)->ddir == DDIR_READ) |
| 272 | #define td_write(td) ((td)->ddir == DDIR_WRITE) |
| 273 | |
| 274 | #define BLOCKS_PER_MAP (8 * sizeof(long)) |
| 275 | #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs)) |
| 276 | #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP) |
| 277 | #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1)) |
| 278 | |
| 279 | #define MAX_JOBS (1024) |
| 280 | |
| 281 | struct disk_util_stat { |
| 282 | unsigned ios[2]; |
| 283 | unsigned merges[2]; |
| 284 | unsigned long long sectors[2]; |
| 285 | unsigned ticks[2]; |
| 286 | unsigned io_ticks; |
| 287 | unsigned time_in_queue; |
| 288 | }; |
| 289 | |
| 290 | struct disk_util { |
| 291 | struct list_head list; |
| 292 | |
| 293 | char *name; |
| 294 | char path[256]; |
| 295 | dev_t dev; |
| 296 | |
| 297 | struct disk_util_stat dus; |
| 298 | struct disk_util_stat last_dus; |
| 299 | |
| 300 | unsigned long msec; |
| 301 | struct timeval time; |
| 302 | }; |
| 303 | |
| 304 | struct io_completion_data { |
| 305 | int nr; /* input */ |
| 306 | |
| 307 | int error; /* output */ |
| 308 | unsigned long bytes_done[2]; /* output */ |
| 309 | }; |
| 310 | |
| 311 | #define DISK_UTIL_MSEC (250) |
| 312 | |
| 313 | #endif |