Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Co-developed-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Link: https://lore.kernel.org/r/20230427234833.1576130-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
b9f82b5c e53de7b6

+7 -7
+7 -7
tools/perf/util/bpf_skel/lock_contention.bpf.c
··· 429 429 SEC("raw_tp/bpf_test_finish") 430 430 int BPF_PROG(collect_lock_syms) 431 431 { 432 - __u64 lock_addr; 432 + __u64 lock_addr, lock_off; 433 433 __u32 lock_flag; 434 + 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); 434 439 435 440 for (int i = 0; i < MAX_CPUS; i++) { 436 441 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; 439 442 440 443 if (rq == NULL) 441 444 break; 442 445 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; 447 447 lock_flag = LOCK_CLASS_RQLOCK; 448 448 bpf_map_update_elem(&lock_syms, &lock_addr, &lock_flag, BPF_ANY); 449 449 }