[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250106-perf_set_event_limit-v3-1-dbde0e90ddde@rivosinc.com>
Date: Mon, 06 Jan 2025 20:07:32 -0800
From: Charlie Jenkins <charlie@...osinc.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>, Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>, Atish Patra <atishp@...osinc.com>
Cc: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Charlie Jenkins <charlie@...osinc.com>
Subject: [PATCH v3 1/3] perf: Add PERF_EVENT_IOC_INC_EVENT_LIMIT
PERF_EVENT_IOC_REFRESH immediately enables after incrementing
event_limit. Provide a new ioctl flag that allows programs to increment
event_limit without enabling the event. A usecase for this is to set an
event_limit in combination with enable_on_exec.
Signed-off-by: Charlie Jenkins <charlie@...osinc.com>
---
include/linux/perf_event.h | 4 ++--
include/uapi/linux/perf_event.h | 1 +
kernel/events/core.c | 17 +++++++++++------
tools/include/uapi/linux/perf_event.h | 1 +
4 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index cb99ec8c9e96f63c64eeeb4470c019d86bc6e50f..9b407d51818f59e1548f8936ec0bb185fc4d9f0c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1147,7 +1147,7 @@ extern int perf_event_task_enable(void);
extern void perf_pmu_resched(struct pmu *pmu);
-extern int perf_event_refresh(struct perf_event *event, int refresh);
+extern int perf_event_refresh(struct perf_event *event, int refresh, bool enable);
extern void perf_event_update_userpage(struct perf_event *event);
extern int perf_event_release_kernel(struct perf_event *event);
extern struct perf_event *
@@ -1835,7 +1835,7 @@ static inline int perf_event_read_local(struct perf_event *event, u64 *value,
static inline void perf_event_print_debug(void) { }
static inline int perf_event_task_disable(void) { return -EINVAL; }
static inline int perf_event_task_enable(void) { return -EINVAL; }
-static inline int perf_event_refresh(struct perf_event *event, int refresh)
+static inline int perf_event_refresh(struct perf_event *event, int refresh, bool enable)
{
return -EINVAL;
}
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 0524d541d4e3d50150da03186467382bc60bdf50..5eeccd57078c95f08f6ac401b1e38c2e84e86d9a 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -569,6 +569,7 @@ struct perf_event_query_bpf {
#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32)
#define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *)
#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *)
+#define PERF_EVENT_IOC_INC_EVENT_LIMIT _IO ('$', 12)
enum perf_event_ioc_flags {
PERF_IOC_FLAG_GROUP = 1U << 0,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 065f9188b44a0d8ee66cc76314ae247dbe45cb57..6514065513ba01e99c88854f3947a114562e81ad 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3210,7 +3210,7 @@ void perf_event_addr_filters_sync(struct perf_event *event)
}
EXPORT_SYMBOL_GPL(perf_event_addr_filters_sync);
-static int _perf_event_refresh(struct perf_event *event, int refresh)
+static int _perf_event_refresh(struct perf_event *event, int refresh, bool enable)
{
/*
* not supported on inherited events
@@ -3219,7 +3219,8 @@ static int _perf_event_refresh(struct perf_event *event, int refresh)
return -EINVAL;
atomic_add(refresh, &event->event_limit);
- _perf_event_enable(event);
+ if (enable)
+ _perf_event_enable(event);
return 0;
}
@@ -3227,13 +3228,13 @@ static int _perf_event_refresh(struct perf_event *event, int refresh)
/*
* See perf_event_disable()
*/
-int perf_event_refresh(struct perf_event *event, int refresh)
+int perf_event_refresh(struct perf_event *event, int refresh, bool enable)
{
struct perf_event_context *ctx;
int ret;
ctx = perf_event_ctx_lock(event);
- ret = _perf_event_refresh(event, refresh);
+ ret = _perf_event_refresh(event, refresh, enable);
perf_event_ctx_unlock(event, ctx);
return ret;
@@ -6019,7 +6020,7 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon
break;
case PERF_EVENT_IOC_REFRESH:
- return _perf_event_refresh(event, arg);
+ return _perf_event_refresh(event, arg, true);
case PERF_EVENT_IOC_PERIOD:
{
@@ -6099,6 +6100,10 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon
return perf_event_modify_attr(event, &new_attr);
}
+
+ case PERF_EVENT_IOC_INC_EVENT_LIMIT:
+ return _perf_event_refresh(event, arg, false);
+
default:
return -ENOTTY;
}
@@ -6820,7 +6825,7 @@ void perf_event_wakeup(struct perf_event *event)
ring_buffer_wakeup(event);
if (event->pending_kill) {
- kill_fasync(perf_event_fasync(event), SIGIO, event->pending_kill);
+ kill_fasync(perf_event_fasync(event), SIGTRAP, event->pending_kill);
event->pending_kill = 0;
}
}
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 0524d541d4e3d50150da03186467382bc60bdf50..5eeccd57078c95f08f6ac401b1e38c2e84e86d9a 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -569,6 +569,7 @@ struct perf_event_query_bpf {
#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32)
#define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *)
#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *)
+#define PERF_EVENT_IOC_INC_EVENT_LIMIT _IO ('$', 12)
enum perf_event_ioc_flags {
PERF_IOC_FLAG_GROUP = 1U << 0,
--
2.34.1
Powered by blists - more mailing lists