Add option to select how to service multiple files
[fio.git] / fio.h
CommitLineData
ebac4655
JA
1#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>
3c39a379
JA
9#include <errno.h>
10#include <stdlib.h>
11#include <stdio.h>
6d6f031f 12#include <unistd.h>
34cfcdaf 13#include <string.h>
ebac4655
JA
14
15#include "list.h"
16#include "md5.h"
17#include "crc32.h"
18#include "arch.h"
19#include "os.h"
20
b6959b55 21#ifdef FIO_HAVE_SYSLET
a4f4fdd7 22#include "syslet.h"
b6959b55 23#endif
a4f4fdd7 24
1e97cce9
JA
25enum fio_ddir {
26 DDIR_READ = 0,
27 DDIR_WRITE,
28 DDIR_SYNC,
29};
30
1c9e06ee
JA
31/*
32 * Use for maintaining statistics
33 */
ebac4655 34struct io_stat {
ebac4655
JA
35 unsigned long max_val;
36 unsigned long min_val;
37 unsigned long samples;
68704084
JA
38
39 double mean;
40 double S;
ebac4655
JA
41};
42
1c9e06ee
JA
43/*
44 * A single data sample
45 */
ebac4655
JA
46struct io_sample {
47 unsigned long time;
48 unsigned long val;
1e97cce9 49 enum fio_ddir ddir;
ebac4655
JA
50};
51
1c9e06ee
JA
52/*
53 * Dynamically growing data sample log
54 */
ebac4655
JA
55struct io_log {
56 unsigned long nr_samples;
57 unsigned long max_samples;
58 struct io_sample *log;
59};
60
1c9e06ee
JA
61/*
62 * When logging io actions, this matches a single sent io_u
63 */
ebac4655
JA
64struct io_piece {
65 struct list_head list;
53cdc686 66 struct fio_file *file;
ebac4655 67 unsigned long long offset;
a4f4fdd7 68 unsigned long len;
1e97cce9 69 enum fio_ddir ddir;
ebac4655
JA
70};
71
a4f4fdd7
JA
72#ifdef FIO_HAVE_SYSLET
73struct syslet_req {
74 struct syslet_uatom atom;
a4f4fdd7
JA
75 long ret;
76};
77#endif
78
0c6e7517
JA
79enum {
80 IO_U_F_FREE = 1 << 0,
81 IO_U_F_FLIGHT = 1 << 1,
82};
83
ebac4655
JA
84/*
85 * The io unit
86 */
87struct io_u {
88 union {
89#ifdef FIO_HAVE_LIBAIO
90 struct iocb iocb;
91#endif
92#ifdef FIO_HAVE_POSIXAIO
93 struct aiocb aiocb;
94#endif
95#ifdef FIO_HAVE_SGIO
96 struct sg_io_hdr hdr;
a4f4fdd7
JA
97#endif
98#ifdef FIO_HAVE_SYSLET
a2e1b08a 99 struct syslet_req req;
ebac4655
JA
100#endif
101 };
102 struct timeval start_time;
103 struct timeval issue_time;
104
1c9e06ee
JA
105 /*
106 * Allocated/set buffer and length
107 */
6b9cea23 108 void *buf;
a4f4fdd7 109 unsigned long buflen;
ebac4655
JA
110 unsigned long long offset;
111
1c9e06ee
JA
112 /*
113 * IO engine state, may be different from above when we get
114 * partial transfers / residual data counts
115 */
cec6b55d 116 void *xfer_buf;
a4f4fdd7 117 unsigned long xfer_buflen;
cec6b55d 118
ebac4655
JA
119 unsigned int resid;
120 unsigned int error;
121
1e97cce9 122 enum fio_ddir ddir;
ebac4655 123
dfd7bc2c
JA
124 /*
125 * io engine private data
126 */
127 union {
128 unsigned int index;
129 unsigned int seen;
130 };
131
0c6e7517
JA
132 unsigned int flags;
133
53cdc686
JA
134 struct fio_file *file;
135
ebac4655
JA
136 struct list_head list;
137};
138
36167d82
JA
139/*
140 * io_ops->queue() return values
141 */
142enum {
143 FIO_Q_COMPLETED = 0, /* completed sync */
144 FIO_Q_QUEUED = 1, /* queued, will complete async */
755200a3 145 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
36167d82
JA
146};
147
ebac4655
JA
148#define FIO_HDR_MAGIC 0xf00baaef
149
150enum {
1c9e06ee
JA
151 VERIFY_NONE = 0, /* no verification */
152 VERIFY_MD5, /* md5 sum data blocks */
153 VERIFY_CRC32, /* crc32 sum data blocks */
ebac4655
JA
154};
155
1c9e06ee
JA
156/*
157 * A header structure associated with each checksummed data block
158 */
ebac4655
JA
159struct verify_header {
160 unsigned int fio_magic;
161 unsigned int len;
162 unsigned int verify_type;
163 union {
164 char md5_digest[MD5_HASH_WORDS * 4];
165 unsigned long crc32;
166 };
167};
168
169struct group_run_stats {
9104f874
JA
170 unsigned long long max_run[2], min_run[2];
171 unsigned long long max_bw[2], min_bw[2];
e9b2a3fa 172 unsigned long long io_kb[2];
9104f874 173 unsigned long long agg[2];
ebac4655
JA
174};
175
e9c047a0
JA
176/*
177 * What type of allocation to use for io buffers
178 */
179enum fio_memtype {
180 MEM_MALLOC = 0, /* ordinary malloc */
181 MEM_SHM, /* use shared memory segments */
74b025b0 182 MEM_SHMHUGE, /* use shared memory segments with huge pages */
e9c047a0 183 MEM_MMAP, /* use anonynomous mmap */
d0bdaf49 184 MEM_MMAPHUGE, /* memory mapped huge file */
e9c047a0
JA
185};
186
187/*
188 * The type of object we are working on
189 */
190enum fio_filetype {
1c9e06ee
JA
191 FIO_TYPE_FILE = 1, /* plain file */
192 FIO_TYPE_BD, /* block device */
193 FIO_TYPE_CHAR, /* character device */
e9c047a0
JA
194};
195
2866c82d 196enum fio_ioengine_flags {
1c9e06ee
JA
197 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
198 FIO_CPUIO = 1 << 1, /* cpu burner, doesn't do real io */
199 FIO_MMAPIO = 1 << 2, /* uses memory mapped io */
200 FIO_RAWIO = 1 << 3, /* some sort of direct/raw io */
201 FIO_NETIO = 1 << 4, /* networked io */
202 FIO_NULLIO = 1 << 5, /* no real data transfer (cpu/null) */
e9c047a0
JA
203};
204
1c9e06ee
JA
205/*
206 * Each thread_data structure has a number of files associated with it,
207 * this structure holds state information for a single file.
208 */
53cdc686
JA
209struct fio_file {
210 /*
211 * A file may not be a file descriptor, let the io engine decide
212 */
213 union {
214 unsigned long file_data;
e26f8f7a 215 int fd;
53cdc686
JA
216 };
217 char *file_name;
218 void *mmap;
219 unsigned long long file_size;
220 unsigned long long real_file_size;
221 unsigned long long file_offset;
222 unsigned long long last_pos;
02bcaa8c 223 unsigned long long last_completed_pos;
53cdc686 224
1c9e06ee
JA
225 /*
226 * block map for random io
227 */
53cdc686
JA
228 unsigned long *file_map;
229 unsigned int num_maps;
1c9e06ee 230 unsigned int last_free_lookup;
9b031dc8
JA
231
232 unsigned int unlink;
53cdc686
JA
233};
234
079ad09b
JA
235struct thread_stat {
236 struct io_log *slat_log;
237 struct io_log *clat_log;
238 struct io_log *bw_log;
239
240 /*
241 * bandwidth and latency stats
242 */
243 struct io_stat clat_stat[2]; /* completion latency */
244 struct io_stat slat_stat[2]; /* submission latency */
245 struct io_stat bw_stat[2]; /* bandwidth stats */
246
247 unsigned long long stat_io_bytes[2];
248 struct timeval stat_sample_time[2];
249
250 /*
251 * fio system usage accounting
252 */
253 struct rusage ru_start;
254 struct rusage ru_end;
255 unsigned long usr_time;
256 unsigned long sys_time;
257 unsigned long ctx;
258};
259
71619dc2
JA
260/*
261 * How many depth levels to log
262 */
263#define FIO_IO_U_MAP_NR 8
ec118304 264#define FIO_IO_U_LAT_NR 12
71619dc2 265
e9c047a0
JA
266/*
267 * This describes a single thread/process executing a fio job.
268 */
ebac4655 269struct thread_data {
61697c37 270 char *description;
b4692828 271 char *name;
ef899b63 272 char *directory;
13f8e2d2 273 char *filename;
ebac4655
JA
274 char verror[80];
275 pthread_t thread;
276 int thread_number;
277 int groupid;
079ad09b 278 struct thread_stat ts;
e9c047a0 279 enum fio_filetype filetype;
53cdc686
JA
280 struct fio_file *files;
281 unsigned int nr_files;
13f8e2d2 282 unsigned int nr_uniq_files;
0aabe160
JA
283 union {
284 unsigned int next_file;
285 os_random_state_t next_file_state;
286 };
ebac4655 287 int error;
ebac4655
JA
288 pid_t pid;
289 char *orig_buffer;
290 size_t orig_buffer_size;
291 volatile int terminate;
292 volatile int runstate;
e9c047a0 293 enum fio_ddir ddir;
3d60d1ed 294 unsigned int iomix;
ebac4655 295 unsigned int ioprio;
87dc1ab1 296 unsigned int last_was_sync;
e9c047a0 297
9158d2f7
JA
298 unsigned int sequential;
299 unsigned int odirect;
300 unsigned int invalidate_cache;
301 unsigned int create_serialize;
302 unsigned int create_fsync;
303 unsigned int end_fsync;
304 unsigned int sync_io;
305 unsigned int verify;
306 unsigned int use_thread;
307 unsigned int unlink;
308 unsigned int do_disk_util;
309 unsigned int override_sync;
310 unsigned int rand_repeatable;
311 unsigned int write_lat_log;
312 unsigned int write_bw_log;
bb8895e0 313 unsigned int norandommap;
690adba3 314 unsigned int bs_unaligned;
e9c047a0 315
a00735e6
JA
316 unsigned int bs[2];
317 unsigned int min_bs[2];
318 unsigned int max_bs[2];
56bb17f2 319 unsigned int hugepage_size;
a00735e6 320 unsigned int rw_min_bs;
ebac4655 321 unsigned int thinktime;
48097d5c 322 unsigned int thinktime_spin;
9c1f7434 323 unsigned int thinktime_blocks;
ebac4655
JA
324 unsigned int fsync_blocks;
325 unsigned int start_delay;
906c8d75 326 unsigned long timeout;
ebac4655 327 unsigned int overwrite;
ebac4655 328 unsigned int bw_avg_time;
ebac4655 329 unsigned int loops;
20dc95c4
JA
330 unsigned long long zone_size;
331 unsigned long long zone_skip;
e9c047a0 332 enum fio_memtype mem_type;
313cb206
JA
333 char *mmapfile;
334 int mmapfd;
ebac4655
JA
335 unsigned int stonewall;
336 unsigned int numjobs;
ebac4655 337 unsigned int iodepth;
e916b390 338 unsigned int iodepth_low;
ebac4655 339 os_cpu_mask_t cpumask;
aea47d44 340 unsigned int iolog;
843a7413 341 unsigned int read_iolog;
a6ccc7be
JA
342 unsigned int rwmixcycle;
343 unsigned int rwmixread;
e1f36503 344 unsigned int rwmixwrite;
b6f4d880 345 unsigned int nice;
0aabe160 346 unsigned int file_service_type;
aea47d44 347
076efc7c
JA
348 char *read_iolog_file;
349 char *write_iolog_file;
843a7413
JA
350 void *iolog_buf;
351 FILE *iolog_f;
ebac4655 352
da86774e 353 char *sysfs_root;
da86774e
JA
354 char *ioscheduler;
355
6dfd46b9
JA
356 os_random_state_t bsrange_state;
357 os_random_state_t verify_state;
ebac4655
JA
358
359 int shm_id;
360
e9c047a0
JA
361 /*
362 * IO engine hooks, contains everything needed to submit an io_u
363 * to any of the available IO engines.
364 */
2866c82d 365 struct ioengine_ops *io_ops;
ebac4655 366
e9c047a0
JA
367 /*
368 * Current IO depth and list of free and busy io_u's.
369 */
ebac4655 370 unsigned int cur_depth;
71619dc2 371 unsigned int io_u_map[FIO_IO_U_MAP_NR];
ec118304 372 unsigned int io_u_lat[FIO_IO_U_LAT_NR];
71619dc2 373 unsigned long total_io_u;
ebac4655
JA
374 struct list_head io_u_freelist;
375 struct list_head io_u_busylist;
755200a3 376 struct list_head io_u_requeues;
ebac4655 377
e9c047a0
JA
378 /*
379 * Rate state
380 */
ebac4655
JA
381 unsigned int rate;
382 unsigned int ratemin;
383 unsigned int ratecycle;
384 unsigned long rate_usec_cycle;
385 long rate_pending_usleep;
386 unsigned long rate_bytes;
387 struct timeval lastrate;
388
389 unsigned long runtime[2]; /* msec */
390 unsigned long long io_size;
53cdc686
JA
391 unsigned long long total_file_size;
392 unsigned long long start_offset;
ebac4655
JA
393 unsigned long long total_io_size;
394
755200a3 395 unsigned long io_issues[2];
9104f874
JA
396 unsigned long long io_blocks[2];
397 unsigned long long io_bytes[2];
9104f874 398 unsigned long long this_io_bytes[2];
079ad09b 399 unsigned long long zone_bytes;
bbfd6b00 400 volatile int mutex;
ebac4655 401
e9c047a0
JA
402 /*
403 * State for random io, a bitmap of blocks done vs not done
404 */
6dfd46b9 405 os_random_state_t random_state;
ebac4655 406
b990b5c0
JA
407 /*
408 * CPU "io" cycle burner
409 */
410 unsigned int cpuload;
411 unsigned int cpucycle;
412
ebac4655
JA
413 struct timeval start; /* start of this loop */
414 struct timeval epoch; /* time job was started */
69008999 415 struct timeval end_time;/* time job ended */
ebac4655 416
e9c047a0
JA
417 /*
418 * read/write mixed workload state
419 */
6dfd46b9 420 os_random_state_t rwmix_state;
a6ccc7be 421 struct timeval rwmix_switch;
e9c047a0 422 enum fio_ddir rwmix_ddir;
a6ccc7be 423
4e0ba8af
JA
424 /*
425 * Pre-run and post-run shell
426 */
427 char *exec_prerun;
428 char *exec_postrun;
429
e9c047a0
JA
430 /*
431 * IO historic logs
432 */
ebac4655 433 struct list_head io_hist_list;
aea47d44 434 struct list_head io_log_list;
433afcb4
JA
435
436 /*
437 * timeout handling
438 */
439 struct timeval timeout_end;
440 struct itimerval timer;
ebac4655
JA
441};
442
0aabe160
JA
443/*
444 * roundrobin available files, or choose one at random.
445 */
446enum {
447 FIO_FSERVICE_RANDOM = 1,
448 FIO_FSERVICE_RR = 2,
449};
450
433afcb4
JA
451/*
452 * 30 second per-io_u timeout, with 5 second intervals to avoid resetting
453 * the timer on each queue operation.
454 */
455#define IO_U_TIMEOUT_INC 5
456#define IO_U_TIMEOUT 30
457
e1161c32 458#define __td_verror(td, err, msg, func) \
ebac4655 459 do { \
19abcd3d
JA
460 if ((td)->error) \
461 break; \
ebac4655
JA
462 int e = (err); \
463 (td)->error = e; \
e1161c32 464 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \
ebac4655
JA
465 } while (0)
466
b990b5c0 467
e1161c32
JA
468#define td_verror(td, err, func) \
469 __td_verror((td), (err), strerror((err)), (func))
470#define td_vmsg(td, err, msg, func) \
471 __td_verror((td), (err), (msg), (func))
b990b5c0 472
ebac4655
JA
473extern int exitall_on_terminate;
474extern int thread_number;
475extern int shm_id;
476extern int groupid;
c6ae0a5b 477extern int terse_output;
eb8bbf48
JA
478extern FILE *f_out;
479extern FILE *f_err;
53cdc686 480extern int temp_stall_ts;
1e97cce9 481extern unsigned long long mlock_size;
ebac4655
JA
482
483extern struct thread_data *threads;
484
ebac4655
JA
485#define td_read(td) ((td)->ddir == DDIR_READ)
486#define td_write(td) ((td)->ddir == DDIR_WRITE)
3d60d1ed 487#define td_rw(td) ((td)->iomix != 0)
ebac4655
JA
488
489#define BLOCKS_PER_MAP (8 * sizeof(long))
a00735e6 490#define TO_MAP_BLOCK(td, f, b) ((b) - ((f)->file_offset / (td)->rw_min_bs))
53cdc686
JA
491#define RAND_MAP_IDX(td, f, b) (TO_MAP_BLOCK(td, f, b) / BLOCKS_PER_MAP)
492#define RAND_MAP_BIT(td, f, b) (TO_MAP_BLOCK(td, f, b) & (BLOCKS_PER_MAP - 1))
ebac4655
JA
493
494#define MAX_JOBS (1024)
495
87dc1ab1
JA
496static inline int should_fsync(struct thread_data *td)
497{
498 if (td->last_was_sync)
499 return 0;
500 if (td->odirect)
501 return 0;
502 if (td_write(td) || td_rw(td) || td->override_sync)
503 return 1;
504
505 return 0;
506}
507
1c9e06ee
JA
508/*
509 * Disk utils as read in /sys/block/<dev>/stat
510 */
ebac4655
JA
511struct disk_util_stat {
512 unsigned ios[2];
513 unsigned merges[2];
514 unsigned long long sectors[2];
515 unsigned ticks[2];
516 unsigned io_ticks;
517 unsigned time_in_queue;
518};
519
1c9e06ee
JA
520/*
521 * Per-device disk util management
522 */
ebac4655
JA
523struct disk_util {
524 struct list_head list;
525
526 char *name;
527 char path[256];
528 dev_t dev;
529
530 struct disk_util_stat dus;
531 struct disk_util_stat last_dus;
532
533 unsigned long msec;
534 struct timeval time;
535};
536
1c9e06ee 537/*
97601024 538 * Callback for io completion
1c9e06ee 539 */
97601024 540typedef int (endio_handler)(struct io_u *);
ebac4655
JA
541
542#define DISK_UTIL_MSEC (250)
543
6a0106a0
JA
544#ifndef min
545#define min(a, b) ((a) < (b) ? (a) : (b))
546#endif
a00735e6
JA
547#ifndef max
548#define max(a, b) ((a) > (b) ? (a) : (b))
549#endif
6a0106a0 550
6796209a
JA
551/*
552 * Log exports
553 */
72cb971b 554extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
6796209a 555extern void write_iolog_put(struct thread_data *, struct io_u *);
72cb971b 556extern int __must_check init_iolog(struct thread_data *td);
6796209a
JA
557extern void log_io_piece(struct thread_data *, struct io_u *);
558extern void prune_io_piece_log(struct thread_data *);
559extern void write_iolog_close(struct thread_data *);
560
561/*
562 * Logging
563 */
1e97cce9
JA
564extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long);
565extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long);
566extern void add_bw_sample(struct thread_data *, enum fio_ddir, struct timeval *);
6796209a
JA
567extern void show_run_stats(void);
568extern void init_disk_util(struct thread_data *);
569extern void update_rusage_stat(struct thread_data *);
570extern void update_io_ticks(void);
571extern void disk_util_timer_arm(void);
8914a9d8
JA
572extern void setup_log(struct io_log **);
573extern void finish_log(struct thread_data *, struct io_log *, const char *);
bb3884d8 574extern void __finish_log(struct io_log *, const char *);
8914a9d8 575extern int setup_rate(struct thread_data *);
bb3884d8
JA
576extern struct io_log *agg_io_log[2];
577extern int write_bw_log;
578extern void add_agg_sample(unsigned long, enum fio_ddir);
6796209a
JA
579
580/*
581 * Time functions
582 */
583extern unsigned long utime_since(struct timeval *, struct timeval *);
69008999 584extern unsigned long utime_since_now(struct timeval *);
6796209a
JA
585extern unsigned long mtime_since(struct timeval *, struct timeval *);
586extern unsigned long mtime_since_now(struct timeval *);
587extern unsigned long time_since_now(struct timeval *);
263e529f 588extern unsigned long mtime_since_genesis(void);
b990b5c0 589extern void __usec_sleep(unsigned int);
6796209a 590extern void usec_sleep(struct thread_data *, unsigned long);
a00735e6 591extern void rate_throttle(struct thread_data *, unsigned long, unsigned int, int);
6043c579 592extern void fill_start_time(struct timeval *);
02bcaa8c 593extern void fio_gettime(struct timeval *, void *);
a2f77c9f 594extern void set_genesis_time(void);
6796209a 595
8914a9d8
JA
596/*
597 * Init functions
598 */
72cb971b
JA
599extern int __must_check parse_options(int, char **);
600extern int __must_check init_random_state(struct thread_data *);
8914a9d8 601
53cdc686
JA
602/*
603 * File setup/shutdown
604 */
605extern void close_files(struct thread_data *);
b2fdda43
JA
606extern int __must_check setup_files(struct thread_data *);
607extern int __must_check open_files(struct thread_data *);
608extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *);
53cdc686 609
263e529f
JA
610/*
611 * ETA/status stuff
612 */
613extern void print_thread_status(void);
614extern void print_status_init(int);
615
616/*
617 * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
618 * will never back again. It may cycle between running/verififying/fsyncing.
619 * Once the thread reaches TD_EXITED, it is just waiting for the core to
620 * reap it.
621 */
622enum {
623 TD_NOT_CREATED = 0,
624 TD_CREATED,
625 TD_INITIALIZED,
626 TD_RUNNING,
627 TD_VERIFYING,
628 TD_FSYNCING,
629 TD_EXITED,
630 TD_REAPED,
631};
632
e29d1b70
JA
633/*
634 * Verify helpers
635 */
636extern void populate_verify_io_u(struct thread_data *, struct io_u *);
b2fdda43
JA
637extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
638extern int __must_check verify_io_u(struct io_u *);
e29d1b70 639
2f9ade3c
JA
640/*
641 * Memory helpers
642 */
b2fdda43 643extern int __must_check fio_pin_memory(void);
2f9ade3c 644extern void fio_unpin_memory(void);
b2fdda43 645extern int __must_check allocate_io_mem(struct thread_data *);
2f9ade3c
JA
646extern void free_io_mem(struct thread_data *);
647
10ba535a
JA
648/*
649 * io unit handling
650 */
651#define queue_full(td) list_empty(&(td)->io_u_freelist)
652extern struct io_u *__get_io_u(struct thread_data *);
3d7c391d 653extern struct io_u *get_io_u(struct thread_data *);
10ba535a 654extern void put_io_u(struct thread_data *, struct io_u *);
755200a3 655extern void requeue_io_u(struct thread_data *, struct io_u **);
b2fdda43
JA
656extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *, endio_handler *);
657extern long __must_check io_u_queued_complete(struct thread_data *, int, endio_handler *);
7e77dd02 658extern void io_u_queued(struct thread_data *, struct io_u *);
433afcb4
JA
659extern void io_u_init_timeout(void);
660extern void io_u_set_timeout(struct thread_data *);
10ba535a
JA
661
662/*
663 * io engine entry points
664 */
b2fdda43
JA
665extern int __must_check td_io_init(struct thread_data *);
666extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
667extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
668extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
669extern int __must_check td_io_getevents(struct thread_data *, int, int, struct timespec *);
670extern int __must_check td_io_commit(struct thread_data *);
10ba535a 671
bbfd6b00
JA
672/*
673 * This is a pretty crappy semaphore implementation, but with the use that fio
674 * has (just signalling start/go conditions), it doesn't have to be better.
675 * Naturally this would not work for any type of contended semaphore or
676 * for real locking.
677 */
1056eaad 678static inline void fio_sem_init(volatile int *sem, int val)
bbfd6b00
JA
679{
680 *sem = val;
681}
682
1056eaad 683static inline void fio_sem_down(volatile int *sem)
bbfd6b00
JA
684{
685 while (*sem == 0)
686 usleep(10000);
687
688 (*sem)--;
689}
690
1056eaad 691static inline void fio_sem_up(volatile int *sem)
bbfd6b00
JA
692{
693 (*sem)++;
694}
695
3b70d7e5
JA
696/*
697 * If logging output to a file, stderr should go to both stderr and f_err
698 */
699#define log_err(args...) do { \
700 fprintf(f_err, ##args); \
701 if (f_err != stderr) \
702 fprintf(stderr, ##args); \
703 } while (0)
704
2866c82d 705struct ioengine_ops {
5f350952 706 struct list_head list;
2866c82d
JA
707 char name[16];
708 int version;
709 int flags;
ea2877a4 710 int (*setup)(struct thread_data *);
2866c82d
JA
711 int (*init)(struct thread_data *);
712 int (*prep)(struct thread_data *, struct io_u *);
713 int (*queue)(struct thread_data *, struct io_u *);
755200a3 714 int (*commit)(struct thread_data *);
2866c82d
JA
715 int (*getevents)(struct thread_data *, int, int, struct timespec *);
716 struct io_u *(*event)(struct thread_data *, int);
717 int (*cancel)(struct thread_data *, struct io_u *);
718 void (*cleanup)(struct thread_data *);
2866c82d
JA
719 void *data;
720 void *dlhandle;
36167d82 721 unsigned long priv;
2866c82d
JA
722};
723
755200a3 724#define FIO_IOOPS_VERSION 5
2866c82d 725
b4692828 726extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
b2fdda43 727extern void register_ioengine(struct ioengine_ops *);
5f350952 728extern void unregister_ioengine(struct ioengine_ops *);
2866c82d
JA
729extern void close_ioengine(struct thread_data *);
730
731/*
732 * Mark unused variables passed to ops functions as unused, to silence gcc
733 */
734#define fio_unused __attribute((__unused__))
5f350952
JA
735#define fio_init __attribute__((constructor))
736#define fio_exit __attribute__((destructor))
2866c82d 737
34572e28
JA
738#define for_each_td(td, i) \
739 for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
53cdc686 740#define for_each_file(td, f, i) \
34572e28 741 for ((i) = 0, (f) = &(td)->files[0]; (i) < (int) (td)->nr_files; (i)++, (f)++)
53cdc686 742
0032bf9f
JA
743#define fio_assert(td, cond) do { \
744 if (!(cond)) { \
340fd243 745 int *__foo = NULL; \
0032bf9f
JA
746 fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \
747 (td)->runstate = TD_EXITED; \
437c9b71 748 (td)->error = EFAULT; \
340fd243 749 *__foo = 0; \
0032bf9f
JA
750 } \
751} while (0)
752
ebac4655 753#endif