UNPLUG does the timing stuff, UNPLUG TIMEOUT only does timeout
[blktrace.git] / btt / globals.h
CommitLineData
63eba147
JA
1/*
2 * blktrace output analysis: generate a timeline & gather statistics
3 *
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21#include <assert.h>
22#include <stdio.h>
23#include <string.h>
6eb42155 24#include <time.h>
63eba147
JA
25
26#include "blktrace.h"
6eb42155 27#include "rbtree.h"
63eba147
JA
28#include "list.h"
29
fa0ab85d
AB
30/*
31 * 0 == 1 blk
32 * 1 == 2 blks
33 * ...
34 * 1022 == 1023 blks
35 * 1023 == 1024 blks
36 * 1024 == > 1024 blks
37 */
38#define N_HIST_BKTS 1025
39
63eba147
JA
40#define BIT_TIME(t) ((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9))
41
42#define BIT_START(iop) ((iop)->t.sector)
43#define BIT_END(iop) ((iop)->t.sector + ((iop)->t.bytes >> 9))
5225e788 44#define IOP_READ(iop) ((iop)->t.action & BLK_TC_ACT(BLK_TC_READ))
21e47d90 45#define IOP_RW(iop) (IOP_READ(iop) ? 1 : 0)
63eba147 46
b2ecdd0f
ADB
47#define TO_SEC(nanosec) ((double)(nanosec) / 1.0e9)
48#define TO_MSEC(nanosec) (1000.0 * TO_SEC(nanosec))
49
63eba147 50#if defined(DEBUG)
6eb42155 51#define DBG_PING() dbg_ping()
63eba147
JA
52#define ASSERT(truth) do { \
53 if (!(truth)) { \
54 DBG_PING(); \
55 assert(truth); \
56 } \
57 } while (0)
58
63eba147
JA
59
60#define LIST_DEL(hp) list_del(hp)
63eba147
JA
61#else
62#define ASSERT(truth)
63#define DBG_PING()
63eba147 64#define LIST_DEL(hp) do { \
d76c5b81
AB
65 ASSERT((hp)->next != NULL); \
66 ASSERT(!list_empty(hp)); \
67 list_del(hp); \
63eba147
JA
68 } while (0)
69#endif
70
63eba147
JA
71enum iop_type {
72 IOP_Q = 0,
73 IOP_X = 1,
74 IOP_A = 2,
4c48f14e 75 IOP_G = 3,
095181f2 76 IOP_M = 4,
d76c5b81
AB
77 IOP_D = 5,
78 IOP_C = 6,
79 IOP_R = 7,
4c48f14e 80 IOP_I = 8
63eba147 81};
4c48f14e 82#define N_IOP_TYPES (IOP_I + 1)
63eba147 83
b2ecdd0f
ADB
84struct file_info {
85 struct file_info *next;
86 FILE *ofp;
69040794 87 char *oname;
b2ecdd0f
ADB
88};
89
6eb42155
ADB
90struct mode {
91 int most_seeks, nmds;
92 long long *modes;
63eba147
JA
93};
94
95struct io;
96struct io_list {
97 struct list_head head;
98 struct io *iop;
99 int cy_users;
100};
101
102struct avg_info {
103 __u64 min, max, total;
104 double avg;
105 int n;
106};
107
108struct avgs_info {
ae6d30f4
AB
109 struct avg_info q2q_dm;
110 struct avg_info q2a_dm;
111 struct avg_info q2c_dm;
112
63eba147 113 struct avg_info q2q;
ae6d30f4
AB
114 struct avg_info q2a;
115 struct avg_info q2g;
116 struct avg_info g2i;
117 struct avg_info q2m;
118 struct avg_info i2d;
119 struct avg_info m2d;
63eba147 120 struct avg_info d2c;
ae6d30f4 121 struct avg_info q2c;
63eba147
JA
122
123 struct avg_info blks; /* Blocks transferred */
124};
125
126struct range_info {
127 struct list_head head; /* on: qranges OR cranges */
128 __u64 start, end;
129};
130
131struct region_info {
132 struct list_head qranges;
133 struct list_head cranges;
63eba147
JA
134};
135
63eba147 136struct p_info {
63eba147
JA
137 struct region_info regions;
138 struct avgs_info avgs;
63eba147 139 __u64 last_q;
6eb42155 140 __u32 pid;
69040794 141 char *name;
63eba147
JA
142};
143
144struct devmap {
145 struct devmap *next;
6eb42155 146 unsigned int host, bus, target, lun, irq, cpu;
63eba147 147 char model[64];
6eb42155 148 char device[32], node[32], pci[32], devno[32];
63eba147
JA
149};
150
21e47d90 151struct stats {
6eb42155 152 __u64 rqm[2], ios[2], sec[2], wait, svctm;
21e47d90 153 double last_qu_change, last_dev_change, tot_qusz, idle_time;
6eb42155 154 int cur_qusz, cur_dev;
21e47d90
ADB
155};
156
4a5cddba
JA
157struct stats_t {
158 double n;
159 double rqm_s[2], ios_s[2], sec_s[2];
160 double avgrq_sz, avgqu_sz, await, svctm, p_util;
161};
162
63eba147 163struct d_info {
6eb42155
ADB
164 struct list_head all_head, hash_head;
165 void *heads;
63eba147 166 struct region_info regions;
63eba147 167 struct devmap *map;
4c48f14e 168 void *q2q_handle, *seek_handle, *bno_dump_handle, *unplug_hist_handle;
951ea56c 169 void *q2d_priv;
b2ecdd0f 170 FILE *d2c_ofp, *q2c_ofp;
6eb42155 171 struct avgs_info avgs;
21e47d90 172 struct stats stats, all_stats;
77f256cd 173 __u64 last_q, n_qs, n_ds;
50f73899 174 __u64 n_act_q, t_act_q; /* # currently active when Q comes in */
6eb42155 175 __u32 device;
b2822cea 176
11997716 177 int pre_culling;
b2822cea
AB
178 int is_plugged, nplugs, n_timer_unplugs;
179 double start_time, last_plug, plugged_time, end_time;
63eba147
JA
180};
181
182struct io {
6eb42155 183 struct rb_node rb_node;
4c48f14e 184 struct list_head f_head;
63eba147
JA
185 struct d_info *dip;
186 struct p_info *pip;
6eb42155 187 void *pdu;
ae6d30f4 188 __u64 bytes_left, g_time, i_time, m_time, d_time, c_time, d_sec, c_sec;
4c48f14e
AB
189 __u32 d_nsec, c_nsec;
190
d76c5b81 191 struct blk_io_trace t;
4c48f14e 192
ae6d30f4 193 int linked;
63eba147 194 enum iop_type type;
4c48f14e 195
c8b0b334
AB
196#if defined(COUNT_IOS)
197 struct list_head cio_head;
198#endif
d76c5b81 199};
095181f2 200
6eb42155
ADB
201/* bt_timeline.c */
202
63eba147 203extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name;
095181f2 204extern char *seek_name, *iostat_name, *d2c_name, *q2c_name, *per_io_name;
fc16a815 205extern char *bno_dump_name, *unplug_hist_name;
63eba147 206extern double range_delta;
69040794
AB
207extern FILE *ranges_ofp, *avgs_ofp, *iostat_ofp, *per_io_ofp;
208extern int verbose, done, time_bounded, output_all_data, seek_absolute;
63eba147 209extern unsigned int n_devs;
6eb42155 210extern unsigned long n_traces;
4c48f14e 211extern struct list_head all_devs, all_procs;
63eba147 212extern struct avgs_info all_avgs;
4c48f14e 213extern __u64 last_q;
63eba147 214extern struct region_info all_regions;
4c48f14e 215extern struct list_head free_ios;
21e47d90 216extern __u64 iostat_interval, iostat_last_stamp;
6eb42155 217extern time_t genesis, last_vtrace;
001b2633 218extern double t_astart, t_aend;
fa0ab85d 219extern __u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];
d76c5b81
AB
220#if defined(DEBUG)
221extern int rb_tree_size;
222#endif
c8b0b334
AB
223#if defined(COUNT_IOS)
224extern unsigned long nios_reused, nios_alloced, nios_freed;
225extern struct list_head cios;
226#endif
63eba147 227
6eb42155 228/* args.c */
63eba147 229void handle_args(int argc, char *argv[]);
6eb42155 230
69040794 231/* devmap.c */
63eba147 232int dev_map_read(char *fname);
6eb42155 233struct devmap *dev_map_find(__u32 device);
69040794 234void dev_map_exit(void);
63eba147 235
6eb42155 236/* devs.c */
d76c5b81
AB
237#if defined(DEBUG)
238void dump_rb_trees(void);
239#endif
6eb42155 240void init_dev_heads(void);
095181f2 241struct d_info *dip_add(__u32 device, struct io *iop);
6eb42155
ADB
242void dip_rem(struct io *iop);
243struct d_info *__dip_find(__u32 device);
095181f2 244void dip_foreach_list(struct io *iop, enum iop_type type, struct list_head *hd);
6eb42155
ADB
245void dip_foreach(struct io *iop, enum iop_type type,
246 void (*fnc)(struct io *iop, struct io *this), int rm_after);
247struct io *dip_find_sec(struct d_info *dip, enum iop_type type, __u64 sec);
248void dip_foreach_out(void (*func)(struct d_info *, void *), void *arg);
b2822cea 249void dip_plug(__u32 dev, double cur_time);
00a47cd1
AB
250void dip_unplug(__u32 dev, double cur_time);
251void dip_unplug_tm(__u32 dev);
69040794 252void dip_exit(void);
6eb42155
ADB
253
254/* dip_rb.c */
095181f2 255int rb_insert(struct rb_root *root, struct io *iop);
6eb42155
ADB
256struct io *rb_find_sec(struct rb_root *root, __u64 sec);
257void rb_foreach(struct rb_node *n, struct io *iop,
258 void (*fnc)(struct io *iop, struct io *this),
259 struct list_head *head);
260
261/* iostat.c */
21e47d90 262void iostat_init(void);
4c48f14e 263void iostat_getrq(struct io *iop);
21e47d90
ADB
264void iostat_merge(struct io *iop);
265void iostat_issue(struct io *iop);
6eb42155
ADB
266void iostat_unissue(struct io *iop);
267void iostat_complete(struct io *d_iop, struct io *c_iop);
21e47d90
ADB
268void iostat_check_time(__u64 stamp);
269void iostat_dump_stats(__u64 stamp, int all);
270
6eb42155 271/* latency.c */
b2ecdd0f
ADB
272void latency_init(struct d_info *dip);
273void latency_clean(void);
274void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency);
275void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency);
276
6eb42155 277/* misc.c */
6eb42155 278int in_devices(struct blk_io_trace *t);
6eb42155
ADB
279void add_file(struct file_info **fipp, FILE *fp, char *oname);
280void clean_files(struct file_info **fipp);
69040794
AB
281void add_buf(void *buf);
282void clean_bufs(void);
6eb42155
ADB
283void dbg_ping(void);
284
d76c5b81
AB
285/* mmap.c */
286void setup_ifile(char *fname);
287void cleanup_ifile(void);
288int next_trace(struct blk_io_trace *t, void **pdu);
289
6eb42155
ADB
290/* output.c */
291int output_avgs(FILE *ofp);
292int output_ranges(FILE *ofp);
293char *make_dev_hdr(char *pad, size_t len, struct d_info *dip);
294
295/* proc.c */
296void add_process(__u32 pid, char *name);
297struct p_info *find_process(__u32 pid, char *name);
298void pip_update_q(struct io *iop);
299void pip_foreach_out(void (*f)(struct p_info *, void *), void *arg);
69040794
AB
300void pip_exit(void);
301
302/* bno_dump.c */
303void *bno_dump_init(__u32 device);
304void bno_dump_exit(void *param);
305void bno_dump_add(void *handle, struct io *iop);
306void bno_dump_clean(void);
6eb42155 307
951ea56c
AB
308/* q2d.c */
309void q2d_histo_add(void *priv, __u64 q2d);
310void *q2d_init(void);
311void q2d_release(void *priv);
312void q2d_display_header(FILE *fp);
313void q2d_display_dashes(FILE *fp);
314void q2d_display(FILE *fp, void *priv);
315int q2d_ok(void *priv);
316void q2d_acc(void *a1, void *a2);
317
6eb42155 318/* seek.c */
4c48f14e 319void *seeki_init(char *str);
69040794 320void seeki_exit(void *param);
6eb42155
ADB
321void seek_clean(void);
322void seeki_add(void *handle, struct io *iop);
323double seeki_mean(void *handle);
324long long seeki_nseeks(void *handle);
325long long seeki_median(void *handle);
326int seeki_mode(void *handle, struct mode *mp);
327
328/* trace.c */
329void add_trace(struct io *iop);
330
095181f2
JA
331/* trace_complete.c */
332void trace_complete(struct io *c_iop);
095181f2
JA
333
334/* trace_im.c */
c8b0b334
AB
335void run_im(struct io *im_iop, struct io *d_iop, struct io *c_iop);
336void run_unim(struct io *im_iop, struct io *d_iop, struct io *c_iop);
d76c5b81 337int ready_im(struct io *im_iop, struct io *c_iop);
095181f2
JA
338void trace_insert(struct io *i_iop);
339void trace_merge(struct io *m_iop);
4c48f14e 340void trace_getrq(struct io *g_iop);
095181f2
JA
341
342/* trace_issue.c */
c8b0b334
AB
343void run_issue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
344void run_unissue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
d76c5b81 345int ready_issue(struct io *d_iop, struct io *c_iop);
095181f2 346void trace_issue(struct io *d_iop);
095181f2 347
b2822cea
AB
348/* trace_plug.c */
349void trace_plug(struct io *p_iop);
350void trace_unplug_io(struct io *u_iop);
351void trace_unplug_timer(struct io *u_iop);
352
095181f2 353/* trace_queue.c */
c8b0b334 354void run_queue(struct io *q_iop, struct io *u_iop, struct io *c_iop);
d76c5b81 355int ready_queue(struct io *q_iop, struct io *c_iop);
095181f2 356void trace_queue(struct io *q_iop);
095181f2
JA
357
358/* trace_remap.c */
c8b0b334 359void run_remap(struct io *a_iop, struct io *u_iop, struct io *c_iop);
d76c5b81 360int ready_remap(struct io *a_iop, struct io *c_iop);
095181f2 361void trace_remap(struct io *a_iop);
095181f2
JA
362
363/* trace_requeue.c */
364void trace_requeue(struct io *r_iop);
095181f2 365
fc16a815
AB
366/* unplug_hist.c */
367void *unplug_hist_init(__u32 device);
368void unplug_hist_exit(void *arg);
369void unplug_hist_add(struct io *u_iop);
370
63eba147 371#include "inlines.h"