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 int rb_insert(struct rb_root *root, struct io *iop)
27 struct rb_node *parent = NULL;
28 struct rb_node **p = &root->rb_node;
29 __u64 __s, s = BIT_START(iop);
33 __iop = rb_entry(parent, struct io, rb_node);
34 __s = BIT_START(__iop);
41 rb_replace_node(parent, &iop->rb_node, root);
46 rb_link_node(&iop->rb_node, parent, p);
47 rb_insert_color(&iop->rb_node, root);
51 struct io *rb_find_sec(struct rb_root *root, __u64 sec)
54 struct rb_node *n = root->rb_node;
57 __iop = rb_entry(n, struct io, rb_node);
58 if (sec < BIT_START(__iop))
60 else if (sec > BIT_START(__iop))
69 void rb_foreach(struct rb_node *n, struct io *iop,
70 void (*fnc)(struct io *iop, struct io *this),
71 struct list_head *head)
74 struct io *this = rb_entry(n, struct io, rb_node);
75 __u64 iop_s = BIT_START(iop), iop_e = BIT_END(iop);
76 __u64 this_s = BIT_START(this), this_e = BIT_END(this);
78 if ((iop_s <= this_s) && (this_e <= iop_e)) {
79 if (fnc) fnc(iop, this);
81 list_add_tail(&this->f_head, head);
84 rb_foreach(n->rb_left, iop, fnc, head);
85 if ((this_e < iop_e) || (this_s < iop_s))
86 rb_foreach(n->rb_right, iop, fnc, head);