From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Song Liu <song@kernel.org>,
Hao Luo <haoluo@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Andi Kleen <ak@linux.intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Stephane Eranian <eranian@google.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
Leo Yan <leo.yan@linaro.org>, James Clark <james.clark@arm.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH 02/10] perf bpf filter: Implement event sample filtering
Date: Thu, 16 Mar 2023 07:15:03 -0300 [thread overview]
Message-ID: <ZBLsJ+tt/hjIBQ6v@kernel.org> (raw)
In-Reply-To: <ZBKmoeGAmlhv+yvc@google.com>
Em Wed, Mar 15, 2023 at 10:18:25PM -0700, Namhyung Kim escreveu:
> On Wed, Mar 15, 2023 at 05:12:44PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Mar 15, 2023 at 09:51:03AM -0700, Namhyung Kim escreveu:
> > > On Wed, Mar 15, 2023 at 9:39 AM Arnaldo Carvalho de Melo
> > > <acme@kernel.org> wrote:
> > > >
> > > > Em Wed, Mar 15, 2023 at 01:24:37PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > > Em Tue, Mar 14, 2023 at 04:42:29PM -0700, Namhyung Kim escreveu:
> > > > > > The BPF program will be attached to a perf_event and be triggered when
> > > > > > it overflows. It'd iterate the filters map and compare the sample
> > > > > > value according to the expression. If any of them fails, the sample
> > > > > > would be dropped.
> > > > > >
> > > > > > Also it needs to have the corresponding sample data for the expression
> > > > > > so it compares data->sample_flags with the given value. To access the
> > > > > > sample data, it uses the bpf_cast_to_kern_ctx() kfunc which was added
> > > > > > in v6.2 kernel.
> > > > > >
> > > > > > Acked-by: Jiri Olsa <jolsa@kernel.org>
> > > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > > > >
> > > > >
> > > > > I'm noticing this while building on a debian:11 container:
> > > > >
> > > > > GENSKEL /tmp/build/perf/util/bpf_skel/bperf_leader.skel.h
> > > > > GENSKEL /tmp/build/perf/util/bpf_skel/bperf_follower.skel.h
> > > > > GENSKEL /tmp/build/perf/util/bpf_skel/func_latency.skel.h
> > > > > GENSKEL /tmp/build/perf/util/bpf_skel/bpf_prog_profiler.skel.h
> > > > > GENSKEL /tmp/build/perf/util/bpf_skel/kwork_trace.skel.h
> > > > > GENSKEL /tmp/build/perf/util/bpf_skel/sample_filter.skel.h
> > > > > libbpf: failed to find BTF for extern 'bpf_cast_to_kern_ctx' [21] section: -2
> > > > > Error: failed to open BPF object file: No such file or directory
> > > > > make[2]: *** [Makefile.perf:1085: /tmp/build/perf/util/bpf_skel/sample_filter.skel.h] Error 254
> > > > > make[2]: *** Deleting file '/tmp/build/perf/util/bpf_skel/sample_filter.skel.h'
> > > > > make[2]: *** Waiting for unfinished jobs....
> > > > > make[1]: *** [Makefile.perf:236: sub-make] Error 2
> > > > > make: *** [Makefile:70: all] Error 2
> > > > > make: Leaving directory '/git/perf-6.3.0-rc1/tools/perf'
> > > > > + exit 1
> > > > > [perfbuilder@five 11]$
> > > >
> > > > Same thing on debian:10
> > >
> > > Hmm.. I thought extern symbols with__ksym are runtime
> > > dependencies and it should build on old kernels too.
> > >
> > > BPF folks, any suggestions?
> >
> > Fedora 33 also fails, see below, but these work:
>
> Maybe I can declare it as a weak symbol. How about this?
Unsure this is the right fix, for now I'm using NO_BPF_SKEL=1 in those
older distros, will check again early next week when I'm back from a
short trip.
- Arnaldo
> Thanks,
> Namhyung
>
> ---8<---
>
> diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/util/bpf_skel/sample_filter.bpf.c
> index 57e3c67d6d37..52cbdd1765cd 100644
> --- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
> +++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
> @@ -17,7 +17,7 @@ struct filters {
>
> int dropped;
>
> -void *bpf_cast_to_kern_ctx(void *) __ksym;
> +void *bpf_cast_to_kern_ctx(void *) __ksym __weak;
>
> /* new kernel perf_sample_data definition */
> struct perf_sample_data___new {
> @@ -118,6 +118,10 @@ int perf_sample_filter(void *ctx)
> int group_result = 0;
> int i;
>
> + /* no kernel context support, no filtering */
> + if (!bpf_cast_to_kern_ctx)
> + return 1;
> +
> kctx = bpf_cast_to_kern_ctx(ctx);
>
> for (i = 0; i < MAX_FILTERS; i++) {
>
--
- Arnaldo
next prev parent reply other threads:[~2023-03-16 10:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-14 23:42 [PATCHSET 00/10] perf record: Implement BPF sample filter (v5) Namhyung Kim
2023-03-14 23:42 ` [PATCH 01/10] perf bpf filter: Introduce basic BPF filter expression Namhyung Kim
2023-03-14 23:42 ` [PATCH 02/10] perf bpf filter: Implement event sample filtering Namhyung Kim
2023-03-15 16:24 ` Arnaldo Carvalho de Melo
2023-03-15 16:39 ` Arnaldo Carvalho de Melo
2023-03-15 16:51 ` Namhyung Kim
2023-03-15 20:12 ` Arnaldo Carvalho de Melo
2023-03-16 5:18 ` Namhyung Kim
2023-03-16 10:15 ` Arnaldo Carvalho de Melo [this message]
2023-03-14 23:42 ` [PATCH 03/10] perf record: Add BPF event filter support Namhyung Kim
2023-03-15 13:47 ` Arnaldo Carvalho de Melo
2023-03-15 16:41 ` Namhyung Kim
2023-03-15 16:51 ` Arnaldo Carvalho de Melo
2023-03-14 23:42 ` [PATCH 04/10] perf record: Record dropped sample count Namhyung Kim
2023-03-14 23:42 ` [PATCH 05/10] perf bpf filter: Add 'pid' sample data support Namhyung Kim
2023-03-14 23:42 ` [PATCH 06/10] perf bpf filter: Add more weight " Namhyung Kim
2023-03-14 23:42 ` [PATCH 07/10] perf bpf filter: Add data_src " Namhyung Kim
2023-03-14 23:42 ` [PATCH 08/10] perf bpf filter: Add logical OR operator Namhyung Kim
2023-03-14 23:42 ` [PATCH 09/10] perf bpf filter: Show warning for missing sample flags Namhyung Kim
2023-03-14 23:42 ` [PATCH 10/10] perf record: Update documentation for BPF filters Namhyung Kim
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=ZBLsJ+tt/hjIBQ6v@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=bpf@vger.kernel.org \
--cc=eranian@google.com \
--cc=haoluo@google.com \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=song@kernel.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 NNTP newsgroup(s).