blob: 6e222f9758721970847a03313281fa7bae07727f [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001#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>
Jens Axboe3c39a372006-06-06 20:56:12 +02009#include <errno.h>
10#include <stdlib.h>
11#include <stdio.h>
Jens Axboe6d6f0312006-06-07 21:39:13 +020012#include <unistd.h>
Jens Axboe34cfcda2006-11-03 14:00:45 +010013#include <string.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +010014#include <getopt.h>
Jens Axboecd14cc12007-07-30 10:59:33 +020015#include <inttypes.h>
Jens Axboe7101d9c2007-09-12 13:12:39 +020016#include <assert.h>
Jens Axboeebac4652005-12-08 15:25:21 +010017
Jens Axboe317b95d2007-04-02 21:36:44 +020018#include "compiler/compiler.h"
Jens Axboe01743ee2008-06-02 12:19:19 +020019#include "flist.h"
Jens Axboee2887562007-05-16 09:25:09 +020020#include "fifo.h"
Jens Axboe4b878982007-03-26 09:32:22 +020021#include "rbtree.h"
Jens Axboe317b95d2007-04-02 21:36:44 +020022#include "arch/arch.h"
23#include "os/os.h"
Jens Axboe07739b52007-03-08 20:25:46 +010024#include "mutex.h"
Jens Axboea3d741f2008-02-27 18:32:33 +010025#include "log.h"
26#include "debug.h"
Jens Axboed6aed792009-06-03 08:41:15 +020027#include "file.h"
28#include "io_ddir.h"
Jens Axboedcefb582009-06-03 08:49:39 +020029#include "ioengine.h"
Jens Axboeebac4652005-12-08 15:25:21 +010030
Davide Libenzi609342f2007-03-21 08:46:18 +010031#ifdef FIO_HAVE_GUASI
32#include <guasi.h>
33#endif
34
Jens Axboe417f0062008-06-02 11:59:30 +020035#ifdef FIO_HAVE_SOLARISAIO
36#include <sys/asynch.h>
37#endif
38
Jens Axboe1c9e06e2007-02-11 04:07:57 +010039/*
40 * Use for maintaining statistics
41 */
Jens Axboeebac4652005-12-08 15:25:21 +010042struct io_stat {
Jens Axboeebac4652005-12-08 15:25:21 +010043 unsigned long max_val;
44 unsigned long min_val;
45 unsigned long samples;
Jens Axboe68704082007-01-10 19:56:37 +010046
47 double mean;
48 double S;
Jens Axboeebac4652005-12-08 15:25:21 +010049};
50
Jens Axboe1c9e06e2007-02-11 04:07:57 +010051/*
52 * A single data sample
53 */
Jens Axboeebac4652005-12-08 15:25:21 +010054struct io_sample {
55 unsigned long time;
56 unsigned long val;
Jens Axboe1e97cce2006-12-05 11:44:16 +010057 enum fio_ddir ddir;
Jens Axboe306ddc92009-05-18 13:08:12 +020058 unsigned int bs;
Jens Axboeebac4652005-12-08 15:25:21 +010059};
60
Jens Axboe1c9e06e2007-02-11 04:07:57 +010061/*
62 * Dynamically growing data sample log
63 */
Jens Axboeebac4652005-12-08 15:25:21 +010064struct io_log {
65 unsigned long nr_samples;
66 unsigned long max_samples;
67 struct io_sample *log;
68};
69
Jens Axboe1c9e06e2007-02-11 04:07:57 +010070/*
71 * When logging io actions, this matches a single sent io_u
72 */
Jens Axboeebac4652005-12-08 15:25:21 +010073struct io_piece {
Jens Axboe4b878982007-03-26 09:32:22 +020074 union {
75 struct rb_node rb_node;
Jens Axboe01743ee2008-06-02 12:19:19 +020076 struct flist_head list;
Jens Axboe4b878982007-03-26 09:32:22 +020077 };
Jens Axboef29b25a2007-07-23 08:56:43 +020078 union {
79 int fileno;
80 struct fio_file *file;
81 };
Jens Axboeebac4652005-12-08 15:25:21 +010082 unsigned long long offset;
Jens Axboea4f4fdd2007-02-14 01:16:39 +010083 unsigned long len;
Jens Axboe1e97cce2006-12-05 11:44:16 +010084 enum fio_ddir ddir;
Jens Axboef29b25a2007-07-23 08:56:43 +020085 union {
86 unsigned long delay;
87 unsigned int file_action;
88 };
Jens Axboeebac4652005-12-08 15:25:21 +010089};
90
Jens Axboeebac4652005-12-08 15:25:21 +010091struct group_run_stats {
Jens Axboe9104f872005-12-28 23:50:45 +010092 unsigned long long max_run[2], min_run[2];
93 unsigned long long max_bw[2], min_bw[2];
Jens Axboee9b2a3f2006-06-06 15:38:33 +020094 unsigned long long io_kb[2];
Jens Axboe9104f872005-12-28 23:50:45 +010095 unsigned long long agg[2];
Jens Axboeebac4652005-12-08 15:25:21 +010096};
97
Jens Axboee9c047a2006-06-07 21:13:04 +020098/*
99 * What type of allocation to use for io buffers
100 */
101enum fio_memtype {
102 MEM_MALLOC = 0, /* ordinary malloc */
103 MEM_SHM, /* use shared memory segments */
Jens Axboe74b025b2006-12-19 15:18:14 +0100104 MEM_SHMHUGE, /* use shared memory segments with huge pages */
Jens Axboee9c047a2006-06-07 21:13:04 +0200105 MEM_MMAP, /* use anonynomous mmap */
Jens Axboed0bdaf42006-12-20 14:40:44 +0100106 MEM_MMAPHUGE, /* memory mapped huge file */
Jens Axboee9c047a2006-06-07 21:13:04 +0200107};
108
Jens Axboe2866c822006-10-09 15:57:48 +0200109enum fio_ioengine_flags {
Jens Axboe1c9e06e2007-02-11 04:07:57 +0100110 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
Jens Axboeba0fbe12007-03-09 14:34:23 +0100111 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
112 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
Jens Axboe02638822007-03-12 09:25:55 +0100113 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
Jens Axboe62d984e2007-03-13 08:15:18 +0100114 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
Jens Axboeb67740d2007-07-26 12:22:30 +0200115 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
Jens Axboe1f809d12007-10-25 18:34:02 +0200116 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
Jens Axboead830ed2008-02-18 21:11:24 +0100117 FIO_SIGQUIT = 1 << 7, /* needs SIGQUIT to exit */
Jens Axboee9c047a2006-06-07 21:13:04 +0200118};
119
Jens Axboeb2560f32007-03-06 12:43:03 +0100120/*
121 * How many depth levels to log
122 */
123#define FIO_IO_U_MAP_NR 8
Jens Axboea9a18a32007-07-06 14:09:49 +0200124#define FIO_IO_U_LAT_U_NR 10
125#define FIO_IO_U_LAT_M_NR 12
Jens Axboeb2560f32007-03-06 12:43:03 +0100126
Jens Axboe079ad092007-02-20 13:58:20 +0100127struct thread_stat {
Jens Axboe756867b2007-03-06 15:19:24 +0100128 char *name;
129 char *verror;
130 int error;
131 int groupid;
132 pid_t pid;
133 char *description;
Jens Axboe6586ee82007-03-06 19:46:09 +0100134 int members;
Jens Axboe756867b2007-03-06 15:19:24 +0100135
Jens Axboe079ad092007-02-20 13:58:20 +0100136 struct io_log *slat_log;
137 struct io_log *clat_log;
138 struct io_log *bw_log;
139
140 /*
141 * bandwidth and latency stats
142 */
143 struct io_stat clat_stat[2]; /* completion latency */
144 struct io_stat slat_stat[2]; /* submission latency */
145 struct io_stat bw_stat[2]; /* bandwidth stats */
146
147 unsigned long long stat_io_bytes[2];
148 struct timeval stat_sample_time[2];
149
150 /*
151 * fio system usage accounting
152 */
153 struct rusage ru_start;
154 struct rusage ru_end;
155 unsigned long usr_time;
156 unsigned long sys_time;
157 unsigned long ctx;
Jens Axboe81887d52007-09-07 20:36:08 +0200158 unsigned long minf, majf;
Jens Axboe079ad092007-02-20 13:58:20 +0100159
Jens Axboeb2560f32007-03-06 12:43:03 +0100160 /*
161 * IO depth and latency stats
162 */
163 unsigned int io_u_map[FIO_IO_U_MAP_NR];
Jens Axboe838bc702008-05-22 13:08:23 +0200164 unsigned int io_u_submit[FIO_IO_U_MAP_NR];
165 unsigned int io_u_complete[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200166 unsigned int io_u_lat_u[FIO_IO_U_LAT_U_NR];
167 unsigned int io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboeb3605062007-03-12 14:19:47 +0100168 unsigned long total_io_u[2];
Jens Axboe30061b92007-04-17 13:31:34 +0200169 unsigned long short_io_u[2];
Jens Axboe838bc702008-05-22 13:08:23 +0200170 unsigned long total_submit;
171 unsigned long total_complete;
Jens Axboe756867b2007-03-06 15:19:24 +0100172
173 unsigned long long io_bytes[2];
174 unsigned long runtime[2];
175 unsigned long total_run_time;
Jens Axboeb2560f32007-03-06 12:43:03 +0100176};
Jens Axboe71619dc2007-01-13 23:56:33 +0100177
Jens Axboe564ca972007-12-14 12:21:19 +0100178struct bssplit {
179 unsigned int bs;
180 unsigned char perc;
181};
182
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100183struct thread_options {
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100184 int pad;
Jens Axboe61697c32007-02-05 15:04:46 +0100185 char *description;
Jens Axboeb4692822006-10-27 13:43:22 +0200186 char *name;
Jens Axboeef899b62006-06-06 09:31:00 +0200187 char *directory;
Jens Axboe13f8e2d2006-10-24 09:29:45 +0200188 char *filename;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100189 char *opendir;
Jens Axboe09629a92007-03-09 09:00:06 +0100190 char *ioengine;
Jens Axboe413dd452007-02-23 09:26:09 +0100191 enum td_ddir td_ddir;
Jens Axboe211097b2007-03-22 18:56:45 +0100192 unsigned int ddir_nr;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100193 unsigned int iodepth;
194 unsigned int iodepth_low;
195 unsigned int iodepth_batch;
Jens Axboe49504212008-06-05 09:03:30 +0200196 unsigned int iodepth_batch_complete;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100197
198 unsigned long long size;
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100199 unsigned int fill_device;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100200 unsigned long long file_size_low;
201 unsigned long long file_size_high;
202 unsigned long long start_offset;
203
204 unsigned int bs[2];
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100205 unsigned int ba[2];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100206 unsigned int min_bs[2];
207 unsigned int max_bs[2];
Jens Axboe720e84a2009-04-21 08:29:55 +0200208 struct bssplit *bssplit[2];
209 unsigned int bssplit_nr[2];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100210
211 unsigned int nr_files;
212 unsigned int open_files;
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100213 enum file_lock_mode file_lock_mode;
Jens Axboe29c13492008-03-01 19:25:20 +0100214 unsigned int lockfile_batch;
Jens Axboee9c047a2006-06-07 21:13:04 +0200215
Jens Axboe9158d2f2006-10-27 14:27:39 +0200216 unsigned int odirect;
217 unsigned int invalidate_cache;
218 unsigned int create_serialize;
219 unsigned int create_fsync;
Jens Axboe814452b2009-03-04 12:53:13 +0100220 unsigned int create_on_open;
Jens Axboe9158d2f2006-10-27 14:27:39 +0200221 unsigned int end_fsync;
Zhang, Yanminafad68f2009-05-20 11:30:55 +0200222 unsigned int pre_read;
Jens Axboe9158d2f2006-10-27 14:27:39 +0200223 unsigned int sync_io;
224 unsigned int verify;
Shawn Lewise84c73a2007-08-02 22:19:32 +0200225 unsigned int do_verify;
Jens Axboe160b9662007-03-27 10:59:49 +0200226 unsigned int verifysort;
Jens Axboea59e1702007-07-30 08:53:27 +0200227 unsigned int verify_interval;
228 unsigned int verify_offset;
Jens Axboe90059d62007-07-30 09:33:12 +0200229 unsigned int verify_pattern;
230 unsigned int verify_pattern_bytes;
Jens Axboea12a3b42007-08-09 10:20:54 +0200231 unsigned int verify_fatal;
Jens Axboe9158d2f2006-10-27 14:27:39 +0200232 unsigned int use_thread;
233 unsigned int unlink;
234 unsigned int do_disk_util;
235 unsigned int override_sync;
236 unsigned int rand_repeatable;
237 unsigned int write_lat_log;
238 unsigned int write_bw_log;
Jens Axboebb8895e2006-10-30 15:14:48 +0100239 unsigned int norandommap;
Jens Axboe2b386d22008-03-26 10:32:57 +0100240 unsigned int softrandommap;
Jens Axboe690adba2006-10-30 15:25:09 +0100241 unsigned int bs_unaligned;
Jens Axboeebb14152007-03-13 14:42:15 +0100242 unsigned int fsync_on_close;
Jens Axboee9c047a2006-06-07 21:13:04 +0200243
Jens Axboe56bb17f2006-12-20 20:27:36 +0100244 unsigned int hugepage_size;
Jens Axboea00735e2006-11-03 08:58:08 +0100245 unsigned int rw_min_bs;
Jens Axboeebac4652005-12-08 15:25:21 +0100246 unsigned int thinktime;
Jens Axboe48097d52007-02-17 06:30:44 +0100247 unsigned int thinktime_spin;
Jens Axboe9c1f7432007-01-03 20:43:19 +0100248 unsigned int thinktime_blocks;
Jens Axboeebac4652005-12-08 15:25:21 +0100249 unsigned int fsync_blocks;
250 unsigned int start_delay;
Jens Axboe0db26792007-05-16 08:59:27 +0200251 unsigned long long timeout;
Jens Axboe721938a2008-09-10 09:46:16 +0200252 unsigned long long ramp_time;
Jens Axboeebac4652005-12-08 15:25:21 +0100253 unsigned int overwrite;
Jens Axboeebac4652005-12-08 15:25:21 +0100254 unsigned int bw_avg_time;
Jens Axboeebac4652005-12-08 15:25:21 +0100255 unsigned int loops;
Jens Axboe20dc95c2005-12-09 10:29:35 +0100256 unsigned long long zone_size;
257 unsigned long long zone_skip;
Jens Axboee9c047a2006-06-07 21:13:04 +0200258 enum fio_memtype mem_type;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100259
Jens Axboeebac4652005-12-08 15:25:21 +0100260 unsigned int stonewall;
Jens Axboeb3d62a72007-03-20 14:23:26 +0100261 unsigned int new_group;
Jens Axboeebac4652005-12-08 15:25:21 +0100262 unsigned int numjobs;
Jens Axboeebac4652005-12-08 15:25:21 +0100263 os_cpu_mask_t cpumask;
Jens Axboe375b2692007-05-22 09:13:02 +0200264 unsigned int cpumask_set;
Jens Axboeaea47d42006-05-26 19:27:29 +0200265 unsigned int iolog;
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200266 unsigned int rwmixcycle;
Jens Axboee47f7992007-03-21 14:05:39 +0100267 unsigned int rwmix[2];
Jens Axboeb6f4d882006-06-02 10:32:51 +0200268 unsigned int nice;
Jens Axboe0aabe162007-02-23 08:45:55 +0100269 unsigned int file_service_type;
Jens Axboeb2560f32007-03-06 12:43:03 +0100270 unsigned int group_reporting;
Jens Axboed2f3ac32007-03-22 19:24:09 +0100271 unsigned int fadvise_hint;
Jens Axboee9459e52007-04-17 15:46:32 +0200272 unsigned int zero_buffers;
Jens Axboe5973caf2008-05-21 19:52:35 +0200273 unsigned int refill_buffers;
Jens Axboecf4464c2007-04-17 20:14:42 +0200274 unsigned int time_based;
Jens Axboe9520ebb2008-10-16 21:03:27 +0200275 unsigned int disable_clat;
276 unsigned int disable_slat;
277 unsigned int disable_bw;
Jens Axboe993bf482008-11-14 13:04:53 +0100278 unsigned int gtod_reduce;
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100279 unsigned int gtod_cpu;
280 unsigned int gtod_offload;
Jens Axboeaea47d42006-05-26 19:27:29 +0200281
Jens Axboe076efc72006-10-27 11:24:25 +0200282 char *read_iolog_file;
283 char *write_iolog_file;
Jens Axboee3cedca2008-11-19 19:57:52 +0100284 char *bw_log_file;
285 char *lat_log_file;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100286
287 /*
288 * Pre-run and post-run shell
289 */
290 char *exec_prerun;
291 char *exec_postrun;
292
293 unsigned int rate;
294 unsigned int ratemin;
295 unsigned int ratecycle;
296 unsigned int rate_iops;
297 unsigned int rate_iops_min;
298
299 char *ioscheduler;
300
301 /*
302 * CPU "io" cycle burner
303 */
304 unsigned int cpuload;
305 unsigned int cpucycle;
306};
307
Jens Axboee4e33252007-03-21 13:07:54 +0100308#define FIO_VERROR_SIZE 128
309
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100310/*
311 * This describes a single thread/process executing a fio job.
312 */
313struct thread_data {
314 struct thread_options o;
Jens Axboee4e33252007-03-21 13:07:54 +0100315 char verror[FIO_VERROR_SIZE];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100316 pthread_t thread;
317 int thread_number;
318 int groupid;
319 struct thread_stat ts;
Jens Axboe126d65c2008-03-01 18:04:31 +0100320 struct fio_file **files;
Jens Axboedd87b2c2009-03-04 15:28:31 +0100321 unsigned int files_size;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100322 unsigned int files_index;
323 unsigned int nr_open_files;
Jens Axboe1020a132007-03-29 11:15:06 +0200324 unsigned int nr_done_files;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100325 unsigned int nr_normal_files;
326 union {
327 unsigned int next_file;
328 os_random_state_t next_file_state;
329 };
330 int error;
Jens Axboe20e354e2007-07-23 14:36:16 +0200331 int done;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100332 pid_t pid;
333 char *orig_buffer;
334 size_t orig_buffer_size;
335 volatile int terminate;
336 volatile int runstate;
337 unsigned int ioprio;
Jens Axboeac684782007-11-08 08:29:07 +0100338 unsigned int ioprio_set;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100339 unsigned int last_was_sync;
340
341 char *mmapfile;
342 int mmapfd;
343
Jens Axboe843a7412006-06-01 21:14:21 -0700344 void *iolog_buf;
345 FILE *iolog_f;
Jens Axboeebac4652005-12-08 15:25:21 +0100346
Jens Axboeda867742006-06-06 10:39:10 -0700347 char *sysfs_root;
Jens Axboeda867742006-06-06 10:39:10 -0700348
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200349 unsigned long rand_seeds[6];
350
Jens Axboe6dfd46b2006-06-07 13:57:06 +0200351 os_random_state_t bsrange_state;
352 os_random_state_t verify_state;
Jens Axboeebac4652005-12-08 15:25:21 +0100353
354 int shm_id;
355
Jens Axboee9c047a2006-06-07 21:13:04 +0200356 /*
357 * IO engine hooks, contains everything needed to submit an io_u
358 * to any of the available IO engines.
359 */
Jens Axboe2866c822006-10-09 15:57:48 +0200360 struct ioengine_ops *io_ops;
Jens Axboeebac4652005-12-08 15:25:21 +0100361
Jens Axboee9c047a2006-06-07 21:13:04 +0200362 /*
363 * Current IO depth and list of free and busy io_u's.
364 */
Jens Axboeebac4652005-12-08 15:25:21 +0100365 unsigned int cur_depth;
Jens Axboed8005752008-05-15 09:49:09 +0200366 unsigned int io_u_queued;
Jens Axboe01743ee2008-06-02 12:19:19 +0200367 struct flist_head io_u_freelist;
368 struct flist_head io_u_busylist;
369 struct flist_head io_u_requeues;
Jens Axboeebac4652005-12-08 15:25:21 +0100370
Jens Axboee9c047a2006-06-07 21:13:04 +0200371 /*
372 * Rate state
373 */
Jens Axboeebac4652005-12-08 15:25:21 +0100374 unsigned long rate_usec_cycle;
375 long rate_pending_usleep;
376 unsigned long rate_bytes;
Jens Axboe4e991c22007-03-15 11:41:11 +0100377 unsigned long rate_blocks;
Jens Axboeebac4652005-12-08 15:25:21 +0100378 struct timeval lastrate;
379
Jens Axboeebac4652005-12-08 15:25:21 +0100380 unsigned long long total_io_size;
381
Jens Axboe755200a2007-02-19 13:08:12 +0100382 unsigned long io_issues[2];
Jens Axboe9104f872005-12-28 23:50:45 +0100383 unsigned long long io_blocks[2];
384 unsigned long long io_bytes[2];
Jens Axboe48f5abd2007-07-20 13:25:04 +0200385 unsigned long long io_skip_bytes;
Jens Axboe9104f872005-12-28 23:50:45 +0100386 unsigned long long this_io_bytes[2];
Jens Axboe079ad092007-02-20 13:58:20 +0100387 unsigned long long zone_bytes;
Jens Axboecdd18ad2008-02-27 18:58:00 +0100388 struct fio_mutex *mutex;
Jens Axboeebac4652005-12-08 15:25:21 +0100389
Jens Axboee9c047a2006-06-07 21:13:04 +0200390 /*
391 * State for random io, a bitmap of blocks done vs not done
392 */
Jens Axboe6dfd46b2006-06-07 13:57:06 +0200393 os_random_state_t random_state;
Jens Axboeebac4652005-12-08 15:25:21 +0100394
Jens Axboeebac4652005-12-08 15:25:21 +0100395 struct timeval start; /* start of this loop */
396 struct timeval epoch; /* time job was started */
Jens Axboe38d77ca2007-03-21 14:20:20 +0100397 struct timeval rw_end[2];
Jens Axboea61edde2007-05-15 14:29:58 +0200398 struct timeval last_issue;
Jens Axboe993bf482008-11-14 13:04:53 +0100399 struct timeval tv_cache;
400 unsigned int tv_cache_nr;
401 unsigned int tv_cache_mask;
Jens Axboe38d77ca2007-03-21 14:20:20 +0100402 unsigned int rw_end_set[2];
Jens Axboe721938a2008-09-10 09:46:16 +0200403 unsigned int ramp_time_over;
Jens Axboeebac4652005-12-08 15:25:21 +0100404
Jens Axboee9c047a2006-06-07 21:13:04 +0200405 /*
Jens Axboee9c047a2006-06-07 21:13:04 +0200406 * read/write mixed workload state
407 */
Jens Axboe6dfd46b2006-06-07 13:57:06 +0200408 os_random_state_t rwmix_state;
Jens Axboee4928662008-04-07 09:19:46 +0200409 unsigned long rwmix_issues;
Jens Axboee9c047a2006-06-07 21:13:04 +0200410 enum fio_ddir rwmix_ddir;
Jens Axboe211097b2007-03-22 18:56:45 +0100411 unsigned int ddir_nr;
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200412
Jens Axboe4e0ba8a2006-06-06 09:36:28 +0200413 /*
Jens Axboe8de8f042007-03-27 10:36:12 +0200414 * IO history logs for verification. We use a tree for sorting,
415 * if we are overwriting. Otherwise just use a fifo.
Jens Axboee9c047a2006-06-07 21:13:04 +0200416 */
Jens Axboe4b878982007-03-26 09:32:22 +0200417 struct rb_root io_hist_tree;
Jens Axboe01743ee2008-06-02 12:19:19 +0200418 struct flist_head io_hist_list;
Jens Axboe8de8f042007-03-27 10:36:12 +0200419
420 /*
421 * For IO replaying
422 */
Jens Axboe01743ee2008-06-02 12:19:19 +0200423 struct flist_head io_log_list;
Jens Axboe433afcb2007-02-22 10:39:01 +0100424
425 /*
Jens Axboe1907dbc2007-03-12 11:44:28 +0100426 * for fileservice, how often to switch to a new file
427 */
428 unsigned int file_service_nr;
429 unsigned int file_service_left;
430 struct fio_file *file_service_file;
Jens Axboe9c60ce62007-03-15 09:14:47 +0100431
432 /*
433 * For generating file sizes
434 */
435 os_random_state_t file_size_state;
Jens Axboeebac4652005-12-08 15:25:21 +0100436};
437
Jens Axboe433afcb2007-02-22 10:39:01 +0100438/*
Jens Axboea086c252009-03-04 08:27:37 +0100439 * roundrobin available files, or choose one at random, or do each one
440 * serially.
Jens Axboe0aabe162007-02-23 08:45:55 +0100441 */
442enum {
443 FIO_FSERVICE_RANDOM = 1,
444 FIO_FSERVICE_RR = 2,
Jens Axboea086c252009-03-04 08:27:37 +0100445 FIO_FSERVICE_SEQ = 3,
Jens Axboe0aabe162007-02-23 08:45:55 +0100446};
447
448/*
Aaron Carrolle592a062007-09-14 09:49:41 +0200449 * when should interactive ETA output be generated
450 */
451enum {
452 FIO_ETA_AUTO,
453 FIO_ETA_ALWAYS,
454 FIO_ETA_NEVER,
455};
456
Jens Axboee1161c32007-02-22 19:36:48 +0100457#define __td_verror(td, err, msg, func) \
Jens Axboeebac4652005-12-08 15:25:21 +0100458 do { \
Jens Axboe19abcd32007-02-21 20:14:33 +0100459 if ((td)->error) \
460 break; \
Jens Axboeebac4652005-12-08 15:25:21 +0100461 int e = (err); \
462 (td)->error = e; \
Jens Axboee1161c32007-02-22 19:36:48 +0100463 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \
Jens Axboeebac4652005-12-08 15:25:21 +0100464 } while (0)
465
Jens Axboeb990b5c2006-09-14 09:48:22 +0200466
Jens Axboee1161c32007-02-22 19:36:48 +0100467#define td_verror(td, err, func) \
468 __td_verror((td), (err), strerror((err)), (func))
469#define td_vmsg(td, err, msg, func) \
470 __td_verror((td), (err), (msg), (func))
Jens Axboeb990b5c2006-09-14 09:48:22 +0200471
Jens Axboeebac4652005-12-08 15:25:21 +0100472extern int exitall_on_terminate;
473extern int thread_number;
Jens Axboe9cedf162007-03-12 11:29:30 +0100474extern int nr_process, nr_thread;
Jens Axboeebac4652005-12-08 15:25:21 +0100475extern int shm_id;
476extern int groupid;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200477extern int terse_output;
Jens Axboe53cdc682006-10-18 11:50:58 +0200478extern int temp_stall_ts;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100479extern unsigned long long mlock_size;
Jens Axboecfc99db2007-03-14 10:34:47 +0100480extern unsigned long page_mask, page_size;
Jens Axboe4241ea82007-09-12 08:18:36 +0200481extern int read_only;
Aaron Carrolle592a062007-09-14 09:49:41 +0200482extern int eta_print;
Jens Axboed3eeeab2008-04-06 12:19:05 +0200483extern unsigned long done_secs;
Jens Axboe01f06b62008-02-18 20:53:47 +0100484extern char *job_section;
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100485extern int fio_gtod_offload;
486extern int fio_gtod_cpu;
Jens Axboeebac4652005-12-08 15:25:21 +0100487
488extern struct thread_data *threads;
489
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100490#define td_read(td) ((td)->o.td_ddir & TD_DDIR_READ)
491#define td_write(td) ((td)->o.td_ddir & TD_DDIR_WRITE)
492#define td_rw(td) (((td)->o.td_ddir & TD_DDIR_RW) == TD_DDIR_RW)
493#define td_random(td) ((td)->o.td_ddir & TD_DDIR_RAND)
Jens Axboe303032a2008-03-26 10:11:10 +0100494#define file_randommap(td, f) (!(td)->o.norandommap && (f)->file_map)
Jens Axboeebac4652005-12-08 15:25:21 +0100495
Jens Axboe7101d9c2007-09-12 13:12:39 +0200496static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u)
497{
498 assert(!(io_u->ddir == DDIR_WRITE && !td_write(td)));
499}
500
Jens Axboede605662008-05-31 00:21:12 +0200501#define BLOCKS_PER_MAP (8 * sizeof(int))
Jens Axboeaec2de22008-04-24 12:44:42 +0200502#define TO_MAP_BLOCK(f, b) (b)
503#define RAND_MAP_IDX(f, b) (TO_MAP_BLOCK(f, b) / BLOCKS_PER_MAP)
504#define RAND_MAP_BIT(f, b) (TO_MAP_BLOCK(f, b) & (BLOCKS_PER_MAP - 1))
Jens Axboeebac4652005-12-08 15:25:21 +0100505
506#define MAX_JOBS (1024)
507
Jens Axboe87dc1ab2006-10-24 14:41:26 +0200508static inline int should_fsync(struct thread_data *td)
509{
510 if (td->last_was_sync)
511 return 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100512 if (td->o.odirect)
Jens Axboe87dc1ab2006-10-24 14:41:26 +0200513 return 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100514 if (td_write(td) || td_rw(td) || td->o.override_sync)
Jens Axboe87dc1ab2006-10-24 14:41:26 +0200515 return 1;
516
517 return 0;
518}
519
Jens Axboe1c9e06e2007-02-11 04:07:57 +0100520/*
521 * Disk utils as read in /sys/block/<dev>/stat
522 */
Jens Axboeebac4652005-12-08 15:25:21 +0100523struct disk_util_stat {
524 unsigned ios[2];
525 unsigned merges[2];
526 unsigned long long sectors[2];
527 unsigned ticks[2];
528 unsigned io_ticks;
529 unsigned time_in_queue;
530};
531
Jens Axboe1c9e06e2007-02-11 04:07:57 +0100532/*
533 * Per-device disk util management
534 */
Jens Axboeebac4652005-12-08 15:25:21 +0100535struct disk_util {
Jens Axboe01743ee2008-06-02 12:19:19 +0200536 struct flist_head list;
Shehjar Tikoo67423012008-09-30 10:35:44 +1000537 /* If this disk is a slave, hook it into the master's
538 * list using this head.
539 */
540 struct flist_head slavelist;
Jens Axboeebac4652005-12-08 15:25:21 +0100541
542 char *name;
Jens Axboee11c4102007-04-03 16:33:04 -0700543 char *sysfs_root;
Jens Axboeebac4652005-12-08 15:25:21 +0100544 char path[256];
Jens Axboe07e5b262007-04-02 14:46:07 +0200545 int major, minor;
Jens Axboeebac4652005-12-08 15:25:21 +0100546
547 struct disk_util_stat dus;
548 struct disk_util_stat last_dus;
549
Shehjar Tikoo67423012008-09-30 10:35:44 +1000550 /* For software raids, this entry maintains pointers to the
551 * entries for the slave devices. The disk_util entries for
552 * the slaves devices should primarily be maintained through
553 * the disk_list list, i.e. for memory allocation and
554 * de-allocation, etc. Whereas this list should be used only
555 * for aggregating a software RAID's disk util figures.
556 */
557 struct flist_head slaves;
558
Jens Axboeebac4652005-12-08 15:25:21 +0100559 unsigned long msec;
560 struct timeval time;
Jens Axboec97bd0f2009-05-27 13:11:20 +0200561
562 struct fio_mutex *lock;
563 unsigned long users;
Jens Axboeebac4652005-12-08 15:25:21 +0100564};
565
Jens Axboec97bd0f2009-05-27 13:11:20 +0200566static inline void disk_util_inc(struct disk_util *du)
567{
568 if (du) {
569 fio_mutex_down(du->lock);
570 du->users++;
571 fio_mutex_up(du->lock);
572 }
573}
574
575static inline void disk_util_dec(struct disk_util *du)
576{
577 if (du) {
578 fio_mutex_down(du->lock);
579 du->users--;
580 fio_mutex_up(du->lock);
581 }
582}
583
Jens Axboeebac4652005-12-08 15:25:21 +0100584#define DISK_UTIL_MSEC (250)
585
Jens Axboe67962092006-06-07 08:45:01 +0200586/*
587 * Log exports
588 */
Jens Axboef29b25a2007-07-23 08:56:43 +0200589enum file_log_act {
590 FIO_LOG_ADD_FILE,
591 FIO_LOG_OPEN_FILE,
592 FIO_LOG_CLOSE_FILE,
Jens Axboef7182732008-03-10 13:57:58 +0100593 FIO_LOG_UNLINK_FILE,
Jens Axboef29b25a2007-07-23 08:56:43 +0200594};
595
Jens Axboe72cb9712007-02-20 20:54:45 +0100596extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
Jens Axboef29b25a2007-07-23 08:56:43 +0200597extern void log_io_u(struct thread_data *, struct io_u *);
598extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
Jens Axboe72cb9712007-02-20 20:54:45 +0100599extern int __must_check init_iolog(struct thread_data *td);
Jens Axboe67962092006-06-07 08:45:01 +0200600extern void log_io_piece(struct thread_data *, struct io_u *);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100601extern void queue_io_piece(struct thread_data *, struct io_piece *);
Jens Axboe67962092006-06-07 08:45:01 +0200602extern void prune_io_piece_log(struct thread_data *);
603extern void write_iolog_close(struct thread_data *);
604
605/*
606 * Logging
607 */
Jens Axboe306ddc92009-05-18 13:08:12 +0200608extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
609 unsigned int);
610extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
611 unsigned int);
612extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
613 struct timeval *);
Jens Axboe67962092006-06-07 08:45:01 +0200614extern void show_run_stats(void);
615extern void init_disk_util(struct thread_data *);
616extern void update_rusage_stat(struct thread_data *);
617extern void update_io_ticks(void);
Jens Axboe8914a9d2006-06-07 11:14:56 +0200618extern void setup_log(struct io_log **);
619extern void finish_log(struct thread_data *, struct io_log *, const char *);
Jens Axboee3cedca2008-11-19 19:57:52 +0100620extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *);
Jens Axboebb3884d2007-01-17 17:23:11 +1100621extern void __finish_log(struct io_log *, const char *);
Jens Axboebb3884d2007-01-17 17:23:11 +1100622extern struct io_log *agg_io_log[2];
623extern int write_bw_log;
Jens Axboe306ddc92009-05-18 13:08:12 +0200624extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
Jens Axboe67962092006-06-07 08:45:01 +0200625
626/*
627 * Time functions
628 */
Shawn Lewis10927312007-11-21 09:38:13 +0100629extern unsigned long long utime_since(struct timeval *, struct timeval *);
630extern unsigned long long utime_since_now(struct timeval *);
Jens Axboe67962092006-06-07 08:45:01 +0200631extern unsigned long mtime_since(struct timeval *, struct timeval *);
632extern unsigned long mtime_since_now(struct timeval *);
633extern unsigned long time_since_now(struct timeval *);
Jens Axboe263e5292006-10-18 15:37:01 +0200634extern unsigned long mtime_since_genesis(void);
Jens Axboe6dd6f2c2008-12-10 13:24:12 +0100635extern void usec_spin(unsigned int);
Jens Axboe67962092006-06-07 08:45:01 +0200636extern void usec_sleep(struct thread_data *, unsigned long);
Jens Axboe413dd452007-02-23 09:26:09 +0100637extern void rate_throttle(struct thread_data *, unsigned long, unsigned int);
Jens Axboe6043c572006-11-03 11:37:47 +0100638extern void fill_start_time(struct timeval *);
Jens Axboe02bcaa82006-11-24 10:42:00 +0100639extern void fio_gettime(struct timeval *, void *);
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100640extern void fio_gtod_init(void);
641extern void fio_gtod_update(void);
Jens Axboea2f77c92007-02-22 11:53:00 +0100642extern void set_genesis_time(void);
Jens Axboe721938a2008-09-10 09:46:16 +0200643extern int ramp_time_over(struct thread_data *);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200644extern int in_ramp_time(struct thread_data *);
Jens Axboe67962092006-06-07 08:45:01 +0200645
Jens Axboe8914a9d2006-06-07 11:14:56 +0200646/*
Jens Axboe214e1ec2007-03-15 10:48:13 +0100647 * Init/option functions
Jens Axboe8914a9d2006-06-07 11:14:56 +0200648 */
Jens Axboe72cb9712007-02-20 20:54:45 +0100649extern int __must_check parse_options(int, char **);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200650extern int fio_options_parse(struct thread_data *, char **, int);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100651extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
652extern void fio_fill_default_options(struct thread_data *);
653extern int fio_show_option_help(const char *);
654extern void fio_options_dup_and_init(struct option *);
Jens Axboed23bb322007-03-23 15:57:56 +0100655extern void options_mem_dupe(struct thread_data *);
656extern void options_mem_free(struct thread_data *);
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200657extern void td_fill_rand_seeds(struct thread_data *);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100658#define FIO_GETOPT_JOB 0x89988998
659#define FIO_NR_OPTIONS 128
Jens Axboe8914a9d2006-06-07 11:14:56 +0200660
Jens Axboebbfd6b02006-06-07 19:42:54 +0200661/*
Jens Axboe263e5292006-10-18 15:37:01 +0200662 * ETA/status stuff
663 */
664extern void print_thread_status(void);
665extern void print_status_init(int);
666
667/*
Jens Axboe9f8f2062007-04-02 15:08:01 +0200668 * disk util stuff
669 */
670#ifdef FIO_HAVE_DISK_UTIL
671extern void show_disk_util(void);
Jens Axboe9f8f2062007-04-02 15:08:01 +0200672extern void init_disk_util(struct thread_data *);
673extern void update_io_ticks(void);
674#else
675#define show_disk_util()
Jens Axboe9f8f2062007-04-02 15:08:01 +0200676#define init_disk_util(td)
677#define update_io_ticks()
678#endif
679
680/*
Jens Axboe263e5292006-10-18 15:37:01 +0200681 * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
682 * will never back again. It may cycle between running/verififying/fsyncing.
683 * Once the thread reaches TD_EXITED, it is just waiting for the core to
684 * reap it.
685 */
686enum {
687 TD_NOT_CREATED = 0,
688 TD_CREATED,
689 TD_INITIALIZED,
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200690 TD_RAMP,
Jens Axboe263e5292006-10-18 15:37:01 +0200691 TD_RUNNING,
Jens Axboeb0f65862009-05-20 11:52:15 +0200692 TD_PRE_READING,
Jens Axboe263e5292006-10-18 15:37:01 +0200693 TD_VERIFYING,
694 TD_FSYNCING,
695 TD_EXITED,
696 TD_REAPED,
697};
698
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200699extern void td_set_runstate(struct thread_data *, int);
700
Jens Axboe263e5292006-10-18 15:37:01 +0200701/*
Jens Axboe2f9ade32006-10-20 11:25:52 +0200702 * Memory helpers
703 */
Jens Axboeb2fdda42007-02-20 20:52:51 +0100704extern int __must_check fio_pin_memory(void);
Jens Axboe2f9ade32006-10-20 11:25:52 +0200705extern void fio_unpin_memory(void);
Jens Axboeb2fdda42007-02-20 20:52:51 +0100706extern int __must_check allocate_io_mem(struct thread_data *);
Jens Axboe2f9ade32006-10-20 11:25:52 +0200707extern void free_io_mem(struct thread_data *);
708
709/*
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200710 * Reset stats after ramp time completes
711 */
712extern void reset_all_stats(struct thread_data *);
713
714/*
Jens Axboefb7b71a2007-05-15 08:44:04 +0200715 * blktrace support
716 */
Jens Axboe5e62c222007-05-22 13:27:30 +0200717#ifdef FIO_HAVE_BLKTRACE
Jens Axboefb7b71a2007-05-15 08:44:04 +0200718extern int is_blktrace(const char *);
719extern int load_blktrace(struct thread_data *, const char *);
Jens Axboe5e62c222007-05-22 13:27:30 +0200720#endif
Jens Axboefb7b71a2007-05-15 08:44:04 +0200721
Jens Axboe2866c822006-10-09 15:57:48 +0200722/*
723 * Mark unused variables passed to ops functions as unused, to silence gcc
724 */
725#define fio_unused __attribute((__unused__))
Jens Axboe5f350952006-11-07 15:20:59 +0100726#define fio_init __attribute__((constructor))
727#define fio_exit __attribute__((destructor))
Jens Axboe2866c822006-10-09 15:57:48 +0200728
Jens Axboe34572e22006-10-20 09:33:18 +0200729#define for_each_td(td, i) \
730 for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
Jens Axboe53cdc682006-10-18 11:50:58 +0200731#define for_each_file(td, f, i) \
Jens Axboe691c8fb2008-03-07 14:26:26 +0100732 if ((td)->files_index) \
733 for ((i) = 0, (f) = (td)->files[0]; \
734 (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \
735 (i)++)
Jens Axboe53cdc682006-10-18 11:50:58 +0200736
Jens Axboe0032bf92007-02-13 17:39:56 +0100737#define fio_assert(td, cond) do { \
738 if (!(cond)) { \
Jens Axboe340fd242007-02-13 20:09:10 +0100739 int *__foo = NULL; \
Jens Axboe0032bf92007-02-13 17:39:56 +0100740 fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \
741 (td)->runstate = TD_EXITED; \
Jens Axboe437c9b72007-02-13 18:20:37 +0100742 (td)->error = EFAULT; \
Jens Axboe340fd242007-02-13 20:09:10 +0100743 *__foo = 0; \
Jens Axboe0032bf92007-02-13 17:39:56 +0100744 } \
745} while (0)
746
Jens Axboe009bd842008-05-15 10:19:46 +0200747static inline void fio_file_reset(struct fio_file *f)
748{
749 f->last_free_lookup = 0;
750 f->last_pos = f->file_offset;
Jens Axboeeaf9b412009-04-07 13:06:43 +0200751 if (f->file_map)
752 memset(f->file_map, 0, f->num_maps * sizeof(int));
Jens Axboe009bd842008-05-15 10:19:46 +0200753}
754
Jens Axboe9bf27b42007-03-27 19:49:31 +0200755static inline void clear_error(struct thread_data *td)
756{
757 td->error = 0;
758 td->verror[0] = '\0';
759}
760
Jens Axboe79e48f72008-02-01 20:37:09 +0100761#ifdef FIO_INC_DEBUG
Jens Axboe2ba1c292008-02-01 13:16:38 +0100762static inline void dprint_io_u(struct io_u *io_u, const char *p)
763{
764 struct fio_file *f = io_u->file;
765
766 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
Jens Axboe5921e802008-05-30 15:02:38 +0200767 (unsigned long long) io_u->offset,
768 io_u->buflen, io_u->ddir);
Jens Axboe8172fe92008-02-01 21:51:02 +0100769 if (fio_debug & (1 << FD_IO)) {
770 if (f)
771 log_info("/%s", f->file_name);
772
773 log_info("\n");
774 }
Jens Axboe2ba1c292008-02-01 13:16:38 +0100775}
Jens Axboe79e48f72008-02-01 20:37:09 +0100776#else
Jens Axboe79e48f72008-02-01 20:37:09 +0100777#define dprint_io_u(io_u, p)
778#endif
Jens Axboe2ba1c292008-02-01 13:16:38 +0100779
Jens Axboe12d9d842008-10-16 21:26:10 +0200780static inline int fio_fill_issue_time(struct thread_data *td)
781{
782 if (td->o.read_iolog_file ||
783 !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw)
784 return 1;
785
786 return 0;
787}
788
Jens Axboeebac4652005-12-08 15:25:21 +0100789#endif