[PATCH] BTT patch: (2/3) per-IO stream output
[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 void trace_issue(struct io *d_iop)
24 {
25         if (!io_setup(d_iop, IOP_D)) {
26                 io_release(d_iop);
27                 return;
28         }
29
30         if (seek_name)
31                 seeki_add(d_iop->dip->seek_handle, d_iop);
32         iostat_issue(d_iop);
33         d_iop->dip->n_ds++;
34 }
35
36 int ready_issue(struct io *d_iop, struct io *top)
37 {
38         LIST_HEAD(head);
39         struct io *im_iop;
40         struct list_head *p, *q;
41         __u64 bl = d_iop->bytes_left;
42
43         dip_foreach_list(d_iop, IOP_I, &head);
44         dip_foreach_list(d_iop, IOP_M, &head);
45         list_for_each_safe(p, q, &head) {
46                 im_iop = list_entry(p, struct io, f_head);
47                 LIST_DEL(&im_iop->f_head);
48
49                 if (!ready_im(im_iop, top))
50                         return 0;
51
52                 bl -= im_iop->bytes_left;
53         }
54
55         return bl == 0;
56 }
57
58 void run_issue(struct io *d_iop, struct io *top, struct list_head *del_head)
59 {
60         LIST_HEAD(head);
61         struct list_head *p, *q;
62         struct io *im_iop;
63
64         dip_foreach_list(d_iop, IOP_I, &head);
65         dip_foreach_list(d_iop, IOP_M, &head);
66         list_for_each_safe(p, q, &head) {
67                 im_iop = list_entry(p, struct io, f_head);
68                 LIST_DEL(&im_iop->f_head);
69
70                 update_i2d(im_iop, tdelta(im_iop, d_iop));
71
72                 __link(im_iop, d_iop);
73                 run_im(im_iop, top, del_head);
74                 __unlink(im_iop, d_iop);
75         }
76
77         dump_iop(per_io_ofp, d_iop, NULL, 0);
78         list_add_tail(&d_iop->f_head, del_head);
79 }
80
81 void run_unissue(struct io *d_iop, struct list_head *del_head)
82 {
83         LIST_HEAD(head);
84         struct io *im_iop;
85         struct list_head *p, *q;
86
87         iostat_unissue(d_iop);
88
89         dip_foreach_list(d_iop, IOP_I, &head);
90         dip_foreach_list(d_iop, IOP_M, &head);
91         list_for_each_safe(p, q, &head) {
92                 im_iop = list_entry(p, struct io, f_head);
93                 LIST_DEL(&im_iop->f_head);
94
95                 __link(im_iop, d_iop);
96                 unupdate_i2d(im_iop, tdelta(im_iop, d_iop));
97                 run_unim(im_iop, del_head);
98                 __unlink(im_iop, d_iop);
99         }
100
101         list_add_tail(&d_iop->f_head, del_head);
102 }