Commit 14f4654c authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar

perf_counter tools: Create new chain_for_each_child() iterator

Iterating through children of a node in the callchain tree
shows something that may be quite confusing at a first glance.
The head is the children field of the parent and the list nodes
are in the brothers field of the children.

This is because the childs are linked to the parent as a list
of "brothers" using the "children" list of the parent as a
head:

  ---------------
 | Parent (head) |-------------------------------------
  ---------------                                      |
     |                                                 |
  children                                             |
     |                                                 |
  -----------               -----------                |
 | 1st child |---brother---| 2nd child |---brother-----
  -----------               -----------

This makes the following strange pattern often occuring:

 list_for_each_entry(child, &parent->children, brothers) {
        // do something with children
 }

Abstract it to chain_for_each_child() to factorize and simplify
this pattern.
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1246550301-8954-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 42976487
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include "callchain.h" #include "callchain.h"
#define chain_for_each_child(child, parent) \
list_for_each_entry(child, &parent->children, brothers)
static void static void
rb_insert_callchain(struct rb_root *root, struct callchain_node *chain) rb_insert_callchain(struct rb_root *root, struct callchain_node *chain)
...@@ -46,7 +49,7 @@ void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node) ...@@ -46,7 +49,7 @@ void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node)
{ {
struct callchain_node *child; struct callchain_node *child;
list_for_each_entry(child, &node->children, brothers) chain_for_each_child(child, node)
sort_chain_to_rbtree(rb_root, child); sort_chain_to_rbtree(rb_root, child);
if (node->hit) if (node->hit)
...@@ -77,7 +80,7 @@ create_child(struct callchain_node *parent, bool inherit_children) ...@@ -77,7 +80,7 @@ create_child(struct callchain_node *parent, bool inherit_children)
list_splice(&parent->children, &new->children); list_splice(&parent->children, &new->children);
INIT_LIST_HEAD(&parent->children); INIT_LIST_HEAD(&parent->children);
list_for_each_entry(next, &new->children, brothers) chain_for_each_child(next, new)
next->parent = new; next->parent = new;
} }
list_add_tail(&new->brothers, &parent->children); list_add_tail(&new->brothers, &parent->children);
...@@ -173,7 +176,7 @@ __append_chain_children(struct callchain_node *root, struct ip_callchain *chain, ...@@ -173,7 +176,7 @@ __append_chain_children(struct callchain_node *root, struct ip_callchain *chain,
struct callchain_node *rnode; struct callchain_node *rnode;
/* lookup in childrens */ /* lookup in childrens */
list_for_each_entry(rnode, &root->children, brothers) { chain_for_each_child(rnode, root) {
unsigned int ret = __append_chain(rnode, chain, start, syms); unsigned int ret = __append_chain(rnode, chain, start, syms);
if (!ret) if (!ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment