From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, vince@deater.net,
eranian@google.com, Arnaldo Carvalho de Melo <acme@infradead.org>,
Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH v2] perf: Synchronously cleanup child events
Date: Wed, 20 Jan 2016 20:55:59 -0800 [thread overview]
Message-ID: <20160121045556.GA99187@ast-mbp.thefacebook.com> (raw)
In-Reply-To: <20160120083222.GF6357@twins.programming.kicks-ass.net>
On Wed, Jan 20, 2016 at 09:32:22AM +0100, Peter Zijlstra wrote:
> On Tue, Jan 19, 2016 at 01:58:19PM -0800, Alexei Starovoitov wrote:
> > On Tue, Jan 19, 2016 at 09:05:58PM +0100, Peter Zijlstra wrote:
>
> > > The most obvious place that generates such magical references would be
> > > the bpf arraymap doing perf_event_get() on things. There are a few other
> > > places that take temp references (perf_mmap_close), but those are
> > > 'short' lived and while ugly will not cause massive grief. The BPF one
> > > OTOH is a real problem here.
> > >
> > > And looking at the BPF stuff, that code seems to assume
> > > perf_event_kernel_release() := put_event(), so this patch breaks that
> > > too.
> > >
> > >
> > > Alexei, is there a reason the arraymap stuff needs a perf event ref as
> > > opposed to a file ref? I'm forever a little confused on how perf<->bpf
> > > works.
> >
> > A file ref will not work, since user space could have closed that
> > perf_event file to avoid unnecessary FDs.
>
> So I'm (possibly again) confused on how BPF works.
>
> I thought the reason you handed in perf events from userspace; as
> opposed to creating your own with perf_event_create_kernel_counter();
> was because userspace was interested in the output.
yes. There are two use cases of perf_events from bpf:
1. sw_bpf_output event is used by bpf to push samples into it and
user spaces reads it as normal via mmap
2. PERF_TYPE_HARDWARE event is used by bpf program to read
counters to measure things like number of cycles or tlb misses
in a given function.
In this case user space typically leaves FDs around, but it doesn't
use them for anything.
> Also, BPF should not be a way to get around the filedesc resource limit.
all bpf tracing stuff is root only and maps are charged for every element.
> > Program only need the stable pointer to 'struct perf_event' which
> > it will use while running.
> > At the end it will call perf_event_kernel_release() which
> > is == put_event().
> > It was the case that 'perf_events' were normal refcnt-ed structures
> > and the last guy frees it.
>
> Sort-of, but user events are (or should be, rather) tied to the filedesc
> to account the resources used.
>
> There is also the event->owner field, we track the task that created the
> event, with your current scheme that is left dangling once userspace
> closes the last filedesc and you still have a ref open.
>
> > This put_event_last() logic definitely looks problematic.
> > There are no ordering guarantees.
> > User space may close FD, while struct perf_event is still alive.
> > The loop around perf_event_last() looks buggy.
> > I'm obviously missing the main goal of this patch.
>
> Right, so the patch in question tries to synchronously clean up
> everything related to the counter when we close the file. Such that the
> file better reflects the actual resource usage.
>
> Currently we do this async (and with holes).
>
> In short, user created event really should be filedesc based, yes we
> have event references, but those 'should' be short lived.
I'm still missing why it's the problem.
Which counter do you want to bump as part of perf_event_get() ?
still event->refcount, right?
but the same perf_event can be stored in multiple bpf maps
and many bpf programs can be using it, while nothing can
possibly prevent the user space to do close(perf_event_fd)
while programs are still running and collecting tlb miss data
from the counters.
So what do you propose?
next prev parent reply other threads:[~2016-01-21 4:56 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-15 11:22 [PATCH] perf: Cleanup user's " Alexander Shishkin
2016-01-15 12:54 ` Peter Zijlstra
2016-01-15 13:05 ` Alexander Shishkin
2016-01-15 13:09 ` Peter Zijlstra
2016-01-15 14:07 ` [PATCH] perf: Synchronously cleanup " Alexander Shishkin
2016-01-15 17:57 ` Peter Zijlstra
2016-01-18 12:07 ` Alexander Shishkin
2016-01-18 12:37 ` Alexander Shishkin
2016-01-18 14:44 ` Peter Zijlstra
2016-01-19 15:12 ` [PATCH v2] " Alexander Shishkin
2016-01-19 20:05 ` Peter Zijlstra
2016-01-19 21:58 ` Alexei Starovoitov
2016-01-20 8:32 ` Peter Zijlstra
2016-01-21 4:55 ` Alexei Starovoitov [this message]
2016-01-20 7:04 ` Alexander Shishkin
2016-01-20 8:03 ` Peter Zijlstra
2016-01-22 11:35 ` Alexander Shishkin
2016-01-22 12:12 ` Peter Zijlstra
2016-01-22 12:38 ` Peter Zijlstra
2016-01-22 19:44 ` Alexei Starovoitov
2016-01-25 11:48 ` Peter Zijlstra
2016-01-25 14:54 ` Peter Zijlstra
2016-01-25 21:04 ` Peter Zijlstra
2016-01-26 4:59 ` Alexei Starovoitov
2016-01-26 16:16 ` Peter Zijlstra
2016-01-26 17:24 ` Peter Zijlstra
2016-01-26 23:31 ` Alexei Starovoitov
2016-01-27 9:58 ` Peter Zijlstra
2016-01-27 17:52 ` Alexei Starovoitov
2016-01-29 11:28 ` [tip:perf/urgent] perf/bpf: Convert perf_event_array to use struct file tip-bot for Alexei Starovoitov
2016-01-29 20:01 ` Alexei Starovoitov
2016-01-19 20:07 ` [PATCH v2] perf: Synchronously cleanup child events Peter Zijlstra
2016-01-19 7:45 ` [PATCH] " Ingo Molnar
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=20160121045556.GA99187@ast-mbp.thefacebook.com \
--to=alexei.starovoitov@gmail.com \
--cc=acme@infradead.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vince@deater.net \
/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