]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf sched stats: Fix SIGCHLD vs pause() race in schedstat_record()
authorSwapnil Sapkal <swapnil.sapkal@amd.com>
Wed, 20 May 2026 10:20:15 +0000 (10:20 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 May 2026 20:46:45 +0000 (17:46 -0300)
commit9416008e5462cf7a1da62bbaca915f483cea8b77
tree71f679c027465b03da2e83827e2c9b289a3629bb
parent9aa1ec2e1d21be400767aa9b754adbae7d8e1d32
perf sched stats: Fix SIGCHLD vs pause() race in schedstat_record()

If the profiled workload exits very quickly, SIGCHLD can be delivered
and consumed by the empty signal handler before the process enters
pause(), causing an indefinite hang.

Fix this with a simpler approach:

 - The signal handler now sets a 'volatile sig_atomic_t done' flag.
   Reset 'done' before registering signal handlers so that an early
   signal during setup is not discarded by a later reset.

 - Replace pause() with a loop that checks 'done' and uses
   waitpid(WNOHANG) to detect child exit without blocking.  This
   handles both workload mode (child exits) and system-wide mode
   (user sends SIGINT/SIGTERM).  Using WNOHANG avoids the SA_RESTART
   problem where a blocking waitpid() would auto-restart and ignore
   the done flag if the child doesn't exit on signal.

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-sched.c