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