Re: Optimize perf stat for large number of events/cpus

From: Arnaldo Carvalho de Melo
Date: Wed Nov 27 2019 - 19:00:58 EST


On November 27, 2019 8:26:57 PM GMT-03:00, Andi Kleen <ak@xxxxxxxxxxxxxxx> wrote:
>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);
> }
>

Just save me some time by saying to which cset in v8 I should squash this into, so that we keep the whole shebang bisectable,

Thanks,

- Arnaldo