Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1836253pxb; Fri, 5 Feb 2021 02:42:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6AP+Te1Mj5V48SBUaG/xBvIr7H+jbCzAPXfOFTkxZQ6JWEV9D8PyuezwVS0T8E6DzpHpW X-Received: by 2002:a50:eacd:: with SMTP id u13mr2895994edp.382.1612521751696; Fri, 05 Feb 2021 02:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612521751; cv=none; d=google.com; s=arc-20160816; b=Ipp0GOpGWXAOJW1faUSipPMrfur5kNv9z3LpmpxNOGfKFx3XT70TjZ3I9Dv0ayyoay B9t1wNaiA0DzRE0zdY29OzWcNRBVjJsakImG6UPawZyRW5nXdaww4mfrg8KH8591+BDN GpMpOXyl0n2SnB7KDiv/iUkSyij95lUW+FzB9dWnC5IZs+eH+Ge8QJsB4H9jYlT2/kix 7MtGkHhrJT2H7m4WRUhyxwvQK+d+Epm02CXidLuILn9qX9JPibuX2YJxm/6FPuv18xch uSBeA7iXeXAydWOFsntdXoaMdvE7+cCBUc/vgkCCWKtgxnxkFCCUpqygeluXLNJWUqx3 iZhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=a6k/aNvuF++mqp+wzBrO3d6/1JtXcTUsmGTcoFLzD7s=; b=nfTluP3fGbx/fTArtnavbYARWRoAAx0znU/2BOIJuqWzEJT66LesRbzf0VwIZDtxYQ QSjDfBVkhMj70uJctItEm8uL02VF+Wpsn2X5frBdqQbIRj91dkv6mKDyL6sA3XyK+6UK xuRdkDshtSFMGfvJf14DSJWMBqdUJ9ciluIj+wbVdoCrj+YduCGG6tY1wHRvh773oPaD 9voBe1+9tINKSQ4+f8gkPh4HSoeP+b8LMFtc5xnCVt/UuK86b9bf0TfQt1T3ZkvK2vym PQI/oISCQ5OCFkG8KQyN790pyEYXWEXg6sH6G6P11mdlq/Ht+yuRD4sWuxCJThqx0g8u WONA== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si4407154ejv.427.2021.02.05.02.42.06; Fri, 05 Feb 2021 02:42:31 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbhBEKjP (ORCPT + 99 others); Fri, 5 Feb 2021 05:39:15 -0500 Received: from mail-lf1-f54.google.com ([209.85.167.54]:39325 "EHLO mail-lf1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231519AbhBEKgQ (ORCPT ); Fri, 5 Feb 2021 05:36:16 -0500 Received: by mail-lf1-f54.google.com with SMTP id h7so9180135lfc.6 for ; Fri, 05 Feb 2021 02:35:59 -0800 (PST) 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=a6k/aNvuF++mqp+wzBrO3d6/1JtXcTUsmGTcoFLzD7s=; b=MmcCptwWE2QnnWElP9+5z5HBWVFq3yWSHy+QEq0FjYtobxjfIOzbzxd4ueLdmRjPV+ 21IaiCt+xszMQb71k/WA6RsNMNUMu9IK2oUDt0sREgVVv4ZZmhzv4+DBQm94jNlnt9YK JO994Audgwha9NK43A+kOyWSR3UwCAXdd9CgJs7cyLlxdxaRH+fwgifEcZLp701n8oi0 kUHVgWUvhsx8yZPpfM2bDORblnXMgJ/czyqFBL3E0fcnslPBc5XIiaaZKdC8jO5AyXWB V1rsQuWn8GLflfL5YNk7Ma46KNMJgkxGYiItYQlUkFhZ4yo9CCgg990cJK0EJ/TGekPj 9Itw== X-Gm-Message-State: AOAM5303YHCDtCc7rG/LVsx+v//sS9tz2/59v3VThcSAC0dF/ntgdTMj HznKJD+Tw1QeiFamiC8gXGEFiYksUJuQ3dvkgqY= X-Received: by 2002:a19:d611:: with SMTP id n17mr2304130lfg.494.1612521333936; Fri, 05 Feb 2021 02:35:33 -0800 (PST) MIME-Version: 1.0 References: <20210205065001.23252-1-yangjihong1@huawei.com> In-Reply-To: <20210205065001.23252-1-yangjihong1@huawei.com> From: Namhyung Kim Date: Fri, 5 Feb 2021 19:35:22 +0900 Message-ID: Subject: Re: [PATCH] perf record: Fix continue profiling after draining the buffer To: Yang Jihong Cc: amistry@google.com, Alexey Budankov , Adrian Hunter , Jiri Olsa , Alexander Shishkin , Mark Rutland , Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , linux-kernel , zhangjinhao2@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Thanks, Namhyung > + > 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 >