blob: 6e1175406f8dd0ed0671f6651a87198686993440 [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 Axboecd14cc12007-07-30 10:59:33 +020014#include <inttypes.h>
Jens Axboe7101d9c2007-09-12 13:12:39 +020015#include <assert.h>
Jens Axboeebac4652005-12-08 15:25:21 +010016
Bruce Cranecc314b2011-01-04 10:59:30 +010017struct thread_data;
18
Jens Axboe317b95d2007-04-02 21:36:44 +020019#include "compiler/compiler.h"
Jens Axboeec412652012-03-08 12:37:31 +010020#include "thread_options.h"
Jens Axboe01743ee2008-06-02 12:19:19 +020021#include "flist.h"
Jens Axboee2887562007-05-16 09:25:09 +020022#include "fifo.h"
Jens Axboe4b878982007-03-26 09:32:22 +020023#include "rbtree.h"
Jens Axboe317b95d2007-04-02 21:36:44 +020024#include "arch/arch.h"
25#include "os/os.h"
Jens Axboe07739b52007-03-08 20:25:46 +010026#include "mutex.h"
Jens Axboea3d741f2008-02-27 18:32:33 +010027#include "log.h"
28#include "debug.h"
Jens Axboed6aed792009-06-03 08:41:15 +020029#include "file.h"
30#include "io_ddir.h"
Jens Axboedcefb582009-06-03 08:49:39 +020031#include "ioengine.h"
Jens Axboe5995a6a2009-06-03 08:53:28 +020032#include "iolog.h"
Jens Axboec5c8bd52009-11-24 13:01:41 +010033#include "helpers.h"
Jens Axboe07b32322010-03-05 09:48:44 +010034#include "options.h"
Jens Axboe7eb36572010-03-08 13:58:49 +010035#include "profile.h"
Jens Axboec223da82010-03-24 13:23:53 +010036#include "time.h"
Jens Axboea7346812012-02-09 15:02:39 +010037#include "gettime.h"
Cigy Cyriacbf2e8212010-08-10 19:51:11 -040038#include "lib/getopt.h"
Jens Axboe2615cc42011-03-28 09:35:09 +020039#include "lib/rand.h"
Stephen M. Camerondd366722012-02-24 08:17:30 +010040#include "client.h"
Jens Axboe37db14f2011-09-30 17:00:42 -060041#include "server.h"
Jens Axboea64e88d2011-10-03 14:20:01 +020042#include "stat.h"
Dan Ehrenberg9e684a42012-02-20 11:05:14 +010043#include "flow.h"
Jens Axboeebac4652005-12-08 15:25:21 +010044
Davide Libenzi609342f2007-03-21 08:46:18 +010045#ifdef FIO_HAVE_GUASI
46#include <guasi.h>
47#endif
48
Jens Axboe417f0062008-06-02 11:59:30 +020049#ifdef FIO_HAVE_SOLARISAIO
50#include <sys/asynch.h>
51#endif
52
Jens Axboee9c047a2006-06-07 21:13:04 +020053/*
Jens Axboe38dad622010-07-20 14:46:00 -060054 * offset generator types
55 */
56enum {
57 RW_SEQ_SEQ = 0,
58 RW_SEQ_IDENT,
59};
60
Steven Lang06842022011-11-17 09:45:17 +010061/*
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010062 * This describes a single thread/process executing a fio job.
63 */
64struct thread_data {
65 struct thread_options o;
Steven Langde890a12011-11-09 14:03:34 +010066 void *eo;
Jens Axboee4e33252007-03-21 13:07:54 +010067 char verror[FIO_VERROR_SIZE];
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010068 pthread_t thread;
Jens Axboe2f122b12012-03-15 13:10:19 +010069 unsigned int thread_number;
70 unsigned int groupid;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010071 struct thread_stat ts;
Jens Axboe7b9f7332011-10-03 10:06:44 +020072
Jens Axboe46bcd492012-03-14 11:31:21 +010073 int client_type;
74
Jens Axboe7b9f7332011-10-03 10:06:44 +020075 struct io_log *slat_log;
76 struct io_log *clat_log;
77 struct io_log *lat_log;
78 struct io_log *bw_log;
Jens Axboec8eeb9d2011-10-05 14:02:22 +020079 struct io_log *iops_log;
Jens Axboe7b9f7332011-10-03 10:06:44 +020080
Jens Axboef0505a12011-10-03 12:12:03 +020081 uint64_t stat_io_bytes[2];
Jens Axboec8eeb9d2011-10-05 14:02:22 +020082 struct timeval bw_sample_time;
83
84 uint64_t stat_io_blocks[2];
85 struct timeval iops_sample_time;
Jens Axboef0505a12011-10-03 12:12:03 +020086
Jens Axboec8aaba12011-10-03 12:14:19 +020087 struct rusage ru_start;
88 struct rusage ru_end;
89
Jens Axboe126d65c2008-03-01 18:04:31 +010090 struct fio_file **files;
Jens Axboedd87b2c2009-03-04 15:28:31 +010091 unsigned int files_size;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010092 unsigned int files_index;
93 unsigned int nr_open_files;
Jens Axboe1020a132007-03-29 11:15:06 +020094 unsigned int nr_done_files;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010095 unsigned int nr_normal_files;
96 union {
97 unsigned int next_file;
98 os_random_state_t next_file_state;
Jens Axboe4c07ad82011-03-28 09:51:09 +020099 struct frand_state __next_file_state;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100100 };
101 int error;
Jens Axboe20e354e2007-07-23 14:36:16 +0200102 int done;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100103 pid_t pid;
104 char *orig_buffer;
105 size_t orig_buffer_size;
106 volatile int terminate;
107 volatile int runstate;
108 unsigned int ioprio;
Jens Axboeac684782007-11-08 08:29:07 +0100109 unsigned int ioprio_set;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100110 unsigned int last_was_sync;
Jens Axboe9e144182010-06-15 14:25:36 +0200111 enum fio_ddir last_ddir;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100112
113 char *mmapfile;
114 int mmapfd;
115
Jens Axboe843a7412006-06-01 21:14:21 -0700116 void *iolog_buf;
117 FILE *iolog_f;
Jens Axboeebac4652005-12-08 15:25:21 +0100118
Jens Axboeda867742006-06-06 10:39:10 -0700119 char *sysfs_root;
Jens Axboeda867742006-06-06 10:39:10 -0700120
Jens Axboe3545a102011-08-31 15:20:15 -0600121 unsigned long rand_seeds[8];
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200122
Jens Axboe4c07ad82011-03-28 09:51:09 +0200123 union {
124 os_random_state_t bsrange_state;
125 struct frand_state __bsrange_state;
126 };
127 union {
128 os_random_state_t verify_state;
129 struct frand_state __verify_state;
130 };
131 union {
132 os_random_state_t trim_state;
133 struct frand_state __trim_state;
134 };
Jens Axboeebac4652005-12-08 15:25:21 +0100135
Jens Axboe3545a102011-08-31 15:20:15 -0600136 struct frand_state buf_state;
137
Jens Axboe9e144182010-06-15 14:25:36 +0200138 unsigned int verify_batch;
Jens Axboe0d29de82010-09-01 13:54:15 +0200139 unsigned int trim_batch;
Jens Axboe9e144182010-06-15 14:25:36 +0200140
Jens Axboeebac4652005-12-08 15:25:21 +0100141 int shm_id;
142
Jens Axboee9c047a2006-06-07 21:13:04 +0200143 /*
144 * IO engine hooks, contains everything needed to submit an io_u
145 * to any of the available IO engines.
146 */
Jens Axboe2866c822006-10-09 15:57:48 +0200147 struct ioengine_ops *io_ops;
Jens Axboeebac4652005-12-08 15:25:21 +0100148
Jens Axboee9c047a2006-06-07 21:13:04 +0200149 /*
Ryan Marchand422f9e42012-01-31 14:05:32 +0100150 * Queue depth of io_u's that fio MIGHT do
Jens Axboee9c047a2006-06-07 21:13:04 +0200151 */
Jens Axboeebac4652005-12-08 15:25:21 +0100152 unsigned int cur_depth;
Ryan Marchand422f9e42012-01-31 14:05:32 +0100153
154 /*
155 * io_u's about to be committed
156 */
Jens Axboed8005752008-05-15 09:49:09 +0200157 unsigned int io_u_queued;
Ryan Marchand422f9e42012-01-31 14:05:32 +0100158
159 /*
160 * io_u's submitted but not completed yet
161 */
162 unsigned int io_u_in_flight;
163
164 /*
165 * List of free and busy io_u's
166 */
Jens Axboe01743ee2008-06-02 12:19:19 +0200167 struct flist_head io_u_freelist;
168 struct flist_head io_u_busylist;
169 struct flist_head io_u_requeues;
Jens Axboee8462bd2009-07-06 12:59:04 +0200170 pthread_mutex_t io_u_lock;
171 pthread_cond_t free_cond;
172
173 /*
174 * async verify offload
175 */
176 struct flist_head verify_list;
177 pthread_t *verify_threads;
178 unsigned int nr_verify_threads;
179 pthread_cond_t verify_cond;
180 int verify_thread_exit;
Jens Axboeebac4652005-12-08 15:25:21 +0100181
Jens Axboee9c047a2006-06-07 21:13:04 +0200182 /*
183 * Rate state
184 */
Steven Lang1b8dbf22011-11-09 13:48:01 +0100185 unsigned long long rate_bps[2];
Jens Axboe581e7142009-06-09 12:47:16 +0200186 long rate_pending_usleep[2];
187 unsigned long rate_bytes[2];
188 unsigned long rate_blocks[2];
189 struct timeval lastrate[2];
Jens Axboeebac4652005-12-08 15:25:21 +0100190
Jens Axboeebac4652005-12-08 15:25:21 +0100191 unsigned long long total_io_size;
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200192 unsigned long long fill_device_size;
Jens Axboeebac4652005-12-08 15:25:21 +0100193
Jens Axboe755200a2007-02-19 13:08:12 +0100194 unsigned long io_issues[2];
Jens Axboe9104f872005-12-28 23:50:45 +0100195 unsigned long long io_blocks[2];
Jens Axboec8eeb9d2011-10-05 14:02:22 +0200196 unsigned long long this_io_blocks[2];
Jens Axboe9104f872005-12-28 23:50:45 +0100197 unsigned long long io_bytes[2];
Jens Axboe48f5abd2007-07-20 13:25:04 +0200198 unsigned long long io_skip_bytes;
Jens Axboe9104f872005-12-28 23:50:45 +0100199 unsigned long long this_io_bytes[2];
Jens Axboe079ad092007-02-20 13:58:20 +0100200 unsigned long long zone_bytes;
Jens Axboecdd18ad2008-02-27 18:58:00 +0100201 struct fio_mutex *mutex;
Jens Axboeebac4652005-12-08 15:25:21 +0100202
Jens Axboee9c047a2006-06-07 21:13:04 +0200203 /*
204 * State for random io, a bitmap of blocks done vs not done
205 */
Jens Axboe4c07ad82011-03-28 09:51:09 +0200206 union {
207 os_random_state_t random_state;
208 struct frand_state __random_state;
209 };
Jens Axboeebac4652005-12-08 15:25:21 +0100210
Jens Axboeebac4652005-12-08 15:25:21 +0100211 struct timeval start; /* start of this loop */
212 struct timeval epoch; /* time job was started */
Jens Axboea61edde2007-05-15 14:29:58 +0200213 struct timeval last_issue;
Jens Axboe993bf482008-11-14 13:04:53 +0100214 struct timeval tv_cache;
215 unsigned int tv_cache_nr;
216 unsigned int tv_cache_mask;
Jens Axboe721938a2008-09-10 09:46:16 +0200217 unsigned int ramp_time_over;
Jens Axboeebac4652005-12-08 15:25:21 +0100218
Jens Axboee9c047a2006-06-07 21:13:04 +0200219 /*
Jens Axboee9c047a2006-06-07 21:13:04 +0200220 * read/write mixed workload state
221 */
Jens Axboe4c07ad82011-03-28 09:51:09 +0200222 union {
223 os_random_state_t rwmix_state;
224 struct frand_state __rwmix_state;
225 };
Jens Axboee4928662008-04-07 09:19:46 +0200226 unsigned long rwmix_issues;
Jens Axboee9c047a2006-06-07 21:13:04 +0200227 enum fio_ddir rwmix_ddir;
Jens Axboe5736c102010-07-20 12:03:25 -0600228 unsigned int ddir_seq_nr;
Jens Axboea6ccc7b2006-06-02 10:14:15 +0200229
Jens Axboe4e0ba8a2006-06-06 09:36:28 +0200230 /*
Jens Axboe8de8f042007-03-27 10:36:12 +0200231 * IO history logs for verification. We use a tree for sorting,
232 * if we are overwriting. Otherwise just use a fifo.
Jens Axboee9c047a2006-06-07 21:13:04 +0200233 */
Jens Axboe4b878982007-03-26 09:32:22 +0200234 struct rb_root io_hist_tree;
Jens Axboe01743ee2008-06-02 12:19:19 +0200235 struct flist_head io_hist_list;
Jens Axboe9e144182010-06-15 14:25:36 +0200236 unsigned long io_hist_len;
Jens Axboe8de8f042007-03-27 10:36:12 +0200237
238 /*
239 * For IO replaying
240 */
Jens Axboe01743ee2008-06-02 12:19:19 +0200241 struct flist_head io_log_list;
Jens Axboe433afcb2007-02-22 10:39:01 +0100242
243 /*
Jens Axboe0d29de82010-09-01 13:54:15 +0200244 * For tracking/handling discards
245 */
246 struct flist_head trim_list;
247 unsigned long trim_entries;
248
249 /*
Jens Axboe1907dbc2007-03-12 11:44:28 +0100250 * for fileservice, how often to switch to a new file
251 */
252 unsigned int file_service_nr;
253 unsigned int file_service_left;
254 struct fio_file *file_service_file;
Jens Axboe9c60ce62007-03-15 09:14:47 +0100255
Jens Axboe44f29692010-03-09 20:09:44 +0100256 unsigned int sync_file_range_nr;
257
Jens Axboe9c60ce62007-03-15 09:14:47 +0100258 /*
259 * For generating file sizes
260 */
Jens Axboe4c07ad82011-03-28 09:51:09 +0200261 union {
262 os_random_state_t file_size_state;
263 struct frand_state __file_size_state;
264 };
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200265
266 /*
267 * Error counts
268 */
269 unsigned int total_err_count;
270 int first_error;
Jens Axboe15dc1932010-03-05 10:59:06 +0100271
Dan Ehrenberg9e684a42012-02-20 11:05:14 +0100272 struct fio_flow *flow;
273
Jens Axboe15dc1932010-03-05 10:59:06 +0100274 /*
275 * Can be overloaded by profiles
276 */
Jens Axboe7eb36572010-03-08 13:58:49 +0100277 struct prof_io_ops prof_io_ops;
Jens Axboe58c55ba2010-03-09 12:20:08 +0100278 void *prof_data;
Jens Axboeebac4652005-12-08 15:25:21 +0100279};
280
Jens Axboe433afcb2007-02-22 10:39:01 +0100281/*
Aaron Carrolle592a062007-09-14 09:49:41 +0200282 * when should interactive ETA output be generated
283 */
284enum {
285 FIO_ETA_AUTO,
286 FIO_ETA_ALWAYS,
287 FIO_ETA_NEVER,
288};
289
Jens Axboee1161c32007-02-22 19:36:48 +0100290#define __td_verror(td, err, msg, func) \
Jens Axboeebac4652005-12-08 15:25:21 +0100291 do { \
Jens Axboe19abcd32007-02-21 20:14:33 +0100292 if ((td)->error) \
293 break; \
Jens Axboeebac4652005-12-08 15:25:21 +0100294 int e = (err); \
295 (td)->error = e; \
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200296 if (!(td)->first_error) \
297 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 +0100298 } while (0)
299
Jens Axboeb990b5c2006-09-14 09:48:22 +0200300
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200301#define td_clear_error(td) \
302 (td)->error = 0;
Jens Axboee1161c32007-02-22 19:36:48 +0100303#define td_verror(td, err, func) \
304 __td_verror((td), (err), strerror((err)), (func))
305#define td_vmsg(td, err, msg, func) \
306 __td_verror((td), (err), (msg), (func))
Jens Axboeb990b5c2006-09-14 09:48:22 +0200307
Jens Axboe81179ee2011-10-04 12:42:06 +0200308#define __fio_stringify_1(x) #x
309#define __fio_stringify(x) __fio_stringify_1(x)
310
Jens Axboeebac4652005-12-08 15:25:21 +0100311extern int exitall_on_terminate;
Jens Axboe11e950b2011-10-16 21:34:14 +0200312extern unsigned int thread_number;
313extern unsigned int nr_process, nr_thread;
Jens Axboeebac4652005-12-08 15:25:21 +0100314extern int shm_id;
315extern int groupid;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200316extern int terse_output;
Jens Axboe53cdc682006-10-18 11:50:58 +0200317extern int temp_stall_ts;
Jens Axboe1e97cce2006-12-05 11:44:16 +0100318extern unsigned long long mlock_size;
Jens Axboecfc99db2007-03-14 10:34:47 +0100319extern unsigned long page_mask, page_size;
Jens Axboe4241ea82007-09-12 08:18:36 +0200320extern int read_only;
Aaron Carrolle592a062007-09-14 09:49:41 +0200321extern int eta_print;
Jens Axboed3eeeab2008-04-06 12:19:05 +0200322extern unsigned long done_secs;
Jens Axboe01f06b62008-02-18 20:53:47 +0100323extern char *job_section;
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100324extern int fio_gtod_offload;
325extern int fio_gtod_cpu;
Jens Axboec223da82010-03-24 13:23:53 +0100326extern enum fio_cs fio_clock_source;
Jens Axboea9523c62011-01-17 16:49:54 -0700327extern int warnings_fatal;
Jens Axboef57a9c52011-09-09 21:01:37 +0200328extern int terse_version;
Jens Axboe5c341e92011-09-29 18:00:35 -0600329extern int is_backend;
Jens Axboea37f69b2011-10-01 12:24:21 -0600330extern int nr_clients;
Jens Axboee46d8092011-10-03 09:11:02 +0200331extern int log_syslog;
Jens Axboe5e726d02011-10-14 08:08:10 +0200332extern const char fio_version_string[];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200333extern const fio_fp64_t def_percentile_list[FIO_IO_U_LIST_MAX_LEN];
Jens Axboeebac4652005-12-08 15:25:21 +0100334
335extern struct thread_data *threads;
336
Jens Axboe7101d9c2007-09-12 13:12:39 +0200337static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u)
338{
339 assert(!(io_u->ddir == DDIR_WRITE && !td_write(td)));
340}
341
Jens Axboe0ce8b112011-01-27 22:25:29 +0100342#define BLOCKS_PER_MAP (8 * sizeof(unsigned long))
Jens Axboeaec2de22008-04-24 12:44:42 +0200343#define TO_MAP_BLOCK(f, b) (b)
344#define RAND_MAP_IDX(f, b) (TO_MAP_BLOCK(f, b) / BLOCKS_PER_MAP)
345#define RAND_MAP_BIT(f, b) (TO_MAP_BLOCK(f, b) & (BLOCKS_PER_MAP - 1))
Jens Axboeebac4652005-12-08 15:25:21 +0100346
Jens Axboefca70352011-07-06 20:12:54 +0200347#define REAL_MAX_JOBS 2048
Jens Axboeebac4652005-12-08 15:25:21 +0100348
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200349#define td_non_fatal_error(e) ((e) == EIO || (e) == EILSEQ)
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200350
Steven Lang06842022011-11-17 09:45:17 +0100351static inline enum error_type td_error_type(enum fio_ddir ddir, int err)
352{
353 if (err == EILSEQ)
354 return ERROR_TYPE_VERIFY;
355 if (ddir == DDIR_READ)
356 return ERROR_TYPE_READ;
357 return ERROR_TYPE_WRITE;
358}
359
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200360static inline void update_error_count(struct thread_data *td, int err)
361{
362 td->total_err_count++;
363 if (td->total_err_count == 1)
364 td->first_error = err;
365}
366
Jens Axboe87dc1ab2006-10-24 14:41:26 +0200367static inline int should_fsync(struct thread_data *td)
368{
369 if (td->last_was_sync)
370 return 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100371 if (td->o.odirect)
Jens Axboe87dc1ab2006-10-24 14:41:26 +0200372 return 0;
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100373 if (td_write(td) || td_rw(td) || td->o.override_sync)
Jens Axboe87dc1ab2006-10-24 14:41:26 +0200374 return 1;
375
376 return 0;
377}
378
Jens Axboe1c9e06e2007-02-11 04:07:57 +0100379/*
Jens Axboe214e1ec2007-03-15 10:48:13 +0100380 * Init/option functions
Jens Axboe8914a9d2006-06-07 11:14:56 +0200381 */
Jens Axboe0420ba62012-02-29 11:16:52 +0100382extern int __must_check fio_init_options(void);
Jens Axboe72cb9712007-02-20 20:54:45 +0100383extern int __must_check parse_options(int, char **);
Jens Axboe46bcd492012-03-14 11:31:21 +0100384extern int parse_jobs_ini(char *, int, int, int);
385extern int parse_cmd_line(int, char **, int);
Jens Axboe2e1df072012-02-09 11:15:02 +0100386extern int fio_backend(void);
Jens Axboe50d16972011-09-29 17:45:28 -0600387extern void reset_fio_state(void);
Jens Axboe2e1df072012-02-09 11:15:02 +0100388extern void clear_io_state(struct thread_data *);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200389extern int fio_options_parse(struct thread_data *, char **, int);
Jens Axboe74929ac2009-08-05 11:42:37 +0200390extern void fio_keywords_init(void);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100391extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
Steven Langde890a12011-11-09 14:03:34 +0100392extern int fio_cmd_ioengine_option_parse(struct thread_data *, const char *, char *);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100393extern void fio_fill_default_options(struct thread_data *);
394extern int fio_show_option_help(const char *);
Steven Langde890a12011-11-09 14:03:34 +0100395extern void fio_options_set_ioengine_opts(struct option *long_options, struct thread_data *td);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100396extern void fio_options_dup_and_init(struct option *);
Steven Langde890a12011-11-09 14:03:34 +0100397extern void fio_options_mem_dupe(struct thread_data *);
398extern void options_mem_dupe(void *data, struct fio_option *options);
Jens Axboe5bfc35d2009-04-07 13:28:12 +0200399extern void td_fill_rand_seeds(struct thread_data *);
Jens Axboe46bcd492012-03-14 11:31:21 +0100400extern void add_job_opts(const char **, int);
Jens Axboe1ec3d692010-09-16 09:35:34 +0200401extern char *num2str(unsigned long, int, int, int);
Steven Langde890a12011-11-09 14:03:34 +0100402extern int ioengine_load(struct thread_data *);
Jens Axboe1ec3d692010-09-16 09:35:34 +0200403
Jens Axboee61ca212012-02-24 12:51:31 +0100404extern unsigned long page_mask;
405extern unsigned long page_size;
406extern int initialize_fio(char *envp[]);
407
Steven Langde890a12011-11-09 14:03:34 +0100408#define FIO_GETOPT_JOB 0x89000000
409#define FIO_GETOPT_IOENGINE 0x98000000
Jens Axboe07b32322010-03-05 09:48:44 +0100410#define FIO_NR_OPTIONS (FIO_MAX_OPTS + 128)
Jens Axboe8914a9d2006-06-07 11:14:56 +0200411
Jens Axboebbfd6b02006-06-07 19:42:54 +0200412/*
Jens Axboe263e5292006-10-18 15:37:01 +0200413 * ETA/status stuff
414 */
415extern void print_thread_status(void);
416extern void print_status_init(int);
417
418/*
419 * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
420 * will never back again. It may cycle between running/verififying/fsyncing.
421 * Once the thread reaches TD_EXITED, it is just waiting for the core to
422 * reap it.
423 */
424enum {
425 TD_NOT_CREATED = 0,
426 TD_CREATED,
427 TD_INITIALIZED,
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200428 TD_RAMP,
Jens Axboe263e5292006-10-18 15:37:01 +0200429 TD_RUNNING,
Jens Axboeb0f65862009-05-20 11:52:15 +0200430 TD_PRE_READING,
Jens Axboe263e5292006-10-18 15:37:01 +0200431 TD_VERIFYING,
432 TD_FSYNCING,
433 TD_EXITED,
434 TD_REAPED,
435};
436
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200437extern void td_set_runstate(struct thread_data *, int);
Jens Axboecc0df002011-10-03 20:53:32 +0200438#define TERMINATE_ALL (-1)
439extern void fio_terminate_threads(int);
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200440
Jens Axboe263e5292006-10-18 15:37:01 +0200441/*
Jens Axboe2f9ade32006-10-20 11:25:52 +0200442 * Memory helpers
443 */
Jens Axboeb2fdda42007-02-20 20:52:51 +0100444extern int __must_check fio_pin_memory(void);
Jens Axboe2f9ade32006-10-20 11:25:52 +0200445extern void fio_unpin_memory(void);
Jens Axboeb2fdda42007-02-20 20:52:51 +0100446extern int __must_check allocate_io_mem(struct thread_data *);
Jens Axboe2f9ade32006-10-20 11:25:52 +0200447extern void free_io_mem(struct thread_data *);
448
449/*
Jens Axboeb29ee5b2008-09-11 10:17:26 +0200450 * Reset stats after ramp time completes
451 */
452extern void reset_all_stats(struct thread_data *);
453
454/*
Jens Axboefb7b71a2007-05-15 08:44:04 +0200455 * blktrace support
456 */
Jens Axboe5e62c222007-05-22 13:27:30 +0200457#ifdef FIO_HAVE_BLKTRACE
Jens Axboefb7b71a2007-05-15 08:44:04 +0200458extern int is_blktrace(const char *);
459extern int load_blktrace(struct thread_data *, const char *);
Jens Axboe5e62c222007-05-22 13:27:30 +0200460#endif
Jens Axboefb7b71a2007-05-15 08:44:04 +0200461
Jens Axboe2866c822006-10-09 15:57:48 +0200462/*
463 * Mark unused variables passed to ops functions as unused, to silence gcc
464 */
465#define fio_unused __attribute((__unused__))
Jens Axboe5f350952006-11-07 15:20:59 +0100466#define fio_init __attribute__((constructor))
467#define fio_exit __attribute__((destructor))
Jens Axboe2866c822006-10-09 15:57:48 +0200468
Jens Axboe34572e22006-10-20 09:33:18 +0200469#define for_each_td(td, i) \
470 for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
Jens Axboe53cdc682006-10-18 11:50:58 +0200471#define for_each_file(td, f, i) \
Jens Axboe691c8fb2008-03-07 14:26:26 +0100472 if ((td)->files_index) \
473 for ((i) = 0, (f) = (td)->files[0]; \
474 (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \
475 (i)++)
Jens Axboe53cdc682006-10-18 11:50:58 +0200476
Jens Axboe0032bf92007-02-13 17:39:56 +0100477#define fio_assert(td, cond) do { \
478 if (!(cond)) { \
Jens Axboe340fd242007-02-13 20:09:10 +0100479 int *__foo = NULL; \
Jens Axboe0032bf92007-02-13 17:39:56 +0100480 fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \
Jens Axboeac18ea32011-05-02 13:14:26 -0600481 td_set_runstate((td), TD_EXITED); \
Jens Axboe437c9b72007-02-13 18:20:37 +0100482 (td)->error = EFAULT; \
Jens Axboe340fd242007-02-13 20:09:10 +0100483 *__foo = 0; \
Jens Axboe0032bf92007-02-13 17:39:56 +0100484 } \
485} while (0)
486
Jens Axboe12d9d842008-10-16 21:26:10 +0200487static inline int fio_fill_issue_time(struct thread_data *td)
488{
489 if (td->o.read_iolog_file ||
490 !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw)
491 return 1;
492
493 return 0;
494}
495
Jens Axboe581e7142009-06-09 12:47:16 +0200496static inline int __should_check_rate(struct thread_data *td,
497 enum fio_ddir ddir)
498{
499 struct thread_options *o = &td->o;
500
501 /*
502 * If some rate setting was given, we need to check it
503 */
504 if (o->rate[ddir] || o->ratemin[ddir] || o->rate_iops[ddir] ||
505 o->rate_iops_min[ddir])
506 return 1;
507
508 return 0;
509}
510
511static inline int should_check_rate(struct thread_data *td,
512 unsigned long *bytes_done)
513{
514 int ret = 0;
515
516 if (bytes_done[0])
517 ret |= __should_check_rate(td, 0);
518 if (bytes_done[1])
519 ret |= __should_check_rate(td, 1);
520
521 return ret;
522}
523
Jens Axboed529ee12009-07-01 10:33:03 +0200524static inline int is_power_of_2(unsigned int val)
525{
526 return (val != 0 && ((val & (val - 1)) == 0));
527}
528
Jens Axboee8462bd2009-07-06 12:59:04 +0200529/*
530 * We currently only need to do locking if we have verifier threads
531 * accessing our internal structures too
532 */
533static inline void td_io_u_lock(struct thread_data *td)
534{
535 if (td->o.verify_async)
536 pthread_mutex_lock(&td->io_u_lock);
537}
538
539static inline void td_io_u_unlock(struct thread_data *td)
540{
541 if (td->o.verify_async)
542 pthread_mutex_unlock(&td->io_u_lock);
543}
544
545static inline void td_io_u_free_notify(struct thread_data *td)
546{
547 if (td->o.verify_async)
548 pthread_cond_signal(&td->free_cond);
549}
550
Jens Axboecca84642011-10-07 12:47:57 +0200551extern const char *fio_get_arch_string(int);
552extern const char *fio_get_os_string(int);
553
Jens Axboeebac4652005-12-08 15:25:21 +0100554#endif