[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220325043829.224045-6-nakamura.shun@fujitsu.com>
Date: Fri, 25 Mar 2022 13:38:27 +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 5/7] libperf: Add perf_evsel__check_overflow() functions
Add the following functions:
perf_evsel__check_overflow
perf_evsel__check_overflow_cpu
to check for perf events with the file descriptor specified in the
argument.
These functions can be used in signal handlers to check overflow.
Signed-off-by: Shunsuke Nakamura <nakamura.shun@...itsu.com>
---
tools/lib/perf/Documentation/libperf.txt | 3 +++
tools/lib/perf/evsel.c | 34 ++++++++++++++++++++++++
tools/lib/perf/include/perf/evsel.h | 4 +++
tools/lib/perf/libperf.map | 2 ++
4 files changed, 43 insertions(+)
diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
index 700c1ce15159..4ae8d738b948 100644
--- a/tools/lib/perf/Documentation/libperf.txt
+++ b/tools/lib/perf/Documentation/libperf.txt
@@ -165,6 +165,9 @@ SYNOPSIS
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);
+ int perf_evsel__check_overflow(struct perf_evsel *evsel, int sig_fd, bool *overflow);
+ int perf_evsel__check_overflow_cpu(struct perf_evsel *evsel, int cpu_map_idx,
+ int sig_fd, bool *overflow);
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 db9b7274feb5..6ff3cf692df3 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -616,3 +616,37 @@ int perf_evsel__open_opts(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
return err;
}
+
+int perf_evsel__check_overflow_cpu(struct perf_evsel *evsel, int cpu_map_idx,
+ int sig_fd, bool *overflow)
+{
+ int thread;
+ int *fd;
+ int err = 0;
+
+ if (!overflow)
+ return -EINVAL;
+
+ *overflow = false;
+
+ for (thread = 0; thread < xyarray__max_y(evsel->fd) && !err; ++thread) {
+ fd = FD(evsel, cpu_map_idx, thread);
+ if (sig_fd <= 0 || !fd || *fd < 0)
+ err = -EINVAL;
+
+ if (sig_fd == *fd)
+ *overflow = true;
+ }
+
+ return err;
+}
+
+int perf_evsel__check_overflow(struct perf_evsel *evsel, int sig_fd, bool *overflow)
+{
+ int cpu_map_idx;
+ int err = 0;
+
+ for (cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->fd) && !err; cpu_map_idx++)
+ err = perf_evsel__check_overflow_cpu(evsel, cpu_map_idx, sig_fd, overflow);
+ return err;
+}
diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
index ecf30bc6303f..d686cfbd88a6 100644
--- a/tools/lib/perf/include/perf/evsel.h
+++ b/tools/lib/perf/include/perf/evsel.h
@@ -74,5 +74,9 @@ LIBPERF_API int perf_evsel__open_opts(struct perf_evsel *evsel,
struct perf_cpu_map *cpus,
struct perf_thread_map *threads,
struct perf_evsel_open_opts *opts);
+LIBPERF_API int perf_evsel__check_overflow(struct perf_evsel *evsel, int sig_fd,
+ bool *overflow);
+LIBPERF_API int perf_evsel__check_overflow_cpu(struct perf_evsel *evsel,
+ int cpu_map_idx, int sig_fd, bool *overflow);
#endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
index 534614fbbb26..981eade34237 100644
--- a/tools/lib/perf/libperf.map
+++ b/tools/lib/perf/libperf.map
@@ -37,6 +37,8 @@ LIBPERF_0.0.1 {
perf_evsel__cpus;
perf_evsel__threads;
perf_evsel__attr;
+ perf_evsel__check_overflow;
+ perf_evsel__check_overflow_cpu;
perf_evlist__new;
perf_evlist__delete;
perf_evlist__open;
--
2.25.1
Powered by blists - more mailing lists