From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751762AbaANPhf (ORCPT ); Tue, 14 Jan 2014 10:37:35 -0500 Received: from mail-ea0-f171.google.com ([209.85.215.171]:46069 "EHLO mail-ea0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbaANPhb (ORCPT ); Tue, 14 Jan 2014 10:37:31 -0500 From: Frederic Weisbecker To: Arnaldo Carvalho de Melo Cc: LKML , Frederic Weisbecker , Adrian Hunter , David Ahern , Ingo Molnar , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Stephane Eranian Subject: [PATCH 2/3] perf tools: Spare double comparison of callchain first entry Date: Tue, 14 Jan 2014 16:37:15 +0100 Message-Id: <1389713836-13375-3-git-send-email-fweisbec@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1389713836-13375-1-git-send-email-fweisbec@gmail.com> References: <1389713836-13375-1-git-send-email-fweisbec@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Adrian Hunter Cc: David Ahern Cc: Ingo Molnar Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian --- tools/perf/util/callchain.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index e3970e3..e5ed16d 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -15,6 +15,8 @@ #include #include +#include "asm/bug.h" + #include "hist.h" #include "util.h" #include "callchain.h" @@ -356,19 +358,14 @@ append_chain_children(struct callchain_node *root, /* lookup in childrens */ while (*p) { s64 ret; - struct callchain_list *cnode; parent = *p; rnode = rb_entry(parent, struct callchain_node, rb_node_in); - cnode = list_first_entry(&rnode->val, struct callchain_list, - list); - /* just check first entry */ - ret = match_chain(node, cnode); - if (ret == 0) { - append_chain(rnode, cursor, period); + /* If at least first entry matches, rely to children */ + ret = append_chain(rnode, cursor, period); + if (ret == 0) goto inc_children_hit; - } if (ret < 0) p = &parent->rb_left; @@ -394,6 +391,7 @@ append_chain(struct callchain_node *root, u64 start = cursor->pos; bool found = false; u64 matches; + int cmp = 0; /* * Lookup in the current node @@ -408,7 +406,8 @@ append_chain(struct callchain_node *root, if (!node) break; - if (match_chain(node, cnode) != 0) + cmp = match_chain(node, cnode); + if (cmp) break; found = true; @@ -418,9 +417,10 @@ append_chain(struct callchain_node *root, /* matches not, relay no the parent */ if (!found) { + WARN_ONCE(!cmp, "Chain comparison error\n"); cursor->curr = curr_snap; cursor->pos = start; - return -1; + return cmp; } matches = cursor->pos - start; -- 1.8.3.1