[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220325043829.224045-4-nakamura.shun@fujitsu.com>
Date: Fri, 25 Mar 2022 13:38:25 +0900
From: Shunsuke Nakamura <nakamura.shun@...itsu.com>
To: peterz@...radead.org, mingo@...hat.com, acme@...nel.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...hat.com, namhyung@...nel.org
Cc: linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org
Subject: [RFC PATCH v2 3/7] libperf: Add perf_evsel__{refresh, period}() functions
Add the following functions:
perf_evsel__refresh()
perf_evsel__refresh_cpu()
perf_evsel__period()
perf_evsel__period_cpu()
to set the over flow limit and period.
Signed-off-by: Shunsuke Nakamura <nakamura.shun@...itsu.com>
---
tools/lib/perf/Documentation/libperf.txt | 5 ++
tools/lib/perf/evsel.c | 68 +++++++++++++++++++++---
tools/lib/perf/include/perf/evsel.h | 5 ++
tools/lib/perf/libperf.map | 4 ++
4 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
index 32c5051c24eb..ae55e62fc4ce 100644
--- a/tools/lib/perf/Documentation/libperf.txt
+++ b/tools/lib/perf/Documentation/libperf.txt
@@ -146,6 +146,11 @@ SYNOPSIS
int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
int perf_evsel__disable(struct perf_evsel *evsel);
int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
+ int perf_evsel__refresh(struct perf_evsel *evsel, int refresh);
+ int perf_evsel__refresh_cpu(struct perf_evsel *evsel, int refresh,
+ int cpu_map_idx);
+ int perf_evsel__period(struct perf_evsel *evsel, int period);
+ int perf_evsel__period_cpu(struct perf_evsel *evsel, int period, int cpu_map_idx);
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 6640a333e6d9..b17842581dea 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -330,7 +330,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;
@@ -353,7 +353,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)
@@ -362,13 +362,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)
@@ -377,7 +377,63 @@ 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_cpu(struct perf_evsel *evsel, int refresh, int cpu_map_idx)
+{
+ return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_REFRESH, refresh, cpu_map_idx);
+}
+
+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_cpu(struct perf_evsel *evsel, __u64 period, int cpu_map_idx)
+{
+ struct perf_event_attr *attr;
+ int err = 0;
+
+ attr = perf_evsel__attr(evsel);
+ if (!attr)
+ return -EINVAL;
+
+ err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
+ (unsigned long)&period, cpu_map_idx);
+ if (err)
+ return err;
+
+ attr->sample_period = period;
+
+ 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;
+
+ 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;
}
@@ -388,7 +444,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 2a9516b42d15..360ced734add 100644
--- a/tools/lib/perf/include/perf/evsel.h
+++ b/tools/lib/perf/include/perf/evsel.h
@@ -38,6 +38,11 @@ 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__refresh_cpu(struct perf_evsel *evsel, int refresh,
+ int cpu_map_idx);
+LIBPERF_API int perf_evsel__period(struct perf_evsel *evsel, __u64 period);
+LIBPERF_API int perf_evsel__period_cpu(struct perf_evsel *evsel, __u64 period, int cpu_map_idx);
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 6fa0d651576b..ab0f44e9bb57 100644
--- a/tools/lib/perf/libperf.map
+++ b/tools/lib/perf/libperf.map
@@ -29,6 +29,10 @@ LIBPERF_0.0.1 {
perf_evsel__munmap;
perf_evsel__mmap_base;
perf_evsel__read;
+ perf_evsel__refresh;
+ perf_evsel__refresh_cpu;
+ perf_evsel__period;
+ perf_evsel__period_cpu;
perf_evsel__cpus;
perf_evsel__threads;
perf_evsel__attr;
--
2.25.1
Powered by blists - more mailing lists