| 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> | 
| Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 9 | #include <errno.h> | 
|  | 10 | #include <stdlib.h> | 
|  | 11 | #include <stdio.h> | 
| Jens Axboe | 6d6f031 | 2006-06-07 21:39:13 +0200 | [diff] [blame] | 12 | #include <unistd.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 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 104 | enum fio_ddir { | 
|  | 105 | DDIR_READ = 0, | 
|  | 106 | DDIR_WRITE, | 
|  | 107 | }; | 
|  | 108 |  | 
|  | 109 | /* | 
|  | 110 | * What type of allocation to use for io buffers | 
|  | 111 | */ | 
|  | 112 | enum fio_memtype { | 
|  | 113 | MEM_MALLOC = 0,	/* ordinary malloc */ | 
|  | 114 | MEM_SHM,	/* use shared memory segments */ | 
|  | 115 | MEM_MMAP,	/* use anonynomous mmap */ | 
|  | 116 | }; | 
|  | 117 |  | 
|  | 118 | /* | 
|  | 119 | * The type of object we are working on | 
|  | 120 | */ | 
|  | 121 | enum fio_filetype { | 
|  | 122 | FIO_TYPE_FILE = 1, | 
|  | 123 | FIO_TYPE_BD, | 
|  | 124 | FIO_TYPE_CHAR, | 
|  | 125 | }; | 
|  | 126 |  | 
| Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame^] | 127 | enum fio_ioengine_flags { | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 128 | FIO_SYNCIO	= 1 << 0, | 
| Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame^] | 129 | FIO_CPUIO	= 1 << 1, | 
|  | 130 | FIO_MMAPIO	= 1 << 2, | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 131 | }; | 
|  | 132 |  | 
|  | 133 | /* | 
|  | 134 | * This describes a single thread/process executing a fio job. | 
|  | 135 | */ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 136 | struct thread_data { | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 137 | char name[32]; | 
|  | 138 | char *file_name; | 
| Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 139 | char *directory; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 140 | char verror[80]; | 
|  | 141 | pthread_t thread; | 
|  | 142 | int thread_number; | 
|  | 143 | int groupid; | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 144 | enum fio_filetype filetype; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 145 | int error; | 
|  | 146 | int fd; | 
|  | 147 | void *mmap; | 
|  | 148 | pid_t pid; | 
|  | 149 | char *orig_buffer; | 
|  | 150 | size_t orig_buffer_size; | 
|  | 151 | volatile int terminate; | 
|  | 152 | volatile int runstate; | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 153 | enum fio_ddir ddir; | 
| Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 154 | unsigned int iomix; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 155 | unsigned int ioprio; | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 156 |  | 
|  | 157 | unsigned char sequential; | 
|  | 158 | unsigned char odirect; | 
|  | 159 | unsigned char create_file; | 
|  | 160 | unsigned char invalidate_cache; | 
|  | 161 | unsigned char create_serialize; | 
|  | 162 | unsigned char create_fsync; | 
|  | 163 | unsigned char end_fsync; | 
|  | 164 | unsigned char sync_io; | 
|  | 165 | unsigned char verify; | 
|  | 166 | unsigned char use_thread; | 
|  | 167 | unsigned char do_disk_util; | 
|  | 168 | unsigned char override_sync; | 
| Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 169 | unsigned char rand_repeatable; | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 170 |  | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 171 | unsigned int bs; | 
|  | 172 | unsigned int min_bs; | 
|  | 173 | unsigned int max_bs; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 174 | unsigned int thinktime; | 
|  | 175 | unsigned int fsync_blocks; | 
|  | 176 | unsigned int start_delay; | 
| Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 177 | unsigned long timeout; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 178 | unsigned int overwrite; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 179 | unsigned int bw_avg_time; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 180 | unsigned int loops; | 
|  | 181 | unsigned long long file_size; | 
| Jens Axboe | 838a3cd | 2006-01-20 12:38:29 +0100 | [diff] [blame] | 182 | unsigned long long real_file_size; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 183 | unsigned long long file_offset; | 
| Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 184 | unsigned long long zone_size; | 
|  | 185 | unsigned long long zone_skip; | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 186 | enum fio_memtype mem_type; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 187 | unsigned int stonewall; | 
|  | 188 | unsigned int numjobs; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 189 | unsigned int iodepth; | 
|  | 190 | os_cpu_mask_t cpumask; | 
| Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 191 | unsigned int iolog; | 
| Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 192 | unsigned int read_iolog; | 
|  | 193 | unsigned int write_iolog; | 
| Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 194 | unsigned int rwmixcycle; | 
|  | 195 | unsigned int rwmixread; | 
| Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 196 | unsigned int nice; | 
| Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 197 |  | 
| Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 198 | char *iolog_file; | 
| Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 199 | void *iolog_buf; | 
|  | 200 | FILE *iolog_f; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 201 |  | 
| Jens Axboe | da86774 | 2006-06-06 10:39:10 -0700 | [diff] [blame] | 202 | char *sysfs_root; | 
| Jens Axboe | da86774 | 2006-06-06 10:39:10 -0700 | [diff] [blame] | 203 | char *ioscheduler; | 
|  | 204 |  | 
| Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 205 | os_random_state_t bsrange_state; | 
|  | 206 | os_random_state_t verify_state; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 207 |  | 
|  | 208 | int shm_id; | 
|  | 209 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 210 | /* | 
|  | 211 | * IO engine hooks, contains everything needed to submit an io_u | 
|  | 212 | * to any of the available IO engines. | 
|  | 213 | */ | 
| Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame^] | 214 | struct ioengine_ops *io_ops; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 215 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 216 | /* | 
|  | 217 | * Current IO depth and list of free and busy io_u's. | 
|  | 218 | */ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 219 | unsigned int cur_depth; | 
|  | 220 | struct list_head io_u_freelist; | 
|  | 221 | struct list_head io_u_busylist; | 
|  | 222 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 223 | /* | 
|  | 224 | * Rate state | 
|  | 225 | */ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 226 | unsigned int rate; | 
|  | 227 | unsigned int ratemin; | 
|  | 228 | unsigned int ratecycle; | 
|  | 229 | unsigned long rate_usec_cycle; | 
|  | 230 | long rate_pending_usleep; | 
|  | 231 | unsigned long rate_bytes; | 
|  | 232 | struct timeval lastrate; | 
|  | 233 |  | 
|  | 234 | unsigned long runtime[2];		/* msec */ | 
|  | 235 | unsigned long long io_size; | 
|  | 236 | unsigned long long total_io_size; | 
|  | 237 |  | 
| Jens Axboe | 9104f87 | 2005-12-28 23:50:45 +0100 | [diff] [blame] | 238 | unsigned long long io_blocks[2]; | 
|  | 239 | unsigned long long io_bytes[2]; | 
|  | 240 | unsigned long long zone_bytes; | 
|  | 241 | unsigned long long this_io_bytes[2]; | 
| Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 242 | unsigned long long last_pos; | 
| Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 243 | volatile int mutex; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 244 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 245 | /* | 
|  | 246 | * State for random io, a bitmap of blocks done vs not done | 
|  | 247 | */ | 
| Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 248 | os_random_state_t random_state; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 249 | unsigned long *file_map; | 
|  | 250 | unsigned int num_maps; | 
|  | 251 |  | 
|  | 252 | /* | 
| Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 253 | * CPU "io" cycle burner | 
|  | 254 | */ | 
|  | 255 | unsigned int cpuload; | 
|  | 256 | unsigned int cpucycle; | 
|  | 257 |  | 
|  | 258 | /* | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 259 | * bandwidth and latency stats | 
|  | 260 | */ | 
|  | 261 | struct io_stat clat_stat[2];		/* completion latency */ | 
|  | 262 | struct io_stat slat_stat[2];		/* submission latency */ | 
|  | 263 | struct io_stat bw_stat[2];		/* bandwidth stats */ | 
|  | 264 |  | 
| Jens Axboe | 9104f87 | 2005-12-28 23:50:45 +0100 | [diff] [blame] | 265 | unsigned long long stat_io_bytes[2]; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 266 | struct timeval stat_sample_time[2]; | 
|  | 267 |  | 
|  | 268 | struct io_log *slat_log; | 
|  | 269 | struct io_log *clat_log; | 
|  | 270 | struct io_log *bw_log; | 
|  | 271 |  | 
|  | 272 | struct timeval start;	/* start of this loop */ | 
|  | 273 | struct timeval epoch;	/* time job was started */ | 
|  | 274 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 275 | /* | 
|  | 276 | * fio system usage accounting | 
|  | 277 | */ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 278 | struct rusage ru_start; | 
|  | 279 | struct rusage ru_end; | 
|  | 280 | unsigned long usr_time; | 
|  | 281 | unsigned long sys_time; | 
|  | 282 | unsigned long ctx; | 
|  | 283 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 284 | /* | 
|  | 285 | * read/write mixed workload state | 
|  | 286 | */ | 
| Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 287 | os_random_state_t rwmix_state; | 
| Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 288 | struct timeval rwmix_switch; | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 289 | enum fio_ddir rwmix_ddir; | 
| Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 290 |  | 
| Jens Axboe | 4e0ba8a | 2006-06-06 09:36:28 +0200 | [diff] [blame] | 291 | /* | 
|  | 292 | * Pre-run and post-run shell | 
|  | 293 | */ | 
|  | 294 | char *exec_prerun; | 
|  | 295 | char *exec_postrun; | 
|  | 296 |  | 
| Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 297 | /* | 
|  | 298 | * IO historic logs | 
|  | 299 | */ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 300 | struct list_head io_hist_list; | 
| Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 301 | struct list_head io_log_list; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 302 | }; | 
|  | 303 |  | 
| Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 304 | #define __td_verror(td, err, msg)					\ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 305 | do {								\ | 
|  | 306 | int e = (err);						\ | 
|  | 307 | (td)->error = e;					\ | 
| Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 308 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, (msg));	\ | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 309 | } while (0) | 
|  | 310 |  | 
| Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 311 |  | 
|  | 312 | #define td_verror(td, err)	__td_verror((td), (err), strerror((err))) | 
|  | 313 | #define td_vmsg(td, err, msg)	__td_verror((td), (err), (msg)) | 
|  | 314 |  | 
| Jens Axboe | b1ff340 | 2006-02-17 11:35:58 +0100 | [diff] [blame] | 315 | extern struct io_u *__get_io_u(struct thread_data *); | 
|  | 316 | extern void put_io_u(struct thread_data *, struct io_u *); | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 317 |  | 
|  | 318 | extern int rate_quit; | 
|  | 319 | extern int write_lat_log; | 
|  | 320 | extern int write_bw_log; | 
|  | 321 | extern int exitall_on_terminate; | 
|  | 322 | extern int thread_number; | 
|  | 323 | extern int shm_id; | 
|  | 324 | extern int groupid; | 
| Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 325 | extern int terse_output; | 
| Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 326 | extern FILE *f_out; | 
|  | 327 | extern FILE *f_err; | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 328 |  | 
|  | 329 | extern struct thread_data *threads; | 
|  | 330 |  | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 331 | #define td_read(td)		((td)->ddir == DDIR_READ) | 
|  | 332 | #define td_write(td)		((td)->ddir == DDIR_WRITE) | 
| Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 333 | #define td_rw(td)		((td)->iomix != 0) | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 334 |  | 
|  | 335 | #define BLOCKS_PER_MAP		(8 * sizeof(long)) | 
|  | 336 | #define TO_MAP_BLOCK(td, b)	((b) - ((td)->file_offset / (td)->min_bs)) | 
|  | 337 | #define RAND_MAP_IDX(td, b)	(TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP) | 
|  | 338 | #define RAND_MAP_BIT(td, b)	(TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1)) | 
|  | 339 |  | 
|  | 340 | #define MAX_JOBS	(1024) | 
|  | 341 |  | 
|  | 342 | struct disk_util_stat { | 
|  | 343 | unsigned ios[2]; | 
|  | 344 | unsigned merges[2]; | 
|  | 345 | unsigned long long sectors[2]; | 
|  | 346 | unsigned ticks[2]; | 
|  | 347 | unsigned io_ticks; | 
|  | 348 | unsigned time_in_queue; | 
|  | 349 | }; | 
|  | 350 |  | 
|  | 351 | struct disk_util { | 
|  | 352 | struct list_head list; | 
|  | 353 |  | 
|  | 354 | char *name; | 
|  | 355 | char path[256]; | 
|  | 356 | dev_t dev; | 
|  | 357 |  | 
|  | 358 | struct disk_util_stat dus; | 
|  | 359 | struct disk_util_stat last_dus; | 
|  | 360 |  | 
|  | 361 | unsigned long msec; | 
|  | 362 | struct timeval time; | 
|  | 363 | }; | 
|  | 364 |  | 
|  | 365 | struct io_completion_data { | 
|  | 366 | int nr;				/* input */ | 
|  | 367 |  | 
|  | 368 | int error;			/* output */ | 
|  | 369 | unsigned long bytes_done[2];	/* output */ | 
|  | 370 | }; | 
|  | 371 |  | 
|  | 372 | #define DISK_UTIL_MSEC	(250) | 
|  | 373 |  | 
| Jens Axboe | 6a0106a | 2006-05-05 10:34:43 +0200 | [diff] [blame] | 374 | #ifndef min | 
|  | 375 | #define min(a, b)	((a) < (b) ? (a) : (b)) | 
|  | 376 | #endif | 
|  | 377 |  | 
| Jens Axboe | 6796209 | 2006-06-07 08:45:01 +0200 | [diff] [blame] | 378 | /* | 
|  | 379 | * Log exports | 
|  | 380 | */ | 
|  | 381 | extern int read_iolog_get(struct thread_data *, struct io_u *); | 
|  | 382 | extern void write_iolog_put(struct thread_data *, struct io_u *); | 
|  | 383 | extern int init_iolog(struct thread_data *td); | 
|  | 384 | extern void log_io_piece(struct thread_data *, struct io_u *); | 
|  | 385 | extern void prune_io_piece_log(struct thread_data *); | 
|  | 386 | extern void write_iolog_close(struct thread_data *); | 
|  | 387 |  | 
|  | 388 | /* | 
|  | 389 | * Logging | 
|  | 390 | */ | 
|  | 391 | extern void add_clat_sample(struct thread_data *, int, unsigned long); | 
|  | 392 | extern void add_slat_sample(struct thread_data *, int, unsigned long); | 
|  | 393 | extern void add_bw_sample(struct thread_data *, int); | 
|  | 394 | extern void show_run_stats(void); | 
|  | 395 | extern void init_disk_util(struct thread_data *); | 
|  | 396 | extern void update_rusage_stat(struct thread_data *); | 
|  | 397 | extern void update_io_ticks(void); | 
|  | 398 | extern void disk_util_timer_arm(void); | 
| Jens Axboe | 8914a9d | 2006-06-07 11:14:56 +0200 | [diff] [blame] | 399 | extern void setup_log(struct io_log **); | 
|  | 400 | extern void finish_log(struct thread_data *, struct io_log *, const char *); | 
|  | 401 | extern int setup_rate(struct thread_data *); | 
| Jens Axboe | 6796209 | 2006-06-07 08:45:01 +0200 | [diff] [blame] | 402 |  | 
|  | 403 | /* | 
|  | 404 | * Time functions | 
|  | 405 | */ | 
|  | 406 | extern unsigned long utime_since(struct timeval *, struct timeval *); | 
|  | 407 | extern unsigned long mtime_since(struct timeval *, struct timeval *); | 
|  | 408 | extern unsigned long mtime_since_now(struct timeval *); | 
|  | 409 | extern unsigned long time_since_now(struct timeval *); | 
| Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 410 | extern void __usec_sleep(unsigned int); | 
| Jens Axboe | 6796209 | 2006-06-07 08:45:01 +0200 | [diff] [blame] | 411 | extern void usec_sleep(struct thread_data *, unsigned long); | 
|  | 412 | extern void rate_throttle(struct thread_data *, unsigned long, unsigned int); | 
|  | 413 |  | 
| Jens Axboe | 8914a9d | 2006-06-07 11:14:56 +0200 | [diff] [blame] | 414 | /* | 
|  | 415 | * Init functions | 
|  | 416 | */ | 
|  | 417 | extern int parse_options(int, char **); | 
|  | 418 | extern int init_random_state(struct thread_data *); | 
|  | 419 |  | 
| Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 420 | /* | 
|  | 421 | * This is a pretty crappy semaphore implementation, but with the use that fio | 
|  | 422 | * has (just signalling start/go conditions), it doesn't have to be better. | 
|  | 423 | * Naturally this would not work for any type of contended semaphore or | 
|  | 424 | * for real locking. | 
|  | 425 | */ | 
| Jens Axboe | 1056eaa | 2006-07-13 10:33:45 -0700 | [diff] [blame] | 426 | static inline void fio_sem_init(volatile int *sem, int val) | 
| Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 427 | { | 
|  | 428 | *sem = val; | 
|  | 429 | } | 
|  | 430 |  | 
| Jens Axboe | 1056eaa | 2006-07-13 10:33:45 -0700 | [diff] [blame] | 431 | static inline void fio_sem_down(volatile int *sem) | 
| Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 432 | { | 
|  | 433 | while (*sem == 0) | 
|  | 434 | usleep(10000); | 
|  | 435 |  | 
|  | 436 | (*sem)--; | 
|  | 437 | } | 
|  | 438 |  | 
| Jens Axboe | 1056eaa | 2006-07-13 10:33:45 -0700 | [diff] [blame] | 439 | static inline void fio_sem_up(volatile int *sem) | 
| Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 440 | { | 
|  | 441 | (*sem)++; | 
|  | 442 | } | 
|  | 443 |  | 
| Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 444 | /* | 
|  | 445 | * If logging output to a file, stderr should go to both stderr and f_err | 
|  | 446 | */ | 
|  | 447 | #define log_err(args...)	do {		\ | 
|  | 448 | fprintf(f_err, ##args);			\ | 
|  | 449 | if (f_err != stderr)			\ | 
|  | 450 | fprintf(stderr, ##args);	\ | 
|  | 451 | } while (0) | 
|  | 452 |  | 
| Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame^] | 453 | struct ioengine_ops { | 
|  | 454 | char name[16]; | 
|  | 455 | int version; | 
|  | 456 | int flags; | 
|  | 457 | int (*init)(struct thread_data *); | 
|  | 458 | int (*prep)(struct thread_data *, struct io_u *); | 
|  | 459 | int (*queue)(struct thread_data *, struct io_u *); | 
|  | 460 | int (*getevents)(struct thread_data *, int, int, struct timespec *); | 
|  | 461 | struct io_u *(*event)(struct thread_data *, int); | 
|  | 462 | int (*cancel)(struct thread_data *, struct io_u *); | 
|  | 463 | void (*cleanup)(struct thread_data *); | 
|  | 464 | int (*sync)(struct thread_data *); | 
|  | 465 | void *data; | 
|  | 466 | void *dlhandle; | 
|  | 467 | }; | 
|  | 468 |  | 
|  | 469 | #define FIO_IOOPS_VERSION	1 | 
|  | 470 |  | 
|  | 471 | extern struct ioengine_ops *load_ioengine(struct thread_data *, char *); | 
|  | 472 | extern void close_ioengine(struct thread_data *); | 
|  | 473 |  | 
|  | 474 | /* | 
|  | 475 | * Mark unused variables passed to ops functions as unused, to silence gcc | 
|  | 476 | */ | 
|  | 477 | #define fio_unused	__attribute((__unused__)) | 
|  | 478 |  | 
| Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 479 | #endif |