perf callchain: Spare double comparison of callchain first entry
authorFrederic Weisbecker <fweisbec@gmail.com>
Tue, 14 Jan 2014 15:37:15 +0000 (16:37 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 17 Jan 2014 14:11:01 +0000 (11:11 -0300)
commitb965bb41061ad8d3eafda6e7feef89279fcd3916
treeef1dd5d78609698145352c1e51d22574dced03df
parent3178f58b989430fd0721df97bf21cf1c0e8cc419
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>
tools/perf/util/callchain.c