From: Swapnil Sapkal <swapnil.sapkal@amd.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<namhyung@kernel.org>, <irogers@google.com>,
<james.clark@linaro.org>
Cc: <mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@kernel.org>, <adrian.hunter@intel.com>,
<ravi.bangoria@amd.com>, <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
"Swapnil Sapkal" <swapnil.sapkal@amd.com>
Subject: [PATCH v3 3/3] perf lock contention: Fix SIGCHLD vs pause() race in __cmd_contention()
Date: Wed, 22 Apr 2026 05:05:45 +0000 [thread overview]
Message-ID: <20260422050545.129448-4-swapnil.sapkal@amd.com> (raw)
In-Reply-To: <20260422050545.129448-1-swapnil.sapkal@amd.com>
__cmd_contention() suffers from the same lost-wakeup race as the perf
sched stats paths: 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-lock.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index e8962c985d34..3c165d632941 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/prctl.h>
+#include <sys/wait.h>
#include <semaphore.h>
#include <math.h>
#include <limits.h>
@@ -1921,8 +1922,11 @@ static int __cmd_report(bool display_info)
return err;
}
+static volatile sig_atomic_t done;
+
static void sighandler(int sig __maybe_unused)
{
+ done = 1;
}
static int check_lock_contention_options(const struct option *options,
@@ -2124,11 +2128,16 @@ static int __cmd_contention(int argc, const char **argv)
if (use_bpf) {
lock_contention_start();
- if (argc)
- evlist__start_workload(con.evlist);
- /* wait for signal */
- pause();
+ done = 0;
+
+ if (argc) {
+ evlist__start_workload(con.evlist);
+ waitpid(con.evlist->workload.pid, NULL, 0);
+ } else {
+ while (!done)
+ sleep(1);
+ }
lock_contention_stop();
lock_contention_read(&con);
--
2.43.0
next prev parent reply other threads:[~2026-04-22 5:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 5:05 [PATCH v3 0/3] perf: Fix SIGCHLD vs pause() race with short-lived workloads Swapnil Sapkal
2026-04-22 5:05 ` [PATCH v3 1/3] perf sched stats: Fix SIGCHLD vs pause() race in schedstat_record() Swapnil Sapkal
2026-04-22 5:29 ` sashiko-bot
2026-04-22 21:21 ` Namhyung Kim
2026-04-22 5:05 ` [PATCH v3 2/3] perf sched stats: Fix SIGCHLD vs pause() race in schedstat_live() Swapnil Sapkal
2026-04-22 7:20 ` sashiko-bot
2026-04-22 5:05 ` Swapnil Sapkal [this message]
2026-04-22 11:31 ` [PATCH v3 3/3] perf lock contention: Fix SIGCHLD vs pause() race in __cmd_contention() sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260422050545.129448-4-swapnil.sapkal@amd.com \
--to=swapnil.sapkal@amd.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox