summaryrefslogtreecommitdiff
path: root/btt/globals.h
blob: 5235ec650b0bc762c1c9b83790ee84bc6267821e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
 * blktrace output analysis: generate a timeline & gather statistics
 *
 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "blktrace.h"
#include "rbtree.h"
#include "list.h"

/*
 * 0 == 1 blk
 * 1 == 2 blks
 * ...
 * 1022 == 1023 blks
 * 1023 == 1024 blks
 * 1024 == > 1024 blks
 */
#define N_HIST_BKTS	1025

#define BIT_TIME(t)	((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9))

#define BIT_START(iop)	((iop)->t.sector)
#define BIT_END(iop)	((iop)->t.sector + ((iop)->t.bytes >> 9))
#define IOP_READ(iop)	((iop)->t.action & BLK_TC_ACT(BLK_TC_READ))
#define IOP_RW(iop)	(IOP_READ(iop) ? 1 : 0)

#define TO_SEC(nanosec)	((double)(nanosec) / 1.0e9)
#define TO_MSEC(nanosec) (1000.0 * TO_SEC(nanosec))

enum iop_type {
	IOP_Q = 0,
	IOP_X = 1,
	IOP_A = 2,
	IOP_G = 3,
	IOP_M = 4,
	IOP_D = 5,
	IOP_C = 6,
	IOP_R = 7,
	IOP_I = 8,
	IOP_S = 9
};
#define N_IOP_TYPES	(IOP_S + 1)

struct mode {
	int most_seeks, nmds;
	long long *modes;
};

struct io;
struct io_list {
	struct list_head head;
	struct io *iop;
	int cy_users;
};

struct avg_info {
	__u64 min, max, total;
	double avg;
	int n;
};

struct avgs_info {
        struct avg_info q2q_dm;
        struct avg_info q2a_dm;
        struct avg_info q2c_dm;

        struct avg_info q2q;
	struct avg_info q2a;
	struct avg_info q2g;
	struct avg_info s2g;
	struct avg_info g2i;
	struct avg_info q2m;
	struct avg_info i2d;
	struct avg_info m2d;
	struct avg_info d2c;
	struct avg_info q2c;

	struct avg_info blks;		/* Blocks transferred */
};

struct range_info {
	struct list_head head;		/* on: qranges OR cranges */
	__u64 start, end;
};

struct region_info {
	struct list_head qranges;
	struct list_head cranges;
};

struct p_info {
	struct region_info regions;
	struct avgs_info avgs;
	__u64 last_q;
	__u32 pid;
	char *name;
};

struct stats {
	__u64 rqm[2], ios[2], sec[2], wait, svctm;
	double last_qu_change, last_dev_change, tot_qusz, idle_time;
	int cur_qusz, cur_dev;
};

struct stats_t {
	double n;
	double rqm_s[2], ios_s[2], sec_s[2];
	double avgrq_sz, avgqu_sz, await, svctm, p_util;
};

struct d_info {
	struct list_head all_head, hash_head;
	void *heads;
	struct region_info regions;
	char *devmap;
	void *q2q_handle, *seek_handle, *bno_dump_handle, *up_hist_handle;
	void *q2d_priv, *aqd_handle, *rstat_handle;
	void *q2d_plat_handle, *q2c_plat_handle, *d2c_plat_handle;
	FILE *q2d_ofp, *d2c_ofp, *q2c_ofp, *pit_fp;
	struct avgs_info avgs;
	struct stats stats, all_stats;
	__u64 last_q, n_qs, n_ds;
	__u64 n_act_q, t_act_q;	/* # currently active when Q comes in */
	__u32 device;

	int pre_culling;
	int is_plugged, nplugs, nplugs_t;
	__u64 nios_up, nios_upt;
	double start_time, last_plug, plugged_time, end_time;
};

struct io {
	struct rb_node rb_node;
	struct list_head f_head, a_head;
	struct d_info *dip;
	struct p_info *pip;
	void *pdu;
	__u64 bytes_left, g_time, i_time, m_time, d_time, c_time, d_sec, c_sec;
	__u64 s_time;
	__u32 d_nsec, c_nsec;

	struct blk_io_trace t;

	int linked;
	enum iop_type type;
};

/* bt_timeline.c */

extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name;
extern char *seek_name, *iostat_name, *d2c_name, *q2c_name, *per_io_name;
extern char *bno_dump_name, *unplug_hist_name, *sps_name, *aqd_name, *q2d_name;
extern char *per_io_trees;
extern double range_delta, plat_freq, last_t_seen;
extern FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *iostat_ofp, *per_io_ofp;
extern FILE *msgs_ofp;
extern int verbose, done, time_bounded, output_all_data, seek_absolute;
extern int easy_parse_avgs, ignore_remaps;
extern unsigned int n_devs;
extern unsigned long n_traces;
extern struct list_head all_devs, all_procs;
extern struct avgs_info all_avgs;
extern __u64 last_q;
extern struct region_info all_regions;
extern struct list_head all_ios, free_ios;
extern __u64 iostat_interval, iostat_last_stamp;
extern time_t genesis, last_vtrace;
extern double t_astart, t_aend;
extern __u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];

/* args.c */
void handle_args(int argc, char *argv[]);
void clean_args();

/* aqd.c */
void *aqd_alloc(char *str);
void aqd_free(void *info);
void aqd_clean(void);
void aqd_issue(void *info, double ts);
void aqd_complete(void *info, double ts);

