Skip to content

Commit b9f82b5

Browse files
namhyungacmel
authored andcommitted
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: 0c12284 ("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]>
1 parent e53de7b commit b9f82b5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/perf/util/bpf_skel/lock_contention.bpf.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,21 +429,21 @@ struct rq___new {
429429
SEC("raw_tp/bpf_test_finish")
430430
int BPF_PROG(collect_lock_syms)
431431
{
432-
__u64 lock_addr;
432+
__u64 lock_addr, lock_off;
433433
__u32 lock_flag;
434434

435+
if (bpf_core_field_exists(struct rq___new, __lock))
436+
lock_off = offsetof(struct rq___new, __lock);
437+
else
438+
lock_off = offsetof(struct rq___old, lock);
439+
435440
for (int i = 0; i < MAX_CPUS; i++) {
436441
struct rq *rq = bpf_per_cpu_ptr(&runqueues, i);
437-
struct rq___new *rq_new = (void *)rq;
438-
struct rq___old *rq_old = (void *)rq;
439442

440443
if (rq == NULL)
441444
break;
442445

443-
if (bpf_core_field_exists(rq_new->__lock))
444-
lock_addr = (__u64)&rq_new->__lock;
445-
else
446-
lock_addr = (__u64)&rq_old->lock;
446+
lock_addr = (__u64)(void *)rq + lock_off;
447447
lock_flag = LOCK_CLASS_RQLOCK;
448448
bpf_map_update_elem(&lock_syms, &lock_addr, &lock_flag, BPF_ANY);
449449
}

0 commit comments

Comments
 (0)