Re: Optimize perf stat for large number of events/cpus
From: Andi Kleen
Date: Wed Nov 27 2019 - 18:27:10 EST
On Wed, Nov 27, 2019 at 12:43:05PM -0300, Arnaldo Carvalho de Melo wrote:
> So, have you tried running 'perf test' after each cset is applied and
> built?
I ran it at the end, but there are quite a few fails out of the box,
so I missed that one thanks.
This patch fixes it. Let me know if I should submit it in a more
formal way.
---
Fix event times test case
Reported-by: Arnaldo
Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 4c6485fc31b9..4dc06289f4c7 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -224,7 +224,7 @@ int perf_evsel__enable(struct perf_evsel *evsel)
int i;
int err = 0;
- for (i = 0; i < evsel->cpus->nr && !err; i++)
+ for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, i);
return err;
}
@@ -239,7 +239,7 @@ int perf_evsel__disable(struct perf_evsel *evsel)
int i;
int err = 0;
- for (i = 0; i < evsel->cpus->nr && !err; i++)
+ for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i);
return err;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 59b9b4f3fe34..0844e3e29fb0 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1853,6 +1853,10 @@ int perf_evsel__open_per_cpu(struct evsel *evsel,
struct perf_cpu_map *cpus,
int cpu)
{
+ if (cpu == -1)
+ return evsel__open_cpu(evsel, cpus, NULL, 0,
+ cpus ? cpus->nr : 1);
+
return evsel__open_cpu(evsel, cpus, NULL, cpu, cpu + 1);
}