[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250317061745.1777584-1-namhyung@kernel.org>
Date: Sun, 16 Mar 2025 23:17:45 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>
Cc: Kan Liang <kan.liang@...ux.intel.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: [RFC/PATCH] perf/core: Use POLLHUP for a pinned event in error
Pinned events can go to an error state when they are failed to be
scheduled in the context. And they won't generate samples anymore
and silently ignored until it's recovered by PERF_EVENT_IOC_ENABLE or
something (and of course the condition also should be changed so that
they can be scheduled in). But then users should know about the state
change.
Currently there's no mechanism to notify users when they go to an error
state.
One way to do this is to issue POLLHUP event to poll(2) to handle this.
Reading events in an error state would return 0 (EOF) and it matches to
the behavior of POLLHUP according to the man page.
Users should remove the fd of the event from pollfd after getting
POLLHUP, otherwise it'll be returned repeatedly.
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
kernel/events/core.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2533fc32d890eacd..cef1f5c60f642d21 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3984,6 +3984,11 @@ static int merge_sched_in(struct perf_event *event, void *data)
if (event->attr.pinned) {
perf_cgroup_event_disable(event, ctx);
perf_event_set_state(event, PERF_EVENT_STATE_ERROR);
+
+ if (*perf_event_fasync(event))
+ event->pending_kill = POLL_HUP;
+
+ perf_event_wakeup(event);
} else {
struct perf_cpu_pmu_context *cpc = this_cpc(event->pmu_ctx->pmu);
@@ -5925,6 +5930,10 @@ static __poll_t perf_poll(struct file *file, poll_table *wait)
if (is_event_hup(event))
return events;
+ if (unlikely(READ_ONCE(event->state) == PERF_EVENT_STATE_ERROR &&
+ event->attr.pinned))
+ return events;
+
/*
* Pin the event->rb by taking event->mmap_mutex; otherwise
* perf_event_set_output() can swizzle our rb and make us miss wakeups.
--
2.49.0.rc1.451.g8f38331e32-goog
Powered by blists - more mailing lists