Commit | Line | Data |
---|---|---|
ebac4655 JA |
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> | |
3c39a379 JA |
10 | #include <errno.h> |
11 | #include <stdlib.h> | |
12 | #include <stdio.h> | |
ebac4655 JA |
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; | |
aea47d44 | 44 | int ddir; |
ebac4655 JA |
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; | |
b1ff3403 | 68 | unsigned int index; |
ebac4655 JA |
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 { | |
9104f874 JA |
98 | unsigned long long max_run[2], min_run[2]; |
99 | unsigned long long max_bw[2], min_bw[2]; | |
e9b2a3fa | 100 | unsigned long long io_kb[2]; |
9104f874 | 101 | unsigned long long agg[2]; |
ebac4655 JA |
102 | }; |
103 | ||
104 | struct thread_data { | |
01452055 | 105 | char name[64]; |
ebac4655 | 106 | char file_name[256]; |
ef899b63 | 107 | char *directory; |
ebac4655 JA |
108 | char verror[80]; |
109 | pthread_t thread; | |
110 | int thread_number; | |
111 | int groupid; | |
112 | int filetype; | |
113 | int error; | |
114 | int fd; | |
115 | void *mmap; | |
116 | pid_t pid; | |
117 | char *orig_buffer; | |
118 | size_t orig_buffer_size; | |
119 | volatile int terminate; | |
120 | volatile int runstate; | |
121 | volatile int old_runstate; | |
122 | unsigned int ddir; | |
3d60d1ed | 123 | unsigned int iomix; |
ebac4655 JA |
124 | unsigned int ioprio; |
125 | unsigned int sequential; | |
126 | unsigned int bs; | |
127 | unsigned int min_bs; | |
128 | unsigned int max_bs; | |
129 | unsigned int odirect; | |
130 | unsigned int thinktime; | |
131 | unsigned int fsync_blocks; | |
132 | unsigned int start_delay; | |
133 | unsigned int timeout; | |
134 | unsigned int io_engine; | |
135 | unsigned int create_file; | |
136 | unsigned int overwrite; | |
137 | unsigned int invalidate_cache; | |
138 | unsigned int bw_avg_time; | |
139 | unsigned int create_serialize; | |
140 | unsigned int create_fsync; | |
fc1a4713 | 141 | unsigned int end_fsync; |
ebac4655 JA |
142 | unsigned int loops; |
143 | unsigned long long file_size; | |
838a3cd3 | 144 | unsigned long long real_file_size; |
ebac4655 | 145 | unsigned long long file_offset; |
20dc95c4 JA |
146 | unsigned long long zone_size; |
147 | unsigned long long zone_skip; | |
ebac4655 JA |
148 | unsigned int sync_io; |
149 | unsigned int mem_type; | |
150 | unsigned int verify; | |
151 | unsigned int stonewall; | |
152 | unsigned int numjobs; | |
153 | unsigned int use_thread; | |
154 | unsigned int iodepth; | |
155 | os_cpu_mask_t cpumask; | |
eba09dd3 | 156 | unsigned int jobnum; |
aea47d44 | 157 | unsigned int iolog; |
843a7413 JA |
158 | unsigned int read_iolog; |
159 | unsigned int write_iolog; | |
a6ccc7be JA |
160 | unsigned int rwmixcycle; |
161 | unsigned int rwmixread; | |
b6f4d880 | 162 | unsigned int nice; |
aea47d44 | 163 | |
ef899b63 | 164 | char *iolog_file; |
843a7413 JA |
165 | void *iolog_buf; |
166 | FILE *iolog_f; | |
ebac4655 | 167 | |
da86774e JA |
168 | char *sysfs_root; |
169 | ||
170 | char *ioscheduler; | |
171 | ||
ebac4655 JA |
172 | struct drand48_data bsrange_state; |
173 | struct drand48_data verify_state; | |
174 | ||
175 | int shm_id; | |
176 | ||
ebac4655 JA |
177 | void *io_data; |
178 | char io_engine_name[16]; | |
179 | int (*io_prep)(struct thread_data *, struct io_u *); | |
180 | int (*io_queue)(struct thread_data *, struct io_u *); | |
181 | int (*io_getevents)(struct thread_data *, int, int, struct timespec *); | |
182 | struct io_u *(*io_event)(struct thread_data *, int); | |
183 | int (*io_cancel)(struct thread_data *, struct io_u *); | |
184 | void (*io_cleanup)(struct thread_data *); | |
185 | int (*io_sync)(struct thread_data *); | |
186 | ||
187 | unsigned int cur_depth; | |
188 | struct list_head io_u_freelist; | |
189 | struct list_head io_u_busylist; | |
190 | ||
191 | unsigned int rate; | |
192 | unsigned int ratemin; | |
193 | unsigned int ratecycle; | |
194 | unsigned long rate_usec_cycle; | |
195 | long rate_pending_usleep; | |
196 | unsigned long rate_bytes; | |
197 | struct timeval lastrate; | |
198 | ||
199 | unsigned long runtime[2]; /* msec */ | |
200 | unsigned long long io_size; | |
201 | unsigned long long total_io_size; | |
202 | ||
9104f874 JA |
203 | unsigned long long io_blocks[2]; |
204 | unsigned long long io_bytes[2]; | |
205 | unsigned long long zone_bytes; | |
206 | unsigned long long this_io_bytes[2]; | |
20dc95c4 | 207 | unsigned long long last_pos; |
ebac4655 JA |
208 | sem_t mutex; |
209 | ||
210 | struct drand48_data random_state; | |
211 | unsigned long *file_map; | |
212 | unsigned int num_maps; | |
213 | ||
214 | /* | |
215 | * bandwidth and latency stats | |
216 | */ | |
217 | struct io_stat clat_stat[2]; /* completion latency */ | |
218 | struct io_stat slat_stat[2]; /* submission latency */ | |
219 | struct io_stat bw_stat[2]; /* bandwidth stats */ | |
220 | ||
9104f874 | 221 | unsigned long long stat_io_bytes[2]; |
ebac4655 JA |
222 | struct timeval stat_sample_time[2]; |
223 | ||
224 | struct io_log *slat_log; | |
225 | struct io_log *clat_log; | |
226 | struct io_log *bw_log; | |
227 | ||
228 | struct timeval start; /* start of this loop */ | |
229 | struct timeval epoch; /* time job was started */ | |
230 | ||
231 | struct rusage ru_start; | |
232 | struct rusage ru_end; | |
233 | unsigned long usr_time; | |
234 | unsigned long sys_time; | |
235 | unsigned long ctx; | |
236 | ||
237 | unsigned int do_disk_util; | |
238 | unsigned int override_sync; | |
239 | ||
a6ccc7be JA |
240 | struct drand48_data rwmix_state; |
241 | struct timeval rwmix_switch; | |
242 | int rwmix_ddir; | |
243 | ||
4e0ba8af JA |
244 | /* |
245 | * Pre-run and post-run shell | |
246 | */ | |
247 | char *exec_prerun; | |
248 | char *exec_postrun; | |
249 | ||
ebac4655 | 250 | struct list_head io_hist_list; |
aea47d44 | 251 | struct list_head io_log_list; |
ebac4655 JA |
252 | }; |
253 | ||
254 | #define td_verror(td, err) \ | |
255 | do { \ | |
256 | int e = (err); \ | |
257 | (td)->error = e; \ | |
258 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \ | |
259 | } while (0) | |
260 | ||
b1ff3403 JA |
261 | extern struct io_u *__get_io_u(struct thread_data *); |
262 | extern void put_io_u(struct thread_data *, struct io_u *); | |
ebac4655 JA |
263 | |
264 | extern int rate_quit; | |
265 | extern int write_lat_log; | |
266 | extern int write_bw_log; | |
267 | extern int exitall_on_terminate; | |
268 | extern int thread_number; | |
269 | extern int shm_id; | |
270 | extern int groupid; | |
271 | ||
272 | extern struct thread_data *threads; | |
273 | ||
274 | enum { | |
275 | DDIR_READ = 0, | |
276 | DDIR_WRITE, | |
277 | }; | |
278 | ||
279 | /* | |
280 | * What type of allocation to use for io buffers | |
281 | */ | |
282 | enum { | |
283 | MEM_MALLOC, /* ordinary malloc */ | |
284 | MEM_SHM, /* use shared memory segments */ | |
285 | MEM_MMAP, /* use anonynomous mmap */ | |
286 | }; | |
287 | ||
288 | /* | |
289 | * The type of object we are working on | |
290 | */ | |
291 | enum { | |
292 | FIO_TYPE_FILE = 1, | |
293 | FIO_TYPE_BD, | |
0af7b542 | 294 | FIO_TYPE_CHAR, |
ebac4655 JA |
295 | }; |
296 | ||
297 | enum { | |
298 | FIO_SYNCIO = 1 << 0, | |
299 | FIO_MMAPIO = 1 << 1 | FIO_SYNCIO, | |
300 | FIO_LIBAIO = 1 << 2, | |
301 | FIO_POSIXAIO = 1 << 3, | |
302 | FIO_SGIO = 1 << 4, | |
8756e4d4 | 303 | FIO_SPLICEIO = 1 << 5 | FIO_SYNCIO, |
ebac4655 JA |
304 | }; |
305 | ||
306 | #define td_read(td) ((td)->ddir == DDIR_READ) | |
307 | #define td_write(td) ((td)->ddir == DDIR_WRITE) | |
3d60d1ed | 308 | #define td_rw(td) ((td)->iomix != 0) |
ebac4655 JA |
309 | |
310 | #define BLOCKS_PER_MAP (8 * sizeof(long)) | |
311 | #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs)) | |
312 | #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP) | |
313 | #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1)) | |
314 | ||
315 | #define MAX_JOBS (1024) | |
316 | ||
317 | struct disk_util_stat { | |
318 | unsigned ios[2]; | |
319 | unsigned merges[2]; | |
320 | unsigned long long sectors[2]; | |
321 | unsigned ticks[2]; | |
322 | unsigned io_ticks; | |
323 | unsigned time_in_queue; | |
324 | }; | |
325 | ||
326 | struct disk_util { | |
327 | struct list_head list; | |
328 | ||
329 | char *name; | |
330 | char path[256]; | |
331 | dev_t dev; | |
332 | ||
333 | struct disk_util_stat dus; | |
334 | struct disk_util_stat last_dus; | |
335 | ||
336 | unsigned long msec; | |
337 | struct timeval time; | |
338 | }; | |
339 | ||
340 | struct io_completion_data { | |
341 | int nr; /* input */ | |
342 | ||
343 | int error; /* output */ | |
344 | unsigned long bytes_done[2]; /* output */ | |
345 | }; | |
346 | ||
347 | #define DISK_UTIL_MSEC (250) | |
348 | ||
6a0106a0 JA |
349 | #ifndef min |
350 | #define min(a, b) ((a) < (b) ? (a) : (b)) | |
351 | #endif | |
352 | ||
6796209a JA |
353 | /* |
354 | * Log exports | |
355 | */ | |
356 | extern int read_iolog_get(struct thread_data *, struct io_u *); | |
357 | extern void write_iolog_put(struct thread_data *, struct io_u *); | |
358 | extern int init_iolog(struct thread_data *td); | |
359 | extern void log_io_piece(struct thread_data *, struct io_u *); | |
360 | extern void prune_io_piece_log(struct thread_data *); | |
361 | extern void write_iolog_close(struct thread_data *); | |
362 | ||
363 | /* | |
364 | * Logging | |
365 | */ | |
366 | extern void add_clat_sample(struct thread_data *, int, unsigned long); | |
367 | extern void add_slat_sample(struct thread_data *, int, unsigned long); | |
368 | extern void add_bw_sample(struct thread_data *, int); | |
369 | extern void show_run_stats(void); | |
370 | extern void init_disk_util(struct thread_data *); | |
371 | extern void update_rusage_stat(struct thread_data *); | |
372 | extern void update_io_ticks(void); | |
373 | extern void disk_util_timer_arm(void); | |
8914a9d8 JA |
374 | extern void setup_log(struct io_log **); |
375 | extern void finish_log(struct thread_data *, struct io_log *, const char *); | |
376 | extern int setup_rate(struct thread_data *); | |
6796209a JA |
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 | ||
8914a9d8 JA |
388 | /* |
389 | * Init functions | |
390 | */ | |
391 | extern int parse_options(int, char **); | |
392 | extern int init_random_state(struct thread_data *); | |
393 | ||
ebac4655 | 394 | #endif |