A couple of weeks ago Ming Zhang had noted that btt was using tremendous
[blktrace.git] / btt / trace_issue.c
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 "globals.h"
22
23 static void __run_issue(struct io *im_iop, struct io *d_iop, struct io *c_iop)
24 {
25         update_i2d(im_iop, tdelta(im_iop, d_iop));
26         run_im(im_iop, d_iop, c_iop);
27         dump_iop(d_iop, 0);
28 }
29
30 static void __run_unissue(struct io *im_iop, struct io *d_iop, 
31                           struct io *c_iop)
32 {
33         unupdate_i2d(im_iop, tdelta(im_iop, d_iop));
34         run_unim(im_iop, d_iop, c_iop);
35 }
36
37 void run_issue(struct io *d_iop, __attribute__((__unused__))struct io *u_iop, 
38                                                         struct io *c_iop)
39 {
40         bilink_for_each_down(__run_issue, d_iop, c_iop, 1);
41         add_rmhd(d_iop);
42 }
43
44 void run_unissue(struct io *d_iop, 
45                  __attribute__((__unused__))struct io *u_iop, 
46                  struct io *c_iop)
47 {
48         bilink_for_each_down(__run_unissue, d_iop, c_iop, 1);
49         add_rmhd(d_iop);
50 }
51
52 int ready_issue(struct io *d_iop, struct io *c_iop)
53 {
54         if (d_iop->bytes_left > 0) {
55                 LIST_HEAD(head);
56                 struct io *im_iop;
57                 struct list_head *p, *q;
58
59                 dip_foreach_list(d_iop, IOP_I, &head);
60                 dip_foreach_list(d_iop, IOP_M, &head);
61                 list_for_each_safe(p, q, &head) {
62                         im_iop = list_entry(p, struct io, f_head);
63                         LIST_DEL(&im_iop->f_head);
64
65                         ASSERT(d_iop->bytes_left >= im_iop->t.bytes);
66                         if (ready_im(im_iop, c_iop)) {
67                                 bilink(im_iop, d_iop);
68                                 dip_rem(im_iop);
69                                 d_iop->bytes_left -= im_iop->t.bytes;
70                         }
71                 }
72         }
73
74         return d_iop->bytes_left == 0;
75 }
76
77 void trace_issue(struct io *d_iop)
78 {
79         if (io_setup(d_iop, IOP_D)) {
80                 seeki_add(d_iop->dip->seek_handle, d_iop);
81                 iostat_issue(d_iop);
82                 d_iop->dip->n_ds++;
83                 if (!remapper_dev(d_iop->t.device))
84                         update_d_histo(d_iop->t.bytes);
85         }
86         else
87                 io_release(d_iop);
88
89 }