From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757032AbbCCQEI (ORCPT ); Tue, 3 Mar 2015 11:04:08 -0500 Received: from mga09.intel.com ([134.134.136.24]:31802 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756234AbbCCQEF (ORCPT ); Tue, 3 Mar 2015 11:04:05 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,682,1418112000"; d="scan'208";a="535460321" From: kan.liang@intel.com To: a.p.zijlstra@chello.nl, acme@kernel.org, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, Kan Liang Subject: [PATCH 3/5] perf,tools: change perf stat to use event's cpu map Date: Tue, 3 Mar 2015 03:54:44 -0500 Message-Id: <1425372886-33397-3-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1425372886-33397-1-git-send-email-kan.liang@intel.com> References: <1425372886-33397-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang With cpu_list, perf stat should use event's cpu map. Different events may have different cpu map. So the same index in cpu map does not point to the same CPU id. perf_evsel__get_cpumap_index is introduced to find out the CPU id's index for a given cpu map. Signed-off-by: Kan Liang --- tools/perf/builtin-stat.c | 5 +++-- tools/perf/util/evsel.h | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index e598e4e..5ae8686 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -165,7 +165,7 @@ static inline void diff_timespec(struct timespec *r, struct timespec *a, static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel) { - return (evsel->cpus && !target.cpu_list) ? evsel->cpus : evsel_list->cpus; + return evsel->cpus ? evsel->cpus : evsel_list->cpus; } static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel) @@ -302,7 +302,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) attr->inherit = !no_inherit; if (target__has_cpu(&target)) - return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); + return perf_evsel__open_per_cpu(evsel, evsel_list->cpus); if (!target__has_task(&target) && perf_evsel__is_group_leader(evsel)) { attr->disabled = 1; @@ -1218,6 +1218,7 @@ static void print_aggr(char *prefix) nr = 0; for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { cpu2 = perf_evsel__cpus(counter)->map[cpu]; + cpu2 = perf_evsel__get_cpumap_index(NULL, cpu2, evsel_list->cpus); s2 = aggr_get_id(evsel_list->cpus, cpu2); if (s2 != id) continue; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index dcf202a..a633320 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -8,6 +8,7 @@ #include #include "xyarray.h" #include "symbol.h" +#include "cpumap.h" struct perf_counts_values { union { @@ -359,4 +360,27 @@ static inline bool has_branch_callstack(struct perf_evsel *evsel) { return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; } + +static inline int perf_evsel__get_cpumap_index(struct perf_evsel *evsel, + int cpu, + struct cpu_map *evlist_cpus) +{ + struct cpu_map *cpus; + int i; + + if (evlist_cpus == NULL) + return -1; + + if (evsel && evsel->cpus) + cpus = evsel->cpus; + else + cpus = evlist_cpus; + + for (i = 0; i < cpus->nr; i++) { + if (cpu == cpus->map[i]) + return i; + } + return -1; +} + #endif /* __PERF_EVSEL_H */ -- 1.8.3.1