Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2088761pxb; Wed, 9 Feb 2022 10:35:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoQAaHVpcb+foYjPZQYS7NkpfsusmW2LzkLfzMWX+Yewmuci6Dh0QktHmGeeiZoMdqHNVs X-Received: by 2002:a17:90b:2342:: with SMTP id ms2mr4808787pjb.109.1644431705599; Wed, 09 Feb 2022 10:35:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644431705; cv=none; d=google.com; s=arc-20160816; b=HyssCPhos4fg0tm9J+DZ2uFC/wAF0lZAPbvOvcmA7tOUMvCGBrP5AK+n/S/czT8T2L Id474UmRPyLI6hFJNlr24aKtLvlALCtvBx/9kYYRjohAT/T4SuCQLretKF8BQX0PUN0W ZwkpPETD1cjA3hJdUghgF91Cwqa7pChOavKNBGcehOBtan/o/FtFwt4TTgAnULzHeBvP D/mpf0svwlzn8lXigSo20AZDc718NnnQ5E29Y4vK5+g7V0PFDdm4UUvAJ/i4n8jrKtXC RyY32TKSpvGCYSCqGi9j2+XLlFbtgRET764Og2WKBE8YyuwKnc3av0hjJc0etZBvZUYS us6w== 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=59r6R8CamhNOPJf3ecn98Vx3RC5ol7vbLhaSn6mMvIo=; b=uQOZnCQZKiirVQ0APBmQUouaPPVxkHlmACHJNm155B9HYnIrw6mBArc8gtKmiT0Tbg U80fz0gZ3ZvRqfvHDZHnARNLdxxcryTMysDKIw5tyUd5ecJr5ImuT3kOzkpJyOV7/NMu 2IUoZIOLmdH8mCKy/MwKM2XFAZv+UHA4RQ1ekMv2T8eswK6MBqYYajV5nRD9kV4NXetY EwL1L9wwsRbCuEu9e414YzFcneqF8hY8E2Ova6OGi5UT0EkgVerJk1Ml+nECSVo86cGi T8PmFU2vJPSmh8ettgjlk8yqhq0VDF2St31/RzvL0GG8fsoQ0iCXcPXILucej6z645Zb a9sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pDois4WM; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si10636661plx.83.2022.02.09.10.34.52; Wed, 09 Feb 2022 10:35:05 -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=@gmail.com header.s=20210112 header.b=pDois4WM; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235403AbiBIPBh (ORCPT + 99 others); Wed, 9 Feb 2022 10:01:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235398AbiBIPBf (ORCPT ); Wed, 9 Feb 2022 10:01:35 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21A36C05CB82; Wed, 9 Feb 2022 07:01:38 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id co28so5736401edb.1; Wed, 09 Feb 2022 07:01:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=59r6R8CamhNOPJf3ecn98Vx3RC5ol7vbLhaSn6mMvIo=; b=pDois4WM2LuDFwB6uV9Teb2Kp/HL9tcYymFG1NtByoNhF1AsQVwIw9j1rpCJx0qnhd E/I14wGx5viSrfhS/qVQbf4T4PiJY3TR1XMxgbfCUcNQBWLOqMIEiCVA+1pJu5d2AZCd Mz1f2fmrcyfB5wqDJmsdTBN6voCGrhsLcB2o0+i8l+Rlj+AtcYxRNrZMU8lBeIdkmDt9 q3RHuVwna+u89qpLbMlS4ItLIOjldB1NkFOdJlIRMh6e43uJS61zSFgE9HwFDQbt92c8 PoFHmTJFj9P2LRJ1RPbODqPWcQrUr8G0DMWc2R0c5fUIElzFBztk/GqXLenIRFYXnzud MZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=59r6R8CamhNOPJf3ecn98Vx3RC5ol7vbLhaSn6mMvIo=; b=3KKx+fHwTnGQtJOlKifp7Y9suqpmFQyuIZ70wzzEwFBG4208OZTCzF2feNXx/lz7wR /GN60sAwmNDZfGcfEHUWnc9rVUgeyKNSM13uwTCGwjRoVCSurqR5Wz13futrdjQFfmAq xLAvNV/teIzHFx/xG9YPEJY0FJwVQjTuUR1cNRACNc6KC92dBCY7GFw8kCEym3lWhC99 Ga2x7s5k0BSek0z3Ickx0lfsmjPtum9IgkGWQp1tr2XQvvj03YHmEdqFYVW5eMyxueqX vpnLApJf0/AcPFWrxfrrBFNTo8ZA3/uA2B5PFXyQW72xiSKHYqAFjW+3xZvUkXaadOAM 3yqw== X-Gm-Message-State: AOAM533iNWSMBKjJQtrNpp5BmGxaeI3aG74cdlxmhtUrLk1WUAd5lJD+ thMZE9JhFdgKAgZk2Fqaf4Y= X-Received: by 2002:aa7:d84e:: with SMTP id f14mr2884470eds.46.1644418896457; Wed, 09 Feb 2022 07:01:36 -0800 (PST) Received: from krava ([2a00:102a:5010:3235:47fb:6193:ef68:761d]) by smtp.gmail.com with ESMTPSA id gu2sm6024567ejb.221.2022.02.09.07.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 07:01:36 -0800 (PST) Date: Wed, 9 Feb 2022 16:01:33 +0100 From: Jiri Olsa To: Changbin Du Cc: Arnaldo Carvalho de Melo , 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: <20220208140725.3947-1-changbin.du@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 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 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 >