Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2665737ybk; Tue, 12 May 2020 05:16:39 -0700 (PDT) X-Google-Smtp-Source: APiQypJAAQwdfn4zI7faEQtdavgX04Za/EH6UQm+nCHNll7MzExu8KwDPSB0OkCcAKD5LOVjgQET X-Received: by 2002:a17:907:43bf:: with SMTP id ok23mr13018951ejb.68.1589285799692; Tue, 12 May 2020 05:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589285799; cv=none; d=google.com; s=arc-20160816; b=zUweSX/TRbNXVLM6swGtZiV/mnBuHq5NreRRYxUyLLuxMQfVeJabruEosEa6sTQrJF TlQDCeLEXRK2NQRaUkG82ZqAgz6yGdzJFlKwkWIVFuxGJ4WcdQX3+BTlHGWM2So5rhOY Rcpb+OJkPg44+WIrNfcb4XAxzbI77Q2WGapQznztEzvHSpjq5tda6HamoF6W7l//tRQV L3pIbP5IO9nlTP+NyWQCYzqCy9LEcAZrKU+rLB+UUtB5wLf7XlHajaC2M+i6iy3NeJTS NbBgvDEbuGnzltgVDbb9pO4Sqo3FA7b5xBEP1TtJCHMyHVKl2wScSwTK/B5mpTY3HemS ReuA== 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:from:date :dkim-signature; bh=asu/+mb4aQxasBk4gTFYsedBOKgWTv0nv0/dQGL9xlg=; b=eirRmUAx4sHmjVLFH5ptJW/VAalRt1XW7ipZ4D1gXLVqLoLLdIkv48pVz23T00/6Ok 2gOVNrlqxiCQ4yAiBKvwDjeNoJkK50DxkJfeaqKOrwcEQtpu83hy1pAiSLpkO0/KPR/e yFyvcxtUxAUgYjBE6wMtaqFJ+paEIGnNoI6yoPAACHm/HHBVrjlG21H85eig0k4Vp6HQ LUtCx7LziVEwqPA4POM/PlMbgptqsernqR4b2DOtR/p/S+vuM/ulw8M+SbpjCDz7mDSS zgL+poGCrjCXXPZzUFiJ3vBm18CHao/IklGsb09jafk+mSryEOlOZbZ8NIJEoW7Nk2YL DQ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VsHJVIRg; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c22si5952982edx.33.2020.05.12.05.16.16; Tue, 12 May 2020 05:16:39 -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=@redhat.com header.s=mimecast20190719 header.b=VsHJVIRg; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729477AbgELMMl (ORCPT + 99 others); Tue, 12 May 2020 08:12:41 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:56147 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726891AbgELMMk (ORCPT ); Tue, 12 May 2020 08:12:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589285559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=asu/+mb4aQxasBk4gTFYsedBOKgWTv0nv0/dQGL9xlg=; b=VsHJVIRgBi1bx/wmjsfvCeu9nGZO2on2zhZBtLcpaIgeOY9dkjv34os/ptiA122AtNii2O tjtt8YDb/cyYxsXF+uy5lftJKOG1W98JejGKxBoHci+qiZNhxrLBJ0mFT9l1jLdNBErVL8 gD9fN9iqUzhmmnfjW7UwSJ71P8JY24E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-69-DBqH8HW2M8uXf1iJrx3s8w-1; Tue, 12 May 2020 08:12:37 -0400 X-MC-Unique: DBqH8HW2M8uXf1iJrx3s8w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6048835B40; Tue, 12 May 2020 12:12:35 +0000 (UTC) Received: from krava (unknown [10.40.194.31]) by smtp.corp.redhat.com (Postfix) with SMTP id 7B18C610AF; Tue, 12 May 2020 12:12:33 +0000 (UTC) Date: Tue, 12 May 2020 14:12:32 +0200 From: Jiri Olsa To: Anand K Mistry Cc: linux-perf-users@vger.kernel.org, Alexander Shishkin , Arnaldo Carvalho de Melo , 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: <20200512121232.GB3150977@krava> References: <20200508145624.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> <20200512145930.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200512145930.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeid> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 thanks, jirka > + > atexit(record__sig_exit); > signal(SIGCHLD, sig_handler); > signal(SIGINT, sig_handler); > -- > 2.26.2.645.ge9eca65c58-goog >