2 * blktrace output analysis: generate a timeline & gather statistics
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
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.
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.
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
23 LIST_HEAD(pending_cs);
25 static inline void __run_complete(struct io *c_iop)
29 if (remapper_dev(c_iop->t.device)) {
31 struct io *iop = bilink_first_down(c_iop, &blp);
33 if (iop->type == IOP_Q) {
34 run_queue(iop, c_iop, &rmhd);
38 bilink_for_each_down(run_remap, c_iop, &rmhd, 1);
41 bilink_for_each_down(run_issue, c_iop, &rmhd, 1);
45 LIST_DEL(&c_iop->c_pending);
48 list_add_tail(&c_iop->f_head, &rmhd);
52 static int ready_complete_remapper(struct io *c_iop)
55 struct list_head *p, *q;
57 dip_foreach_list(c_iop, IOP_L, &head);
58 if (list_empty(&head)) {
61 dip_foreach_list(c_iop, IOP_Q, &head);
62 list_for_each_safe(p, q, &head) {
63 q_iop = list_entry(p, struct io, f_head);
64 LIST_DEL(&q_iop->f_head);
66 ASSERT(list_empty(&q_iop->up_list));
67 ASSERT(list_empty(&q_iop->down_list));
68 ASSERT(q_iop->t.bytes == c_iop->t.bytes);
69 if (ready_queue(q_iop, c_iop)) {
72 c_iop->bytes_left -= q_iop->t.bytes;
77 struct io *l_iop, *a_iop;
79 list_for_each_safe(p, q, &head) {
80 l_iop = list_entry(p, struct io, f_head);
81 LIST_DEL(&l_iop->f_head);
83 ASSERT(!list_empty(&l_iop->up_list));
84 a_iop = bilink_first_up(l_iop, NULL);
85 if (ready_remap(a_iop, c_iop)) {
88 c_iop->bytes_left -= a_iop->t.bytes;
93 return c_iop->bytes_left == 0;
96 int ready_complete(struct io *c_iop)
101 if (c_iop->bytes_left == 0)
104 if (remapper_dev(c_iop->t.device))
105 return ready_complete_remapper(c_iop);
107 if (!list_empty(&c_iop->down_list))
110 d_iop = dip_find_sec(c_iop->dip, IOP_D, BIT_START(c_iop));
114 if (c_iop->t.bytes != d_iop->t.bytes) {
116 "\nFATAL: Probable time anomaly detected\n");
118 "D @ %15.9lf missing C, later C @ %15.9lf\n",
119 BIT_TIME(d_iop->t.time),
120 BIT_TIME(c_iop->t.time));
124 if (!ready_issue(d_iop, c_iop))
127 c_iop->bytes_left = 0;
129 d2c = tdelta(d_iop, c_iop);
130 update_d2c(d_iop, d_iop->down_len, d2c);
131 latency_d2c(d_iop->dip, c_iop->t.time, d2c);
132 iostat_complete(d_iop, c_iop);
134 bilink(d_iop, c_iop);
139 void trace_complete(struct io *c_iop)
141 if (io_setup(c_iop, IOP_C)) {
143 update_cregion(&all_regions, c_iop->t.time);
144 update_cregion(&c_iop->dip->regions, c_iop->t.time);
146 update_cregion(&c_iop->pip->regions, c_iop->t.time);
148 list_add_tail(&c_iop->c_pending, &pending_cs);
149 switch (ready_complete(c_iop)) {
151 __run_complete(c_iop);
157 LIST_DEL(&c_iop->c_pending);
167 void retry_complete(struct io *c_iop, __u64 now)
169 double tc = BIT_TIME(c_iop->t.time);
171 switch (ready_complete(c_iop)) {
174 fprintf(stderr, "Retried %15.9lf success!\n", tc);
176 __run_complete(c_iop);
179 if (now == 0 || ((BIT_TIME(now) - tc) < 1.0))
181 if (!list_empty(&c_iop->down_list))
185 LIST_DEL(&c_iop->c_pending);