/* devmap.c */
int dev_map_read(char *fname);
char *dev_map_find(__u32 device);
void dev_map_exit(void);

/* devs.c */
void init_dev_heads(void);
struct d_info *dip_alloc(__u32 device, struct io *iop);
void iop_rem_dip(struct io *iop);
struct d_info *__dip_find(__u32 device);
void dip_foreach_list(struct io *iop, enum iop_type type, struct list_head *hd);
void dip_foreach(struct io *iop, enum iop_type type,
		 void (*fnc)(struct io *iop, struct io *this), int rm_after);
struct io *dip_find_sec(struct d_info *dip, enum iop_type type, __u64 sec);
void dip_foreach_out(void (*func)(struct d_info *, void *), void *arg);
void dip_plug(__u32 dev, double cur_time);
void dip_unplug(__u32 dev, double cur_time, __u64 nio_ups);
void dip_unplug_tm(__u32 dev, double cur_time, __u64 nio_ups);
void dip_exit(void);
void dip_cleanup(void);

/* dip_rb.c */
int rb_insert(struct rb_root *root, struct io *iop);
struct io *rb_find_sec(struct rb_root *root, __u64 sec);
void rb_foreach(struct rb_node *n, struct io *iop,
		      void (*fnc)(struct io *iop, struct io *this),
		      struct list_head *head);

/* iostat.c */
void iostat_init(void);
void iostat_getrq(struct io *iop);
void iostat_merge(struct io *iop);
void iostat_issue(struct io *iop);
void iostat_complete(struct io *d_iop, struct io *c_iop);
void iostat_check_time(__u64 stamp);
void iostat_dump_stats(__u64 stamp, int all);

/* latency.c */
void latency_alloc(struct d_info *dip);
void latency_clean(void);
void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency);
void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency);
void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency);

/* misc.c */
void add_file(FILE *fp, char *oname);
void add_buf(void *buf);
char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens);
FILE *my_fopen(const char *path, const char *mode);
int my_open(const char *path, int flags);
void dbg_ping(void);
void clean_allocs(void);

/* mmap.c */
void setup_ifile(char *fname);
void cleanup_ifile(void);
int next_trace(struct blk_io_trace *t, void **pdu);
double pct_done(void);

/* output.c */
int output_avgs(FILE *ofp);
int output_ranges(FILE *ofp);

/* proc.c */
void process_alloc(__u32 pid, char *name);
struct p_info *find_process(__u32 pid, char *name);
void pip_update_q(struct io *iop);
void pip_foreach_out(void (*f)(struct p_info *, void *), void *arg);
void pip_exit(void);

/* bno_dump.c */
void *bno_dump_alloc(__u32 device);
void bno_dump_free(void *param);
void bno_dump_add(void *handle, struct io *iop);
void bno_dump_clean(void);

/* plat.c */
void *plat_alloc(char *str);
void plat_free(void *info);
void plat_clean(void);
void plat_x2c(void *info, __u64 ts, __u64 latency);

/* q2d.c */
void q2d_histo_add(void *priv, __u64 q2d);
void *q2d_alloc(void);
void q2d_free(void *priv);
void q2d_display_header(FILE *fp);
void q2d_display_dashes(FILE *fp);
void q2d_display(FILE *fp, void *priv);
int q2d_ok(void *priv);
void q2d_acc(void *a1, void *a2);

/* rstats.c */
void *rstat_alloc(char *bn);
void rstat_free(void *ptr);
void rstat_add(void *ptr, double cur, unsigned long long nblks);
int rstat_init(void);
void rstat_exit(void);

/* seek.c */
void *seeki_alloc(char *str);
void seeki_free(void *param);
void seek_clean(void);
void seeki_add(void *handle, struct io *iop);
double seeki_mean(void *handle);
long long seeki_nseeks(void *handle);
long long seeki_median(void *handle);
int seeki_mode(void *handle, struct mode *mp);

/* trace.c */
void add_trace(struct io *iop);

/* trace_complete.c */
void trace_complete(struct io *c_iop);

/* trace_im.c */
void run_im(struct io *im_iop, struct io *d_iop, struct io *c_iop);
void run_unim(struct io *im_iop, struct io *d_iop, struct io *c_iop);
int ready_im(struct io *im_iop, struct io *c_iop);
void trace_insert(struct io *i_iop);
void trace_merge(struct io *m_iop);
void trace_getrq(struct io *g_iop);
void trace_sleeprq(struct io *s_iop);

/* trace_issue.c */
void run_issue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
void run_unissue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
int ready_issue(struct io *d_iop, struct io *c_iop);
void trace_issue(struct io *d_iop);

/* trace_plug.c */
void trace_plug(struct io *p_iop);
void trace_unplug_io(struct io *u_iop);
void trace_unplug_timer(struct io *u_iop);

/* trace_queue.c */
void run_queue(struct io *q_iop, struct io *u_iop, struct io *c_iop);
int ready_queue(struct io *q_iop, struct io *c_iop);
void trace_queue(struct io *q_iop);

/* trace_remap.c */
void run_remap(struct io *a_iop, struct io *u_iop, struct io *c_iop);
int ready_remap(struct io *a_iop, struct io *c_iop);
void trace_remap(struct io *a_iop);

/* trace_requeue.c */
void trace_requeue(struct io *r_iop);

/* unplug_hist.c */
void *unplug_hist_alloc(__u32 device);
void unplug_hist_free(void *arg);
void unplug_hist_add(struct io *u_iop);

#include "inlines.h"