]> Git Repo - linux.git/commitdiff
perf trace: Fix race in signal handling
authorMichael Petlan <[email protected]>
Tue, 2 Mar 2021 14:41:20 +0000 (15:41 +0100)
committerArnaldo Carvalho de Melo <[email protected]>
Sat, 6 Mar 2021 19:54:32 +0000 (16:54 -0300)
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.

Suggested-by: Jiri Olsa <[email protected]>
Signed-off-by: Michael Petlan <[email protected]>
Tested-by: Michael Petlan <[email protected]>
Cc: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/builtin-trace.c

index 85b6a46e85b686b99b2e7b99ba5e7a4de71b13d3..7ec18ff57fc4ae353eae76c8d53f26e68ea6b1c7 100644 (file)
@@ -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();
This page took 0.064032 seconds and 4 git commands to generate.