8 #include <sys/resource.h>
23 unsigned long max_val;
24 unsigned long min_val;
25 unsigned long samples;
35 unsigned long nr_samples;
36 unsigned long max_samples;
37 struct io_sample *log;
41 struct list_head list;
42 unsigned long long offset;
52 #ifdef FIO_HAVE_LIBAIO
55 #ifdef FIO_HAVE_POSIXAIO
62 struct timeval start_time;
63 struct timeval issue_time;
67 unsigned long long offset;
76 struct list_head list;
79 #define FIO_HDR_MAGIC 0xf00baaef
87 struct verify_header {
88 unsigned int fio_magic;
90 unsigned int verify_type;
92 char md5_digest[MD5_HASH_WORDS * 4];
97 struct group_run_stats {
98 unsigned long long max_run[2], min_run[2];
99 unsigned long long max_bw[2], min_bw[2];
100 unsigned long long io_kb[2];
101 unsigned long long agg[2];
110 * What type of allocation to use for io buffers
113 MEM_MALLOC = 0, /* ordinary malloc */
114 MEM_SHM, /* use shared memory segments */
115 MEM_MMAP, /* use anonynomous mmap */
119 * The type of object we are working on
127 enum fio_ioengine_flags {
134 * This describes a single thread/process executing a fio job.
144 enum fio_filetype filetype;
150 size_t orig_buffer_size;
151 volatile int terminate;
152 volatile int runstate;
157 unsigned char sequential;
158 unsigned char odirect;
159 unsigned char create_file;
160 unsigned char invalidate_cache;
161 unsigned char create_serialize;
162 unsigned char create_fsync;
163 unsigned char end_fsync;
164 unsigned char sync_io;
165 unsigned char verify;
166 unsigned char use_thread;
167 unsigned char do_disk_util;
168 unsigned char override_sync;
169 unsigned char rand_repeatable;
174 unsigned int thinktime;
175 unsigned int fsync_blocks;
176 unsigned int start_delay;
177 unsigned long timeout;
178 unsigned int overwrite;
179 unsigned int bw_avg_time;
181 unsigned long long file_size;
182 unsigned long long real_file_size;
183 unsigned long long file_offset;
184 unsigned long long zone_size;
185 unsigned long long zone_skip;
186 enum fio_memtype mem_type;
187 unsigned int stonewall;
188 unsigned int numjobs;
189 unsigned int iodepth;
190 os_cpu_mask_t cpumask;
192 unsigned int read_iolog;
193 unsigned int write_iolog;
194 unsigned int rwmixcycle;
195 unsigned int rwmixread;
205 os_random_state_t bsrange_state;
206 os_random_state_t verify_state;
211 * IO engine hooks, contains everything needed to submit an io_u
212 * to any of the available IO engines.
214 struct ioengine_ops *io_ops;
217 * Current IO depth and list of free and busy io_u's.
219 unsigned int cur_depth;
220 struct list_head io_u_freelist;
221 struct list_head io_u_busylist;
227 unsigned int ratemin;
228 unsigned int ratecycle;
229 unsigned long rate_usec_cycle;
230 long rate_pending_usleep;
231 unsigned long rate_bytes;
232 struct timeval lastrate;
234 unsigned long runtime[2]; /* msec */
235 unsigned long long io_size;
236 unsigned long long total_io_size;
238 unsigned long long io_blocks[2];
239 unsigned long long io_bytes[2];
240 unsigned long long zone_bytes;
241 unsigned long long this_io_bytes[2];
242 unsigned long long last_pos;
246 * State for random io, a bitmap of blocks done vs not done
248 os_random_state_t random_state;
249 unsigned long *file_map;
250 unsigned int num_maps;
253 * CPU "io" cycle burner
255 unsigned int cpuload;
256 unsigned int cpucycle;
259 * bandwidth and latency stats
261 struct io_stat clat_stat[2]; /* completion latency */
262 struct io_stat slat_stat[2]; /* submission latency */
263 struct io_stat bw_stat[2]; /* bandwidth stats */
265 unsigned long long stat_io_bytes[2];
266 struct timeval stat_sample_time[2];
268 struct io_log *slat_log;
269 struct io_log *clat_log;
270 struct io_log *bw_log;
272 struct timeval start; /* start of this loop */
273 struct timeval epoch; /* time job was started */
276 * fio system usage accounting
278 struct rusage ru_start;
279 struct rusage ru_end;
280 unsigned long usr_time;
281 unsigned long sys_time;
285 * read/write mixed workload state
287 os_random_state_t rwmix_state;
288 struct timeval rwmix_switch;
289 enum fio_ddir rwmix_ddir;
292 * Pre-run and post-run shell
300 struct list_head io_hist_list;
301 struct list_head io_log_list;
304 #define __td_verror(td, err, msg) \
308 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, (msg)); \
312 #define td_verror(td, err) __td_verror((td), (err), strerror((err)))
313 #define td_vmsg(td, err, msg) __td_verror((td), (err), (msg))
315 extern struct io_u *__get_io_u(struct thread_data *);
316 extern void put_io_u(struct thread_data *, struct io_u *);
318 extern int rate_quit;
319 extern int write_lat_log;
320 extern int write_bw_log;
321 extern int exitall_on_terminate;
322 extern int thread_number;
325 extern int terse_output;
328 extern char *fio_inst_prefix;
330 extern struct thread_data *threads;
332 #define td_read(td) ((td)->ddir == DDIR_READ)
333 #define td_write(td) ((td)->ddir == DDIR_WRITE)
334 #define td_rw(td) ((td)->iomix != 0)
336 #define BLOCKS_PER_MAP (8 * sizeof(long))
337 #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs))
338 #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP)
339 #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1))
341 #define MAX_JOBS (1024)
343 struct disk_util_stat {
346 unsigned long long sectors[2];
349 unsigned time_in_queue;
353 struct list_head list;
359 struct disk_util_stat dus;
360 struct disk_util_stat last_dus;
366 struct io_completion_data {
369 int error; /* output */
370 unsigned long bytes_done[2]; /* output */
373 #define DISK_UTIL_MSEC (250)
376 #define min(a, b) ((a) < (b) ? (a) : (b))
382 extern int read_iolog_get(struct thread_data *, struct io_u *);
383 extern void write_iolog_put(struct thread_data *, struct io_u *);
384 extern int init_iolog(struct thread_data *td);
385 extern void log_io_piece(struct thread_data *, struct io_u *);
386 extern void prune_io_piece_log(struct thread_data *);
387 extern void write_iolog_close(struct thread_data *);
392 extern void add_clat_sample(struct thread_data *, int, unsigned long);
393 extern void add_slat_sample(struct thread_data *, int, unsigned long);
394 extern void add_bw_sample(struct thread_data *, int);
395 extern void show_run_stats(void);
396 extern void init_disk_util(struct thread_data *);
397 extern void update_rusage_stat(struct thread_data *);
398 extern void update_io_ticks(void);
399 extern void disk_util_timer_arm(void);
400 extern void setup_log(struct io_log **);
401 extern void finish_log(struct thread_data *, struct io_log *, const char *);
402 extern int setup_rate(struct thread_data *);
407 extern unsigned long utime_since(struct timeval *, struct timeval *);
408 extern unsigned long mtime_since(struct timeval *, struct timeval *);
409 extern unsigned long mtime_since_now(struct timeval *);
410 extern unsigned long time_since_now(struct timeval *);
411 extern void __usec_sleep(unsigned int);
412 extern void usec_sleep(struct thread_data *, unsigned long);
413 extern void rate_throttle(struct thread_data *, unsigned long, unsigned int);
418 extern int parse_options(int, char **);
419 extern int init_random_state(struct thread_data *);
422 * This is a pretty crappy semaphore implementation, but with the use that fio
423 * has (just signalling start/go conditions), it doesn't have to be better.
424 * Naturally this would not work for any type of contended semaphore or
427 static inline void fio_sem_init(volatile int *sem, int val)
432 static inline void fio_sem_down(volatile int *sem)
440 static inline void fio_sem_up(volatile int *sem)
446 * If logging output to a file, stderr should go to both stderr and f_err
448 #define log_err(args...) do { \
449 fprintf(f_err, ##args); \
450 if (f_err != stderr) \
451 fprintf(stderr, ##args); \
454 struct ioengine_ops {
458 int (*init)(struct thread_data *);
459 int (*prep)(struct thread_data *, struct io_u *);
460 int (*queue)(struct thread_data *, struct io_u *);
461 int (*getevents)(struct thread_data *, int, int, struct timespec *);
462 struct io_u *(*event)(struct thread_data *, int);
463 int (*cancel)(struct thread_data *, struct io_u *);
464 void (*cleanup)(struct thread_data *);
465 int (*sync)(struct thread_data *);
470 #define FIO_IOOPS_VERSION 1
472 extern struct ioengine_ops *load_ioengine(struct thread_data *, char *);
473 extern void close_ioengine(struct thread_data *);
476 * Mark unused variables passed to ops functions as unused, to silence gcc
478 #define fio_unused __attribute((__unused__))