perf stat: Make use of index clearer with perf_counts
authorIan Rogers <irogers@google.com>
Thu, 19 May 2022 03:20:05 +0000 (20:20 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 23 May 2022 12:54:02 +0000 (09:54 -0300)
Try to disambiguate further when perf_counts is being accessed it is
with a cpu map index rather than a CPU.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Dave Marchevsky <davemarchevsky@fb.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Lv Ruyi <lv.ruyi@zte.com.cn>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Monnet <quentin@isovalent.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org
Link: https://lore.kernel.org/r/20220519032005.1273691-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/stat-display.c
tools/perf/util/stat.c

index 98669ca5a86bcbaa3dfa1b83280db93fc0b54f1a..606f09b09226f6f8bc23f5761190e014da0d3e67 100644 (file)
@@ -764,11 +764,11 @@ static int cmp_val(const void *a, const void *b)
 
 static struct perf_aggr_thread_value *sort_aggr_thread(
                                        struct evsel *counter,
-                                       int nthreads, int ncpus,
                                        int *ret,
                                        struct target *_target)
 {
-       int cpu, thread, i = 0;
+       int nthreads = perf_thread_map__nr(counter->core.threads);
+       int i = 0;
        double uval;
        struct perf_aggr_thread_value *buf;
 
@@ -776,13 +776,17 @@ static struct perf_aggr_thread_value *sort_aggr_thread(
        if (!buf)
                return NULL;
 
-       for (thread = 0; thread < nthreads; thread++) {
+       for (int thread = 0; thread < nthreads; thread++) {
+               int idx;
                u64 ena = 0, run = 0, val = 0;
 
-               for (cpu = 0; cpu < ncpus; cpu++) {
-                       val += perf_counts(counter->counts, cpu, thread)->val;
-                       ena += perf_counts(counter->counts, cpu, thread)->ena;
-                       run += perf_counts(counter->counts, cpu, thread)->run;
+               perf_cpu_map__for_each_idx(idx, evsel__cpus(counter)) {
+                       struct perf_counts_values *counts =
+                               perf_counts(counter->counts, idx, thread);
+
+                       val += counts->val;
+                       ena += counts->ena;
+                       run += counts->run;
                }
 
                uval = val * counter->scale;
@@ -817,13 +821,11 @@ static void print_aggr_thread(struct perf_stat_config *config,
                              struct evsel *counter, char *prefix)
 {
        FILE *output = config->output;
-       int nthreads = perf_thread_map__nr(counter->core.threads);
-       int ncpus = perf_cpu_map__nr(counter->core.cpus);
        int thread, sorted_threads;
        struct aggr_cpu_id id;
        struct perf_aggr_thread_value *buf;
 
-       buf = sort_aggr_thread(counter, nthreads, ncpus, &sorted_threads, _target);
+       buf = sort_aggr_thread(counter, &sorted_threads, _target);
        if (!buf) {
                perror("cannot sort aggr thread");
                return;
index a77c282322985be4ab46554f62e3b0243cd0a52f..37ea2d044708545cb5a86636366d10e172629f19 100644 (file)
@@ -237,14 +237,12 @@ void evlist__reset_prev_raw_counts(struct evlist *evlist)
 
 static void evsel__copy_prev_raw_counts(struct evsel *evsel)
 {
-       int ncpus = evsel__nr_cpus(evsel);
-       int nthreads = perf_thread_map__nr(evsel->core.threads);
+       int idx, nthreads = perf_thread_map__nr(evsel->core.threads);
 
        for (int thread = 0; thread < nthreads; thread++) {
-               for (int cpu = 0; cpu < ncpus; cpu++) {
-                       *perf_counts(evsel->counts, cpu, thread) =
-                               *perf_counts(evsel->prev_raw_counts, cpu,
-                                            thread);
+               perf_cpu_map__for_each_idx(idx, evsel__cpus(evsel)) {
+                       *perf_counts(evsel->counts, idx, thread) =
+                               *perf_counts(evsel->prev_raw_counts, idx, thread);
                }
        }