Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3542453ybz; Mon, 20 Apr 2020 05:01:11 -0700 (PDT) X-Google-Smtp-Source: APiQypJwFReWxf+SRvqZLvv3BRupIA2aG0DoWbT89GWCaJk5tsdSEitfiVGnbIG8D2oqI1X5eWXa X-Received: by 2002:a50:c3c2:: with SMTP id i2mr4116102edf.227.1587384071149; Mon, 20 Apr 2020 05:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587384071; cv=none; d=google.com; s=arc-20160816; b=Eudx5QY76gG871cjVyPzZacDGN9k7jnI4CH5+7sikFC4ovrIfStLtR/lIaVqzOcUjJ Ea0M6xCb/N36MZfBOrC0sxWPfmyc3FmfBMpESPENIf9gfRUKfC1LKNfbDgOhEE3j8MpA 1SF+oTpYx8A5NQDG19dTgHHCaxVPB7XAfDPBw04OCtlyVI/yHOz8ynAzn+LwdHbePjrG U5jyLxxpMnRE3gCBpui6XkQ58h8p413hjJ2whog1dPGNMbyPT79NtSzIstvO9rD+4evd 7NbTsVaOq8ekZkYo4jElL4ltNibnIxVwnSAFdmBsQp980+hnZtZJ3QDckZgeMYBvAGXV hvfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u9c1klgCQV1S4e5+hjSEgFQDP2TZtA/lu4hBbAz0wlc=; b=mFoQ0awJRNmnqrlVvvXtRhSUR12PbRKDb8m3sWMDPVY/XZBNAGYcNtrY7ED72/0WW5 aiho9VJOAnUvgfpaiPRLbd70+i/yy4+dsJMUYnbZHyUknupyBOkwbO7KFyuTfhvlGPZc KX5XfaF2M7bUM2+dEcCjUw882ncBMuX8Cfjpv7+RhKnhoHugsHBxW3ondohKYA4nu5hK 8JOftd8aveFXL+xbuumdJbZjWuBQl2h1lEx3Ak5vnAK0C7ZBJ8RlJOQ0j3GpioG/ne5o MeY82q1+cOTbcExfMYWuI8AHUE6EWZlxH04P2AD63QbixfRyGfMzXMQasSxnKhLtIYhY NJ5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IHJAdtdr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn10si565458ejc.357.2020.04.20.05.00.48; Mon, 20 Apr 2020 05:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IHJAdtdr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726868AbgDTL6C (ORCPT + 99 others); Mon, 20 Apr 2020 07:58:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:42816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbgDTL57 (ORCPT ); Mon, 20 Apr 2020 07:57:59 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A2E2E218AC; Mon, 20 Apr 2020 11:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383878; bh=sBo0ETqKABkMCsr76EZqZ5ujxcCuP3Z8QPgHg3B0ZOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IHJAdtdrPscQVP0ga8dj6w45kO95LCX/2uZeO2wJ43A5pw1uRI8Zil7PI4FGA8fwj OzLiAdpVDS8pXsElVfIMfIMp63ybYD8OEEa3fIVtwoJI7B6dibU+IGCg91KO6GhsC4 pwbwDkzAosDaj+3J+zVwOA1yCP8/PL78G9shZEHc= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Kan Liang , Jiri Olsa , Adrian Hunter , Alexey Budankov , Andi Kleen , Mathieu Poirier , Michael Ellerman , Pavel Gerasimov , Peter Zijlstra , Ravi Bangoria , Stephane Eranian , Vitaly Slobodskoy , Arnaldo Carvalho de Melo Subject: [PATCH 60/60] perf hist: Add fast path for duplicate entries check Date: Mon, 20 Apr 2020 08:53:16 -0300 Message-Id: <20200420115316.18781-61-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang Perf checks the duplicate entries in a callchain before adding an entry. However the check is very slow especially with deeper call stack. Almost ~50% elapsed time of perf report is spent on the check when the call stack is always depth of 32. The hist_entry__cmp() is used to compare the new entry with the old entries. It will go through all the available sorts in the sort_list, and call the specific cmp of each sort, which is very slow. Actually, for most cases, there are no duplicate entries in callchain. The symbols are usually different. It's much faster to do a quick check for symbols first. Only do the full cmp when the symbols are exactly the same. The quick check is only to check symbols, not dso. Export _sort__sym_cmp. $ perf record --call-graph lbr ./tchain_edit_64 Without the patch $time perf report --stdio real 0m21.142s user 0m21.110s sys 0m0.033s With the patch $time perf report --stdio real 0m10.977s user 0m10.948s sys 0m0.027s Signed-off-by: Kan Liang Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexey Budankov Cc: Andi Kleen Cc: Mathieu Poirier Cc: Michael Ellerman Cc: Namhyung Kim Cc: Pavel Gerasimov Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Stephane Eranian Cc: Vitaly Slobodskoy Link: http://lore.kernel.org/lkml/20200319202517.23423-18-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/hist.c | 23 +++++++++++++++++++++++ tools/perf/util/sort.c | 2 +- tools/perf/util/sort.h | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 283a69ff6a3d..c2550dbe7dc3 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1070,6 +1070,20 @@ iter_next_cumulative_entry(struct hist_entry_iter *iter, return fill_callchain_info(al, node, iter->hide_unresolved); } +static bool +hist_entry__fast__sym_diff(struct hist_entry *left, + struct hist_entry *right) +{ + struct symbol *sym_l = left->ms.sym; + struct symbol *sym_r = right->ms.sym; + + if (!sym_l && !sym_r) + return left->ip != right->ip; + + return !!_sort__sym_cmp(sym_l, sym_r); +} + + static int iter_add_next_cumulative_entry(struct hist_entry_iter *iter, struct addr_location *al) @@ -1096,6 +1110,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, }; int i; struct callchain_cursor cursor; + bool fast = hists__has(he_tmp.hists, sym); callchain_cursor_snapshot(&cursor, &callchain_cursor); @@ -1106,6 +1121,14 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, * It's possible that it has cycles or recursive calls. */ for (i = 0; i < iter->curr; i++) { + /* + * For most cases, there are no duplicate entries in callchain. + * The symbols are usually different. Do a quick check for + * symbols first. + */ + if (fast && hist_entry__fast__sym_diff(he_cache[i], &he_tmp)) + continue; + if (hist_entry__cmp(he_cache[i], &he_tmp) == 0) { /* to avoid calling callback function */ iter->he = NULL; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index f14cc728c358..dc15ddc18b7d 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -237,7 +237,7 @@ static int64_t _sort__addr_cmp(u64 left_ip, u64 right_ip) return (int64_t)(right_ip - left_ip); } -static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r) +int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r) { if (!sym_l || !sym_r) return cmp_null(sym_l, sym_r); diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index cfa6ac6f7d06..66d39c4cfe2b 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -311,5 +311,7 @@ int64_t sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right); int64_t sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right); +int64_t +_sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r); char *hist_entry__srcline(struct hist_entry *he); #endif /* __PERF_SORT_H */ -- 2.21.1