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