Switching single dimensional array of 'struct perf_counts_values'
with xyarray object, so we could store thread dimension counts.

Link: http://lkml.kernel.org/n/tip-t1wefzwb3z78sjlpzt95l...@git.kernel.org
Signed-off-by: Jiri Olsa <jo...@kernel.org>
---
 tools/perf/builtin-stat.c         |  2 +-
 tools/perf/tests/openat-syscall.c |  2 +-
 tools/perf/util/evsel.c           | 31 ++++++++++++++++++++++---------
 tools/perf/util/evsel.h           |  6 +++---
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7d1aebd5e1e4..2221a75e11e5 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 e86fc477a74f..bd882f09ebbc 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/evsel.c b/tools/perf/util/evsel.c
index 1a6bdd16ec37..e69a7ee4cc0b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -853,26 +853,39 @@ int perf_evsel__alloc_id(struct perf_evsel *evsel, int 
ncpus, int nthreads)
 
 struct perf_counts *perf_counts__alloc(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__free(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__zero(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/evsel.h b/tools/perf/util/evsel.h
index 3037c24e1fea..12e87f917d44 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -24,7 +24,7 @@ struct perf_counts_values {
 struct perf_counts {
        s8                        scaled;
        struct perf_counts_values aggr;
-       struct perf_counts_values cpu[];
+       struct xyarray            *cpu;
 };
 
 struct perf_evsel;
@@ -137,7 +137,7 @@ void perf_counts__free(struct perf_counts *counts);
 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);
 }
 
 int perf_evsel__object_config(size_t object_size,
@@ -192,7 +192,7 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char 
*buf, size_t size);
 
 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
-void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
+void perf_evsel__reset_counts(struct perf_evsel *evsel);
 void perf_evsel__free_counts(struct perf_evsel *evsel);
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to