From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users <linux-perf-users@vger.kernel.org>,
Marco Elver <elver@google.com>, Song Liu <song@kernel.org>
Subject: Re: [PATCH v3] perf test: Skip sigtrap test on old kernels
Date: Wed, 7 Sep 2022 10:51:27 -0700 [thread overview]
Message-ID: <CAM9d7chEOJJTX3F-5Nzy+BBpr5dBnayHDx9MOSmkC0axrttzJQ@mail.gmail.com> (raw)
In-Reply-To: <CAP-5=fXyY_aGYW4R-PZvzG3FiTtHvLfS+s9bp_oCQUaRCGrcwg@mail.gmail.com>
Hi Ian,
On Wed, Sep 7, 2022 at 8:48 AM Ian Rogers <irogers@google.com> wrote:
>
> On Wed, Sep 7, 2022 at 12:12 AM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > If it runs on an old kernel, perf_event_open would fail because of the
> > new fields sigtrap and sig_data. Just skipping the test could miss an
> > actual bug in the kernel.
> >
> > Let's check BTF if it has the perf_event_attr.sigtrap field.
> >
> > Cc: Marco Elver <elver@google.com>
> > Acked-by: Song Liu <song@kernel.org>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> > * move #include under #ifdef
> > * return true when BPF is not supported
> > * update comment
> >
> > tools/perf/tests/sigtrap.c | 50 +++++++++++++++++++++++++++++++++++++-
> > 1 file changed, 49 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> > index e32ece90e164..cdf75eab6a8a 100644
> > --- a/tools/perf/tests/sigtrap.c
> > +++ b/tools/perf/tests/sigtrap.c
> > @@ -54,6 +54,48 @@ static struct perf_event_attr make_event_attr(void)
> > return attr;
> > }
> >
> > +#ifdef HAVE_BPF_SKEL
> > +#include <bpf/btf.h>
> > +
> > +static bool attr_has_sigtrap(void)
> > +{
> > + bool ret = false;
> > + struct btf *btf;
> > + const struct btf_type *t;
> > + const struct btf_member *m;
> > + const char *name;
> > + int i, id;
> > +
> > + btf = btf__load_vmlinux_btf();
> > + if (btf == NULL) {
> > + /* should be an old kernel */
> > + return false;
> > + }
> > +
> > + id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> > + if (id < 0)
> > + goto out;
> > +
> > + t = btf__type_by_id(btf, id);
> > + for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> > + name = btf__name_by_offset(btf, m->name_off);
> > + if (!strcmp(name, "sigtrap")) {
> > + ret = true;
> > + break;
> > + }
> > + }
> > +out:
> > + btf__free(btf);
> > + return ret;
> > +}
> > +#else /* !HAVE_BPF_SKEL */
> > +static bool attr_has_sigtrap(void)
> > +{
> > + /* to maintain current behavior */
>
> nit: I don't think this comment will age well and the behavior of the
> function is a bit counterintuitive. Perhaps:
>
> /* If we don't have libbpf then guess we're on a newer kernel with
> sigtrap support. This will mean the test will fail on older kernels.
> */
Thanks for the clarification, will update!
Namhyung
next prev parent reply other threads:[~2022-09-07 17:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 7:12 [PATCH v3] perf test: Skip sigtrap test on old kernels Namhyung Kim
2022-09-07 15:47 ` Ian Rogers
2022-09-07 17:51 ` Namhyung Kim [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-09-08 23:01 Namhyung Kim
2022-09-09 13:23 ` Arnaldo Carvalho de Melo
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=CAM9d7chEOJJTX3F-5Nzy+BBpr5dBnayHDx9MOSmkC0axrttzJQ@mail.gmail.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=elver@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--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).