Re: [PATCH v6 11/12] perf evsel: Add functions to enable/disable for a specific CPU

From: Jiri Olsa
Date: Fri Nov 15 2019 - 09:55:27 EST


On Mon, Nov 11, 2019 at 04:59:40PM -0800, Andi Kleen wrote:
> From: Andi Kleen <ak@xxxxxxxxxxxxxxx>
>
> Refactor the existing functions to use these functions internally.
>
> Used in the next patch
>
> Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
> ---
> tools/perf/lib/evsel.c | 49 +++++++++++++++++++++--------
> tools/perf/lib/include/perf/evsel.h | 2 ++
> tools/perf/util/evsel.c | 13 +++++++-
> tools/perf/util/evsel.h | 2 ++
> 4 files changed, 52 insertions(+), 14 deletions(-)
>
> diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
> index ea775dacbd2d..89ddfade0b96 100644
> --- a/tools/perf/lib/evsel.c
> +++ b/tools/perf/lib/evsel.c
> @@ -198,38 +198,61 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
> }
>
> static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
> - int ioc, void *arg)
> + int ioc, void *arg,
> + int cpu)
> {
> - int cpu, thread;
> + int thread;
>
> - for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) {
> - for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
> - int fd = FD(evsel, cpu, thread),
> - err = ioctl(fd, ioc, arg);
> + for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
> + int fd = FD(evsel, cpu, thread),
> + err = ioctl(fd, ioc, arg);
>
> - if (err)
> - return err;
> - }
> + if (err)
> + return err;
> }
>
> return 0;
> }
>
> +int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu)
> +{
> + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, cpu);

please use NULL instead of 0, I initialy confused it for index

for all the calls perf_evsel__run_ioctl below

thanks,
jirka

> +}
> +
> int perf_evsel__enable(struct perf_evsel *evsel)
> {
> - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0);
> + int i;
> + int err = 0;
> +
> + for (i = 0; i < evsel->cpus->nr && !err; i++)
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, i);
> + return err;
> +}
> +
> +int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu)
> +{
> + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, cpu);
> }
>
> int perf_evsel__disable(struct perf_evsel *evsel)
> {
> - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0);
> + int i;
> + int err = 0;
> +
> + for (i = 0; i < evsel->cpus->nr && !err; i++)
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, i);
> + return err;
> }
>

SNIP