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);
31 ASSERT(root != NULL && iop != NULL);
34 __iop = rb_entry(parent, struct io, rb_node);
35 __s = BIT_START(__iop);
45 rb_link_node(&iop->rb_node, parent, p);
46 rb_insert_color(&iop->rb_node, root);
50 struct io *rb_find_sec(struct rb_root *root, __u64 sec)
53 struct rb_node *n = root->rb_node;
56 __iop = rb_entry(n, struct io, rb_node);
57 if (sec < BIT_START(__iop))
59 else if (sec >= BIT_END(__iop))
68 void rb_foreach(struct rb_node *n, struct io *iop,
69 void (*fnc)(struct io *iop, struct io *this),
70 struct list_head *head)
73 struct io *this = rb_entry(n, struct io, rb_node);
74 __u64 iop_s = BIT_START(iop), iop_e = BIT_END(iop);
75 __u64 this_s = BIT_START(this), this_e = BIT_END(this);
77 if ((iop_s <= this_s) && (this_e <= iop_e)) {
78 if (fnc) fnc(iop, this);
79 if (head) list_add_tail(&this->f_head, head);
82 rb_foreach(n->rb_left, iop, fnc, head);
84 rb_foreach(n->rb_right, iop, fnc, head);