linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH] perf/core: Use POLLHUP for a pinned event in error
@ 2025-03-17  6:17 Namhyung Kim
  2025-03-17  7:47 ` [tip: perf/core] perf/core: Use POLLHUP for pinned events " tip-bot2 for Namhyung Kim
  2025-06-02 14:10 ` [RFC/PATCH] perf/core: Use POLLHUP for a pinned event " Lai, Yi
  0 siblings, 2 replies; 6+ messages in thread
From: Namhyung Kim @ 2025-03-17  6:17 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar
  Cc: Kan Liang, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, LKML

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@kernel.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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-06-03  4:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17  6:17 [RFC/PATCH] perf/core: Use POLLHUP for a pinned event in error Namhyung Kim
2025-03-17  7:47 ` [tip: perf/core] perf/core: Use POLLHUP for pinned events " tip-bot2 for Namhyung Kim
2025-06-02 14:10 ` [RFC/PATCH] perf/core: Use POLLHUP for a pinned event " Lai, Yi
2025-06-02 17:32   ` Namhyung Kim
2025-06-03  1:48     ` Lai, Yi
2025-06-03  4:49       ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).