aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamhyung Kim <[email protected]>2023-04-27 16:48:33 -0700
committerArnaldo Carvalho de Melo <[email protected]>2023-05-02 08:36:14 -0300
commitb9f82b5c63bf5390da19e879275a792a959a8dac (patch)
tree3c7f3c5c239da5f859eaf798ba504e899a734f82
parente53de7b65a3ca59af268c78df2d773f277f717fd (diff)
perf lock contention: Rework offset calculation with BPF CO-RE
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: 0c1228486befa3d6 ("perf lock contention: Support pre-5.14 kernels") Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Hao Luo <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: [email protected] Co-developed-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/bpf_skel/lock_contention.bpf.c14
1 files 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);
}