[PATCH] btt: seek additions
[blktrace.git] / btt / globals.h
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>
24
25 #include "blktrace.h"
26 #include "list.h"
27
28 #define pdu_start(t)    (((void *) (t) + sizeof(struct blk_io_trace)))
29
30 #define BIT_TIME(t)     ((double)SECONDS(t) + ((double)NANO_SECONDS(t) / 1.0e9))
31
32 #define BIT_START(iop)  ((iop)->t.sector)
33 #define BIT_END(iop)    ((iop)->t.sector + ((iop)->t.bytes >> 9))
34 #define IOP_READ(iop)   ((iop)->t.action & BLK_TC_ACT(BLK_TC_READ))
35
36 #if defined(DEBUG)
37 #define ASSERT(truth)   do {                                            \
38                                 if (!(truth)) {                         \
39                                         DBG_PING();                     \
40                                         assert(truth);                  \
41                                 }                                       \
42                         } while (0)
43
44 #define DBG_PING()              dbg_ping()
45
46 #define LIST_DEL(hp)    list_del(hp)
47
48 #else
49 #define ASSERT(truth)
50 #define DBG_PING()
51
52 #define LIST_DEL(hp)    do {                                            \
53                                 if (((hp)->next != NULL) &&             \
54                                     ((hp)->next != LIST_POISON1))       \
55                                         list_del(hp);                   \
56                         } while (0)
57 #endif
58
59 #define IO_ZALLOC()     my_zmalloc(&free_ios, sizeof(struct io))
60 #define IO_FREE(iop)    my_free(&free_ios, iop)
61
62 enum iop_type {
63         IOP_Q = 0,
64         IOP_X = 1,
65         IOP_A = 2,
66         IOP_M = 3,
67         IOP_I = 4,
68         IOP_D = 5,
69         IOP_C = 6,
70         IOP_Y = 7,
71 };
72 #define N_IOP_TYPES     (IOP_Y + 1)
73
74 struct my_mem {
75         struct my_mem *next;
76 };
77
78 struct io;
79 struct io_list {
80         struct list_head head;
81         struct io *iop;
82         int cy_users;
83 };
84
85 struct avg_info {
86         __u64 min, max, total;
87         double avg;
88         int n;
89 };
90
91 struct avgs_info {
92         struct avg_info q2q;
93         struct avg_info q2c;
94         struct avg_info q2a;            /* Q to (A or X) */
95         struct avg_info q2i;            /* Q to (I or M) */
96         struct avg_info i2d;            /* (I or M) to D */
97         struct avg_info d2c;
98
99         struct avg_info blks;           /* Blocks transferred */
100 };
101
102 struct range_info {
103         struct list_head head;          /* on: qranges OR cranges */
104         __u64 start, end;
105 };
106
107 struct region_info {
108         struct list_head qranges;
109         struct list_head cranges;
110         struct range_info *qr_cur, *cr_cur;
111 };
112
113 struct p_info;
114 struct p_pid {
115         struct list_head head;
116         struct p_info *pip;
117         __u32 pid;
118 };
119
120 struct p_info {
121         struct list_head head;
122         struct region_info regions;
123         struct avgs_info avgs;
124         char *name;
125         __u64 last_q;
126 };
127
128 struct devmap {
129         struct devmap *next;
130         char device[32];
131         char model[64];
132         unsigned int host, bus, target, lun;
133         char node[32], pci[32];
134         unsigned int irq, cpu;
135         char devno[32];
136 };
137
138 struct d_info {
139         struct list_head head, hash_head;
140         struct list_head iop_heads[N_IOP_TYPES];
141         struct region_info regions;
142         struct avgs_info avgs;
143         __u64 last_q;
144         __u32 device;
145         __u64 n_ds;
146         struct devmap *map;
147         void *seek_handle;
148 };
149
150 struct io {
151         struct list_head all_head, dev_head;
152         struct d_info *dip;
153         struct p_info *pip;
154         void *pdu;
155
156         struct blk_io_trace t;
157
158         int users, traversed;
159         enum iop_type type;
160
161         union {
162                 struct {
163                         union {
164                                 struct io *q_a;
165                                 struct io *q_x;
166                         } qp;
167                         enum {
168                                 Q_NONE = 10,
169                                 Q_A = 20,
170                                 Q_X = 30,
171                         } qp_type;
172                 }                                         q;
173                 struct { struct io *x_q;                } x;
174                 struct { struct io *a_q;                } a;
175                 struct { struct io *m_q;                } m;
176                 struct { struct list_head i_qs_head;    } i;
177                 struct { struct list_head d_im_head;    } d;
178                 struct { struct io *c_d;                } c;
179                 struct { struct io *y_c1, *y_c2;        } y;
180         } u;
181 };
182
183 extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name;
184 extern char *seek_name;
185 extern double range_delta;
186 extern FILE *ranges_ofp, *avgs_ofp;
187 extern int is_lvm, verbose, ifd;
188 extern unsigned int n_devs;
189 extern unsigned long n_traces, n_io_allocs, n_io_frees;
190 extern struct list_head all_devs, all_ios, all_procs;
191 extern struct avgs_info all_avgs;
192 extern __u64 last_q;
193 extern struct region_info all_regions;
194 extern struct my_mem *free_ios, *free_bits;
195 extern char iop_map[];
196 extern unsigned int pending_xs;
197
198 void add_trace(struct io *iop);
199 int in_devices(struct blk_io_trace *t);
200 int output_avgs(FILE *ofp);
201 int output_ranges(FILE *ofp);
202 unsigned int do_read(int ifd, void *buf, int len);
203 void add_process(__u32 pid, char *name);
204 struct p_info *find_process(__u32 pid, char *name);
205 void pip_update_q(struct io *iop);
206 void handle_args(int argc, char *argv[]);
207 struct devmap *dev_map_find(__u32 device);
208 int dev_map_read(char *fname);
209 void add_cy(struct io *iop);
210 void rem_c(struct io *iop);
211 void cy_init(void);
212 void cy_shutdown(void);
213 struct d_info *__dip_find(__u32 device);
214 struct d_info *dip_add(__u32 device, struct io *iop);
215 void traverse(struct io *iop);
216 void io_free_resources(struct io *iop);
217 void *seeki_init(__u32 device);
218 void seeki_add(void *handle, struct io *iop);
219 double seeki_mean(void *handle);
220 long long seeki_nseeks(void *handle);
221 long long seeki_median(void *handle);
222 int seeki_mode(void *handle, long long **modes_p, int *nseeks_p);
223
224 #include "inlines.h"