From: Ian Rogers <irogers@google.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
Andrii Nakryiko <andrii@kernel.org>, Hao Luo <haoluo@google.com>,
Song Liu <song@kernel.org>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Subject: Re: [PATCH 2/2] perf lock contention: Rework offset calculation with BPF CO-RE
Date: Thu, 27 Apr 2023 17:32:26 -0700 [thread overview]
Message-ID: <CAP-5=fXf12-Ym_iFhXeKpj5mb-QsnFCEdorp9gf=OC86c8p8WA@mail.gmail.com> (raw)
In-Reply-To: <20230427234833.1576130-2-namhyung@kernel.org>
On Thu, Apr 27, 2023 at 4:48 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> It seems BPF CO-RE reloc doesn't work well with the pattern that gets
> the field-offset only. Use offsetof() to make it explicit so that
> the compiler would generate the correct code.
>
> Fixes: 0c1228486bef ("perf lock contention: Support pre-5.14 kernels")
> Co-developed-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> tools/perf/util/bpf_skel/lock_contention.bpf.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c
> index 30c193078bdb..8d3cfbb3cc65 100644
> --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c
> +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c
> @@ -429,21 +429,21 @@ struct rq___new {
> SEC("raw_tp/bpf_test_finish")
> int BPF_PROG(collect_lock_syms)
> {
> - __u64 lock_addr;
> + __u64 lock_addr, lock_off;
> __u32 lock_flag;
>
> + if (bpf_core_field_exists(struct rq___new, __lock))
> + lock_off = offsetof(struct rq___new, __lock);
> + else
> + lock_off = offsetof(struct rq___old, lock);
> +
> for (int i = 0; i < MAX_CPUS; i++) {
> struct rq *rq = bpf_per_cpu_ptr(&runqueues, i);
> - struct rq___new *rq_new = (void *)rq;
> - struct rq___old *rq_old = (void *)rq;
>
> if (rq == NULL)
> break;
>
> - if (bpf_core_field_exists(rq_new->__lock))
> - lock_addr = (__u64)&rq_new->__lock;
> - else
> - lock_addr = (__u64)&rq_old->lock;
> + lock_addr = (__u64)(void *)rq + lock_off;
> lock_flag = LOCK_CLASS_RQLOCK;
> bpf_map_update_elem(&lock_syms, &lock_addr, &lock_flag, BPF_ANY);
> }
> --
> 2.40.1.495.gc816e09b53d-goog
>
next prev parent reply other threads:[~2023-04-28 0:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-27 23:48 [PATCH 1/2] perf lock contention: Fix struct rq lock access Namhyung Kim
2023-04-27 23:48 ` [PATCH 2/2] perf lock contention: Rework offset calculation with BPF CO-RE Namhyung Kim
2023-04-28 0:32 ` Ian Rogers [this message]
2023-04-28 0:32 ` [PATCH 1/2] perf lock contention: Fix struct rq lock access Ian Rogers
2023-04-29 1:27 ` 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='CAP-5=fXf12-Ym_iFhXeKpj5mb-QsnFCEdorp9gf=OC86c8p8WA@mail.gmail.com' \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=haoluo@google.com \
--cc=jolsa@kernel.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=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).