[PATCH] fio: display percent of agg bw a job got
[disktools.git] / fio.h
1 #ifndef FIO_H
2 #define FIO_H
3
4 #include <sched.h>
5 #include <libaio.h>
6 #include <limits.h>
7 #include <sys/time.h>
8 #include <sys/resource.h>
9 #include <semaphore.h>
10
11 #include "list.h"
12 #include "md5.h"
13 #include "arch.h"
14
15 struct io_stat {
16         unsigned long val;
17         unsigned long val_sq;
18         unsigned long max_val;
19         unsigned long min_val;
20         unsigned long samples;
21 };
22
23 struct io_sample {
24         unsigned long time;
25         unsigned long val;
26 };
27
28 struct io_log {
29         unsigned long nr_samples;
30         unsigned long max_samples;
31         struct io_sample *log;
32 };
33
34 struct io_piece {
35         struct list_head list;
36         unsigned long long offset;
37         unsigned int len;
38 };
39
40 #define FIO_HDR_MAGIC   0xf00baaef
41
42 struct verify_header {
43         unsigned int fio_magic;
44         unsigned int len;
45         char md5_digest[MD5_HASH_WORDS * 4];
46 };
47
48 struct group_run_stats {
49         unsigned long max_run[2], min_run[2];
50         unsigned long max_bw[2], min_bw[2];
51         unsigned long io_mb[2];
52         unsigned long agg[2];
53 };
54
55 struct thread_data {
56         char file_name[256];
57         char directory[256];
58         pthread_t thread;
59         int thread_number;
60         int groupid;
61         int error;
62         int fd;
63         pid_t pid;
64         char *orig_buffer;
65         volatile int terminate;
66         volatile int runstate;
67         volatile int old_runstate;
68         unsigned int ddir;
69         unsigned int ioprio;
70         unsigned int sequential;
71         unsigned int bs;
72         unsigned int min_bs;
73         unsigned int max_bs;
74         unsigned int odirect;
75         unsigned int thinktime;
76         unsigned int fsync_blocks;
77         unsigned int start_delay;
78         unsigned int timeout;
79         unsigned int use_aio;
80         unsigned int create_file;
81         unsigned int overwrite;
82         unsigned int invalidate_cache;
83         unsigned int bw_avg_time;
84         unsigned int create_serialize;
85         unsigned int create_fsync;
86         unsigned int loops;
87         unsigned long long file_size;
88         unsigned long long file_offset;
89         unsigned int sync_io;
90         unsigned int mem_type;
91         unsigned int verify;
92         unsigned int stonewall;
93         unsigned int numjobs;
94         unsigned int use_thread;
95         cpu_set_t cpumask;
96
97         struct drand48_data bsrange_state;
98         struct drand48_data verify_state;
99
100         int shm_id;
101
102         off_t cur_off;
103
104         io_context_t aio_ctx;
105         unsigned int aio_depth;
106         struct io_event *aio_events;
107
108         unsigned int cur_depth;
109         struct list_head io_u_freelist;
110         struct list_head io_u_busylist;
111
112         unsigned int rate;
113         unsigned int ratemin;
114         unsigned int ratecycle;
115         unsigned long rate_usec_cycle;
116         long rate_pending_usleep;
117         unsigned long rate_bytes;
118         struct timeval lastrate;
119
120         unsigned long runtime;          /* sec */
121         unsigned long long io_size;
122
123         unsigned long io_blocks;
124         unsigned long io_bytes;
125         unsigned long this_io_bytes;
126         unsigned long last_bytes;
127         sem_t mutex;
128
129         struct drand48_data random_state;
130         unsigned long *file_map;
131         unsigned int num_maps;
132
133         /*
134          * bandwidth and latency stats
135          */
136         struct io_stat clat_stat;               /* completion latency */
137         struct io_stat slat_stat;               /* submission latency */
138
139         struct io_stat bw_stat;                 /* bandwidth stats */
140         unsigned long stat_io_bytes;
141         struct timeval stat_sample_time;
142
143         struct io_log *lat_log;
144         struct io_log *bw_log;
145
146         struct timeval start;
147
148         struct rusage ru_start;
149         struct rusage ru_end;
150         unsigned long usr_time;
151         unsigned long sys_time;
152         unsigned long ctx;
153
154         struct list_head io_hist_list;
155 };
156
157 extern int parse_jobs_ini(char *);
158 extern int parse_options(int, char **);
159 extern void finish_log(struct thread_data *, struct io_log *, const char *);
160 extern int init_random_state(struct thread_data *);
161
162 extern int rate_quit;
163 extern int write_lat_log;
164 extern int write_bw_log;
165 extern int exitall_on_terminate;
166 extern int thread_number;
167 extern int shm_id;
168 extern int groupid;
169
170 extern char run_str[];
171
172 extern struct thread_data *threads;
173
174 enum {
175         DDIR_READ = 0,
176         DDIR_WRITE,
177 };
178
179 enum {
180         MEM_MALLOC,
181         MEM_SHM,
182 };
183
184 #define td_read(td)             ((td)->ddir == DDIR_READ)
185 #define td_write(td)            ((td)->ddir == DDIR_WRITE)
186
187 #define BLOCKS_PER_MAP          (8 * sizeof(long))
188 #define TO_MAP_BLOCK(td, b)     ((b) - ((td)->file_offset / (td)->min_bs))
189 #define RAND_MAP_IDX(td, b)     (TO_MAP_BLOCK(td, b) / BLOCKS_PER_MAP)
190 #define RAND_MAP_BIT(td, b)     (TO_MAP_BLOCK(td, b) & (BLOCKS_PER_MAP - 1))
191
192 #define MAX_JOBS        (1024)
193
194 #endif