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
24 #define N_DEV_HASH 128
25 #define DEV_HASH(dev) ((MAJOR(dev) ^ MINOR(dev)) & (N_DEV_HASH - 1))
26 struct list_head dev_heads[N_DEV_HASH];
28 void init_dev_heads(void)
31 for (i = 0; i < N_DEV_HASH; i++)
32 INIT_LIST_HEAD(&dev_heads[i]);
35 struct d_info *__dip_find(__u32 device)
40 __list_for_each(p, &dev_heads[DEV_HASH(device)]) {
41 dip = list_entry(p, struct d_info, hash_head);
42 if (device == dip->device)
49 struct d_info *dip_add(__u32 device, struct io *iop)
51 struct d_info *dip = __dip_find(device);
54 dip = malloc(sizeof(struct d_info));
55 dip->heads = dip_rb_mkhds();
56 init_region(&dip->regions);
58 dip->last_q = (__u64)-1;
59 dip->map = dev_map_find(device);
60 dip->seek_handle = seeki_init(device);
62 memset(&dip->stats, 0, sizeof(dip->stats));
63 memset(&dip->all_stats, 0, sizeof(dip->all_stats));
64 list_add_tail(&dip->hash_head, &dev_heads[DEV_HASH(device)]);
65 list_add_tail(&dip->all_head, &all_devs);
69 iop->linked = dip_rb_ins(dip, iop);
73 void dip_rem(struct io *iop)
78 void dip_foreach(struct io *iop, enum iop_type type,
79 void (*fnc)(struct io *iop, struct io *this), int rm_after)
84 struct list_head *p, *q;
86 dip_rb_fe(iop->dip, type, iop, fnc, &head);
87 list_for_each_safe(p, q, &head) {
88 this = list_entry(p, struct io, f_head);
89 LIST_DEL(&this->f_head);
94 dip_rb_fe(iop->dip, type, iop, fnc, NULL);
97 void dip_foreach_list(struct io *iop, enum iop_type type, struct list_head *hd)
99 dip_rb_fe(iop->dip, type, iop, NULL, hd);
102 struct io *dip_find_sec(struct d_info *dip, enum iop_type type, __u64 sec)
104 return dip_rb_find_sec(dip, type, sec);
107 void dip_foreach_out(void (*func)(struct d_info *, void *), void *arg)
109 if (devices == NULL) {
111 __list_for_each(p, &all_devs)
112 func(list_entry(p, struct d_info, all_head), arg);
117 unsigned int mjr, mnr;
120 while (p && ((i = sscanf(p, "%u,%u", &mjr, &mnr)) == 2)) {
121 dip = __dip_find((__u32)((mjr << MINORBITS) | mnr));