Commit | Line | Data |
---|---|---|
27c32a38 JA |
1 | #ifndef FIO_H |
2 | #define FIO_H | |
3 | ||
4 | #include <sched.h> | |
5 | #include <libaio.h> | |
6 | #include <limits.h> | |
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 JA |
14 | #include "arch.h" |
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 | ||
41 | #define FIO_HDR_MAGIC 0xf00baaef | |
42 | ||
7f46ef08 JA |
43 | enum { |
44 | VERIFY_NONE = 0, | |
45 | VERIFY_MD5, | |
46 | VERIFY_CRC32, | |
47 | }; | |
48 | ||
27c32a38 JA |
49 | struct verify_header { |
50 | unsigned int fio_magic; | |
51 | unsigned int len; | |
7f46ef08 JA |
52 | unsigned int verify_type; |
53 | union { | |
54 | char md5_digest[MD5_HASH_WORDS * 4]; | |
55 | unsigned long crc32; | |
56 | }; | |
27c32a38 JA |
57 | }; |
58 | ||
557e4102 JA |
59 | struct group_run_stats { |
60 | unsigned long max_run[2], min_run[2]; | |
61 | unsigned long max_bw[2], min_bw[2]; | |
62 | unsigned long io_mb[2]; | |
63 | unsigned long agg[2]; | |
64 | }; | |
65 | ||
27c32a38 JA |
66 | struct thread_data { |
67 | char file_name[256]; | |
68 | char directory[256]; | |
d0963ac4 | 69 | char verror[80]; |
189873de | 70 | pthread_t thread; |
27c32a38 JA |
71 | int thread_number; |
72 | int groupid; | |
c4c8f7b3 | 73 | int filetype; |
27c32a38 JA |
74 | int error; |
75 | int fd; | |
6e2c38cc | 76 | void *mmap; |
27c32a38 JA |
77 | pid_t pid; |
78 | char *orig_buffer; | |
891e70f8 | 79 | size_t orig_buffer_size; |
27c32a38 JA |
80 | volatile int terminate; |
81 | volatile int runstate; | |
82 | volatile int old_runstate; | |
83 | unsigned int ddir; | |
84 | unsigned int ioprio; | |
85 | unsigned int sequential; | |
86 | unsigned int bs; | |
87 | unsigned int min_bs; | |
88 | unsigned int max_bs; | |
89 | unsigned int odirect; | |
90 | unsigned int thinktime; | |
91 | unsigned int fsync_blocks; | |
92 | unsigned int start_delay; | |
93 | unsigned int timeout; | |
94 | unsigned int use_aio; | |
95 | unsigned int create_file; | |
96 | unsigned int overwrite; | |
97 | unsigned int invalidate_cache; | |
98 | unsigned int bw_avg_time; | |
99 | unsigned int create_serialize; | |
100 | unsigned int create_fsync; | |
101 | unsigned int loops; | |
102 | unsigned long long file_size; | |
103 | unsigned long long file_offset; | |
104 | unsigned int sync_io; | |
105 | unsigned int mem_type; | |
106 | unsigned int verify; | |
107 | unsigned int stonewall; | |
108 | unsigned int numjobs; | |
189873de | 109 | unsigned int use_thread; |
6e2c38cc | 110 | unsigned int use_mmap; |
27c32a38 JA |
111 | cpu_set_t cpumask; |
112 | ||
113 | struct drand48_data bsrange_state; | |
114 | struct drand48_data verify_state; | |
115 | ||
116 | int shm_id; | |
117 | ||
118 | off_t cur_off; | |
119 | ||
120 | io_context_t aio_ctx; | |
121 | unsigned int aio_depth; | |
122 | struct io_event *aio_events; | |
123 | ||
124 | unsigned int cur_depth; | |
125 | struct list_head io_u_freelist; | |
126 | struct list_head io_u_busylist; | |
127 | ||
128 | unsigned int rate; | |
129 | unsigned int ratemin; | |
130 | unsigned int ratecycle; | |
131 | unsigned long rate_usec_cycle; | |
132 | long rate_pending_usleep; | |
133 | unsigned long rate_bytes; | |
134 | struct timeval lastrate; | |
135 | ||
136 | unsigned long runtime; /* sec */ | |
137 | unsigned long long io_size; | |
138 | ||
139 | unsigned long io_blocks; | |
140 | unsigned long io_bytes; | |
141 | unsigned long this_io_bytes; | |
142 | unsigned long last_bytes; | |
143 | sem_t mutex; | |
144 | ||
145 | struct drand48_data random_state; | |
146 | unsigned long *file_map; | |
147 | unsigned int num_maps; | |
148 | ||
149 | /* | |
150 | * bandwidth and latency stats | |
151 | */ | |
152 | struct io_stat clat_stat; /* completion latency */ | |
153 | struct io_stat slat_stat; /* submission latency */ | |
154 | ||
155 | struct io_stat bw_stat; /* bandwidth stats */ | |
156 | unsigned long stat_io_bytes; | |
157 | struct timeval stat_sample_time; | |
158 | ||
159 | struct io_log *lat_log; | |
160 | struct io_log *bw_log; | |
161 | ||
162 | struct timeval start; | |
163 | ||
164 | struct rusage ru_start; | |
165 | struct rusage ru_end; | |
166 | unsigned long usr_time; | |
167 | unsigned long sys_time; | |
168 | unsigned long ctx; | |
169 | ||
170 | struct list_head io_hist_list; | |
171 | }; | |
172 | ||
b5a4be48 JA |
173 | #define td_verror(td, err) \ |
174 | do { \ | |
175 | int e = (err); \ | |
176 | (td)->error = e; \ | |
d0963ac4 | 177 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \ |
b5a4be48 JA |
178 | } while (0) |
179 | ||
27c32a38 JA |
180 | extern int parse_jobs_ini(char *); |
181 | extern int parse_options(int, char **); | |
182 | extern void finish_log(struct thread_data *, struct io_log *, const char *); | |
183 | extern int init_random_state(struct thread_data *); | |
184 | ||
185 | extern int rate_quit; | |
186 | extern int write_lat_log; | |
187 | extern int write_bw_log; | |
188 | extern int exitall_on_terminate; | |
189 | extern int thread_number; | |
190 | extern int shm_id; | |
191 | extern int groupid; | |
192 | ||
193 | extern char run_str[]; | |
194 | ||
195 | extern struct thread_data *threads; | |
196 | ||
197 | enum { | |
198 | DDIR_READ = 0, | |
199 | DDIR_WRITE, | |
200 | }; | |
201 | ||
891e70f8 JA |
202 | /* |
203 | * What type of allocation to use for io buffers | |
204 | */ | |
27c32a38 | 205 | enum { |
891e70f8 JA |
206 | MEM_MALLOC, /* ordinary malloc */ |
207 | MEM_SHM, /* use shared memory segments */ | |
208 | MEM_MMAP, /* use anonynomous mmap */ | |
27c32a38 JA |
209 | }; |
210 | ||
891e70f8 JA |
211 | /* |
212 | * The type of object we are working on | |
213 | */ | |
c4c8f7b3 JA |
214 | enum { |
215 | FIO_TYPE_FILE = 1, | |
216 | FIO_TYPE_BD, | |
217 | }; | |
218 | ||
27c32a38 JA |
219 | #define td_read(td) ((td)->ddir == DDIR_READ) |
220 | #define td_write(td) ((td)->ddir == DDIR_WRITE) | |
221 | ||
222 | #define BLOCKS_PER_MAP (8 * sizeof(long)) | |
223 | #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs)) | |
224 | #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP) | |
225 | #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1)) | |
226 | ||
227 | #define MAX_JOBS (1024) | |
228 | ||
0b100202 JA |
229 | struct disk_util_stat { |
230 | unsigned ios[2]; | |
231 | unsigned merges[2]; | |
232 | unsigned long long sectors[2]; | |
233 | unsigned ticks[2]; | |
234 | unsigned io_ticks; | |
235 | unsigned time_in_queue; | |
236 | }; | |
237 | ||
6f75d67c JA |
238 | struct disk_util { |
239 | struct list_head list; | |
240 | ||
241 | char *name; | |
242 | char path[256]; | |
243 | dev_t dev; | |
0b100202 JA |
244 | |
245 | struct disk_util_stat dus; | |
246 | struct disk_util_stat last_dus; | |
247 | ||
6f75d67c JA |
248 | unsigned long msec; |
249 | struct timeval time; | |
250 | }; | |
251 | ||
252 | #define DISK_UTIL_MSEC (250) | |
253 | ||
27c32a38 | 254 | #endif |