From: Jiri Olsa <jolsa@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Yang Jihong <yangjihong1@huawei.com>,
amistry@google.com,
Alexey Budankov <alexey.budankov@linux.intel.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Mark Rutland <mark.rutland@arm.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
zhangjinhao2@huawei.com
Subject: Re: [PATCH] perf record: Fix continue profiling after draining the buffer
Date: Fri, 5 Feb 2021 11:46:12 +0100 [thread overview]
Message-ID: <YB0h9Gj5lpcuqndo@krava> (raw)
In-Reply-To: <CAM9d7cgGGWtTkReghATVmMnOd=0dBrghBLgEc9AqT_PF-UP1Rg@mail.gmail.com>
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 <yangjihong1@huawei.com> 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 <yangjihong1@huawei.com>
> > ---
> > 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
jirka
>
> 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
> >
>
next prev parent reply other threads:[~2021-02-06 0:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-05 6:50 Yang Jihong
2021-02-05 10:35 ` Namhyung Kim
2021-02-05 10:46 ` Jiri Olsa [this message]
2021-02-07 0:56 ` Yang Jihong
2021-02-18 10:18 ` Yang Jihong
2021-02-18 13:20 ` Arnaldo Carvalho de Melo
2021-02-18 17:09 ` Arnaldo Carvalho de Melo
2021-02-22 1:31 ` Yang Jihong
2021-03-03 16:43 ` Arnaldo Carvalho de Melo
2021-03-04 1:19 ` Yang Jihong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YB0h9Gj5lpcuqndo@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=amistry@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=yangjihong1@huawei.com \
--cc=zhangjinhao2@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome