* [PATCH] perf lock contention: Load kernel map before lookup
@ 2025-10-30 4:01 Namhyung Kim
2025-10-31 16:56 ` Ian Rogers
2025-11-03 17:53 ` Namhyung Kim
0 siblings, 2 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-10-30 4:01 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Ian Rogers
Cc: Jiri Olsa, Adrian Hunter, James Clark, Peter Zijlstra,
Ingo Molnar, LKML, linux-perf-users
On some machines, it caused troubles when it tried to find kernel
symbols. I think it's because kernel modules and kallsyms are messed
up during load and split.
Basically we want to make sure the kernel map is loaded and the code has
it in the lock_contention_read(). But recently we added more lookups in
the lock_contention_prepare() which is called before _read().
Also the kernel map (kallsyms) may not be the first one in the group
like on ARM. Let's use machine__kernel_map() rather than just loading
the first map.
Fixes: 688d2e8de231c54e ("perf lock contention: Add -l/--lock-addr option")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/bpf_lock_contention.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c
index 60b81d586323f379..7b5671f13c53525d 100644
--- a/tools/perf/util/bpf_lock_contention.c
+++ b/tools/perf/util/bpf_lock_contention.c
@@ -184,6 +184,9 @@ int lock_contention_prepare(struct lock_contention *con)
struct evlist *evlist = con->evlist;
struct target *target = con->target;
+ /* make sure it loads the kernel map before lookup */
+ map__load(machine__kernel_map(con->machine));
+
skel = lock_contention_bpf__open();
if (!skel) {
pr_err("Failed to open lock-contention BPF skeleton\n");
@@ -749,9 +752,6 @@ int lock_contention_read(struct lock_contention *con)
bpf_prog_test_run_opts(prog_fd, &opts);
}
- /* make sure it loads the kernel map */
- maps__load_first(machine->kmaps);
-
prev_key = NULL;
while (!bpf_map_get_next_key(fd, prev_key, &key)) {
s64 ls_key;
--
2.51.1.851.g4ebd6896fd-goog
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] perf lock contention: Load kernel map before lookup
2025-10-30 4:01 [PATCH] perf lock contention: Load kernel map before lookup Namhyung Kim
@ 2025-10-31 16:56 ` Ian Rogers
2025-11-03 17:53 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2025-10-31 16:56 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Wed, Oct 29, 2025 at 9:01 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On some machines, it caused troubles when it tried to find kernel
> symbols. I think it's because kernel modules and kallsyms are messed
> up during load and split.
>
> Basically we want to make sure the kernel map is loaded and the code has
> it in the lock_contention_read(). But recently we added more lookups in
> the lock_contention_prepare() which is called before _read().
>
> Also the kernel map (kallsyms) may not be the first one in the group
> like on ARM. Let's use machine__kernel_map() rather than just loading
> the first map.
>
> Fixes: 688d2e8de231c54e ("perf lock contention: Add -l/--lock-addr option")
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> tools/perf/util/bpf_lock_contention.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c
> index 60b81d586323f379..7b5671f13c53525d 100644
> --- a/tools/perf/util/bpf_lock_contention.c
> +++ b/tools/perf/util/bpf_lock_contention.c
> @@ -184,6 +184,9 @@ int lock_contention_prepare(struct lock_contention *con)
> struct evlist *evlist = con->evlist;
> struct target *target = con->target;
>
> + /* make sure it loads the kernel map before lookup */
> + map__load(machine__kernel_map(con->machine));
> +
> skel = lock_contention_bpf__open();
> if (!skel) {
> pr_err("Failed to open lock-contention BPF skeleton\n");
> @@ -749,9 +752,6 @@ int lock_contention_read(struct lock_contention *con)
> bpf_prog_test_run_opts(prog_fd, &opts);
> }
>
> - /* make sure it loads the kernel map */
> - maps__load_first(machine->kmaps);
> -
> prev_key = NULL;
> while (!bpf_map_get_next_key(fd, prev_key, &key)) {
> s64 ls_key;
> --
> 2.51.1.851.g4ebd6896fd-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] perf lock contention: Load kernel map before lookup
2025-10-30 4:01 [PATCH] perf lock contention: Load kernel map before lookup Namhyung Kim
2025-10-31 16:56 ` Ian Rogers
@ 2025-11-03 17:53 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-11-03 17:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Ian Rogers, Namhyung Kim
Cc: Jiri Olsa, Adrian Hunter, James Clark, Peter Zijlstra,
Ingo Molnar, LKML, linux-perf-users
On Wed, 29 Oct 2025 21:01:39 -0700, Namhyung Kim wrote:
> On some machines, it caused troubles when it tried to find kernel
> symbols. I think it's because kernel modules and kallsyms are messed
> up during load and split.
>
> Basically we want to make sure the kernel map is loaded and the code has
> it in the lock_contention_read(). But recently we added more lookups in
> the lock_contention_prepare() which is called before _read().
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-03 17:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-30 4:01 [PATCH] perf lock contention: Load kernel map before lookup Namhyung Kim
2025-10-31 16:56 ` Ian Rogers
2025-11-03 17:53 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®