aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2014-01-14 10:37:15 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-01-17 09:11:01 -0500
commitb965bb41061ad8d3eafda6e7feef89279fcd3916 (patch)
treeef1dd5d78609698145352c1e51d22574dced03df /tools
parent3178f58b989430fd0721df97bf21cf1c0e8cc419 (diff)
perf callchain: Spare double comparison of callchain first entry
When a new callchain child branch matches an existing one in the rbtree, the comparison of its first entry is performed twice: 1) From append_chain_children() on branch lookup 2) If 1) reports a match, append_chain() then compares all entries of the new branch against the matching node in the rbtree, and this comparison includes the first entry of the new branch again. Lets shortcut this by performing the whole comparison only from append_chain() which then returns the result of the comparison between the first entry of the new branch and the iterating node in the rbtree. If the first entry matches, the lookup on the current level of siblings stops and propagates to the children of the matching nodes. This results in less comparisons performed by the CPU. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1389713836-13375-3-git-send-email-fweisbec@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/callchain.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 9eb4f57f8663..662867d5c374 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -15,6 +15,8 @@
15#include <errno.h> 15#include <errno.h>
16#include <math.h> 16#include <math.h>
17 17
18#include "asm/bug.h"
19
18#include "hist.h" 20#include "hist.h"
19#include "util.h" 21#include "util.h"
20#include "sort.h" 22#include "sort.h"
@@ -358,19 +360,14 @@ append_chain_children(struct callchain_node *root,
358 /* lookup in childrens */ 360 /* lookup in childrens */
359 while (*p) { 361 while (*p) {
360 s64 ret; 362 s64 ret;
361 struct callchain_list *cnode;
362 363
363 parent = *p; 364 parent = *p;
364 rnode = rb_entry(parent, struct callchain_node, rb_node_in); 365 rnode = rb_entry(parent, struct callchain_node, rb_node_in);
365 cnode = list_first_entry(&rnode->val, struct callchain_list,
366 list);
367 366
368 /* just check first entry */ 367 /* If at least first entry matches, rely to children */
369 ret = match_chain(node, cnode); 368 ret = append_chain(rnode, cursor, period);
370 if (ret == 0) { 369 if (ret == 0)
371 append_chain(rnode, cursor, period);
372 goto inc_children_hit; 370 goto inc_children_hit;
373 }
374 371
375 if (ret < 0) 372 if (ret < 0)
376 p = &parent->rb_left; 373 p = &parent->rb_left;
@@ -396,6 +393,7 @@ append_chain(struct callchain_node *root,
396 u64 start = cursor->pos; 393 u64 start = cursor->pos;
397 bool found = false; 394 bool found = false;
398 u64 matches; 395 u64 matches;
396 int cmp = 0;
399 397
400 /* 398 /*
401 * Lookup in the current node 399 * Lookup in the current node
@@ -410,7 +408,8 @@ append_chain(struct callchain_node *root,
410 if (!node) 408 if (!node)
411 break; 409 break;
412 410
413 if (match_chain(node, cnode) != 0) 411 cmp = match_chain(node, cnode);
412 if (cmp)
414 break; 413 break;
415 414
416 found = true; 415 found = true;
@@ -420,9 +419,10 @@ append_chain(struct callchain_node *root,
420 419
421 /* matches not, relay no the parent */ 420 /* matches not, relay no the parent */
422 if (!found) { 421 if (!found) {
422 WARN_ONCE(!cmp, "Chain comparison error\n");
423 cursor->curr = curr_snap; 423 cursor->curr = curr_snap;
424 cursor->pos = start; 424 cursor->pos = start;
425 return -1; 425 return cmp;
426 } 426 }
427 427
428 matches = cursor->pos - start; 428 matches = cursor->pos - start;