From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753800AbbF3EyI (ORCPT ); Tue, 30 Jun 2015 00:54:08 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38449 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbbF3EyD (ORCPT ); Tue, 30 Jun 2015 00:54:03 -0400 Date: Mon, 29 Jun 2015 21:53:46 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: acme@redhat.com, mingo@kernel.org, tglx@linutronix.de, namhyung@kernel.org, ak@linux.intel.com, hpa@zytor.com, a.p.zijlstra@chello.nl, adrian.hunter@intel.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, dsahern@gmail.com, eranian@google.com Reply-To: mingo@kernel.org, acme@redhat.com, a.p.zijlstra@chello.nl, hpa@zytor.com, ak@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, eranian@google.com, dsahern@gmail.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, jolsa@kernel.org In-Reply-To: <1435310967-14570-6-git-send-email-jolsa@kernel.org> References: <1435310967-14570-6-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf stat: Use xyarray for cpu evsel counts Git-Commit-ID: a8e02324dfe6bcafc15d02b790f33321ec4facb0 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: a8e02324dfe6bcafc15d02b790f33321ec4facb0 Gitweb: http://git.kernel.org/tip/a8e02324dfe6bcafc15d02b790f33321ec4facb0 Author: Jiri Olsa AuthorDate: Fri, 26 Jun 2015 11:29:10 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 26 Jun 2015 11:19:19 -0300 perf stat: Use xyarray for cpu evsel counts Switching single dimensional array of 'struct perf_counts_values' with xyarray object, so we could store thread dimension counts. Signed-off-by: Jiri Olsa Cc: Adrian Hunter Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1435310967-14570-6-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 2 +- tools/perf/tests/openat-syscall.c | 2 +- tools/perf/util/stat.c | 31 ++++++++++++++++++++++--------- tools/perf/util/stat.h | 7 ++++--- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 49b9037..055ce83 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -218,7 +218,7 @@ static void perf_stat__reset_stats(struct perf_evlist *evlist) evlist__for_each(evlist, evsel) { perf_evsel__reset_stat_priv(evsel); - perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel)); + perf_evsel__reset_counts(evsel); } perf_stat__reset_shadow_stats(); diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c index e86fc47..bd882f0 100644 --- a/tools/perf/tests/openat-syscall.c +++ b/tools/perf/tests/openat-syscall.c @@ -46,7 +46,7 @@ int test__openat_syscall_event(void) if (perf_counts(evsel->counts, 0)->val != nr_openat_calls) { pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", - nr_openat_calls, evsel->counts->cpu[0].val); + nr_openat_calls, perf_counts(evsel->counts, 0)->val); goto out_close_fd; } diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 4014b70..453480a 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -97,26 +97,39 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel) struct perf_counts *perf_counts__new(int ncpus) { - int size = sizeof(struct perf_counts) + - ncpus * sizeof(struct perf_counts_values); + struct perf_counts *counts = zalloc(sizeof(*counts)); - return zalloc(size); + if (counts) { + struct xyarray *cpu; + + cpu = xyarray__new(ncpus, 1, sizeof(struct perf_counts_values)); + if (!cpu) { + free(counts); + return NULL; + } + + counts->cpu = cpu; + } + + return counts; } void perf_counts__delete(struct perf_counts *counts) { - free(counts); + if (counts) { + xyarray__delete(counts->cpu); + free(counts); + } } -static void perf_counts__reset(struct perf_counts *counts, int ncpus) +static void perf_counts__reset(struct perf_counts *counts) { - memset(counts, 0, (sizeof(*counts) + - (ncpus * sizeof(struct perf_counts_values)))); + xyarray__reset(counts->cpu); } -void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus) +void perf_evsel__reset_counts(struct perf_evsel *evsel) { - perf_counts__reset(evsel->counts, ncpus); + perf_counts__reset(evsel->counts); } int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 5e43348..6d07612 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -3,6 +3,7 @@ #include #include +#include "xyarray.h" struct stats { @@ -45,13 +46,13 @@ struct perf_counts_values { struct perf_counts { s8 scaled; struct perf_counts_values aggr; - struct perf_counts_values cpu[]; + struct xyarray *cpu; }; static inline struct perf_counts_values* perf_counts(struct perf_counts *counts, int cpu) { - return &counts->cpu[cpu]; + return xyarray__entry(counts->cpu, cpu, 0); } void update_stats(struct stats *stats, u64 val); @@ -88,7 +89,7 @@ void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, struct perf_counts *perf_counts__new(int ncpus); void perf_counts__delete(struct perf_counts *counts); -void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus); +void perf_evsel__reset_counts(struct perf_evsel *evsel); int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); void perf_evsel__free_counts(struct perf_evsel *evsel); #endif