Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp182691ybk; Tue, 12 May 2020 19:35:22 -0700 (PDT) X-Google-Smtp-Source: APiQypI3Cv3YsuM1nX6KKSQ780zzp4HZN+HToE7kXRCkfeALZr1ZsQkSfCxtp+lBtZfyMNxgWNQB X-Received: by 2002:a17:906:390a:: with SMTP id f10mr19893741eje.74.1589337322815; Tue, 12 May 2020 19:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589337322; cv=none; d=google.com; s=arc-20160816; b=o5nNZl2eVV/H6B1xR7f6/viuVwJ5cg57lcCNWgDWRhi+NBFFcG/lQbVXVFbL3ELJvm xE1vPGMDRrRO33aNu9fiV23dHNCmJ2QcykFc6yqnfy25p7vEEE3omS5H6JW9L1ocRMjz rR/Td18b/rL5B/8JOSZgclhtrhE/LVnGWUXaiMi5t5JFnF7bfV/HqMjm0suR0t6f7yB7 pzKyuRAB/FB33DTNj7h5Jpr18NlM++XYGbJQvbjoOrtVnmXemotXjcFHr4+41Th14WeV YK/2PD7a+pRxBzJIhrgf9OH9caRwK9h009u1b4eOBzBJb/2p1E4vyLAclP++VLF7jam5 H20w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=mpKvcF6cYRPs0VzgIvpbSSok+xEKbZDD7B97t881690=; b=PcfHQK+cHUDuGkT88j+XSLc/seTQ66PJqlsUjUT5d4hXdNZXK2TNk16N4hPkBjnTxI Nuqz4jdxoBd3BKrScxcWLMfTBZF6U0+ULvq9MhI7lIv/BS+PfpW40O9yj+TruENDEOEg 56qNpVQnePJuGgCdDG8F3LDHTUGXcdpzSa+tXaH917oEsTnKaC5zf3JursapIvSa/i77 nQLDf8baHBJ6OXdDz5dR4XMQUq6AtTLlvhiHM+/RKxH/nGanD2yuLWbwHdCszKcPlz52 X50VbqngYTm4c2tHrpJ86jKms0hsgifSI/PFEOo+0Ry8BaJXpfoo7TLeRXqDeRDrNYwP aIEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sqMPCg3Q; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si1499567edl.560.2020.05.12.19.35.00; Tue, 12 May 2020 19:35:22 -0700 (PDT) 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=@google.com header.s=20161025 header.b=sqMPCg3Q; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728842AbgEMCaf (ORCPT + 99 others); Tue, 12 May 2020 22:30:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbgEMCad (ORCPT ); Tue, 12 May 2020 22:30:33 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA245C061A0E for ; Tue, 12 May 2020 19:30:32 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id x5so7342756ioh.6 for ; Tue, 12 May 2020 19:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mpKvcF6cYRPs0VzgIvpbSSok+xEKbZDD7B97t881690=; b=sqMPCg3QfMXcQFjaw5y++wf6akTbJosdSGIyVaJm9w71VV8Hc95x4E+S5im0s5FIm9 mQMVfAMXxucEo5Qy2klvk5FWU469JLCzitibrEuW48AAyNgw8C9TvXd2ZGb7bFTXxDXC vmxUIwnPjAufC9vq8KFfDJDtAQUGaAB8PYUAi5xmchF2Ax/PLc9hmATwDz6uiFeK5dSf uxtcncnqHgcQp6MmBZNktKYrFwfVz+cuRl7rVuovioS7eDtOerqssnXLyBt7jUHYDw9a 1fWxnT/bqc/ulzP9cHhGYMCYdPHfGP6ZaAzMqmaBurU9D2zwWwu+Ny3RrA07xaeP7Bjw 77XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mpKvcF6cYRPs0VzgIvpbSSok+xEKbZDD7B97t881690=; b=uJXJ0MFkxmZtdyC2iPPUODftV0vLbmQl0G+yVOjwHTYjMUSoGaqsT2FKWhMBSNXDS7 Y95WgkhgzkhoO3EsxJuZ3ZS7ROV/K8dkNrX/EC3tH886Mi7YYwu556VFmicg/r7ZDtLS VEFeHUdGWCQcrxoy3JJdNPsxnfNwSXeXMP33LVZHbZ7/PZshFMmaohvQekvrZCmk1PaG mxHg9vKmg4JKu8dddEPuAIVBSXZ++REGZKqxm3gx8m3J7f86L7pN2vUFuzZ4ZSOMij+5 fD6RdYhgiAjQ29XzWeKuo3/YWzuGpnrk2JOaau7q5q1xI/UrEJKdb7JGy0RU4aHP8Ib+ VtUQ== X-Gm-Message-State: AGi0PuablMSKt4gZJ8Z/ffBsPOSaVpE05y6ljll3BGNYvUrtop6/505i jKJoHhDgsdY9tTy/1gQ7PIrSgrht+PWDoiO157la9Q== X-Received: by 2002:a6b:ea11:: with SMTP id m17mr17257024ioc.149.1589337031931; Tue, 12 May 2020 19:30:31 -0700 (PDT) MIME-Version: 1.0 References: <20200508145624.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> <20200512145930.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> <20200512121232.GB3150977@krava> <20200512141221.GL28888@kernel.org> In-Reply-To: <20200512141221.GL28888@kernel.org> From: "Anand K. Mistry" Date: Wed, 13 May 2020 12:30:20 +1000 Message-ID: Subject: Re: [PATCH] perf record: Use an eventfd to wakeup when done To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , linux-perf-users@vger.kernel.org, Alexander Shishkin , Ingo Molnar , Mark Rutland , Namhyung Kim , Peter Zijlstra , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 13 May 2020 at 00:12, Arnaldo Carvalho de Melo wrote: > > Em Tue, May 12, 2020 at 02:12:32PM +0200, Jiri Olsa escreveu: > > On Tue, May 12, 2020 at 02:59:36PM +1000, Anand K Mistry wrote: > > > > SNIP > > > > > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > > > index 1ab349abe90469..099ecaa66732a2 100644 > > > --- a/tools/perf/builtin-record.c > > > +++ b/tools/perf/builtin-record.c > > > @@ -53,6 +53,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > #include > > > @@ -518,15 +519,28 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size) > > > > > > static volatile int signr = -1; > > > static volatile int child_finished; > > > +static int done_fd = -1; > > > > > > static void sig_handler(int sig) > > > { > > > + u64 tmp = 1; > > > if (sig == SIGCHLD) > > > child_finished = 1; > > > else > > > signr = sig; > > > > > > done = 1; > > > + > > > + /* > > > + * It is possible for this signal handler to run after done is checked > > > + * in the main loop, but before the perf counter fds are polled. If this > > > + * happens, the poll() will continue to wait even though done is set, > > > + * and will only break out if either another signal is received, or the > > > + * counters are ready for read. To ensure the poll() doesn't sleep when > > > + * done is set, use an eventfd (done_fd) to wake up the poll(). > > > + */ > > > + if (write(done_fd, &tmp, sizeof(tmp)) < 0) > > > + pr_err("failed to signal wakeup fd\n"); > > > } > > > > > > static void sigsegv_handler(int sig) > > > @@ -1424,6 +1438,17 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) > > > int fd; > > > float ratio = 0; > > > > > > + done_fd = eventfd(0, EFD_NONBLOCK); > > > + if (done_fd < 0) { > > > + pr_err("Failed to create wakeup eventfd, error: %m\n"); > > > + return -1; > > > + } > > > + err = evlist__add_pollfd(rec->evlist, done_fd); > > > + if (err < 0) { > > > + pr_err("Failed to add wakeup eventfd to poll list\n"); > > > + return -1; > > > + } > > > > sorry I did not notice before, but I think we also > > need to close done_fd descriptor on the exit path > > > > also please change subject to PATCHv3 for the next version Apologies. I'm still getting the hang of this. > > Yeah, and, and don't take this as a requirement for this patch to be > processed, this can be made as a follow up patch by you or someone else > (me, maybe :)), that maybe tools/perf/builtin-top.c and > tools/perf/builtin-trace.c have the same issue? > > Could you please take a look there as well? I looked at 'top', 'trace', and 'kvm'. kvm doesn't really have this issue because the poll() has a 100ms timeout. Even though it's technically affected, the timeout will make it unnoticeable (just delaying the exit for 100ms). top is in the same boat (uses a timeout). trace is the affected one because it has the following code: int timeout = done ? 100 : -1; if (!draining && evlist__poll(evlist, timeout) > 0) { Different logic, but still a gap and an indefinite timeout. > > - Arnaldo > > > thanks, > > jirka > > > > > + > > > atexit(record__sig_exit); > > > signal(SIGCHLD, sig_handler); > > > signal(SIGINT, sig_handler); > > > -- > > > 2.26.2.645.ge9eca65c58-goog > > > > > > > -- > > - Arnaldo -- Anand K. Mistry Software Engineer Google Australia