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