[PATCH v3 2/3] perf sched stats: Fix SIGCHLD vs pause() race in schedstat_live()

Swapnil Sapkal
2026-04-22T05:06:56Z

perf_sched__schedstat_live() has the same lost-wakeup race as
perf_sched__schedstat_record(): a short-lived workload's SIGCHLD
can be consumed by the signal handler before pause() is entered,
hanging the process.

Apply the same fix: use waitpid() for workload mode and
'while (!done) sleep(1)' for system-wide mode.

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
tools/perf/builtin-sched.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index cfd93bf11c2e..36fbc20dbebd 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4695,11 +4695,15 @@ static int perf_sched__schedstat_live(struct perf_sched *sched,
if (err < 0)
goto out;

- if (argc)
- evlist__start_workload(evlist);
+ done = 0;

- /* wait for signal */
- pause();
+ if (argc) {
+ evlist__start_workload(evlist);
+ waitpid(evlist->workload.pid, NULL, 0);
+ } else {
+ while (!done)
+ sleep(1);
+ }

if (reset) {
err = disable_sched_schedstat();
--
2.43.0