Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1723454pxb; Thu, 4 Feb 2021 22:53:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJYyqbLxzqPVWFk/nAYqdAHbef91eZNF0PzqBRdSu0j9nny7b+ZbHtFOJAEQJZNbEGMMH5 X-Received: by 2002:a17:907:1119:: with SMTP id qu25mr2644352ejb.268.1612508015161; Thu, 04 Feb 2021 22:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612508015; cv=none; d=google.com; s=arc-20160816; b=PrYw5Cx9Ql3ypheljhHOrx1Oc+legH8XqZIW8h58Snc5P80vI2bjFwPilUYXoWeA83 ST+1s25bmg5ltrtsAzQ3XAlSAA+oM5JkyGDg21MK/3m+i3+el7fSE+6IOhT8pmyUXJHT 6lO+IQltfDurya+eJobWnOisUm2skLRc/YrjxtqToJ8shi1ENix9KoH+z5ai4jlMZb3K na/ncXnhEbjSyiB4BHkVWHDpvyD7xw5z7UY1vg+PFptUymHC/0UAec2TexG9EHrTHSg6 Wjx3xHojvC4F/wxeSPb16n9Pgvc92qTEYa6YYZmTmhea4872SXry9mMkNe2u+X/Ilw1e MYZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=49qLdoIpPN8vpqkEYj3PUyiqr9DOwm/Q9rXa33gTbmM=; b=I2X8700MB8Ze1cEanFsFypQn0WnG5qW7By54E3gDyraFYLlVZqdao4A2ArG+w0AJJS BYXF4xp7bsTgEmAJl0rgeJwL+nszJPH6sllvACwP/TRjfnOF/GTDFpCdqNiDgTWDZFSq jjCn/6spLs8nHp7ZGoT9AXIsFYEKpsRqzzALxCfsIhQQN4fytJOHSAE5GTS9fKBCjh69 LQGjfnyychA9JCfsV1BteAg/DTDgg/SF21lKo7859+rlLeEQ/LSoHvrKDKJhGsrav5fs 7153Z4KpWdHNJaEC0dTPJ/+tcTvTXZYTdie7jRl5AErMrUS72CYYmPW69A6x0nsCDLDT m3+Q== 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 z17si4763136edl.91.2021.02.04.22.53.11; Thu, 04 Feb 2021 22:53:35 -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 S231253AbhBEGwa (ORCPT + 99 others); Fri, 5 Feb 2021 01:52:30 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11680 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbhBEGvd (ORCPT ); Fri, 5 Feb 2021 01:51:33 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DX5cM36rqzlGw7; Fri, 5 Feb 2021 14:49:07 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.61) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 14:50:40 +0800 From: Yang Jihong To: , , , , , , , , , , CC: , Subject: [PATCH] perf record: Fix continue profiling after draining the buffer Date: Fri, 5 Feb 2021 14:50:01 +0800 Message-ID: <20210205065001.23252-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 + int evlist__poll(struct evlist *evlist, int timeout) { return perf_evlist__poll(&evlist->core, timeout); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 1aae75895dea..6d4d62151bc8 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -142,6 +142,10 @@ struct evsel *evlist__find_tracepoint_by_name(struct evlist *evlist, const char int evlist__add_pollfd(struct evlist *evlist, int fd); int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask); +#ifdef HAVE_EVENTFD_SUPPORT +int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd); +#endif + int evlist__poll(struct evlist *evlist, int timeout); struct evsel *evlist__id2evsel(struct evlist *evlist, u64 id); -- 2.17.1