mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] perf test task-exit: Fix POLLHUP busy-loop race waiting for SIGCHLD
@ 2026-10-25 21:49 Ian Rogers
  0 siblings, 0 replies; only message in thread
From: Ian Rogers @ 2026-10-25 21:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
	Leo Yan, linux-perf-users, linux-kernel

In the kernel's do_exit(), perf_event_exit_task() runs before exit_mm()
and exit_notify() (which delivers SIGCHLD to the parent). Once
perf_event_exit_task() completes, PERF_RECORD_EXIT is written to the
ring buffer and POLLHUP is set on the perf event file descriptor.

In test__task_exit(), once POLLHUP is set on the fd, evlist__poll()
returns immediately on every call without blocking. If the child is
still in exit_mm()..exit_notify() on another CPU when the parent reads
PERF_RECORD_EXIT, exited is still 0 and the retry loop spins through all
1000 non-blocking poll() calls in less than a millisecond before SIGCHLD
is delivered.

Sleep briefly with usleep(1000) on subsequent retries (which also wakes
early on EINTR when SIGCHLD arrives), mark exited as volatile
sig_atomic_t, and reset exited and nr_exit on test entry.

Fixes: 791ce9c48c79 ("perf test: Avoid infinite loop for task exit case")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/task-exit.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 9fac426ac2f9..1a9de2d13497 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -9,13 +9,14 @@
 
 #include <errno.h>
 #include <signal.h>
+#include <unistd.h>
 #include <linux/string.h>
 #include <perf/cpumap.h>
 #include <perf/evlist.h>
 #include <perf/mmap.h>
 
-static int exited;
-static int nr_exit;
+static volatile sig_atomic_t exited;
+static volatile int nr_exit;
 
 static void sig_handler(int sig __maybe_unused)
 {
@@ -55,6 +56,8 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _
 	struct mmap *md;
 	int retry_count = 0;
 
+	exited = 0;
+	nr_exit = 0;
 	signal(SIGCHLD, sig_handler);
 
 	evlist = evlist__new_dummy();
@@ -135,6 +138,8 @@ static int test__task_exit(struct test_suite *test __maybe_unused, int subtest _
 			err = -1;
 			goto out_put_evlist;
 		}
+		if (retry_count > 1)
+			usleep(1000);
 
 		goto retry;
 	}
-- 
2.56.0.307.g5fe7bd680c-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-25 21:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 21:49 [PATCH v1] perf test task-exit: Fix POLLHUP busy-loop race waiting for SIGCHLD Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®