From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753856AbdL1PYz (ORCPT ); Thu, 28 Dec 2017 10:24:55 -0500 Received: from terminus.zytor.com ([65.50.211.136]:59049 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753815AbdL1PYx (ORCPT ); Thu, 28 Dec 2017 10:24:53 -0500 Date: Thu, 28 Dec 2017 07:22:28 -0800 From: tip-bot for Jin Yao Message-ID: Cc: jolsa@kernel.org, tglx@linutronix.de, acme@redhat.com, peterz@infradead.org, kan.liang@intel.com, hpa@zytor.com, yao.jin@linux.intel.com, mingo@kernel.org, alexander.shishkin@linux.intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, ak@linux.intel.com, mingo@kernel.org, alexander.shishkin@linux.intel.com, yao.jin@linux.intel.com, hpa@zytor.com, kan.liang@intel.com, peterz@infradead.org, tglx@linutronix.de, acme@redhat.com, jolsa@kernel.org In-Reply-To: <1512482591-4646-3-git-send-email-yao.jin@linux.intel.com> References: <1512482591-4646-3-git-send-email-yao.jin@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf stat: Extend rbtree to support per-thread shadow stats Git-Commit-ID: 49cd456af1dcb13ff3e94cb997c82968ae86722a X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 49cd456af1dcb13ff3e94cb997c82968ae86722a Gitweb: https://git.kernel.org/tip/49cd456af1dcb13ff3e94cb997c82968ae86722a Author: Jin Yao AuthorDate: Tue, 5 Dec 2017 22:03:02 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 27 Dec 2017 12:15:42 -0300 perf stat: Extend rbtree to support per-thread shadow stats Previously the rbtree was used to link generic metrics. This patches adds new ctx/type/stat into rbtree keys because we will use this rbtree to maintain shadow metrics to replace original a couple of static arrays for supporting per-thread shadow stats. Signed-off-by: Jin Yao Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Kan Liang Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1512482591-4646-3-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/stat-shadow.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 93aac27..528be3e 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -45,7 +45,10 @@ struct stats walltime_nsecs_stats; struct saved_value { struct rb_node rb_node; struct perf_evsel *evsel; + enum stat_type type; + int ctx; int cpu; + struct runtime_stat *stat; struct stats stats; }; @@ -58,6 +61,30 @@ static int saved_value_cmp(struct rb_node *rb_node, const void *entry) if (a->cpu != b->cpu) return a->cpu - b->cpu; + + /* + * Previously the rbtree was used to link generic metrics. + * The keys were evsel/cpu. Now the rbtree is extended to support + * per-thread shadow stats. For shadow stats case, the keys + * are cpu/type/ctx/stat (evsel is NULL). For generic metrics + * case, the keys are still evsel/cpu (type/ctx/stat are 0 or NULL). + */ + if (a->type != b->type) + return a->type - b->type; + + if (a->ctx != b->ctx) + return a->ctx - b->ctx; + + if (a->evsel == NULL && b->evsel == NULL) { + if (a->stat == b->stat) + return 0; + + if ((char *)a->stat < (char *)b->stat) + return -1; + + return 1; + } + if (a->evsel == b->evsel) return 0; if ((char *)a->evsel < (char *)b->evsel)