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
129 FIO_MMAPIO = 1 << 1 | FIO_SYNCIO,
131 FIO_POSIXAIO = 1 << 3,
133 FIO_SPLICEIO = 1 << 5 | FIO_SYNCIO,
138 * This describes a single thread/process executing a fio job.
148 enum fio_filetype filetype;
154 size_t orig_buffer_size;
155 volatile int terminate;
156 volatile int runstate;
161 unsigned char sequential;
162 unsigned char odirect;
163 unsigned char create_file;
164 unsigned char invalidate_cache;
165 unsigned char create_serialize;
166 unsigned char create_fsync;
167 unsigned char end_fsync;
168 unsigned char sync_io;
169 unsigned char verify;
170 unsigned char use_thread;
171 unsigned char do_disk_util;
172 unsigned char override_sync;
173 unsigned char rand_repeatable;
178 unsigned int thinktime;
179 unsigned int fsync_blocks;
180 unsigned int start_delay;
181 unsigned long timeout;
182 enum fio_iotype io_engine;
183 unsigned int overwrite;
184 unsigned int bw_avg_time;
186 unsigned long long file_size;
187 unsigned long long real_file_size;
188 unsigned long long file_offset;
189 unsigned long long zone_size;
190 unsigned long long zone_skip;
191 enum fio_memtype mem_type;
192 unsigned int stonewall;
193 unsigned int numjobs;
194 unsigned int iodepth;
195 os_cpu_mask_t cpumask;
197 unsigned int read_iolog;
198 unsigned int write_iolog;
199 unsigned int rwmixcycle;
200 unsigned int rwmixread;
210 os_random_state_t bsrange_state;
211 os_random_state_t verify_state;
216 * IO engine hooks, contains everything needed to submit an io_u
217 * to any of the available IO engines.
220 char io_engine_name[16];
221 int (*io_prep)(struct thread_data *, struct io_u *);
222 int (*io_queue)(struct thread_data *, struct io_u *);
223 int (*io_getevents)(struct thread_data *, int, int, struct timespec *);
224 struct io_u *(*io_event)(struct thread_data *, int);
225 int (*io_cancel)(struct thread_data *, struct io_u *);
226 void (*io_cleanup)(struct thread_data *);
227 int (*io_sync)(struct thread_data *);
230 * Current IO depth and list of free and busy io_u's.
232 unsigned int cur_depth;
233 struct list_head io_u_freelist;
234 struct list_head io_u_busylist;
240 unsigned int ratemin;
241 unsigned int ratecycle;
242 unsigned long rate_usec_cycle;
243 long rate_pending_usleep;
244 unsigned long rate_bytes;
245 struct timeval lastrate;
247 unsigned long runtime[2]; /* msec */
248 unsigned long long io_size;
249 unsigned long long total_io_size;
251 unsigned long long io_blocks[2];
252 unsigned long long io_bytes[2];
253 unsigned long long zone_bytes;
254 unsigned long long this_io_bytes[2];
255 unsigned long long last_pos;
259 * State for random io, a bitmap of blocks done vs not done
261 os_random_state_t random_state;
262 unsigned long *file_map;
263 unsigned int num_maps;
266 * CPU "io" cycle burner
268 unsigned int cpuload;
269 unsigned int cpucycle;
272 * bandwidth and latency stats
274 struct io_stat clat_stat[2]; /* completion latency */
275 struct io_stat slat_stat[2]; /* submission latency */
276 struct io_stat bw_stat[2]; /* bandwidth stats */
278 unsigned long long stat_io_bytes[2];
279 struct timeval stat_sample_time[2];
281 struct io_log *slat_log;
282 struct io_log *clat_log;
283 struct io_log *bw_log;
285 struct timeval start; /* start of this loop */
286 struct timeval epoch; /* time job was started */
289 * fio system usage accounting
291 struct rusage ru_start;
292 struct rusage ru_end;
293 unsigned long usr_time;
294 unsigned long sys_time;
298 * read/write mixed workload state
300 os_random_state_t rwmix_state;
301 struct timeval rwmix_switch;
302 enum fio_ddir rwmix_ddir;
305 * Pre-run and post-run shell
313 struct list_head io_hist_list;
314 struct list_head io_log_list;
317 #define __td_verror(td, err, msg) \
321 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, (msg)); \
325 #define td_verror(td, err) __td_verror((td), (err), strerror((err)))
326 #define td_vmsg(td, err, msg) __td_verror((td), (err), (msg))
328 extern struct io_u *__get_io_u(struct thread_data *);
329 extern void put_io_u(struct thread_data *, struct io_u *);
331 extern int rate_quit;
332 extern int write_lat_log;
333 extern int write_bw_log;
334 extern int exitall_on_terminate;
335 extern int thread_number;
338 extern int terse_output;
342 extern struct thread_data *threads;
344 #define td_read(td) ((td)->ddir == DDIR_READ)
345 #define td_write(td) ((td)->ddir == DDIR_WRITE)
346 #define td_rw(td) ((td)->iomix != 0)
348 #define BLOCKS_PER_MAP (8 * sizeof(long))
349 #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs))
350 #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP)
351 #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1))
353 #define MAX_JOBS (1024)
355 struct disk_util_stat {
358 unsigned long long sectors[2];
361 unsigned time_in_queue;
365 struct list_head list;
371 struct disk_util_stat dus;
372 struct disk_util_stat last_dus;
378 struct io_completion_data {
381 int error; /* output */
382 unsigned long bytes_done[2]; /* output */
385 #define DISK_UTIL_MSEC (250)
388 #define min(a, b) ((a) < (b) ? (a) : (b))
394 extern int read_iolog_get(struct thread_data *, struct io_u *);
395 extern void write_iolog_put(struct thread_data *, struct io_u *);
396 extern int init_iolog(struct thread_data *td);
397 extern void log_io_piece(struct thread_data *, struct io_u *);
398 extern void prune_io_piece_log(struct thread_data *);
399 extern void write_iolog_close(struct thread_data *);
404 extern void add_clat_sample(struct thread_data *, int, unsigned long);
405 extern void add_slat_sample(struct thread_data *, int, unsigned long);
406 extern void add_bw_sample(struct thread_data *, int);
407 extern void show_run_stats(void);
408 extern void init_disk_util(struct thread_data *);
409 extern void update_rusage_stat(struct thread_data *);
410 extern void update_io_ticks(void);
411 extern void disk_util_timer_arm(void);
412 extern void setup_log(struct io_log **);
413 extern void finish_log(struct thread_data *, struct io_log *, const char *);
414 extern int setup_rate(struct thread_data *);
419 extern unsigned long utime_since(struct timeval *, struct timeval *);
420 extern unsigned long mtime_since(struct timeval *, struct timeval *);
421 extern unsigned long mtime_since_now(struct timeval *);
422 extern unsigned long time_since_now(struct timeval *);
423 extern void __usec_sleep(unsigned int);
424 extern void usec_sleep(struct thread_data *, unsigned long);
425 extern void rate_throttle(struct thread_data *, unsigned long, unsigned int);
430 extern int parse_options(int, char **);
431 extern int init_random_state(struct thread_data *);
434 * This is a pretty crappy semaphore implementation, but with the use that fio
435 * has (just signalling start/go conditions), it doesn't have to be better.
436 * Naturally this would not work for any type of contended semaphore or
439 static inline void fio_sem_init(volatile int *sem, int val)
444 static inline void fio_sem_down(volatile int *sem)
452 static inline void fio_sem_up(volatile int *sem)
458 * If logging output to a file, stderr should go to both stderr and f_err
460 #define log_err(args...) do { \
461 fprintf(f_err, ##args); \
462 if (f_err != stderr) \
463 fprintf(stderr, ##args); \