Merge branch 'fix-m' into add-P
[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 */
63eba147
JA
21#include <stdio.h>
22#include <string.h>
6eb42155 23#include <time.h>
63eba147
JA
24
25#include "blktrace.h"
6eb42155 26#include "rbtree.h"
63eba147
JA
27#include "list.h"
28
fa0ab85d
AB
29/*
30 * 0 == 1 blk
31 * 1 == 2 blks
32 * ...
33 * 1022 == 1023 blks
34 * 1023 == 1024 blks
35 * 1024 == > 1024 blks
36 */
37#define N_HIST_BKTS 1025
38
63eba147
JA
39#define BIT_TIME(t) ((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9))
40
41#define BIT_START(iop) ((iop)->t.sector)
42#define BIT_END(iop) ((iop)->t.sector + ((iop)->t.bytes >> 9))
5225e788 43#define IOP_READ(iop) ((iop)->t.action & BLK_TC_ACT(BLK_TC_READ))
21e47d90 44#define IOP_RW(iop) (IOP_READ(iop) ? 1 : 0)
63eba147 45
b2ecdd0f
ADB
46#define TO_SEC(nanosec) ((double)(nanosec) / 1.0e9)
47#define TO_MSEC(nanosec) (1000.0 * TO_SEC(nanosec))
48
63eba147
JA
49enum iop_type {
50 IOP_Q = 0,
51 IOP_X = 1,
52 IOP_A = 2,
4c48f14e 53 IOP_G = 3,
095181f2 54 IOP_M = 4,
d76c5b81
AB
55 IOP_D = 5,
56 IOP_C = 6,
57 IOP_R = 7,
354db430
AB
58 IOP_I = 8,
59 IOP_S = 9
63eba147 60};
354db430 61#define N_IOP_TYPES (IOP_S + 1)
63eba147 62
b2ecdd0f
ADB
63struct file_info {
64 struct file_info *next;
65 FILE *ofp;
69040794 66 char *oname;
b2ecdd0f
ADB
67};
68
6eb42155
ADB
69struct mode {
70 int most_seeks, nmds;
71 long long *modes;
63eba147
JA
72};
73
74struct io;
75struct io_list {
76 struct list_head head;
77 struct io *iop;
78 int cy_users;
79};
80
81struct avg_info {
82 __u64 min, max, total;
83 double avg;
84 int n;
85};
86
87struct avgs_info {
ae6d30f4
AB
88 struct avg_info q2q_dm;
89 struct avg_info q2a_dm;
90 struct avg_info q2c_dm;
91
63eba147 92 struct avg_info q2q;
ae6d30f4
AB
93 struct avg_info q2a;
94 struct avg_info q2g;
354db430 95 struct avg_info s2g;
ae6d30f4
AB
96 struct avg_info g2i;
97 struct avg_info q2m;
98 struct avg_info i2d;
99 struct avg_info m2d;
63eba147 100 struct avg_info d2c;
ae6d30f4 101 struct avg_info q2c;
63eba147
JA
102
103 struct avg_info blks; /* Blocks transferred */
104};
105
106struct range_info {
107 struct list_head head; /* on: qranges OR cranges */
108 __u64 start, end;
109};
110
111struct region_info {
112 struct list_head qranges;
113 struct list_head cranges;
63eba147
JA
114};
115
63eba147 116struct p_info {
63eba147
JA
117 struct region_info regions;
118 struct avgs_info avgs;
63eba147 119 __u64 last_q;
6eb42155 120 __u32 pid;
69040794 121 char *name;
63eba147
JA
122};
123
124struct devmap {
125 struct devmap *next;
6eb42155 126 unsigned int host, bus, target, lun, irq, cpu;
63eba147 127 char model[64];
6eb42155 128 char device[32], node[32], pci[32], devno[32];
63eba147
JA
129};
130
21e47d90 131struct stats {
6eb42155 132 __u64 rqm[2], ios[2], sec[2], wait, svctm;
21e47d90 133 double last_qu_change, last_dev_change, tot_qusz, idle_time;
6eb42155 134 int cur_qusz, cur_dev;
21e47d90
ADB
135};
136
4a5cddba
JA
137struct stats_t {
138 double n;
139 double rqm_s[2], ios_s[2], sec_s[2];
140 double avgrq_sz, avgqu_sz, await, svctm, p_util;
141};
142
63eba147 143struct d_info {
6eb42155
ADB
144 struct list_head all_head, hash_head;
145 void *heads;
63eba147 146 struct region_info regions;
63eba147 147 struct devmap *map;
4c48f14e 148 void *q2q_handle, *seek_handle, *bno_dump_handle, *unplug_hist_handle;
e47ada10
AB
149 void *q2d_priv, *aqd_handle;
150 void *q2d_plat_handle, *q2c_plat_handle, *d2c_plat_handle;
151 FILE *q2d_ofp, *d2c_ofp, *q2c_ofp;
6eb42155 152 struct avgs_info avgs;
21e47d90 153 struct stats stats, all_stats;
77f256cd 154 __u64 last_q, n_qs, n_ds;
50f73899 155 __u64 n_act_q, t_act_q; /* # currently active when Q comes in */
6eb42155 156 __u32 device;
b2822cea 157
11997716 158 int pre_culling;
b70a6642
AB
159 int is_plugged, nplugs, nplugs_t, n_timer_unplugs;
160 __u64 nios_up, nios_upt;
b2822cea 161 double start_time, last_plug, plugged_time, end_time;
63eba147
JA
162};
163
164struct io {
6eb42155 165 struct rb_node rb_node;
8b10aae0 166 struct list_head f_head, a_head;
63eba147
JA
167 struct d_info *dip;
168 struct p_info *pip;
6eb42155 169 void *pdu;
ae6d30f4 170 __u64 bytes_left, g_time, i_time, m_time, d_time, c_time, d_sec, c_sec;
354db430 171 __u64 s_time;
4c48f14e
AB
172 __u32 d_nsec, c_nsec;
173
d76c5b81 174 struct blk_io_trace t;
4c48f14e 175
ae6d30f4 176 int linked;
63eba147 177 enum iop_type type;
d76c5b81 178};
095181f2 179
6eb42155
ADB
180/* bt_timeline.c */
181
63eba147 182extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name;
095181f2 183extern char *seek_name, *iostat_name, *d2c_name, *q2c_name, *per_io_name;
e47ada10 184extern char *bno_dump_name, *unplug_hist_name, *sps_name, *aqd_name, *q2d_name;
2baef508 185extern double range_delta, plat_freq;
f028c958 186extern FILE *ranges_ofp, *avgs_ofp, *xavgs_ofp, *iostat_ofp, *per_io_ofp;
84a26fcd 187extern FILE *msgs_ofp;
69040794 188extern int verbose, done, time_bounded, output_all_data, seek_absolute;
f028c958 189extern int easy_parse_avgs;
63eba147 190extern unsigned int n_devs;
6eb42155 191extern unsigned long n_traces;
4c48f14e 192extern struct list_head all_devs, all_procs;
63eba147 193extern struct avgs_info all_avgs;
4c48f14e 194extern __u64 last_q;
63eba147 195extern struct region_info all_regions;
8b10aae0 196extern struct list_head all_ios, free_ios;
21e47d90 197extern __u64 iostat_interval, iostat_last_stamp;
6eb42155 198extern time_t genesis, last_vtrace;
001b2633 199extern double t_astart, t_aend;
fa0ab85d 200extern __u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS];
63eba147 201
6eb42155 202/* args.c */
63eba147 203void handle_args(int argc, char *argv[]);
c8aea612 204void clean_args();
6eb42155 205
4ae2c3c6
AB
206/* aqd.c */
207void *aqd_init(char *str);
2baef508
AB
208void aqd_exit(void *info);
209void aqd_clean(void);
4ae2c3c6
AB
210void aqd_issue(void *info, double ts);
211void aqd_complete(void *info, double ts);
212
69040794 213/* devmap.c */
63eba147 214int dev_map_read(char *fname);
6eb42155 215struct devmap *dev_map_find(__u32 device);
69040794 216void dev_map_exit(void);
63eba147 217
6eb42155
ADB
218/* devs.c */
219void init_dev_heads(void);
095181f2 220struct d_info *dip_add(__u32 device, struct io *iop);
6eb42155
ADB
221void dip_rem(struct io *iop);
222struct d_info *__dip_find(__u32 device);
095181f2 223void dip_foreach_list(struct io *iop, enum iop_type type, struct list_head *hd);
8b10aae0 224void dip_foreach(struct io *iop, enum iop_type type,
6eb42155
ADB
225 void (*fnc)(struct io *iop, struct io *this), int rm_after);
226struct io *dip_find_sec(struct d_info *dip, enum iop_type type, __u64 sec);
227void dip_foreach_out(void (*func)(struct d_info *, void *), void *arg);
b2822cea 228void dip_plug(__u32 dev, double cur_time);
b70a6642
AB
229void dip_unplug(__u32 dev, double cur_time, __u64 nio_ups);
230void dip_unplug_tm(__u32 dev, __u64 nio_ups);
69040794 231void dip_exit(void);
6eb42155
ADB
232
233/* dip_rb.c */
095181f2 234int rb_insert(struct rb_root *root, struct io *iop);
6eb42155 235struct io *rb_find_sec(struct rb_root *root, __u64 sec);
8b10aae0 236void rb_foreach(struct rb_node *n, struct io *iop,
6eb42155
ADB
237 void (*fnc)(struct io *iop, struct io *this),
238 struct list_head *head);
239
240/* iostat.c */
21e47d90 241void iostat_init(void);
4c48f14e 242void iostat_getrq(struct io *iop);
21e47d90
ADB
243void iostat_merge(struct io *iop);
244void iostat_issue(struct io *iop);
6eb42155
ADB
245void iostat_unissue(struct io *iop);
246void iostat_complete(struct io *d_iop, struct io *c_iop);
21e47d90
ADB
247void iostat_check_time(__u64 stamp);
248void iostat_dump_stats(__u64 stamp, int all);
249
6eb42155 250/* latency.c */
b2ecdd0f
ADB
251void latency_init(struct d_info *dip);
252void latency_clean(void);
e47ada10 253void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency);
b2ecdd0f
ADB
254void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency);
255void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency);
256
6eb42155 257/* misc.c */
6eb42155 258int in_devices(struct blk_io_trace *t);
6eb42155
ADB
259void add_file(struct file_info **fipp, FILE *fp, char *oname);
260void clean_files(struct file_info **fipp);
69040794
AB
261void add_buf(void *buf);
262void clean_bufs(void);
84a26fcd 263char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens);
6eb42155
ADB
264void dbg_ping(void);
265
d76c5b81
AB
266/* mmap.c */
267void setup_ifile(char *fname);
268void cleanup_ifile(void);
269int next_trace(struct blk_io_trace *t, void **pdu);
32ff7e3b 270double pct_done(void);
d76c5b81 271
6eb42155
ADB
272/* output.c */
273int output_avgs(FILE *ofp);
274int output_ranges(FILE *ofp);
6eb42155
ADB
275
276/* proc.c */
277void add_process(__u32 pid, char *name);
278struct p_info *find_process(__u32 pid, char *name);
279void pip_update_q(struct io *iop);
280void pip_foreach_out(void (*f)(struct p_info *, void *), void *arg);
69040794
AB
281void pip_exit(void);
282
283/* bno_dump.c */
284void *bno_dump_init(__u32 device);
285void bno_dump_exit(void *param);
286void bno_dump_add(void *handle, struct io *iop);
287void bno_dump_clean(void);
6eb42155 288
2baef508
AB
289/* plat.c */
290void *plat_init(char *str);
291void plat_exit(void *info);
292void plat_clean(void);
293void plat_x2c(void *info, __u64 ts, __u64 latency);
294
951ea56c
AB
295/* q2d.c */
296void q2d_histo_add(void *priv, __u64 q2d);
297void *q2d_init(void);
298void q2d_release(void *priv);
299void q2d_display_header(FILE *fp);
300void q2d_display_dashes(FILE *fp);
301void q2d_display(FILE *fp, void *priv);
302int q2d_ok(void *priv);
303void q2d_acc(void *a1, void *a2);
304
6eb42155 305/* seek.c */
4c48f14e 306void *seeki_init(char *str);
69040794 307void seeki_exit(void *param);
6eb42155
ADB
308void seek_clean(void);
309void seeki_add(void *handle, struct io *iop);
310double seeki_mean(void *handle);
311long long seeki_nseeks(void *handle);
312long long seeki_median(void *handle);
313int seeki_mode(void *handle, struct mode *mp);
314
315/* trace.c */
316void add_trace(struct io *iop);
317
095181f2
JA
318/* trace_complete.c */
319void trace_complete(struct io *c_iop);
095181f2
JA
320
321/* trace_im.c */
c8b0b334
AB
322void run_im(struct io *im_iop, struct io *d_iop, struct io *c_iop);
323void run_unim(struct io *im_iop, struct io *d_iop, struct io *c_iop);
d76c5b81 324int ready_im(struct io *im_iop, struct io *c_iop);
095181f2
JA
325void trace_insert(struct io *i_iop);
326void trace_merge(struct io *m_iop);
4c48f14e 327void trace_getrq(struct io *g_iop);
354db430 328void trace_sleeprq(struct io *s_iop);
095181f2
JA
329
330/* trace_issue.c */
c8b0b334
AB
331void run_issue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
332void run_unissue(struct io *d_iop, struct io *u_iop, struct io *c_iop);
d76c5b81 333int ready_issue(struct io *d_iop, struct io *c_iop);
095181f2 334void trace_issue(struct io *d_iop);
095181f2 335
b2822cea 336/* trace_plug.c */
b70a6642 337__u64 get_nio_up(struct io *u_iop);
b2822cea
AB
338void trace_plug(struct io *p_iop);
339void trace_unplug_io(struct io *u_iop);
340void trace_unplug_timer(struct io *u_iop);
341
095181f2 342/* trace_queue.c */
c8b0b334 343void run_queue(struct io *q_iop, struct io *u_iop, struct io *c_iop);
d76c5b81 344int ready_queue(struct io *q_iop, struct io *c_iop);
095181f2 345void trace_queue(struct io *q_iop);
095181f2
JA
346
347/* trace_remap.c */
c8b0b334 348void run_remap(struct io *a_iop, struct io *u_iop, struct io *c_iop);
d76c5b81 349int ready_remap(struct io *a_iop, struct io *c_iop);
095181f2 350void trace_remap(struct io *a_iop);
095181f2
JA
351
352/* trace_requeue.c */
353void trace_requeue(struct io *r_iop);
095181f2 354
fc16a815
AB
355/* unplug_hist.c */
356void *unplug_hist_init(__u32 device);
357void unplug_hist_exit(void *arg);
358void unplug_hist_add(struct io *u_iop);
359
63eba147 360#include "inlines.h"