Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1218272pxb; Thu, 4 Mar 2021 06:24:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlDdW+YtM/5nUeboyQJW/cqBlNjlza1GAXW+8A029brpBnupG8IqymDL+zKTB/muTzq8+S X-Received: by 2002:aa7:cc94:: with SMTP id p20mr4615381edt.353.1614867867179; Thu, 04 Mar 2021 06:24:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614867867; cv=none; d=google.com; s=arc-20160816; b=wdYYxQhru2G6UY9zlkWsq6Lw3klofuMR9WiXRC+0iI+QBlcLRzFt/pPrlqbGp9pwMF Nqz6rylaU+yIp1eA3YmkT9ccmPdQAkctpcbZukPOe8rlCgz+s75Tp7LARvh8NpmoIWJJ WCs1aKR4ke+UhGGK7aaIFQ7tFYS7gLw8+RMMPOupx7WridvSg9875RcRWt0bgOGdUi4t Kfg4UVYVCXyB7H+hVHutT0UxwxUGn8r2XqaUHC74dyGZZd5W1+RaawfrlFkmsSXSvIYW Vm1NAAtCmpAw0VhmbzKufGwvA8ySjxPw1+hHq+7i/3MxKL6hm1fI/0z/5LFBGw0VxGCB +Acw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=5kxtmDao1yCVzdbwqk4mci+DemKSFhKsb7A14V+ki3g=; b=I/YIHL1ihom6cy9V4TWUDouLQi4lE/grKEglYyFfpkaRTGNFypVuEG4Jk2jvOd85gk eEmg9MCWlvPRJXDPhMhXDxqMwaY2Fw33gJ2rox0lg0RBEhIiwoT1MTE2kfBHoxRBefEa CVfXFBc7TegCc9KyekfqHGpGQPHlHAFBa4mPhFr7BNmiqbTbnoN70siJZTbl9iwQ0FmU 9j3NCbQ3K0pjlZGv6Kba2NqNpd9d4peBKapMN2KxKQ3ghxqxPxjWYkQZeQUOGpPFTLW8 dS5P2rmrSF2OAAh6SsldBoCl+DoibB4qX2Sp72cD5IJOty+CpIxy9IrmjR/UlfS+/pjN 6prw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r1si17621465ejp.0.2021.03.04.06.24.02; Thu, 04 Mar 2021 06:24:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237121AbhCDBVL (ORCPT + 99 others); Wed, 3 Mar 2021 20:21:11 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:13466 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236199AbhCDBUZ (ORCPT ); Wed, 3 Mar 2021 20:20:25 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DrXzq4CSJzjTZL; Thu, 4 Mar 2021 09:17:59 +0800 (CST) Received: from [10.67.102.248] (10.67.102.248) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Thu, 4 Mar 2021 09:19:32 +0800 Subject: Re: [PATCH] perf record: Fix continue profiling after draining the buffer To: Arnaldo Carvalho de Melo CC: Jiri Olsa , Namhyung Kim , , Alexey Budankov , Adrian Hunter , Alexander Shishkin , Mark Rutland , Ingo Molnar , Peter Zijlstra , linux-kernel , References: <20210205065001.23252-1-yangjihong1@huawei.com> <5a76a82e-7ec1-d510-309e-a38a1b41027e@huawei.com> From: Yang Jihong Message-ID: Date: Thu, 4 Mar 2021 09:19:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.248] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/4 0:43, Arnaldo Carvalho de Melo wrote: > Em Mon, Feb 22, 2021 at 09:31:51AM +0800, Yang Jihong escreveu: >> Hello, >> >> On 2021/2/19 1:09, Arnaldo Carvalho de Melo wrote: >>> Em Thu, Feb 18, 2021 at 10:20:53AM -0300, Arnaldo Carvalho de Melo escreveu: >>>> Em Fri, Feb 05, 2021 at 11:46:12AM +0100, Jiri Olsa escreveu: >>>>> On Fri, Feb 05, 2021 at 07:35:22PM +0900, Namhyung Kim wrote: >>>>>> Hello, >>>>>> >>>>>> On Fri, Feb 5, 2021 at 3:50 PM Yang Jihong wrote: >>>>>>> >>>>>>> commit da231338ec9c098707c8a1e4d8a50e2400e2fe17 uses eventfd to solve rare race >>>>>>> where the setting and checking of 'done' which add done_fd to pollfd. >>>>>>> When draining buffer, revents of done_fd is 0 and evlist__filter_pollfd >>>>>>> function returns a non-zero value. >>>>>>> As a result, perf record does not stop profiling. >>>>>>> >>>>>>> The following simple scenarios can trigger this condition: >>>>>>> >>>>>>> sleep 10 & >>>>>>> perf record -p $! >>>>>>> >>>>>>> After the sleep process exits, perf record should stop profiling and exit. >>>>>>> However, perf record keeps running. >>>>>>> >>>>>>> If pollfd revents contains only POLLERR or POLLHUP, >>>>>>> perf record indicates that buffer is draining and need to stop profiling. >>>>>>> Use fdarray_flag__nonfilterable to set done eventfd to nonfilterable objects, >>>>>>> so that evlist__filter_pollfd does not filter and check done eventfd. >>>>>>> >>>>>>> Fixes: da231338ec9c (perf record: Use an eventfd to wakeup when done) >>>>>>> Signed-off-by: Yang Jihong >>>>>>> --- >>>>>>> tools/perf/builtin-record.c | 2 +- >>>>>>> tools/perf/util/evlist.c | 8 ++++++++ >>>>>>> tools/perf/util/evlist.h | 4 ++++ >>>>>>> 3 files changed, 13 insertions(+), 1 deletion(-) >>>>>>> >>>>>>> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c >>>>>>> index fd3911650612..51e593e896ea 100644 >>>>>>> --- a/tools/perf/builtin-record.c >>>>>>> +++ b/tools/perf/builtin-record.c >>>>>>> @@ -1663,7 +1663,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) >>>>>>> status = -1; >>>>>>> goto out_delete_session; >>>>>>> } >>>>>>> - err = evlist__add_pollfd(rec->evlist, done_fd); >>>>>>> + err = evlist__add_wakeup_eventfd(rec->evlist, done_fd); >>>>>>> if (err < 0) { >>>>>>> pr_err("Failed to add wakeup eventfd to poll list\n"); >>>>>>> status = err; >>>>>>> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c >>>>>>> index 05363a7247c4..fea4c1e8010d 100644 >>>>>>> --- a/tools/perf/util/evlist.c >>>>>>> +++ b/tools/perf/util/evlist.c >>>>>>> @@ -572,6 +572,14 @@ int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask) >>>>>>> return perf_evlist__filter_pollfd(&evlist->core, revents_and_mask); >>>>>>> } >>>>>>> >>>>>>> +#ifdef HAVE_EVENTFD_SUPPORT >>>>>>> +int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd) >>>>>>> +{ >>>>>>> + return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN, >>>>>>> + fdarray_flag__nonfilterable); >>>>>>> +} >>>>>>> +#endif >>>>>> >>>>>> Does it build when HAVE_EVENTFD_SUPPORT is not defined? >>>>> >>>>> yea, I was wondering the same.. but it's called only from >>>>> code within HAVE_EVENTFD_SUPPORT ifdef >>>> >>>> Yes, this can't work on systems without eventfd, it will simply not >>>> build, and why do we have to make the definition of this function >>>> conditional on HAVE_EVENTFD_SUPPORT? >>>> >>>> I'm missing something :-\ >>>> >>>> Yeah, this whole call to evlist__add_pollfd is already surrounded by >>>> #ifdef HAVE_EVENTFD_SUPPORT: >>>> >>>> 1656 if (zstd_init(&session->zstd_data, rec->opts.comp_level) < 0) { >>>> 1657 pr_err("Compression initialization failed.\n"); >>>> 1658 return -1; >>>> 1659 } >>>> 1660 #ifdef HAVE_EVENTFD_SUPPORT >>>> 1661 done_fd = eventfd(0, EFD_NONBLOCK); >>>> 1662 if (done_fd < 0) { >>>> 1663 pr_err("Failed to create wakeup eventfd, error: %m\n"); >>>> 1664 status = -1; >>>> 1665 goto out_delete_session; >>>> 1666 } >>>> 1667 err = evlist__add_pollfd(rec->evlist, done_fd); >>>> 1668 if (err < 0) { >>>> 1669 pr_err("Failed to add wakeup eventfd to poll list\n"); >>>> 1670 status = err; >>>> 1671 goto out_delete_session; >>>> 1672 } >>>> 1673 #endif // HAVE_EVENTFD_SUPPORT >>>> 1674 >>>> 1675 session->header.env.comp_type = PERF_COMP_ZSTD; >>>> 1676 session->header.env.comp_level = rec->opts.comp_level; >>>> >>>> Jiri, does your Acked-by stands? Namhyung? >>> >>> Thanks tested and applied, together with Jiri's Tested-by, >>> >>> - Arnaldo >>> . >>> >> Is this patch okay? Is there anything that needs to be modified? > > It was merged: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/tools/perf/builtin-record.c?id=e16c2ce7c5ed5de881066c1fd10ba5c09af69559 > > - Arnaldo > . > Thanks. Yang