Skip to content

Commit de9f498

Browse files
changbinduacmel
authored andcommitted
perf trace: Avoid early exit due SIGCHLD from non-workload processes
The function trace__symbols_init() runs "perf-read-vdso32" and that ends up with a SIGCHLD delivered to 'perf'. And this SIGCHLD make perf exit early. 'perf trace' should exit only if the SIGCHLD is from our workload process. So let's use sigaction() instead of signal() to match such condition. Committer notes: Use memset to zero the 'struct sigaction' variable as the '= { 0 }' method isn't accepted in many compiler versions, e.g.: 4 34.02 alpine:3.6 : FAIL clang version 4.0.0 (tags/RELEASE_400/final) builtin-trace.c:4897:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] struct sigaction sigchld_act = { 0 }; ^ {} builtin-trace.c:4897:37: error: missing field 'sa_mask' initializer [-Werror,-Wmissing-field-initializers] struct sigaction sigchld_act = { 0 }; ^ 2 errors generated. 6 32.60 alpine:3.8 : FAIL gcc version 6.4.0 (Alpine 6.4.0) builtin-trace.c:4897:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] struct sigaction sigchld_act = { 0 }; ^ {} builtin-trace.c:4897:37: error: missing field 'sa_mask' initializer [-Werror,-Wmissing-field-initializers] struct sigaction sigchld_act = { 0 }; ^ 2 errors generated. 7 34.82 alpine:3.9 : FAIL gcc version 8.3.0 (Alpine 8.3.0) builtin-trace.c:4897:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] struct sigaction sigchld_act = { 0 }; ^ {} builtin-trace.c:4897:37: error: missing field 'sa_mask' initializer [-Werror,-Wmissing-field-initializers] struct sigaction sigchld_act = { 0 }; ^ 2 errors generated. Signed-off-by: Changbin Du <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0bc2ba4 commit de9f498

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

tools/perf/builtin-trace.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,20 @@ static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
15361536
return fprintf(fp, " ? ");
15371537
}
15381538

1539+
static pid_t workload_pid = -1;
15391540
static bool done = false;
15401541
static bool interrupted = false;
15411542

1542-
static void sig_handler(int sig)
1543+
static void sighandler_interrupt(int sig __maybe_unused)
15431544
{
1544-
done = true;
1545-
interrupted = sig == SIGINT;
1545+
done = interrupted = true;
1546+
}
1547+
1548+
static void sighandler_chld(int sig __maybe_unused, siginfo_t *info,
1549+
void *context __maybe_unused)
1550+
{
1551+
if (info->si_pid == workload_pid)
1552+
done = true;
15461553
}
15471554

15481555
static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp)
@@ -3938,7 +3945,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
39383945
bool draining = false;
39393946

39403947
trace->live = true;
3941-
signal(SIGCHLD, sig_handler);
39423948

39433949
if (!trace->raw_augmented_syscalls) {
39443950
if (trace->trace_syscalls && trace__add_syscall_newtp(trace))
@@ -4018,6 +4024,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
40184024
fprintf(trace->output, "Couldn't run the workload!\n");
40194025
goto out_delete_evlist;
40204026
}
4027+
workload_pid = evlist->workload.pid;
40214028
}
40224029

40234030
err = evlist__open(evlist);
@@ -4887,10 +4894,16 @@ int cmd_trace(int argc, const char **argv)
48874894
const char * const trace_subcommands[] = { "record", NULL };
48884895
int err = -1;
48894896
char bf[BUFSIZ];
4897+
struct sigaction sigchld_act;
48904898

48914899
signal(SIGSEGV, sighandler_dump_stack);
48924900
signal(SIGFPE, sighandler_dump_stack);
4893-
signal(SIGINT, sig_handler);
4901+
signal(SIGINT, sighandler_interrupt);
4902+
4903+
memset(&sigchld_act, 0, sizeof(sigchld_act));
4904+
sigchld_act.sa_flags = SA_SIGINFO;
4905+
sigchld_act.sa_sigaction = sighandler_chld;
4906+
sigaction(SIGCHLD, &sigchld_act, NULL);
48944907

48954908
trace.evlist = evlist__new();
48964909
trace.sctbl = syscalltbl__new();

0 commit comments

Comments
 (0)