[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAM9d7cix9Oe3tjCV_w-ZRw6bTJpqe-g2n+ezn5mTvmPPri+Xdw@mail.gmail.com>
Date: Fri, 20 May 2022 12:38:55 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Shunsuke Nakamura <nakamura.shun@...itsu.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...hat.com>,
linux-kernel <linux-kernel@...r.kernel.org>,
linux-perf-users <linux-perf-users@...r.kernel.org>
Subject: Re: [PATCH 5/7] libperf: Add perf_evsel__{refresh, period}() functions
On Fri, Apr 22, 2022 at 2:45 AM Shunsuke Nakamura
<nakamura.shun@...itsu.com> wrote:
>
> Add the following functions:
>
> perf_evsel__refresh()
> perf_evsel__period()
>
> to set the over flow limit and period.
>
> Signed-off-by: Shunsuke Nakamura <nakamura.shun@...itsu.com>
> ---
> tools/lib/perf/Documentation/libperf.txt | 2 ++
> tools/lib/perf/evsel.c | 44 ++++++++++++++++++++----
> tools/lib/perf/include/perf/evsel.h | 2 ++
> tools/lib/perf/libperf.map | 2 ++
> 4 files changed, 44 insertions(+), 6 deletions(-)
>
> diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
> index bc7881348c76..773224a96bd3 100644
> --- a/tools/lib/perf/Documentation/libperf.txt
> +++ b/tools/lib/perf/Documentation/libperf.txt
> @@ -162,6 +162,8 @@ SYNOPSIS
> int perf_evsel__disable(struct perf_evsel *evsel);
> int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
> bool perf_evsel__has_fd(struct perf_evsel *evsel, int fd);
> + int perf_evsel__refresh(struct perf_evsel *evsel, int refresh);
> + int perf_evsel__period(struct perf_evsel *evsel, int period);
> struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
> struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
> struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
> diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
> index 446934c0e5e5..578ae0050036 100644
> --- a/tools/lib/perf/evsel.c
> +++ b/tools/lib/perf/evsel.c
> @@ -334,7 +334,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread,
> }
>
> static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
> - int ioc, void *arg,
> + int ioc, unsigned long arg,
> int cpu_map_idx)
> {
> int thread;
> @@ -357,7 +357,7 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
>
> int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx)
> {
> - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, cpu_map_idx);
> + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, cpu_map_idx);
> }
>
> int perf_evsel__enable(struct perf_evsel *evsel)
> @@ -366,13 +366,13 @@ int perf_evsel__enable(struct perf_evsel *evsel)
> int err = 0;
>
> for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
> - err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, 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_map_idx)
> {
> - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, cpu_map_idx);
> + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, cpu_map_idx);
> }
>
> int perf_evsel__disable(struct perf_evsel *evsel)
> @@ -381,7 +381,39 @@ int perf_evsel__disable(struct perf_evsel *evsel)
> int err = 0;
>
> for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
> - err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i);
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, i);
> + return err;
> +}
> +
> +int perf_evsel__refresh(struct perf_evsel *evsel, int refresh)
> +{
> + int i;
> + int err = 0;
> +
> + for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_REFRESH, refresh, i);
> + return err;
> +}
> +
> +int perf_evsel__period(struct perf_evsel *evsel, __u64 period)
> +{
> + struct perf_event_attr *attr;
> + int i;
> + int err = 0;
> +
> + attr = perf_evsel__attr(evsel);
> + if (!attr)
> + return -EINVAL;
I don't think it'd return NULL..
Thanks,
Namhyung
> +
> + for (i = 0; i < xyarray__max_x(evsel->fd); i++) {
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
> + (unsigned long)&period, i);
> + if (err)
> + return err;
> + }
> +
> + attr->sample_period = period;
> +
> return err;
> }
>
> @@ -392,7 +424,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
> for (i = 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++)
> err = perf_evsel__run_ioctl(evsel,
> PERF_EVENT_IOC_SET_FILTER,
> - (void *)filter, i);
> + (unsigned long)filter, i);
> return err;
> }
>
> diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
> index 19a7993d9021..2c5e52c17d28 100644
> --- a/tools/lib/perf/include/perf/evsel.h
> +++ b/tools/lib/perf/include/perf/evsel.h
> @@ -60,6 +60,8 @@ LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel);
> LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
> LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
> LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
> +LIBPERF_API int perf_evsel__refresh(struct perf_evsel *evsel, int refresh);
> +LIBPERF_API int perf_evsel__period(struct perf_evsel *evsel, __u64 period);
> LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
> LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
> LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
> diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
> index b2ace16bbc32..d97e208c5be8 100644
> --- a/tools/lib/perf/libperf.map
> +++ b/tools/lib/perf/libperf.map
> @@ -31,6 +31,8 @@ LIBPERF_0.0.1 {
> perf_evsel__munmap;
> perf_evsel__mmap_base;
> perf_evsel__read;
> + perf_evsel__refresh;
> + perf_evsel__period;
> perf_evsel__cpus;
> perf_evsel__threads;
> perf_evsel__attr;
> --
> 2.25.1
>
Powered by blists - more mailing lists