Skip to contentSkip to conversation

perf tools: Fix build-id matching on vmlinux

PATCH Superseded Namhyung Kim 3 participants 11 messages Aug 26, 2014 – Sep 5, 2014

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf tools: Fix build-id matching on vmlinux

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map

After:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
---
 tools/perf/util/header.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/header.c +3 -0
index 158c787ce0c4..5c4093dee467 100644
@@ -263,6 +263,9 @@ static int __dsos__write_buildid_table(struct list_head *head,
 			machine__mmap_name(machine, nm, sizeof(nm));
 			name = nm;
 			name_len = strlen(nm) + 1;
+		} else if (dso__is_vmlinux(pos)) {
+			name = pos->name;
+			name_len = strlen(pos->name) + 1;
 		} else {
 			name = pos->long_name;
 			name_len = pos->long_name_len + 1;
Signature · 1 line
2.0.0
author maintainer
#1 lore raw

Ping!

Quoted 84 lines · Namhyung Kim

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map

After:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
---
 tools/perf/util/header.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/header.c +3 -0
index 158c787ce0c4..5c4093dee467 100644
@@ -263,6 +263,9 @@ static int __dsos__write_buildid_table(struct list_head *head,
 			machine__mmap_name(machine, nm, sizeof(nm));
 			name = nm;
 			name_len = strlen(nm) + 1;
+		} else if (dso__is_vmlinux(pos)) {
+			name = pos->name;
+			name_len = strlen(pos->name) + 1;
 		} else {
 			name = pos->long_name;
 			name_len = pos->long_name_len + 1;
#2 lore raw
In reply to Namhyung Kim

Em Tue, Aug 26, 2014 at 03:38:39PM +0900, Namhyung Kim escreveu:

Quoted 47 lines

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
Quoted 6 lines

After:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]

We are losing information, namely the pathname for the kernel used, that may be useful in analysis.

Why not make sure that if there is a build-id in the perf.data header, then we completely refusing anything that doesn't match the build-id? I.e. the name is irrelevant for this purpose, the contents, as keyed by the build-id, is what matters.

- Arnaldo

Quoted 33 lines

78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so 4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so 1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so

  $ perf buildid-list -H
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
---
 tools/perf/util/header.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/header.c +3 -0
index 158c787ce0c4..5c4093dee467 100644
@@ -263,6 +263,9 @@ static int __dsos__write_buildid_table(struct list_head *head,
 			machine__mmap_name(machine, nm, sizeof(nm));
 			name = nm;
 			name_len = strlen(nm) + 1;
+		} else if (dso__is_vmlinux(pos)) {
+			name = pos->name;
+			name_len = strlen(pos->name) + 1;
 		} else {
 			name = pos->long_name;
 			name_len = pos->long_name_len + 1;
Signature · 1 line
2.0.0
#7 lore raw
In reply to Namhyung Kim
Quoted 41 lines · Namhyung Kim

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
Quoted 7 lines
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map

There is something I don't understand in your example above. The -H option shows only DSO with samples. So why do you get the buildid without -H
and you get no buildid with -H? In other words, I don't connect the dots between what
-H does on the buildid change for the kernel. Looks like you have the buildid in the
perf.data file.

Quoted 41 lines

After:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
---
 tools/perf/util/header.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/header.c +3 -1
index 158c787ce0c4..5c4093dee467 100644
@@ -263,6 +263,9 @@ static int __dsos__write_buildid_table(struct list_head *head,
                        machine__mmap_name(machine, nm, sizeof(nm));
                        name = nm;
                        name_len = strlen(nm) + 1;
+               } else if (dso__is_vmlinux(pos)) {
+                       name = pos->name;
+                       name_len = strlen(pos->name) + 1;
                } else {
                        name = pos->long_name;
                        name_len = pos->long_name_len + 1;
--

2.0.0

author maintainer
#3 lore raw
In reply to Arnaldo Carvalho de Melo

Hi Arnaldo,

Quoted 50 lines · Arnaldo Carvalho de Melo

Em Tue, Aug 26, 2014 at 03:38:39PM +0900, Namhyung Kim escreveu:

Quoted 49 lines

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map

After:

Quoted 7 lines
Quoted 4 lines
  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]

We are losing information, namely the pathname for the kernel used, that may be useful in analysis.

Right. That's a problem.

Quoted 5 lines

Why not make sure that if there is a build-id in the perf.data header, then we completely refusing anything that doesn't match the build-id? I.e. the name is irrelevant for this purpose, the contents, as keyed by the build-id, is what matters.

The perf report rebuilds machine states from the event records only. In this case, the kernel map was recorded in the name of [kernel.kallsyms] so it couldn't find the build-id from the table.

Thanks,
Namhyung

Quoted 36 lines

- Arnaldo

Quoted 33 lines

78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so 4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so 1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so

  $ perf buildid-list -H
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
---
 tools/perf/util/header.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/header.c +3 -0
index 158c787ce0c4..5c4093dee467 100644
@@ -263,6 +263,9 @@ static int __dsos__write_buildid_table(struct list_head *head,
 			machine__mmap_name(machine, nm, sizeof(nm));
 			name = nm;
 			name_len = strlen(nm) + 1;
+		} else if (dso__is_vmlinux(pos)) {
+			name = pos->name;
+			name_len = strlen(pos->name) + 1;
 		} else {
 			name = pos->long_name;
 			name_len = pos->long_name_len + 1;
Signature · 1 line
2.0.0
author maintainer
#8 lore raw
In reply to Stephane Eranian

Hi Stephane,

Quoted 49 lines · Stephane Eranian
Quoted 41 lines · Namhyung Kim

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
Quoted 7 lines
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
Quoted 5 lines

There is something I don't understand in your example above. The -H option shows only DSO with samples. So why do you get the buildid without -H and you get no buildid with -H? In other words, I don't connect the dots between what -H does on the buildid change for the kernel. Looks like you have the buildid in the perf.data file.

Without -H, it just prints all DSOs found in build-id table (rebuilt during read perf data file header) and skips processing events. But with -H, it'd process the event records and so set kernel map to '[kernel.kallsyms]' - since the kernel mmap event always has the name - and mark it as hit. Thus the actual vmlinux can't be marked and then cannot be printed.

Hmm.. now I'm curious that why the -H option is needed at all.. the perf record already wrote build-ids that are actually hits..

Thanks,
Namhyung

#9 lore raw

Em Fri, Sep 05, 2014 at 09:23:56AM +0900, Namhyung Kim escreveu:

Quoted 2 lines

Hmm.. now I'm curious that why the -H option is needed at all.. the perf record already wrote build-ids that are actually hits..

Probably because when 'perf buildid-list' was introduced 'perf record' was inserting all the PERF_RECORD_MMAP dsos into the buildid-list, not just the ones with hits.

Then, later on, 'perf record' probably moved to register just the ones with hits.

This way -H ends up being a nop, i.e. should produce the same result as 'perf buildid-list' with no options.

If it doesn't, then it is a bug.

- Arnaldo

#4 lore raw
In reply to Namhyung Kim

Em Fri, Sep 05, 2014 at 09:09:49AM +0900, Namhyung Kim escreveu:

Quoted 22 lines
Quoted 11 lines
Quoted 10 lines

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
Quoted 8 lines
Quoted 5 lines

After:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 [kernel.kallsyms]

We are losing information, namely the pathname for the kernel used, that may be useful in analysis.

Right. That's a problem.

Quoted 8 lines
Quoted 4 lines

Why not make sure that if there is a build-id in the perf.data header, then we completely refusing anything that doesn't match the build-id? I.e. the name is irrelevant for this purpose, the contents, as keyed by the build-id, is what matters.

The perf report rebuilds machine states from the event records only. In this case, the kernel map was recorded in the name of [kernel.kallsyms] so it couldn't find the build-id from the table.

Ok, but then we can special case this one, no?

Somehow mark in the buildid table that that entry is the one for the kernel and hook it up to the synthesized event that has the [kernel.kallsyms].ref_reloc_sym entry.

- Arnaldo

author maintainer
#5 lore raw
Quoted 10 lines · Arnaldo Carvalho de Melo

Em Fri, Sep 05, 2014 at 09:09:49AM +0900, Namhyung Kim escreveu:

Quoted 3 lines

The perf report rebuilds machine states from the event records only. In this case, the kernel map was recorded in the name of [kernel.kallsyms] so it couldn't find the build-id from the table.

Ok, but then we can special case this one, no?

Somehow mark in the buildid table that that entry is the one for the kernel and hook it up to the synthesized event that has the [kernel.kallsyms].ref_reloc_sym entry.

Maybe we can search vmlinux in machine->kernel_dsos first when processing kernel mmap event. And in this case do you want replace the name of mapping to a fullname of vmlinux?

Thanks,
Namhyung

author maintainer
#6 lore raw
Quoted 9 lines · Namhyung Kim
Quoted 7 lines · Arnaldo Carvalho de Melo

Em Fri, Sep 05, 2014 at 09:09:49AM +0900, Namhyung Kim escreveu:

Quoted 3 lines

The perf report rebuilds machine states from the event records only. In this case, the kernel map was recorded in the name of [kernel.kallsyms] so it couldn't find the build-id from the table.

Ok, but then we can special case this one, no?

Quoted 7 lines
Quoted 3 lines

Somehow mark in the buildid table that that entry is the one for the kernel and hook it up to the synthesized event that has the [kernel.kallsyms].ref_reloc_sym entry.

Maybe we can search vmlinux in machine->kernel_dsos first when processing kernel mmap event. And in this case do you want replace the name of mapping to a fullname of vmlinux?

Ah.. the name of mapping is not used at all after finding a matching dso. Ok then, I'll post a new patch to search vmlinux before kallsyms.

Thanks
Namhyung

#10 lore raw
In reply to Namhyung Kim
Quoted 58 lines · Namhyung Kim

Hi Stephane,

Quoted 49 lines · Stephane Eranian
Quoted 41 lines · Namhyung Kim

There's a problem on finding correct kernel symbols when perf report runs on a different kernel. Although a part of the problem was solved by the prior commit 0a7e6d1b6844 ("perf tools: Check recorded kernel version when finding vmlinux"), there's a remaining problem still.

When perf records samples, it synthesizes the kernel map using machine__mmap_name() and ref_reloc_sym like "[kernel.kallsyms]_text". You can easily see it using 'perf report -D' command.

After finishing record, it goes through the recorded events to find maps/dsos actually used. And then record build-id info of them.

During this process, it needs to load symbols in a dso and it'd call dso__load_vmlinux() since the default value of the symbol_conf.try_ vmlinux_path is true. However it changes dso->long_name to a real path of the vmlinux file (e.g. /lib/modules/3.16.0-rc2+/build/vmlinux) if one is running on a custom kernel.

It resulted in that perf report reads the build-id of the vmlinux, but cannot use it since it only knows about the [kernel.kallsyms] map. It then falls back to possible vmlinux paths by using the recorded kernel version (in case of a recent version) or a running kernel silently (which might break the result). I think it's worth going to the stable tree.

I can think of a couple of ways to fix it. In this patch, I changed to use the name of "[kernel.kallsyms]" for the kernel build-id event instead of not trying vmlinux paths. This way we can provide maximum info (like annotation) with minimum change IMHO.

Before:

  $ perf record -a usleep 1
  $ perf buildid-list
  00d5ff078efe1d30b8492854f259215fd877ce30 /lib/modules/3.16.0-rc2+/build/vmlinux
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
Quoted 7 lines
  $ perf buildid-list -H
  0000000000000000000000000000000000000000 [kernel.kallsyms]
  78186287bba77069a056a5ccbeb14b7fd2ca3a4b /usr/lib64/libc-2.17.so
  4eadca6cb82e0a85edb87c15b5e3980742514501 /usr/lib64/ld-2.17.so
  1e272ca30081e81ef41935a630eb2f4c636798b4 /usr/lib64/dri/swrast_dri.so
  0000000000000000000000000000000000000000 /tmp/perf-2523.map
Quoted 5 lines

There is something I don't understand in your example above. The -H option shows only DSO with samples. So why do you get the buildid without -H and you get no buildid with -H? In other words, I don't connect the dots between what -H does on the buildid change for the kernel. Looks like you have the buildid in the perf.data file.

Quoted 7 lines

Without -H, it just prints all DSOs found in build-id table (rebuilt during read perf data file header) and skips processing events. But with -H, it'd process the event records and so set kernel map to '[kernel.kallsyms]' - since the kernel mmap event always has the name - and mark it as hit. Thus the actual vmlinux can't be marked and then cannot be printed.

Still don't follow this. You're saying because as part of processing the events, you create or replace the mmap record corresponding to the kernel from the synthesized mmap (actual kernel filename) to the generic kernel.kallsyms, you lose the buildid. Why not just transfer it? It has to be the one listed without -H.
This would certainly be much less confusing (to me at least)! Seems to me you have one piece of information or the other (buildid or filename) but never both.

Quoted 5 lines

Hmm.. now I'm curious that why the -H option is needed at all.. the perf record already wrote build-ids that are actually hits..

Thanks,
Namhyung