Skip to contentSkip to conversation

perf trace: Fix race in signal handling

PATCH Applied Michael Petlan 2 participants 2 messages Mar 3, 2021 – Mar 5, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf trace: Fix race in signal handling

Since a lot of stuff happens before the SIGINT signal handler is registered (scanning /proc/*, etc.), on bigger systems, such as Cavium Sabre CN99xx, it may happen that first interrupt signal is lost and perf isn't correctly terminated.

The reproduction code might look like the following:

perf trace -a &
PERF_PID=$!
sleep 4
kill -INT $PERF_PID

The issue has been found on a CN99xx machine with RHEL-8 and the patch fixes it by registering the signal handlers earlier in the init stage.

---
 tools/perf/builtin-trace.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/builtin-trace.c +2 -3
index 85b6a46e85b6..7ec18ff57fc4 100644
@@ -3964,9 +3964,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 
 	evlist__config(evlist, &trace->opts, &callchain_param);
 
-	signal(SIGCHLD, sig_handler);
-	signal(SIGINT, sig_handler);
-
 	if (forks) {
 		err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL);
 		if (err < 0) {
@@ -4827,6 +4824,8 @@ int cmd_trace(int argc, const char **argv)
 
 	signal(SIGSEGV, sighandler_dump_stack);
 	signal(SIGFPE, sighandler_dump_stack);
+	signal(SIGCHLD, sig_handler);
+	signal(SIGINT, sig_handler);
 
 	trace.evlist = evlist__new();
 	trace.sctbl = syscalltbl__new();
Signature · 1 line
2.18.4
maintainer Applied
#1 lore raw

Em Tue, Mar 02, 2021 at 03:41:20PM +0100, Michael Petlan escreveu:

Quoted 7 lines

Since a lot of stuff happens before the SIGINT signal handler is registered (scanning /proc/*, etc.), on bigger systems, such as Cavium Sabre CN99xx, it may happen that first interrupt signal is lost and perf isn't correctly terminated.

The reproduction code might look like the following:

Quoted 7 lines

perf trace -a &
PERF_PID=$!
sleep 4
kill -INT $PERF_PID

The issue has been found on a CN99xx machine with RHEL-8 and the patch fixes it by registering the signal handlers earlier in the init stage.

Thanks, applied.

- Arnaldo

Quoted 33 lines
---
 tools/perf/builtin-trace.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/builtin-trace.c +2 -3
index 85b6a46e85b6..7ec18ff57fc4 100644
@@ -3964,9 +3964,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 
 	evlist__config(evlist, &trace->opts, &callchain_param);
 
-	signal(SIGCHLD, sig_handler);
-	signal(SIGINT, sig_handler);
-
 	if (forks) {
 		err = evlist__prepare_workload(evlist, &trace->opts.target, argv, false, NULL);
 		if (err < 0) {
@@ -4827,6 +4824,8 @@ int cmd_trace(int argc, const char **argv)
 
 	signal(SIGSEGV, sighandler_dump_stack);
 	signal(SIGFPE, sighandler_dump_stack);
+	signal(SIGCHLD, sig_handler);
+	signal(SIGINT, sig_handler);
 
 	trace.evlist = evlist__new();
 	trace.sctbl = syscalltbl__new();
Signature · 1 line
2.18.4
Signature · 1 line
- Arnaldo