blob: d765ac6e2ebda32595940375ee8767a39322d65f [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001#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
17struct 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
25struct io_sample {
26 unsigned long time;
27 unsigned long val;
28 unsigned int ddir;
29};
30
31struct io_log {
32 unsigned long nr_samples;
33 unsigned long max_samples;
34 struct io_sample *log;
35};
36
37struct io_piece {
38 struct list_head list;
39 unsigned long long offset;
40 unsigned int len;
Jens Axboeaea47d42006-05-26 19:27:29 +020041 int ddir;
Jens Axboeebac4652005-12-08 15:25:21 +010042};
43
44/*
45 * The io unit
46 */
47struct io_u {
48 union {
49#ifdef FIO_HAVE_LIBAIO
50 struct iocb iocb;
51#endif
52#ifdef FIO_HAVE_POSIXAIO
53 struct aiocb aiocb;
54#endif
55#ifdef FIO_HAVE_SGIO
56 struct sg_io_hdr hdr;
57#endif
58 };
59 struct timeval start_time;
60 struct timeval issue_time;
61
62 char *buf;
63 unsigned int buflen;
64 unsigned long long offset;
Jens Axboeb1ff3402006-02-17 11:35:58 +010065 unsigned int index;
Jens Axboeebac4652005-12-08 15:25:21 +010066
67 unsigned int resid;
68 unsigned int error;
69
70 unsigned char seen;
71 unsigned char ddir;
72
73 struct list_head list;
74};
75
76#define FIO_HDR_MAGIC 0xf00baaef
77
78enum {
79 VERIFY_NONE = 0,
80 VERIFY_MD5,
81 VERIFY_CRC32,
82};
83
84struct verify_header {
85 unsigned int fio_magic;
86 unsigned int len;
87 unsigned int verify_type;
88 union {
89 char md5_digest[MD5_HASH_WORDS * 4];
90 unsigned long crc32;
91 };
92};
93
94struct group_run_stats {
Jens Axboe9104f872005-12-28 23:50:45 +010095 unsigned long long max_run[2], min_run[2];
96 unsigned long long max_bw[2], min_bw[2];
97 unsigned long long io_mb[2];
98 unsigned long long agg[2];
Jens Axboeebac4652005-12-08 15:25:21 +010099};
100
101struct thread_data {
102 char file_name[256];
Jens Axboeef899b62006-06-06 09:31:00 +0200103 char *directory;
Jens Axboeebac4652005-12-08 15:25:21 +0100104 char verror[80];
105 pthread_t thread;
106 int thread_number;
107 int groupid;
108 int filetype;
109 int error;
110 int fd;
111 void *mmap;
112 pid_t pid;
113 char *orig_buffer;
114 size_t orig_buffer_size;
115 volatile int terminate;
116 volatile int runstate;
117 volatile int old_runstate;
118 unsigned int ddir;
Jens Axboe3d60d1e2006-05-25 06:31:06 +0200119 unsigned int iomix;
Jens Axboeebac4652005-12-08 15:25:21 +0100120 unsigned int ioprio;
121 unsigned int sequential;
122 unsigned int bs;
123 unsigned int min_bs;
124 unsigned int max_bs;
125 unsigned int odirect;
126 unsigned int thinktime;
127 unsigned int fsync_blocks;
128 unsigned int start_delay;
129 unsigned int timeout;
130 unsigned int io_engine;
131 unsigned int create_file;
132 unsigned int overwrite;
133 unsigned int invalidate_cache;
134 unsigned int bw_avg_time;
135 unsigned int create_serialize;
136 unsigned int create_fsync;
Jens Axboefc1a4712006-05-30 13:04:05 +0200137 unsigned int end_fsync;
Jens Axboeebac4652005-12-08 15:25:21 +0100138 unsigned int loops;
139 unsigned long long file_size;
Jens Axboe838a3cd2006-01-20 12:38:29 +0100140 unsigned long long real_file_size;
Jens Axboeebac4652005-12-08 15:25:21 +0100141 unsigned long long file_offset;
Jens Axboe20dc95c2005-12-09 10:29:35 +0100142 unsigned long long zone_size;
143 unsigned long long zone_skip;
Jens Axboeebac4652005-12-08 15:25:21 +0100144 unsigned int sync_io;
145 unsigned int mem_type;
146 unsigned int verify;
147 unsigned int stonewall;
148 unsigned int numjobs;
149 unsigned int use_thread;
150 unsigned int iodepth;
151 os_cpu_mask_t cpumask;
Jens Axboeeba09dd2006-05-22 20:20:54 +0200152 unsigned int jobnum;
Jens Axboeaea47d42006-05-26 19:27:29 +0200153 unsigned int iolog;
Jens Axboe843a7412006-06-01 21:14:21 -0700154 unsigned int read_iolog;
155 unsigned int write_iolog;
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200156 unsigned int rwmixcycle;
157 unsigned int rwmixread;
Jens Axboeb6f4d882006-06-02 10:32:51 +0200158 unsigned int nice;
Jens Axboeaea47d42006-05-26 19:27:29 +0200159
Jens Axboeef899b62006-06-06 09:31:00 +0200160 char *iolog_file;
Jens Axboe843a7412006-06-01 21:14:21 -0700161 void *iolog_buf;
162 FILE *iolog_f;
Jens Axboeebac4652005-12-08 15:25:21 +0100163
164 struct drand48_data bsrange_state;
165 struct drand48_data verify_state;
166
167 int shm_id;
168
Jens Axboeebac4652005-12-08 15:25:21 +0100169 void *io_data;
170 char io_engine_name[16];
171 int (*io_prep)(struct thread_data *, struct io_u *);
172 int (*io_queue)(struct thread_data *, struct io_u *);
173 int (*io_getevents)(struct thread_data *, int, int, struct timespec *);
174 struct io_u *(*io_event)(struct thread_data *, int);
175 int (*io_cancel)(struct thread_data *, struct io_u *);
176 void (*io_cleanup)(struct thread_data *);
177 int (*io_sync)(struct thread_data *);
178
179 unsigned int cur_depth;
180 struct list_head io_u_freelist;
181 struct list_head io_u_busylist;
182
183 unsigned int rate;
184 unsigned int ratemin;
185 unsigned int ratecycle;
186 unsigned long rate_usec_cycle;
187 long rate_pending_usleep;
188 unsigned long rate_bytes;
189 struct timeval lastrate;
190
191 unsigned long runtime[2]; /* msec */
192 unsigned long long io_size;
193 unsigned long long total_io_size;
194
Jens Axboe9104f872005-12-28 23:50:45 +0100195 unsigned long long io_blocks[2];
196 unsigned long long io_bytes[2];
197 unsigned long long zone_bytes;
198 unsigned long long this_io_bytes[2];
Jens Axboe20dc95c2005-12-09 10:29:35 +0100199 unsigned long long last_pos;
Jens Axboeebac4652005-12-08 15:25:21 +0100200 sem_t mutex;
201
202 struct drand48_data random_state;
203 unsigned long *file_map;
204 unsigned int num_maps;
205
206 /*
207 * bandwidth and latency stats
208 */
209 struct io_stat clat_stat[2]; /* completion latency */
210 struct io_stat slat_stat[2]; /* submission latency */
211 struct io_stat bw_stat[2]; /* bandwidth stats */
212
Jens Axboe9104f872005-12-28 23:50:45 +0100213 unsigned long long stat_io_bytes[2];
Jens Axboeebac4652005-12-08 15:25:21 +0100214 struct timeval stat_sample_time[2];
215
216 struct io_log *slat_log;
217 struct io_log *clat_log;
218 struct io_log *bw_log;
219
220 struct timeval start; /* start of this loop */
221 struct timeval epoch; /* time job was started */
222
223 struct rusage ru_start;
224 struct rusage ru_end;
225 unsigned long usr_time;
226 unsigned long sys_time;
227 unsigned long ctx;
228
229 unsigned int do_disk_util;
230 unsigned int override_sync;
231
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200232 struct drand48_data rwmix_state;
233 struct timeval rwmix_switch;
234 int rwmix_ddir;
235
Jens Axboe4e0ba8a2006-06-06 09:36:28 +0200236 /*
237 * Pre-run and post-run shell
238 */
239 char *exec_prerun;
240 char *exec_postrun;
241
Jens Axboeebac4652005-12-08 15:25:21 +0100242 struct list_head io_hist_list;
Jens Axboeaea47d42006-05-26 19:27:29 +0200243 struct list_head io_log_list;
Jens Axboeebac4652005-12-08 15:25:21 +0100244};
245
246#define td_verror(td, err) \
247 do { \
248 int e = (err); \
249 (td)->error = e; \
250 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \
251 } while (0)
252
253extern int parse_jobs_ini(char *);
254extern int parse_options(int, char **);
255extern void finish_log(struct thread_data *, struct io_log *, const char *);
256extern int init_random_state(struct thread_data *);
Jens Axboeb1ff3402006-02-17 11:35:58 +0100257extern struct io_u *__get_io_u(struct thread_data *);
258extern void put_io_u(struct thread_data *, struct io_u *);
Jens Axboeebac4652005-12-08 15:25:21 +0100259
260extern int rate_quit;
261extern int write_lat_log;
262extern int write_bw_log;
263extern int exitall_on_terminate;
264extern int thread_number;
265extern int shm_id;
266extern int groupid;
267
268extern struct thread_data *threads;
269
270enum {
271 DDIR_READ = 0,
272 DDIR_WRITE,
273};
274
275/*
276 * What type of allocation to use for io buffers
277 */
278enum {
279 MEM_MALLOC, /* ordinary malloc */
280 MEM_SHM, /* use shared memory segments */
281 MEM_MMAP, /* use anonynomous mmap */
282};
283
284/*
285 * The type of object we are working on
286 */
287enum {
288 FIO_TYPE_FILE = 1,
289 FIO_TYPE_BD,
Jens Axboe0af7b542006-02-17 10:10:12 +0100290 FIO_TYPE_CHAR,
Jens Axboeebac4652005-12-08 15:25:21 +0100291};
292
293enum {
294 FIO_SYNCIO = 1 << 0,
295 FIO_MMAPIO = 1 << 1 | FIO_SYNCIO,
296 FIO_LIBAIO = 1 << 2,
297 FIO_POSIXAIO = 1 << 3,
298 FIO_SGIO = 1 << 4,
Jens Axboe8756e4d2006-05-27 20:24:53 +0200299 FIO_SPLICEIO = 1 << 5 | FIO_SYNCIO,
Jens Axboeebac4652005-12-08 15:25:21 +0100300};
301
302#define td_read(td) ((td)->ddir == DDIR_READ)
303#define td_write(td) ((td)->ddir == DDIR_WRITE)
Jens Axboe3d60d1e2006-05-25 06:31:06 +0200304#define td_rw(td) ((td)->iomix != 0)
Jens Axboeebac4652005-12-08 15:25:21 +0100305
306#define BLOCKS_PER_MAP (8 * sizeof(long))
307#define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs))
308#define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP)
309#define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1))
310
311#define MAX_JOBS (1024)
312
313struct disk_util_stat {
314 unsigned ios[2];
315 unsigned merges[2];
316 unsigned long long sectors[2];
317 unsigned ticks[2];
318 unsigned io_ticks;
319 unsigned time_in_queue;
320};
321
322struct disk_util {
323 struct list_head list;
324
325 char *name;
326 char path[256];
327 dev_t dev;
328
329 struct disk_util_stat dus;
330 struct disk_util_stat last_dus;
331
332 unsigned long msec;
333 struct timeval time;
334};
335
336struct io_completion_data {
337 int nr; /* input */
338
339 int error; /* output */
340 unsigned long bytes_done[2]; /* output */
341};
342
343#define DISK_UTIL_MSEC (250)
344
Jens Axboe6a0106a2006-05-05 10:34:43 +0200345#ifndef min
346#define min(a, b) ((a) < (b) ? (a) : (b))
347#endif
348
Jens Axboeebac4652005-12-08 15:25:21 +0100349#endif