Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1979342pxb; Wed, 9 Feb 2022 08:27:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFOPDeVljs6wi/cj5902sxb89yF5SGhFffLXQg1qby7lQOROIpwtoXi80vYwZCioabduGD X-Received: by 2002:a17:90a:1bc2:: with SMTP id r2mr4200823pjr.15.1644424024514; Wed, 09 Feb 2022 08:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644424024; cv=none; d=google.com; s=arc-20160816; b=J66oW7J7iOQ16NNpg4xxJBazeRtEndjz7hCkdwjU7Zb0Z1Vkh6DpHdYXPxLtwpEun4 pIuXxGeCXOY4VzH2YH0eM/YRv+Y7OZtzS02C2znR0UGjh7DVFL1lTBgP+2TBiagUdGrQ L/CN6mogtgsLw9eNrkJYGIwkRHyCoJbOse5+vbOUfybqx8DbJIyvMYyGU5tQ5MgPqbQo pxLWBxxhWSZInmzQ6iNS8f8roKRSVhe8fsbz01xRXrlxyzG4VrdxzAO9OqmPTNImifFT cVM6027F3Iq0D4PP1aYCQyEkE7d7MNLXyeKDdDWhCCI0byDbXa/PGbJdIzUI5zAPGooE 6cuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RpsFFufSgZxF9c2Hp3nUYbzijvPIIlzNxPWiAkM3IVA=; b=VbxOj9CPWz/TALCTaZ/IYyxyZVFDJofO5zrL5CS6MVhNvJVUT5DbvH4t3ea3a9lCpe l0KjS/utf/Dqoa+6zeEWKi48fNMXbC+TXI49eZPcnGqdaC4hN2/a40Z0oJf2t0uJbL5X NRX1bOMT+bhJv7a0R5YD9vuLcD1O0dGcpoK/ZvAV2HhWhTZ9l53JoyoqSDCro5RTLthf RQYW1pbqvcV3M+EDXwblNfjRHerM6DsWTDgw/vrZ4iXwM5l3XcBQdp3Aww2oCj9jO4ZM UacN1ziLP5l2p5Z8BNEM1Yiz+sGKhMkki50vR5dUrtCvrOAKYYOgVPdsUSHoQpEvVjxS 72NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rOHL3v3W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g27si1885661pgb.442.2022.02.09.08.26.50; Wed, 09 Feb 2022 08:27:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rOHL3v3W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236301AbiBIPu2 (ORCPT + 99 others); Wed, 9 Feb 2022 10:50:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbiBIPuY (ORCPT ); Wed, 9 Feb 2022 10:50:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4AF7C0613C9; Wed, 9 Feb 2022 07:50:27 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 53D61B8219F; Wed, 9 Feb 2022 15:50:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A99BCC340E7; Wed, 9 Feb 2022 15:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644421825; bh=wMNYrDXg2eHpDbxlrXn7r2hj+pvWdMuwOJy/MY0tMDg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rOHL3v3Wkf6gp7AH52BgCfkRMhI06e+OP9ytlZElSwIuKi78ecjK/3PI7Z/lBDVt8 xDeYXB3o5O8374P3RNUY79qg/vKyqpyk3G7MAKP29F1aJOpNn74XCq0f3t7coJOp+3 qsoa+8f8JmBJIWa1ow3lBfse+BFBgwnDZJKLyU45hruLaYpwgQqib7S8T0R2jGvOiw gerlI0J4bEq7j/7VYMmTb23EP6NvsoqVpd2dnk19MMsxjCbPPRUCVcsawnbk9s3ZeW HodtwIviFB93fiU4Ru6f4Atm1bmU0pem/EOxLE4oPBJbBpumYNNZphYxdsG2cf2Yl5 XR6nhjF0OPFpw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id B910E400FE; Wed, 9 Feb 2022 12:50:07 -0300 (-03) Date: Wed, 9 Feb 2022 12:50:07 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: Changbin Du , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf trace: Avoid early exit due SIGCHLD from non-workload processes Message-ID: References: <20220208140725.3947-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Feb 09, 2022 at 04:01:33PM +0100, Jiri Olsa escreveu: > On Tue, Feb 08, 2022 at 10:07:25PM +0800, Changbin Du wrote: > > 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. > > > > Signed-off-by: Changbin Du > > good idea, I tested with the reproducer for: > f06a82f9d31a perf trace: Avoid early exit due to running SIGCHLD handler before it makes sense to > > and it's working properly > > Acked-by: Jiri Olsa So can I replace this with the stronger: Tested-by: Jiri Olsa ? - Arnaldo > thanks, > jirka > > > --- > > tools/perf/builtin-trace.c | 21 ++++++++++++++++----- > > 1 file changed, 16 insertions(+), 5 deletions(-) > > > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > > index 32844d8a0ea5..d03556c14b0a 100644 > > --- a/tools/perf/builtin-trace.c > > +++ b/tools/perf/builtin-trace.c > > @@ -1536,13 +1536,20 @@ static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) > > return fprintf(fp, " ? "); > > } > > > > +static pid_t workload_pid = -1; > > static bool done = false; > > static bool interrupted = false; > > > > -static void sig_handler(int sig) > > +static void sighandler_interrupt(int sig __maybe_unused) > > { > > - done = true; > > - interrupted = sig == SIGINT; > > + done = interrupted = true; > > +} > > + > > +static void sighandler_chld(int sig __maybe_unused, siginfo_t *info, > > + void *context __maybe_unused) > > +{ > > + if (info->si_pid == workload_pid) > > + done = true; > > } > > > > 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) > > bool draining = false; > > > > trace->live = true; > > - signal(SIGCHLD, sig_handler); > > > > if (!trace->raw_augmented_syscalls) { > > 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) > > fprintf(trace->output, "Couldn't run the workload!\n"); > > goto out_delete_evlist; > > } > > + workload_pid = evlist->workload.pid; > > } > > > > err = evlist__open(evlist); > > @@ -4887,10 +4894,14 @@ int cmd_trace(int argc, const char **argv) > > const char * const trace_subcommands[] = { "record", NULL }; > > int err = -1; > > char bf[BUFSIZ]; > > + struct sigaction sigchld_act = { 0 }; > > > > signal(SIGSEGV, sighandler_dump_stack); > > signal(SIGFPE, sighandler_dump_stack); > > - signal(SIGINT, sig_handler); > > + signal(SIGINT, sighandler_interrupt); > > + sigchld_act.sa_flags = SA_SIGINFO; > > + sigchld_act.sa_sigaction = sighandler_chld; > > + sigaction(SIGCHLD, &sigchld_act, NULL); > > > > trace.evlist = evlist__new(); > > trace.sctbl = syscalltbl__new(); > > -- > > 2.25.1 > > -- - Arnaldo