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,
137 * This describes a single thread/process executing a fio job.
147 enum fio_filetype filetype;
153 size_t orig_buffer_size;
154 volatile int terminate;
155 volatile int runstate;
160 unsigned char sequential;
161 unsigned char odirect;
162 unsigned char create_file;
163 unsigned char invalidate_cache;
164 unsigned char create_serialize;
165 unsigned char create_fsync;
166 unsigned char end_fsync;
167 unsigned char sync_io;
168 unsigned char verify;
169 unsigned char use_thread;
170 unsigned char do_disk_util;
171 unsigned char override_sync;
172 unsigned char rand_repeatable;
177 unsigned int thinktime;
178 unsigned int fsync_blocks;
179 unsigned int start_delay;
180 unsigned int timeout;
181 enum fio_iotype io_engine;
182 unsigned int overwrite;
183 unsigned int bw_avg_time;
185 unsigned long long file_size;
186 unsigned long long real_file_size;
187 unsigned long long file_offset;
188 unsigned long long zone_size;
189 unsigned long long zone_skip;
190 enum fio_memtype mem_type;
191 unsigned int stonewall;
192 unsigned int numjobs;
193 unsigned int iodepth;
194 os_cpu_mask_t cpumask;
196 unsigned int read_iolog;
197 unsigned int write_iolog;
198 unsigned int rwmixcycle;
199 unsigned int rwmixread;
209 os_random_state_t bsrange_state;
210 os_random_state_t verify_state;
215 * IO engine hooks, contains everything needed to submit an io_u
216 * to any of the available IO engines.
219 char io_engine_name[16];
220 int (*io_prep)(struct thread_data *, struct io_u *);
221 int (*io_queue)(struct thread_data *, struct io_u *);
222 int (*io_getevents)(struct thread_data *, int, int, struct timespec *);
223 struct io_u *(*io_event)(struct thread_data *, int);
224 int (*io_cancel)(struct thread_data *, struct io_u *);
225 void (*io_cleanup)(struct thread_data *);
226 int (*io_sync)(struct thread_data *);
229 * Current IO depth and list of free and busy io_u's.
231 unsigned int cur_depth;
232 struct list_head io_u_freelist;
233 struct list_head io_u_busylist;
239 unsigned int ratemin;
240 unsigned int ratecycle;
241 unsigned long rate_usec_cycle;
242 long rate_pending_usleep;
243 unsigned long rate_bytes;
244 struct timeval lastrate;
246 unsigned long runtime[2]; /* msec */
247 unsigned long long io_size;
248 unsigned long long total_io_size;
250 unsigned long long io_blocks[2];
251 unsigned long long io_bytes[2];
252 unsigned long long zone_bytes;
253 unsigned long long this_io_bytes[2];
254 unsigned long long last_pos;
258 * State for random io, a bitmap of blocks done vs not done
260 os_random_state_t random_state;
261 unsigned long *file_map;
262 unsigned int num_maps;
265 * bandwidth and latency stats
267 struct io_stat clat_stat[2]; /* completion latency */
268 struct io_stat slat_stat[2]; /* submission latency */
269 struct io_stat bw_stat[2]; /* bandwidth stats */
271 unsigned long long stat_io_bytes[2];
272 struct timeval stat_sample_time[2];
274 struct io_log *slat_log;
275 struct io_log *clat_log;
276 struct io_log *bw_log;
278 struct timeval start; /* start of this loop */
279 struct timeval epoch; /* time job was started */
282 * fio system usage accounting
284 struct rusage ru_start;
285 struct rusage ru_end;
286 unsigned long usr_time;
287 unsigned long sys_time;
291 * read/write mixed workload state
293 os_random_state_t rwmix_state;
294 struct timeval rwmix_switch;
295 enum fio_ddir rwmix_ddir;
298 * Pre-run and post-run shell
306 struct list_head io_hist_list;
307 struct list_head io_log_list;
310 #define td_verror(td, err) \
314 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, error=%s", __FILE__, __LINE__, strerror(e)); \
317 extern struct io_u *__get_io_u(struct thread_data *);
318 extern void put_io_u(struct thread_data *, struct io_u *);
320 extern int rate_quit;
321 extern int write_lat_log;
322 extern int write_bw_log;
323 extern int exitall_on_terminate;
324 extern int thread_number;
327 extern int terse_output;
331 extern struct thread_data *threads;
333 #define td_read(td) ((td)->ddir == DDIR_READ)
334 #define td_write(td) ((td)->ddir == DDIR_WRITE)
335 #define td_rw(td) ((td)->iomix != 0)
337 #define BLOCKS_PER_MAP (8 * sizeof(long))
338 #define TO_MAP_BLOCK(td, b) ((b) - ((td)->file_offset / (td)->min_bs))
339 #define RAND_MAP_IDX(td, b) (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP)
340 #define RAND_MAP_BIT(td, b) (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1))
342 #define MAX_JOBS (1024)
344 struct disk_util_stat {
347 unsigned long long sectors[2];
350 unsigned time_in_queue;
354 struct list_head list;
360 struct disk_util_stat dus;
361 struct disk_util_stat last_dus;
367 struct io_completion_data {
370 int error; /* output */
371 unsigned long bytes_done[2]; /* output */
374 #define DISK_UTIL_MSEC (250)
377 #define min(a, b) ((a) < (b) ? (a) : (b))
383 extern int read_iolog_get(struct thread_data *, struct io_u *);
384 extern void write_iolog_put(struct thread_data *, struct io_u *);
385 extern int init_iolog(struct thread_data *td);
386 extern void log_io_piece(struct thread_data *, struct io_u *);
387 extern void prune_io_piece_log(struct thread_data *);
388 extern void write_iolog_close(struct thread_data *);
393 extern void add_clat_sample(struct thread_data *, int, unsigned long);
394 extern void add_slat_sample(struct thread_data *, int, unsigned long);
395 extern void add_bw_sample(struct thread_data *, int);
396 extern void show_run_stats(void);
397 extern void init_disk_util(struct thread_data *);
398 extern void update_rusage_stat(struct thread_data *);
399 extern void update_io_ticks(void);
400 extern void disk_util_timer_arm(void);
401 extern void setup_log(struct io_log **);
402 extern void finish_log(struct thread_data *, struct io_log *, const char *);
403 extern int setup_rate(struct thread_data *);
408 extern unsigned long utime_since(struct timeval *, struct timeval *);
409 extern unsigned long mtime_since(struct timeval *, struct timeval *);
410 extern unsigned long mtime_since_now(struct timeval *);
411 extern unsigned long time_since_now(struct timeval *);
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 volatile *sem, int val)
432 static inline void fio_sem_down(volatile int volatile *sem)
440 static inline void fio_sem_up(volatile int volatile *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); \