From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Changbin Du <changbin.du@huawei.com>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH v1 0/3] Use BPF filters for a "perf top -u" workaround
Date: Thu, 16 May 2024 10:34:06 -0700 [thread overview]
Message-ID: <CAP-5=fUBJOaE3Tp1NP4Urdt-r_kHEaR00aTKxMrvfe_0fyPxYA@mail.gmail.com> (raw)
In-Reply-To: <CAP-5=fW8TA0KQOepQRuC_0mhyp6kHbPodh+6-uoVxsmC=09tTw@mail.gmail.com>
On Wed, May 15, 2024 at 10:04 PM Ian Rogers <irogers@google.com> wrote:
>
> On Wed, May 15, 2024 at 9:20 PM Ian Rogers <irogers@google.com> wrote:
> >
> > Allow uid and gid to be terms in BPF filters by first breaking the
> > connection between filter terms and PERF_SAMPLE_xx values. Calculate
> > the uid and gid using the bpf_get_current_uid_gid helper, rather than
> > from a value in the sample. Allow filters to be passed to perf top, this allows:
> >
> > $ perf top -e cycles:P --filter "uid == $(id -u)"
> >
> > to work as a "perf top -u" workaround, as "perf top -u" usually fails
> > due to processes/threads terminating between the /proc scan and the
> > perf_event_open.
>
> Fwiw, something I noticed playing around with this (my workload was
> `perf test -w noploop 100000` as different users) is that old samples
> appeared to linger around making terminated processes still appear in
> the top list. My guess is that there aren't other samples showing up
> and pushing the old sample events out of the ring buffers due to the
> filter. This can look quite odd and I don't know if we have a way to
> improve upon it, flush the ring buffers, histograms, etc. It appears
> to be a latent `perf top` issue that you could encounter on other low
> frequency events, but I thought I'd mention it anyway.
Some other thoughts:
- It is kind of annoying with the --filter option (either on top or
record) that there first needs to be an event to filter on. It'd be
nice if we could just filter the default event.
- Should "perf top --uid=1234" be removed or turned into an alias
for '--filter "uid == $(id -u)"' given the --uid option generally
doesn't work?
- What should happen to the perf top --pid and --tid options, should
they be filters? Should they fallback on /proc scanning if there
aren't sufficient BPF permissions? The plumbing for that is going to
be messy.
- There should probably be a way to filter on cgroups.
- Does the user care that there are 3 kinds of filter that will work
differently? Could we break them apart to make it more explicit, I may
want tracepoint events with a BPF filter. How can we ensure 1 syntax
for the 3 kinds of filter.
- Filtering on register values could be potentially interesting, for
example, sampling on memcpy-s where the length is over a threshold. We
have a register capture test:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/record.sh#n81
Perhaps the filter could look something like 'perf record -g -e
mem:$ADDRESS_OF_MEMCPY:x --filter "reg:rdx > 1024"' - this makes me
think we need to make a more convenient way to specify memory
addresses as symbols.
Thanks,
Ian
>
> > Ian Rogers (3):
> > perf bpf filter: Give terms their own enum
> > perf bpf filter: Add uid and gid terms
> > perf top: Allow filters on events
> >
> > tools/perf/Documentation/perf-record.txt | 2 +-
> > tools/perf/Documentation/perf-top.txt | 4 ++
> > tools/perf/builtin-top.c | 9 +++
> > tools/perf/util/bpf-filter.c | 55 ++++++++++++----
> > tools/perf/util/bpf-filter.h | 5 +-
> > tools/perf/util/bpf-filter.l | 66 +++++++++----------
> > tools/perf/util/bpf-filter.y | 7 +-
> > tools/perf/util/bpf_skel/sample-filter.h | 27 +++++++-
> > tools/perf/util/bpf_skel/sample_filter.bpf.c | 67 +++++++++++++++-----
> > 9 files changed, 172 insertions(+), 70 deletions(-)
> >
> > --
> > 2.45.0.rc1.225.g2a3ae87e7f-goog
> >
next prev parent reply other threads:[~2024-05-16 17:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-16 4:19 [PATCH v1 0/3] Use BPF filters for a "perf top -u" workaround Ian Rogers
2024-05-16 4:19 ` [PATCH v1 1/3] perf bpf filter: Give terms their own enum Ian Rogers
2024-05-18 1:36 ` Namhyung Kim
2024-05-18 3:29 ` Ian Rogers
2024-05-20 20:27 ` Namhyung Kim
2024-05-16 4:19 ` [PATCH v1 2/3] perf bpf filter: Add uid and gid terms Ian Rogers
2024-05-16 4:19 ` [PATCH v1 3/3] perf top: Allow filters on events Ian Rogers
2024-05-16 5:04 ` [PATCH v1 0/3] Use BPF filters for a "perf top -u" workaround Ian Rogers
2024-05-16 17:34 ` Ian Rogers [this message]
2024-05-18 1:21 ` Namhyung Kim
2024-05-16 21:47 ` Ian Rogers
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='CAP-5=fUBJOaE3Tp1NP4Urdt-r_kHEaR00aTKxMrvfe_0fyPxYA@mail.gmail.com' \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=changbin.du@huawei.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).