Commit | Line | Data |
---|---|---|
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 |
49 | enum 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 | |
6eb42155 ADB |
63 | struct mode { |
64 | int most_seeks, nmds; | |
65 | long long *modes; | |
63eba147 JA |
66 | }; |
67 | ||
68 | struct io; | |
69 | struct io_list { | |
70 | struct list_head head; | |
71 | struct io *iop; | |
72 | int cy_users; | |
73 | }; | |
74 | ||
75 | struct avg_info { | |
76 | __u64 min, max, total; | |
77 | double avg; | |
78 | int n; | |
79 | }; | |
80 | ||
81 | struct avgs_info { | |
ae6d30f4 AB |
82 | struct avg_info q2q_dm; |
83 | struct avg_info q2a_dm; | |
84 | struct avg_info q2c_dm; | |
85 | ||
63eba147 | 86 | struct avg_info q2q; |
ae6d30f4 AB |
87 | struct avg_info q2a; |
88 | struct avg_info q2g; | |
354db430 | 89 | struct avg_info s2g; |
ae6d30f4 AB |
90 | struct avg_info g2i; |
91 | struct avg_info q2m; | |
92 | struct avg_info i2d; | |
93 | struct avg_info m2d; | |
63eba147 | 94 | struct avg_info d2c; |
ae6d30f4 | 95 | struct avg_info q2c; |
63eba147 JA |
96 | |
97 | struct avg_info blks; /* Blocks transferred */ | |
98 | }; | |
99 | ||
100 | struct range_info { | |
101 | struct list_head head; /* on: qranges OR cranges */ | |
102 | __u64 start, end; | |
103 | }; | |
104 | ||
105 | struct region_info { | |
106 | struct list_head qranges; | |
107 | struct list_head cranges; | |
63eba147 JA |
108 | }; |
109 | ||
63eba147 | 110 | struct p_info { |
63eba147 JA |
111 | struct region_info regions; |
112 | struct avgs_info avgs; | |
63eba147 | 113 | __u64 last_q; |
6eb42155 | 114 | __u32 pid; |
69040794 | 115 | char *name; |
63eba147 JA |
116 | }; |
117 | ||
21e47d90 | 118 | struct stats { |
6eb42155 | 119 | __u64 rqm[2], ios[2], sec[2], wait, svctm; |
21e47d90 | 120 | double last_qu_change, last_dev_change, tot_qusz, idle_time; |
6eb42155 | 121 | int cur_qusz, cur_dev; |
21e47d90 ADB |
122 | }; |
123 | ||
4a5cddba JA |
124 | struct stats_t { |
125 | double n; | |
126 | double rqm_s[2], ios_s[2], sec_s[2]; | |
127 | double avgrq_sz, avgqu_sz, await, svctm, p_util; | |
128 | }; | |
129 | ||
63eba147 | 130 | struct d_info { |
6eb42155 ADB |
131 | struct list_head all_head, hash_head; |
132 | void *heads; | |
63eba147 | 133 | struct region_info regions; |
a155ab98 | 134 | char *devmap, dip_name[256]; |
c053af42 | 135 | void *q2q_handle, *seek_handle, *bno_dump_handle, *up_hist_handle; |
2e37a10e | 136 | void *q2d_priv, *aqd_handle, *rstat_handle, *p_live_handle; |
e47ada10 | 137 | void *q2d_plat_handle, *q2c_plat_handle, *d2c_plat_handle; |
a22df989 | 138 | FILE *q2d_ofp, *d2c_ofp, *q2c_ofp, *pit_fp; |
6eb42155 | 139 | struct avgs_info avgs; |
21e47d90 | 140 | struct stats stats, all_stats; |
77f256cd | 141 | __u64 last_q, n_qs, n_ds; |
50f73899 | 142 | __u64 n_act_q, t_act_q; /* # currently active when Q comes in */ |
6eb42155 | 143 | __u32 device; |
b2822cea | 144 | |
11997716 | 145 | int pre_culling; |
bb4a6607 | 146 | int is_plugged, nplugs, nplugs_t; |
b70a6642 | 147 | __u64 nios_up, nios_upt; |
b2822cea | 148 | double start_time, last_plug, plugged_time, end_time; |
63eba147 JA |
149 | }; |
150 | ||
151 | struct io { | |
6eb42155 | 152 | struct rb_node rb_node; |
8b10aae0 | 153 | struct list_head f_head, a_head; |
63eba147 JA |
154 | struct d_info *dip; |
155 | struct p_info *pip; | |
6eb42155 | 156 | void *pdu; |
ae6d30f4 | 157 | __u64 bytes_left, g_time, i_time, m_time, d_time, c_time, d_sec, c_sec; |
354db430 | 158 | __u64 s_time; |
4c48f14e AB |
159 | __u32 d_nsec, c_nsec; |
160 | ||
d76c5b81 | 161 | struct blk_io_trace t; |
4c48f14e | 162 | |
ae6d30f4 | 163 | int linked; |
63eba147 | 164 | enum iop_type type; |
d76c5b81 | 165 | }; |
095181f2 | 166 | |
2e37a10e AB |
167 | struct p_live_info { |
168 | unsigned long nlives; | |
169 | double avg_live, avg_lull, p_live; | |
170 | }; | |
171 | ||
6eb42155 ADB |
172 | /* bt_timeline.c */ |
173 | ||
63eba147 | 174 | extern char bt_timeline_version[], *devices, *exes, *input_name, *output_name; |
095181f2 | 175 | extern char *seek_name, *iostat_name, *d2c_name, *q2c_name, *per_io_name; |
e47ada10 | 176 | extern char *bno_dump_name, *unplug_hist_name, *sps_name, *aqd_name, *q2d_name; |
a22df989 | 177 | extern char *per_io_trees; |
dbb8d92d | 178 | extern double range_delta, plat_freq, last_t_seen; |
c053af42 | 179 | extern FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *iostat_ofp, *per_io_ofp; |
84a26fcd | 180 | extern FILE *msgs_ofp; |
69040794 | 181 | extern int verbose, done, time_bounded, output_all_data, seek_absolute; |
2e37a10e | 182 | extern int easy_parse_avgs, ignore_remaps, do_p_live; |
63eba147 | 183 | extern unsigned int n_devs; |
6eb42155 | 184 | extern unsigned long n_traces; |
4c48f14e | 185 | extern struct list_head all_devs, all_procs; |
63eba147 | 186 | extern struct avgs_info all_avgs; |
4c48f14e | 187 | extern __u64 last_q; |
63eba147 | 188 | extern struct region_info all_regions; |
8b10aae0 | 189 | extern struct list_head all_ios, free_ios; |
21e47d90 | 190 | extern __u64 iostat_interval, iostat_last_stamp; |
6eb42155 | 191 | extern time_t genesis, last_vtrace; |
001b2633 | 192 | extern double t_astart, t_aend; |
fa0ab85d | 193 | extern __u64 q_histo[N_HIST_BKTS], d_histo[N_HIST_BKTS]; |
63eba147 | 194 | |
6eb42155 | 195 | /* args.c */ |
63eba147 | 196 | void handle_args(int argc, char *argv[]); |
c8aea612 | 197 | void clean_args(); |
6eb42155 | 198 | |
4ae2c3c6 | 199 | /* aqd.c */ |
a155ab98 | 200 | void *aqd_alloc(struct d_info *dip); |
c053af42 | 201 | void aqd_free(void *info); |
2baef508 | 202 | void aqd_clean(void); |
4ae2c3c6 AB |
203 | void aqd_issue(void *info, double ts); |
204 | void aqd_complete(void *info, double ts); | |
205 | ||
69040794 | 206 | /* devmap.c */ |
63eba147 | 207 | int dev_map_read(char *fname); |
c053af42 | 208 | char *dev_map_find(__u32 device); |
69040794 | 209 | void dev_map_exit(void); |
63eba147 | 210 | |
6eb42155 ADB |
211 | /* devs.c */ |
212 | void init_dev_heads(void); | |
c053af42 AB |
213 | struct d_info *dip_alloc(__u32 device, struct io *iop); |
214 | void iop_rem_dip(struct io *iop); | |
6eb42155 | 215 | struct d_info *__dip_find(__u32 device); |
095181f2 | 216 | void dip_foreach_list(struct io *iop, enum iop_type type, struct list_head *hd); |
8b10aae0 | 217 | void dip_foreach(struct io *iop, enum iop_type type, |
6eb42155 ADB |
218 | void (*fnc)(struct io *iop, struct io *this), int rm_after); |
219 | struct io *dip_find_sec(struct d_info *dip, enum iop_type type, __u64 sec); | |
220 | void dip_foreach_out(void (*func)(struct d_info *, void *), void *arg); | |
b2822cea | 221 | void dip_plug(__u32 dev, double cur_time); |
b70a6642 | 222 | void dip_unplug(__u32 dev, double cur_time, __u64 nio_ups); |
15d67efc | 223 | void dip_unplug_tm(__u32 dev, double cur_time, __u64 nio_ups); |
69040794 | 224 | void dip_exit(void); |
52481561 | 225 | void dip_cleanup(void); |
6eb42155 ADB |
226 | |
227 | /* dip_rb.c */ | |
095181f2 | 228 | int rb_insert(struct rb_root *root, struct io *iop); |
6eb42155 | 229 | struct io *rb_find_sec(struct rb_root *root, __u64 sec); |
8b10aae0 | 230 | void rb_foreach(struct rb_node *n, struct io *iop, |
6eb42155 ADB |
231 | void (*fnc)(struct io *iop, struct io *this), |
232 | struct list_head *head); | |
233 | ||
234 | /* iostat.c */ | |
21e47d90 | 235 | void iostat_init(void); |
4c48f14e | 236 | void iostat_getrq(struct io *iop); |
21e47d90 ADB |
237 | void iostat_merge(struct io *iop); |
238 | void iostat_issue(struct io *iop); | |
6eb42155 | 239 | void iostat_complete(struct io *d_iop, struct io *c_iop); |
21e47d90 ADB |
240 | void iostat_check_time(__u64 stamp); |
241 | void iostat_dump_stats(__u64 stamp, int all); | |
242 | ||
6eb42155 | 243 | /* latency.c */ |
c053af42 | 244 | void latency_alloc(struct d_info *dip); |
b2ecdd0f | 245 | void latency_clean(void); |
e47ada10 | 246 | void latency_q2d(struct d_info *dip, __u64 tstamp, __u64 latency); |
b2ecdd0f ADB |
247 | void latency_d2c(struct d_info *dip, __u64 tstamp, __u64 latency); |
248 | void latency_q2c(struct d_info *dip, __u64 tstamp, __u64 latency); | |
249 | ||
6eb42155 | 250 | /* misc.c */ |
c053af42 | 251 | void add_file(FILE *fp, char *oname); |
69040794 | 252 | void add_buf(void *buf); |
84a26fcd | 253 | char *make_dev_hdr(char *pad, size_t len, struct d_info *dip, int add_parens); |
a155ab98 | 254 | char *mkhandle(struct d_info *dip, char *str, size_t len); |
99bb5ebc | 255 | FILE *my_fopen(const char *path, const char *mode); |
e6855475 | 256 | int my_open(const char *path, int flags); |
6eb42155 | 257 | void dbg_ping(void); |
c053af42 | 258 | void clean_allocs(void); |
6eb42155 | 259 | |
d76c5b81 AB |
260 | /* mmap.c */ |
261 | void setup_ifile(char *fname); | |
262 | void cleanup_ifile(void); | |
263 | int next_trace(struct blk_io_trace *t, void **pdu); | |
32ff7e3b | 264 | double pct_done(void); |
d76c5b81 | 265 | |
6eb42155 ADB |
266 | /* output.c */ |
267 | int output_avgs(FILE *ofp); | |
268 | int output_ranges(FILE *ofp); | |
6eb42155 ADB |
269 | |
270 | /* proc.c */ | |
c053af42 | 271 | void process_alloc(__u32 pid, char *name); |
6eb42155 ADB |
272 | struct p_info *find_process(__u32 pid, char *name); |
273 | void pip_update_q(struct io *iop); | |
274 | void pip_foreach_out(void (*f)(struct p_info *, void *), void *arg); | |
69040794 AB |
275 | void pip_exit(void); |
276 | ||
277 | /* bno_dump.c */ | |
a155ab98 | 278 | void *bno_dump_alloc(struct d_info *dip); |
c053af42 | 279 | void bno_dump_free(void *param); |
69040794 AB |
280 | void bno_dump_add(void *handle, struct io *iop); |
281 | void bno_dump_clean(void); | |
6eb42155 | 282 | |
2baef508 | 283 | /* plat.c */ |
a155ab98 | 284 | void *plat_alloc(struct d_info *dip, char *post); |
c053af42 | 285 | void plat_free(void *info); |
2baef508 AB |
286 | void plat_clean(void); |
287 | void plat_x2c(void *info, __u64 ts, __u64 latency); | |
288 | ||
2e37a10e AB |
289 | /* p_live.c */ |
290 | void *p_live_alloc(void); | |
291 | void p_live_free(void *p); | |
292 | void p_live_add(struct d_info *dip, __u64 dt, __u64 ct); | |
293 | void p_live_exit(void); | |
294 | struct p_live_info *p_live_get(struct d_info *dip, int base_y); | |
295 | ||
951ea56c AB |
296 | /* q2d.c */ |
297 | void q2d_histo_add(void *priv, __u64 q2d); | |
c053af42 AB |
298 | void *q2d_alloc(void); |
299 | void q2d_free(void *priv); | |
951ea56c AB |
300 | void q2d_display_header(FILE *fp); |
301 | void q2d_display_dashes(FILE *fp); | |
302 | void q2d_display(FILE *fp, void *priv); | |
303 | int q2d_ok(void *priv); | |
304 | void q2d_acc(void *a1, void *a2); | |
305 | ||
dbb8d92d | 306 | /* rstats.c */ |
a155ab98 | 307 | void *rstat_alloc(struct d_info *dip); |
dbb8d92d AB |
308 | void rstat_free(void *ptr); |
309 | void rstat_add(void *ptr, double cur, unsigned long long nblks); | |
310 | int rstat_init(void); | |
311 | void rstat_exit(void); | |
312 | ||
6eb42155 | 313 | /* seek.c */ |
a155ab98 | 314 | void *seeki_alloc(struct d_info *dip, char *post); |
c053af42 | 315 | void seeki_free(void *param); |
6eb42155 ADB |
316 | void seek_clean(void); |
317 | void seeki_add(void *handle, struct io *iop); | |
318 | double seeki_mean(void *handle); | |
319 | long long seeki_nseeks(void *handle); | |
320 | long long seeki_median(void *handle); | |
321 | int seeki_mode(void *handle, struct mode *mp); | |
322 | ||
323 | /* trace.c */ | |
324 | void add_trace(struct io *iop); | |
325 | ||
095181f2 JA |
326 | /* trace_complete.c */ |
327 | void trace_complete(struct io *c_iop); | |
095181f2 JA |
328 | |
329 | /* trace_im.c */ | |
c8b0b334 AB |
330 | void run_im(struct io *im_iop, struct io *d_iop, struct io *c_iop); |
331 | void run_unim(struct io *im_iop, struct io *d_iop, struct io *c_iop); | |
d76c5b81 | 332 | int ready_im(struct io *im_iop, struct io *c_iop); |
095181f2 JA |
333 | void trace_insert(struct io *i_iop); |
334 | void trace_merge(struct io *m_iop); | |
4c48f14e | 335 | void trace_getrq(struct io *g_iop); |
354db430 | 336 | void trace_sleeprq(struct io *s_iop); |
095181f2 JA |
337 | |
338 | /* trace_issue.c */ | |
c8b0b334 AB |
339 | void run_issue(struct io *d_iop, struct io *u_iop, struct io *c_iop); |
340 | void run_unissue(struct io *d_iop, struct io *u_iop, struct io *c_iop); | |
d76c5b81 | 341 | int ready_issue(struct io *d_iop, struct io *c_iop); |
095181f2 | 342 | void trace_issue(struct io *d_iop); |
095181f2 | 343 | |
b2822cea AB |
344 | /* trace_plug.c */ |
345 | void trace_plug(struct io *p_iop); | |
346 | void trace_unplug_io(struct io *u_iop); | |
347 | void trace_unplug_timer(struct io *u_iop); | |
348 | ||
095181f2 | 349 | /* trace_queue.c */ |
c8b0b334 | 350 | void run_queue(struct io *q_iop, struct io *u_iop, struct io *c_iop); |
d76c5b81 | 351 | int ready_queue(struct io *q_iop, struct io *c_iop); |
095181f2 | 352 | void trace_queue(struct io *q_iop); |
095181f2 JA |
353 | |
354 | /* trace_remap.c */ | |
c8b0b334 | 355 | void run_remap(struct io *a_iop, struct io *u_iop, struct io *c_iop); |
d76c5b81 | 356 | int ready_remap(struct io *a_iop, struct io *c_iop); |
095181f2 | 357 | void trace_remap(struct io *a_iop); |
095181f2 JA |
358 | |
359 | /* trace_requeue.c */ | |
360 | void trace_requeue(struct io *r_iop); | |
095181f2 | 361 | |
fc16a815 | 362 | /* unplug_hist.c */ |
a155ab98 | 363 | void *unplug_hist_alloc(struct d_info *dip); |
c053af42 | 364 | void unplug_hist_free(void *arg); |
fc16a815 AB |
365 | void unplug_hist_add(struct io *u_iop); |
366 | ||
63eba147 | 367 | #include "inlines.h" |