Commit | Line | Data |
---|---|---|
ebac4655 JA |
1 | #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> | |
3c39a379 JA |
9 | #include <errno.h> |
10 | #include <stdlib.h> | |
11 | #include <stdio.h> | |
6d6f031f | 12 | #include <unistd.h> |
34cfcdaf | 13 | #include <string.h> |
214e1eca | 14 | #include <getopt.h> |
cd14cc10 | 15 | #include <inttypes.h> |
7101d9c2 | 16 | #include <assert.h> |
ebac4655 | 17 | |
317b95d0 | 18 | #include "compiler/compiler.h" |
01743ee1 | 19 | #include "flist.h" |
e2887563 | 20 | #include "fifo.h" |
4b87898e | 21 | #include "rbtree.h" |
317b95d0 JA |
22 | #include "arch/arch.h" |
23 | #include "os/os.h" | |
07739b57 | 24 | #include "mutex.h" |
a3d741fa JA |
25 | #include "log.h" |
26 | #include "debug.h" | |
d6aed795 JA |
27 | #include "file.h" |
28 | #include "io_ddir.h" | |
dcefb588 | 29 | #include "ioengine.h" |
ebac4655 | 30 | |
609342ff DL |
31 | #ifdef FIO_HAVE_GUASI |
32 | #include <guasi.h> | |
33 | #endif | |
34 | ||
417f0068 JA |
35 | #ifdef FIO_HAVE_SOLARISAIO |
36 | #include <sys/asynch.h> | |
37 | #endif | |
38 | ||
1c9e06ee JA |
39 | /* |
40 | * Use for maintaining statistics | |
41 | */ | |
ebac4655 | 42 | struct io_stat { |
ebac4655 JA |
43 | unsigned long max_val; |
44 | unsigned long min_val; | |
45 | unsigned long samples; | |
68704084 JA |
46 | |
47 | double mean; | |
48 | double S; | |
ebac4655 JA |
49 | }; |
50 | ||
1c9e06ee JA |
51 | /* |
52 | * A single data sample | |
53 | */ | |
ebac4655 JA |
54 | struct io_sample { |
55 | unsigned long time; | |
56 | unsigned long val; | |
1e97cce9 | 57 | enum fio_ddir ddir; |
306ddc97 | 58 | unsigned int bs; |
ebac4655 JA |
59 | }; |
60 | ||
1c9e06ee JA |
61 | /* |
62 | * Dynamically growing data sample log | |
63 | */ | |
ebac4655 JA |
64 | struct io_log { |
65 | unsigned long nr_samples; | |
66 | unsigned long max_samples; | |
67 | struct io_sample *log; | |
68 | }; | |
69 | ||
1c9e06ee JA |
70 | /* |
71 | * When logging io actions, this matches a single sent io_u | |
72 | */ | |
ebac4655 | 73 | struct io_piece { |
4b87898e JA |
74 | union { |
75 | struct rb_node rb_node; | |
01743ee1 | 76 | struct flist_head list; |
4b87898e | 77 | }; |
f29b25a3 JA |
78 | union { |
79 | int fileno; | |
80 | struct fio_file *file; | |
81 | }; | |
ebac4655 | 82 | unsigned long long offset; |
a4f4fdd7 | 83 | unsigned long len; |
1e97cce9 | 84 | enum fio_ddir ddir; |
f29b25a3 JA |
85 | union { |
86 | unsigned long delay; | |
87 | unsigned int file_action; | |
88 | }; | |
ebac4655 JA |
89 | }; |
90 | ||
ebac4655 | 91 | struct group_run_stats { |
9104f874 JA |
92 | unsigned long long max_run[2], min_run[2]; |
93 | unsigned long long max_bw[2], min_bw[2]; | |
e9b2a3fa | 94 | unsigned long long io_kb[2]; |
9104f874 | 95 | unsigned long long agg[2]; |
ebac4655 JA |
96 | }; |
97 | ||
e9c047a0 JA |
98 | /* |
99 | * What type of allocation to use for io buffers | |
100 | */ | |
101 | enum fio_memtype { | |
102 | MEM_MALLOC = 0, /* ordinary malloc */ | |
103 | MEM_SHM, /* use shared memory segments */ | |
74b025b0 | 104 | MEM_SHMHUGE, /* use shared memory segments with huge pages */ |
e9c047a0 | 105 | MEM_MMAP, /* use anonynomous mmap */ |
d0bdaf49 | 106 | MEM_MMAPHUGE, /* memory mapped huge file */ |
e9c047a0 JA |
107 | }; |
108 | ||
b2560f3c JA |
109 | /* |
110 | * How many depth levels to log | |
111 | */ | |
112 | #define FIO_IO_U_MAP_NR 8 | |
a9a18a3f JA |
113 | #define FIO_IO_U_LAT_U_NR 10 |
114 | #define FIO_IO_U_LAT_M_NR 12 | |
b2560f3c | 115 | |
079ad09b | 116 | struct thread_stat { |
756867bd JA |
117 | char *name; |
118 | char *verror; | |
119 | int error; | |
120 | int groupid; | |
121 | pid_t pid; | |
122 | char *description; | |
6586ee89 | 123 | int members; |
756867bd | 124 | |
079ad09b JA |
125 | struct io_log *slat_log; |
126 | struct io_log *clat_log; | |
127 | struct io_log *bw_log; | |
128 | ||
129 | /* | |
130 | * bandwidth and latency stats | |
131 | */ | |
132 | struct io_stat clat_stat[2]; /* completion latency */ | |
133 | struct io_stat slat_stat[2]; /* submission latency */ | |
134 | struct io_stat bw_stat[2]; /* bandwidth stats */ | |
135 | ||
136 | unsigned long long stat_io_bytes[2]; | |
137 | struct timeval stat_sample_time[2]; | |
138 | ||
139 | /* | |
140 | * fio system usage accounting | |
141 | */ | |
142 | struct rusage ru_start; | |
143 | struct rusage ru_end; | |
144 | unsigned long usr_time; | |
145 | unsigned long sys_time; | |
146 | unsigned long ctx; | |
81887d5d | 147 | unsigned long minf, majf; |
079ad09b | 148 | |
b2560f3c JA |
149 | /* |
150 | * IO depth and latency stats | |
151 | */ | |
152 | unsigned int io_u_map[FIO_IO_U_MAP_NR]; | |
838bc709 JA |
153 | unsigned int io_u_submit[FIO_IO_U_MAP_NR]; |
154 | unsigned int io_u_complete[FIO_IO_U_MAP_NR]; | |
04a0feae JA |
155 | unsigned int io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
156 | unsigned int io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
b3605062 | 157 | unsigned long total_io_u[2]; |
30061b97 | 158 | unsigned long short_io_u[2]; |
838bc709 JA |
159 | unsigned long total_submit; |
160 | unsigned long total_complete; | |
756867bd JA |
161 | |
162 | unsigned long long io_bytes[2]; | |
163 | unsigned long runtime[2]; | |
164 | unsigned long total_run_time; | |
b2560f3c | 165 | }; |
71619dc2 | 166 | |
564ca972 JA |
167 | struct bssplit { |
168 | unsigned int bs; | |
169 | unsigned char perc; | |
170 | }; | |
171 | ||
2dc1bbeb | 172 | struct thread_options { |
b1ec1da6 | 173 | int pad; |
61697c37 | 174 | char *description; |
b4692828 | 175 | char *name; |
ef899b63 | 176 | char *directory; |
13f8e2d2 | 177 | char *filename; |
2dc1bbeb | 178 | char *opendir; |
09629a90 | 179 | char *ioengine; |
413dd459 | 180 | enum td_ddir td_ddir; |
211097b2 | 181 | unsigned int ddir_nr; |
2dc1bbeb JA |
182 | unsigned int iodepth; |
183 | unsigned int iodepth_low; | |
184 | unsigned int iodepth_batch; | |
4950421a | 185 | unsigned int iodepth_batch_complete; |
2dc1bbeb JA |
186 | |
187 | unsigned long long size; | |
aa31f1f1 | 188 | unsigned int fill_device; |
2dc1bbeb JA |
189 | unsigned long long file_size_low; |
190 | unsigned long long file_size_high; | |
191 | unsigned long long start_offset; | |
192 | ||
193 | unsigned int bs[2]; | |
2b7a01d0 | 194 | unsigned int ba[2]; |
2dc1bbeb JA |
195 | unsigned int min_bs[2]; |
196 | unsigned int max_bs[2]; | |
720e84ad JA |
197 | struct bssplit *bssplit[2]; |
198 | unsigned int bssplit_nr[2]; | |
2dc1bbeb JA |
199 | |
200 | unsigned int nr_files; | |
201 | unsigned int open_files; | |
4d4e80f2 | 202 | enum file_lock_mode file_lock_mode; |
29c1349f | 203 | unsigned int lockfile_batch; |
e9c047a0 | 204 | |
9158d2f7 JA |
205 | unsigned int odirect; |
206 | unsigned int invalidate_cache; | |
207 | unsigned int create_serialize; | |
208 | unsigned int create_fsync; | |
814452bd | 209 | unsigned int create_on_open; |
9158d2f7 | 210 | unsigned int end_fsync; |
afad68f7 | 211 | unsigned int pre_read; |
9158d2f7 JA |
212 | unsigned int sync_io; |
213 | unsigned int verify; | |
e84c73a8 | 214 | unsigned int do_verify; |
160b966d | 215 | unsigned int verifysort; |
a59e170d JA |
216 | unsigned int verify_interval; |
217 | unsigned int verify_offset; | |
90059d65 JA |
218 | unsigned int verify_pattern; |
219 | unsigned int verify_pattern_bytes; | |
a12a3b4d | 220 | unsigned int verify_fatal; |
9158d2f7 JA |
221 | unsigned int use_thread; |
222 | unsigned int unlink; | |
223 | unsigned int do_disk_util; | |
224 | unsigned int override_sync; | |
225 | unsigned int rand_repeatable; | |
226 | unsigned int write_lat_log; | |
227 | unsigned int write_bw_log; | |
bb8895e0 | 228 | unsigned int norandommap; |
2b386d25 | 229 | unsigned int softrandommap; |
690adba3 | 230 | unsigned int bs_unaligned; |
ebb1415f | 231 | unsigned int fsync_on_close; |
e9c047a0 | 232 | |
56bb17f2 | 233 | unsigned int hugepage_size; |
a00735e6 | 234 | unsigned int rw_min_bs; |
ebac4655 | 235 | unsigned int thinktime; |
48097d5c | 236 | unsigned int thinktime_spin; |
9c1f7434 | 237 | unsigned int thinktime_blocks; |
ebac4655 JA |
238 | unsigned int fsync_blocks; |
239 | unsigned int start_delay; | |
0db26797 | 240 | unsigned long long timeout; |
721938ae | 241 | unsigned long long ramp_time; |
ebac4655 | 242 | unsigned int overwrite; |
ebac4655 | 243 | unsigned int bw_avg_time; |
ebac4655 | 244 | unsigned int loops; |
20dc95c4 JA |
245 | unsigned long long zone_size; |
246 | unsigned long long zone_skip; | |
e9c047a0 | 247 | enum fio_memtype mem_type; |
2dc1bbeb | 248 | |
ebac4655 | 249 | unsigned int stonewall; |
b3d62a75 | 250 | unsigned int new_group; |
ebac4655 | 251 | unsigned int numjobs; |
ebac4655 | 252 | os_cpu_mask_t cpumask; |
375b2695 | 253 | unsigned int cpumask_set; |
aea47d44 | 254 | unsigned int iolog; |
a6ccc7be | 255 | unsigned int rwmixcycle; |
e47f799f | 256 | unsigned int rwmix[2]; |
b6f4d880 | 257 | unsigned int nice; |
0aabe160 | 258 | unsigned int file_service_type; |
b2560f3c | 259 | unsigned int group_reporting; |
d2f3ac35 | 260 | unsigned int fadvise_hint; |
e9459e5a | 261 | unsigned int zero_buffers; |
5973cafb | 262 | unsigned int refill_buffers; |
cf4464ca | 263 | unsigned int time_based; |
9520ebb9 JA |
264 | unsigned int disable_clat; |
265 | unsigned int disable_slat; | |
266 | unsigned int disable_bw; | |
993bf48b | 267 | unsigned int gtod_reduce; |
be4ecfdf JA |
268 | unsigned int gtod_cpu; |
269 | unsigned int gtod_offload; | |
aea47d44 | 270 | |
076efc7c JA |
271 | char *read_iolog_file; |
272 | char *write_iolog_file; | |
e3cedca7 JA |
273 | char *bw_log_file; |
274 | char *lat_log_file; | |
2dc1bbeb JA |
275 | |
276 | /* | |
277 | * Pre-run and post-run shell | |
278 | */ | |
279 | char *exec_prerun; | |
280 | char *exec_postrun; | |
281 | ||
282 | unsigned int rate; | |
283 | unsigned int ratemin; | |
284 | unsigned int ratecycle; | |
285 | unsigned int rate_iops; | |
286 | unsigned int rate_iops_min; | |
287 | ||
288 | char *ioscheduler; | |
289 | ||
290 | /* | |
291 | * CPU "io" cycle burner | |
292 | */ | |
293 | unsigned int cpuload; | |
294 | unsigned int cpucycle; | |
295 | }; | |
296 | ||
e4e33258 JA |
297 | #define FIO_VERROR_SIZE 128 |
298 | ||
2dc1bbeb JA |
299 | /* |
300 | * This describes a single thread/process executing a fio job. | |
301 | */ | |
302 | struct thread_data { | |
303 | struct thread_options o; | |
e4e33258 | 304 | char verror[FIO_VERROR_SIZE]; |
2dc1bbeb JA |
305 | pthread_t thread; |
306 | int thread_number; | |
307 | int groupid; | |
308 | struct thread_stat ts; | |
126d65c6 | 309 | struct fio_file **files; |
dd87b2c9 | 310 | unsigned int files_size; |
2dc1bbeb JA |
311 | unsigned int files_index; |
312 | unsigned int nr_open_files; | |
1020a139 | 313 | unsigned int nr_done_files; |
2dc1bbeb JA |
314 | unsigned int nr_normal_files; |
315 | union { | |
316 | unsigned int next_file; | |
317 | os_random_state_t next_file_state; | |
318 | }; | |
319 | int error; | |
20e354ef | 320 | int done; |
2dc1bbeb JA |
321 | pid_t pid; |
322 | char *orig_buffer; | |
323 | size_t orig_buffer_size; | |
324 | volatile int terminate; | |
325 | volatile int runstate; | |
326 | unsigned int ioprio; | |
ac684785 | 327 | unsigned int ioprio_set; |
2dc1bbeb JA |
328 | unsigned int last_was_sync; |
329 | ||
330 | char *mmapfile; | |
331 | int mmapfd; | |
332 | ||
843a7413 JA |
333 | void *iolog_buf; |
334 | FILE *iolog_f; | |
ebac4655 | 335 | |
da86774e | 336 | char *sysfs_root; |
da86774e | 337 | |
5bfc35d7 JA |
338 | unsigned long rand_seeds[6]; |
339 | ||
6dfd46b9 JA |
340 | os_random_state_t bsrange_state; |
341 | os_random_state_t verify_state; | |
ebac4655 JA |
342 | |
343 | int shm_id; | |
344 | ||
e9c047a0 JA |
345 | /* |
346 | * IO engine hooks, contains everything needed to submit an io_u | |
347 | * to any of the available IO engines. | |
348 | */ | |
2866c82d | 349 | struct ioengine_ops *io_ops; |
ebac4655 | 350 | |
e9c047a0 JA |
351 | /* |
352 | * Current IO depth and list of free and busy io_u's. | |
353 | */ | |
ebac4655 | 354 | unsigned int cur_depth; |
d8005759 | 355 | unsigned int io_u_queued; |
01743ee1 JA |
356 | struct flist_head io_u_freelist; |
357 | struct flist_head io_u_busylist; | |
358 | struct flist_head io_u_requeues; | |
ebac4655 | 359 | |
e9c047a0 JA |
360 | /* |
361 | * Rate state | |
362 | */ | |
ebac4655 JA |
363 | unsigned long rate_usec_cycle; |
364 | long rate_pending_usleep; | |
365 | unsigned long rate_bytes; | |
4e991c23 | 366 | unsigned long rate_blocks; |
ebac4655 JA |
367 | struct timeval lastrate; |
368 | ||
ebac4655 JA |
369 | unsigned long long total_io_size; |
370 | ||
755200a3 | 371 | unsigned long io_issues[2]; |
9104f874 JA |
372 | unsigned long long io_blocks[2]; |
373 | unsigned long long io_bytes[2]; | |
48f5abd3 | 374 | unsigned long long io_skip_bytes; |
9104f874 | 375 | unsigned long long this_io_bytes[2]; |
079ad09b | 376 | unsigned long long zone_bytes; |
cdd18ad8 | 377 | struct fio_mutex *mutex; |
ebac4655 | 378 | |
e9c047a0 JA |
379 | /* |
380 | * State for random io, a bitmap of blocks done vs not done | |
381 | */ | |
6dfd46b9 | 382 | os_random_state_t random_state; |
ebac4655 | 383 | |
ebac4655 JA |
384 | struct timeval start; /* start of this loop */ |
385 | struct timeval epoch; /* time job was started */ | |
38d77cae | 386 | struct timeval rw_end[2]; |
a61eddec | 387 | struct timeval last_issue; |
993bf48b JA |
388 | struct timeval tv_cache; |
389 | unsigned int tv_cache_nr; | |
390 | unsigned int tv_cache_mask; | |
38d77cae | 391 | unsigned int rw_end_set[2]; |
721938ae | 392 | unsigned int ramp_time_over; |
ebac4655 | 393 | |
e9c047a0 JA |
394 | /* |
395 | * read/write mixed workload state | |
396 | */ | |
6dfd46b9 | 397 | os_random_state_t rwmix_state; |
e4928662 | 398 | unsigned long rwmix_issues; |
e9c047a0 | 399 | enum fio_ddir rwmix_ddir; |
211097b2 | 400 | unsigned int ddir_nr; |
a6ccc7be | 401 | |
e9c047a0 | 402 | /* |
8de8f047 JA |
403 | * IO history logs for verification. We use a tree for sorting, |
404 | * if we are overwriting. Otherwise just use a fifo. | |
e9c047a0 | 405 | */ |
4b87898e | 406 | struct rb_root io_hist_tree; |
01743ee1 | 407 | struct flist_head io_hist_list; |
8de8f047 JA |
408 | |
409 | /* | |
410 | * For IO replaying | |
411 | */ | |
01743ee1 | 412 | struct flist_head io_log_list; |
433afcb4 | 413 | |
1907dbc6 JA |
414 | /* |
415 | * for fileservice, how often to switch to a new file | |
416 | */ | |
417 | unsigned int file_service_nr; | |
418 | unsigned int file_service_left; | |
419 | struct fio_file *file_service_file; | |
9c60ce64 JA |
420 | |
421 | /* | |
422 | * For generating file sizes | |
423 | */ | |
424 | os_random_state_t file_size_state; | |
ebac4655 JA |
425 | }; |
426 | ||
0aabe160 | 427 | /* |
a086c257 JA |
428 | * roundrobin available files, or choose one at random, or do each one |
429 | * serially. | |
0aabe160 JA |
430 | */ |
431 | enum { | |
432 | FIO_FSERVICE_RANDOM = 1, | |
433 | FIO_FSERVICE_RR = 2, | |
a086c257 | 434 | FIO_FSERVICE_SEQ = 3, |
0aabe160 JA |
435 | }; |
436 | ||
e592a06b AC |
437 | /* |
438 | * when should interactive ETA output be generated | |
439 | */ | |
440 | enum { | |
441 | FIO_ETA_AUTO, | |
442 | FIO_ETA_ALWAYS, | |
443 | FIO_ETA_NEVER, | |
444 | }; | |
445 | ||
e1161c32 | 446 | #define __td_verror(td, err, msg, func) \ |
ebac4655 | 447 | do { \ |
19abcd3d JA |
448 | if ((td)->error) \ |
449 | break; \ | |
ebac4655 JA |
450 | int e = (err); \ |
451 | (td)->error = e; \ | |
e1161c32 | 452 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \ |
ebac4655 JA |
453 | } while (0) |
454 | ||
b990b5c0 | 455 | |
e1161c32 JA |
456 | #define td_verror(td, err, func) \ |
457 | __td_verror((td), (err), strerror((err)), (func)) | |
458 | #define td_vmsg(td, err, msg, func) \ | |
459 | __td_verror((td), (err), (msg), (func)) | |
b990b5c0 | 460 | |
ebac4655 JA |
461 | extern int exitall_on_terminate; |
462 | extern int thread_number; | |
9cedf167 | 463 | extern int nr_process, nr_thread; |
ebac4655 JA |
464 | extern int shm_id; |
465 | extern int groupid; | |
c6ae0a5b | 466 | extern int terse_output; |
53cdc686 | 467 | extern int temp_stall_ts; |
1e97cce9 | 468 | extern unsigned long long mlock_size; |
cfc99db7 | 469 | extern unsigned long page_mask, page_size; |
4241ea8f | 470 | extern int read_only; |
e592a06b | 471 | extern int eta_print; |
d3eeeabc | 472 | extern unsigned long done_secs; |
01f06b63 | 473 | extern char *job_section; |
be4ecfdf JA |
474 | extern int fio_gtod_offload; |
475 | extern int fio_gtod_cpu; | |
ebac4655 JA |
476 | |
477 | extern struct thread_data *threads; | |
478 | ||
2dc1bbeb JA |
479 | #define td_read(td) ((td)->o.td_ddir & TD_DDIR_READ) |
480 | #define td_write(td) ((td)->o.td_ddir & TD_DDIR_WRITE) | |
481 | #define td_rw(td) (((td)->o.td_ddir & TD_DDIR_RW) == TD_DDIR_RW) | |
482 | #define td_random(td) ((td)->o.td_ddir & TD_DDIR_RAND) | |
303032ae | 483 | #define file_randommap(td, f) (!(td)->o.norandommap && (f)->file_map) |
ebac4655 | 484 | |
7101d9c2 JA |
485 | static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u) |
486 | { | |
487 | assert(!(io_u->ddir == DDIR_WRITE && !td_write(td))); | |
488 | } | |
489 | ||
de605666 | 490 | #define BLOCKS_PER_MAP (8 * sizeof(int)) |
aec2de20 JA |
491 | #define TO_MAP_BLOCK(f, b) (b) |
492 | #define RAND_MAP_IDX(f, b) (TO_MAP_BLOCK(f, b) / BLOCKS_PER_MAP) | |
493 | #define RAND_MAP_BIT(f, b) (TO_MAP_BLOCK(f, b) & (BLOCKS_PER_MAP - 1)) | |
ebac4655 JA |
494 | |
495 | #define MAX_JOBS (1024) | |
496 | ||
87dc1ab1 JA |
497 | static inline int should_fsync(struct thread_data *td) |
498 | { | |
499 | if (td->last_was_sync) | |
500 | return 0; | |
2dc1bbeb | 501 | if (td->o.odirect) |
87dc1ab1 | 502 | return 0; |
2dc1bbeb | 503 | if (td_write(td) || td_rw(td) || td->o.override_sync) |
87dc1ab1 JA |
504 | return 1; |
505 | ||
506 | return 0; | |
507 | } | |
508 | ||
1c9e06ee JA |
509 | /* |
510 | * Disk utils as read in /sys/block/<dev>/stat | |
511 | */ | |
ebac4655 JA |
512 | struct disk_util_stat { |
513 | unsigned ios[2]; | |
514 | unsigned merges[2]; | |
515 | unsigned long long sectors[2]; | |
516 | unsigned ticks[2]; | |
517 | unsigned io_ticks; | |
518 | unsigned time_in_queue; | |
519 | }; | |
520 | ||
1c9e06ee JA |
521 | /* |
522 | * Per-device disk util management | |
523 | */ | |
ebac4655 | 524 | struct disk_util { |
01743ee1 | 525 | struct flist_head list; |
67423013 ST |
526 | /* If this disk is a slave, hook it into the master's |
527 | * list using this head. | |
528 | */ | |
529 | struct flist_head slavelist; | |
ebac4655 JA |
530 | |
531 | char *name; | |
e11c410c | 532 | char *sysfs_root; |
ebac4655 | 533 | char path[256]; |
07e5b264 | 534 | int major, minor; |
ebac4655 JA |
535 | |
536 | struct disk_util_stat dus; | |
537 | struct disk_util_stat last_dus; | |
538 | ||
67423013 ST |
539 | /* For software raids, this entry maintains pointers to the |
540 | * entries for the slave devices. The disk_util entries for | |
541 | * the slaves devices should primarily be maintained through | |
542 | * the disk_list list, i.e. for memory allocation and | |
543 | * de-allocation, etc. Whereas this list should be used only | |
544 | * for aggregating a software RAID's disk util figures. | |
545 | */ | |
546 | struct flist_head slaves; | |
547 | ||
ebac4655 JA |
548 | unsigned long msec; |
549 | struct timeval time; | |
c97bd0fa JA |
550 | |
551 | struct fio_mutex *lock; | |
552 | unsigned long users; | |
ebac4655 JA |
553 | }; |
554 | ||
c97bd0fa JA |
555 | static inline void disk_util_inc(struct disk_util *du) |
556 | { | |
557 | if (du) { | |
558 | fio_mutex_down(du->lock); | |
559 | du->users++; | |
560 | fio_mutex_up(du->lock); | |
561 | } | |
562 | } | |
563 | ||
564 | static inline void disk_util_dec(struct disk_util *du) | |
565 | { | |
566 | if (du) { | |
567 | fio_mutex_down(du->lock); | |
568 | du->users--; | |
569 | fio_mutex_up(du->lock); | |
570 | } | |
571 | } | |
572 | ||
ebac4655 JA |
573 | #define DISK_UTIL_MSEC (250) |
574 | ||
6796209a JA |
575 | /* |
576 | * Log exports | |
577 | */ | |
f29b25a3 JA |
578 | enum file_log_act { |
579 | FIO_LOG_ADD_FILE, | |
580 | FIO_LOG_OPEN_FILE, | |
581 | FIO_LOG_CLOSE_FILE, | |
f718273e | 582 | FIO_LOG_UNLINK_FILE, |
f29b25a3 JA |
583 | }; |
584 | ||
72cb971b | 585 | extern int __must_check read_iolog_get(struct thread_data *, struct io_u *); |
f29b25a3 JA |
586 | extern void log_io_u(struct thread_data *, struct io_u *); |
587 | extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act); | |
72cb971b | 588 | extern int __must_check init_iolog(struct thread_data *td); |
6796209a | 589 | extern void log_io_piece(struct thread_data *, struct io_u *); |
691c8fb0 | 590 | extern void queue_io_piece(struct thread_data *, struct io_piece *); |
6796209a JA |
591 | extern void prune_io_piece_log(struct thread_data *); |
592 | extern void write_iolog_close(struct thread_data *); | |
593 | ||
594 | /* | |
595 | * Logging | |
596 | */ | |
306ddc97 JA |
597 | extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long, |
598 | unsigned int); | |
599 | extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long, | |
600 | unsigned int); | |
601 | extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int, | |
602 | struct timeval *); | |
6796209a JA |
603 | extern void show_run_stats(void); |
604 | extern void init_disk_util(struct thread_data *); | |
605 | extern void update_rusage_stat(struct thread_data *); | |
606 | extern void update_io_ticks(void); | |
8914a9d8 JA |
607 | extern void setup_log(struct io_log **); |
608 | extern void finish_log(struct thread_data *, struct io_log *, const char *); | |
e3cedca7 | 609 | extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *); |
bb3884d8 | 610 | extern void __finish_log(struct io_log *, const char *); |
bb3884d8 JA |
611 | extern struct io_log *agg_io_log[2]; |
612 | extern int write_bw_log; | |
306ddc97 | 613 | extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int); |
6796209a JA |
614 | |
615 | /* | |
616 | * Time functions | |
617 | */ | |
10927316 SL |
618 | extern unsigned long long utime_since(struct timeval *, struct timeval *); |
619 | extern unsigned long long utime_since_now(struct timeval *); | |
6796209a JA |
620 | extern unsigned long mtime_since(struct timeval *, struct timeval *); |
621 | extern unsigned long mtime_since_now(struct timeval *); | |
622 | extern unsigned long time_since_now(struct timeval *); | |
263e529f | 623 | extern unsigned long mtime_since_genesis(void); |
6dd6f2cd | 624 | extern void usec_spin(unsigned int); |
6796209a | 625 | extern void usec_sleep(struct thread_data *, unsigned long); |
413dd459 | 626 | extern void rate_throttle(struct thread_data *, unsigned long, unsigned int); |
6043c579 | 627 | extern void fill_start_time(struct timeval *); |
02bcaa8c | 628 | extern void fio_gettime(struct timeval *, void *); |
be4ecfdf JA |
629 | extern void fio_gtod_init(void); |
630 | extern void fio_gtod_update(void); | |
a2f77c9f | 631 | extern void set_genesis_time(void); |
721938ae | 632 | extern int ramp_time_over(struct thread_data *); |
b29ee5b3 | 633 | extern int in_ramp_time(struct thread_data *); |
6796209a | 634 | |
8914a9d8 | 635 | /* |
214e1eca | 636 | * Init/option functions |
8914a9d8 | 637 | */ |
72cb971b | 638 | extern int __must_check parse_options(int, char **); |
3b8b7135 | 639 | extern int fio_options_parse(struct thread_data *, char **, int); |
214e1eca JA |
640 | extern int fio_cmd_option_parse(struct thread_data *, const char *, char *); |
641 | extern void fio_fill_default_options(struct thread_data *); | |
642 | extern int fio_show_option_help(const char *); | |
643 | extern void fio_options_dup_and_init(struct option *); | |
d23bb327 JA |
644 | extern void options_mem_dupe(struct thread_data *); |
645 | extern void options_mem_free(struct thread_data *); | |
5bfc35d7 | 646 | extern void td_fill_rand_seeds(struct thread_data *); |
214e1eca JA |
647 | #define FIO_GETOPT_JOB 0x89988998 |
648 | #define FIO_NR_OPTIONS 128 | |
8914a9d8 | 649 | |
263e529f JA |
650 | /* |
651 | * ETA/status stuff | |
652 | */ | |
653 | extern void print_thread_status(void); | |
654 | extern void print_status_init(int); | |
655 | ||
9f8f2064 JA |
656 | /* |
657 | * disk util stuff | |
658 | */ | |
659 | #ifdef FIO_HAVE_DISK_UTIL | |
660 | extern void show_disk_util(void); | |
9f8f2064 JA |
661 | extern void init_disk_util(struct thread_data *); |
662 | extern void update_io_ticks(void); | |
663 | #else | |
664 | #define show_disk_util() | |
9f8f2064 JA |
665 | #define init_disk_util(td) |
666 | #define update_io_ticks() | |
667 | #endif | |
668 | ||
263e529f JA |
669 | /* |
670 | * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it | |
671 | * will never back again. It may cycle between running/verififying/fsyncing. | |
672 | * Once the thread reaches TD_EXITED, it is just waiting for the core to | |
673 | * reap it. | |
674 | */ | |
675 | enum { | |
676 | TD_NOT_CREATED = 0, | |
677 | TD_CREATED, | |
678 | TD_INITIALIZED, | |
b29ee5b3 | 679 | TD_RAMP, |
263e529f | 680 | TD_RUNNING, |
b0f65863 | 681 | TD_PRE_READING, |
263e529f JA |
682 | TD_VERIFYING, |
683 | TD_FSYNCING, | |
684 | TD_EXITED, | |
685 | TD_REAPED, | |
686 | }; | |
687 | ||
b29ee5b3 JA |
688 | extern void td_set_runstate(struct thread_data *, int); |
689 | ||
2f9ade3c JA |
690 | /* |
691 | * Memory helpers | |
692 | */ | |
b2fdda43 | 693 | extern int __must_check fio_pin_memory(void); |
2f9ade3c | 694 | extern void fio_unpin_memory(void); |
b2fdda43 | 695 | extern int __must_check allocate_io_mem(struct thread_data *); |
2f9ade3c JA |
696 | extern void free_io_mem(struct thread_data *); |
697 | ||
b29ee5b3 JA |
698 | /* |
699 | * Reset stats after ramp time completes | |
700 | */ | |
701 | extern void reset_all_stats(struct thread_data *); | |
702 | ||
fb7b71a3 JA |
703 | /* |
704 | * blktrace support | |
705 | */ | |
5e62c22a | 706 | #ifdef FIO_HAVE_BLKTRACE |
fb7b71a3 JA |
707 | extern int is_blktrace(const char *); |
708 | extern int load_blktrace(struct thread_data *, const char *); | |
5e62c22a | 709 | #endif |
fb7b71a3 | 710 | |
2866c82d JA |
711 | /* |
712 | * Mark unused variables passed to ops functions as unused, to silence gcc | |
713 | */ | |
714 | #define fio_unused __attribute((__unused__)) | |
5f350952 JA |
715 | #define fio_init __attribute__((constructor)) |
716 | #define fio_exit __attribute__((destructor)) | |
2866c82d | 717 | |
34572e28 JA |
718 | #define for_each_td(td, i) \ |
719 | for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++) | |
53cdc686 | 720 | #define for_each_file(td, f, i) \ |
691c8fb0 JA |
721 | if ((td)->files_index) \ |
722 | for ((i) = 0, (f) = (td)->files[0]; \ | |
723 | (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \ | |
724 | (i)++) | |
53cdc686 | 725 | |
0032bf9f JA |
726 | #define fio_assert(td, cond) do { \ |
727 | if (!(cond)) { \ | |
340fd243 | 728 | int *__foo = NULL; \ |
0032bf9f JA |
729 | fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \ |
730 | (td)->runstate = TD_EXITED; \ | |
437c9b71 | 731 | (td)->error = EFAULT; \ |
340fd243 | 732 | *__foo = 0; \ |
0032bf9f JA |
733 | } \ |
734 | } while (0) | |
735 | ||
009bd847 JA |
736 | static inline void fio_file_reset(struct fio_file *f) |
737 | { | |
738 | f->last_free_lookup = 0; | |
739 | f->last_pos = f->file_offset; | |
eaf9b417 JA |
740 | if (f->file_map) |
741 | memset(f->file_map, 0, f->num_maps * sizeof(int)); | |
009bd847 JA |
742 | } |
743 | ||
9bf27b45 JA |
744 | static inline void clear_error(struct thread_data *td) |
745 | { | |
746 | td->error = 0; | |
747 | td->verror[0] = '\0'; | |
748 | } | |
749 | ||
79e48f72 | 750 | #ifdef FIO_INC_DEBUG |
2ba1c290 JA |
751 | static inline void dprint_io_u(struct io_u *io_u, const char *p) |
752 | { | |
753 | struct fio_file *f = io_u->file; | |
754 | ||
755 | dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u, | |
5921e80c JA |
756 | (unsigned long long) io_u->offset, |
757 | io_u->buflen, io_u->ddir); | |
8172fe97 JA |
758 | if (fio_debug & (1 << FD_IO)) { |
759 | if (f) | |
760 | log_info("/%s", f->file_name); | |
761 | ||
762 | log_info("\n"); | |
763 | } | |
2ba1c290 | 764 | } |
79e48f72 | 765 | #else |
79e48f72 JA |
766 | #define dprint_io_u(io_u, p) |
767 | #endif | |
2ba1c290 | 768 | |
12d9d841 JA |
769 | static inline int fio_fill_issue_time(struct thread_data *td) |
770 | { | |
771 | if (td->o.read_iolog_file || | |
772 | !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw) | |
773 | return 1; | |
774 | ||
775 | return 0; | |
776 | } | |
777 | ||
ebac4655 | 778 | #endif |