Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2748707ybk; Tue, 12 May 2020 07:15:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0qnkc9GS/i+DtaoANQB/gLdalyJt1lQC+qnfXmDpkWPrsLHY7dKXhzUPq7LtXuNSSUMJP X-Received: by 2002:a50:ccc5:: with SMTP id b5mr1163126edj.340.1589292908588; Tue, 12 May 2020 07:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589292908; cv=none; d=google.com; s=arc-20160816; b=Kkls2OBaRHRNkQ2Au7m1PwxCa24rP/5Rsa+QHG/S9t0wepXc78oEIc3jyIbKM6UWAj LgZgbHgExE+a84qhrWqKR+uoKKjtQ19PqzWTdPo6z7ke1vy/SmW58WkiQLpO023WbNYO j1RnV4dah0f7V6HH7NtQKXlPy5bapjsFEZP+5t4ZnxiOPt6BnBWLL8TZoojYkfo8nt5X ZbRMn/DVd4ZAVgCgKOxBfFt/KKa2VLqJwXM7/Qg6jH83osL+MDqeS+29s8l68DnXmGzw SWiGStS+9L1hWm1ZCtYVQKBFppBrWHKb8yL3wePq3kTS+plLxD5Z9Tsddihz6KEJHyZ1 N4Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=gLlHheD6LOkmkommetBCdbZlMJmwyT7+bS4yMcoDtq4=; b=eWYXxNviOK9dR5NFIAQMBy3FDUNfaoOAQl/XV948psHB7OtN5ZfAQGULMr6//LYQsb ul45lTgoqBSME6bw9VvcBO2I93mGu1giXIZYmgTYh9CcQqOXugYyGIagY5KOeVqaEItM UBrShT1wlFHzefgAqyrEACYgGdImmF1jcpky59ZG82WlPLcieoz+cykyS8x7DYbWy8eE PHs/k+JduTy5UIhYeVZfqRS9BrFO/llni81Sucije3xHnVi4+FbtqihtFSdabA3RO5RI 7i2Nq9VAc1IIHk1wFxRvG9X0itE4cwDBgn7Y4jT849q3HTJEHyAt4Er6f3MbxLP+yzPM r+Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hP5ckQta; 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 n7si1399618eji.91.2020.05.12.07.14.45; Tue, 12 May 2020 07:15:08 -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=@gmail.com header.s=20161025 header.b=hP5ckQta; 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 S1730249AbgELOM1 (ORCPT + 99 others); Tue, 12 May 2020 10:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728283AbgELOM0 (ORCPT ); Tue, 12 May 2020 10:12:26 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD71C061A0C; Tue, 12 May 2020 07:12:25 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id l1so7592455qtp.6; Tue, 12 May 2020 07:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=gLlHheD6LOkmkommetBCdbZlMJmwyT7+bS4yMcoDtq4=; b=hP5ckQtarO3Kj2nj5YGtyndG5YmjzNrFFoURaiK9DOHfFW+5RqSnBCa/ynEUUBC9uk 2d52d/YNEj/iT3NKyAXlNkF4ZNdbrbf0N7GyAUrA/1L1uqgZyulITpdOM9ELLEt/CUwh T0EArrE+qeQB7w5LYO8P4CRnZ0w2AsEim15cBQiz5ZbCOCS9jtjBlgMSRg7zHLmbJ+IF ZQpqoxirjxNMZqTbeT8STLeMg32z7XaOkyueKlwYHkxW8nnoNKhLx0WchVzt4qw5EW+F +GNw6RhrQ3kEJjqv1Hb7UBG8gkVz8LYEDmmd7QGNckqr7jcxAo/7+GJJRE9mMrNvrdfj 6iiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=gLlHheD6LOkmkommetBCdbZlMJmwyT7+bS4yMcoDtq4=; b=kHe8b3Oa5NAgu2MOeMjrmjmHXnpyi/LZLX4Q000IlyCiAT/DbQXHEo4JAZTOCwJyds vs/xHumrDSfe7bqwYDQdNhPFJAS4NIvbH7yI4VutQ7FrMaQHSshNTJvKOcQX64QicmJA Dfox6P7bPEzXfVdZKKGh19vacIE1NNglIacWVnPS2MIcylcR+4X9RexgystZPpEjeelT ShGAWSNyJXnPDvUxWAFj7+cB+nMbxyfzgOiq98sSSyScqvaZalFuak9F0wbnmegIRV/r f+kBR7b70wjLIMJly4uUxVUuf6ODF9D9NSQlLTOHoXUq/RcMlE3oCocLLiPFMKZSABfk dt2w== X-Gm-Message-State: AGi0PuZrjLM6Ym/NJJ3Fc2txdHw0UYqW7wz3yE7z2enabvWaD+BpzZij WBzQ0bMBKBBPKhlDONlXb/Y= X-Received: by 2002:ac8:66c6:: with SMTP id m6mr22446881qtp.25.1589292744880; Tue, 12 May 2020 07:12:24 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.37.151]) by smtp.gmail.com with ESMTPSA id y28sm6811400qtc.62.2020.05.12.07.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 07:12:24 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id F19C940AFD; Tue, 12 May 2020 11:12:21 -0300 (-03) Date: Tue, 12 May 2020 11:12:21 -0300 To: Jiri Olsa Cc: Anand K Mistry , linux-perf-users@vger.kernel.org, Alexander Shishkin , Ingo Molnar , Mark Rutland , Namhyung Kim , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf record: Use an eventfd to wakeup when done Message-ID: <20200512141221.GL28888@kernel.org> References: <20200508145624.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> <20200512145930.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> <20200512121232.GB3150977@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200512121232.GB3150977@krava> X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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? - Arnaldo > thanks, > jirka > > > + > > atexit(record__sig_exit); > > signal(SIGCHLD, sig_handler); > > signal(SIGINT, sig_handler); > > -- > > 2.26.2.645.ge9eca65c58-goog > > > -- - Arnaldo