[PATCH RFC V1] perf tests: ignore symbols before kernel start

From: Song Shan Gong
Date: Tue Jul 19 2016 - 05:05:41 EST


perf gets kernel map start in function 'machine__get_running_kernel_start',
by finding the first no-zero value of symbol start value of '_text' or
'_stext'. Though kernel maybe start from a no-zero value, perf loads all
symbols into a red-black tree, even if one symbol starts from zero (for
example, '_text' is zero, '_stext' is kernel map start value, '_text' is
also added to the red-black tree).

In test function 'test__vmlinux_matches_kallsyms', perf traverses all
vmlinux symbols by enumerating its red-black tree, but finding the pair
symbol in kallsyms by 'machine__find_kernel_symbol'. For function
'machine__find_kernel_symbol', it will find the matched map firstly, then
find the pair symbol in the red-black tree corresponding to that map.

So when '_text' is zero, '_stext' is kernel map start(no-zero), we can
get '_text' symbol of vmlinux, but we can't find the pair '_text' symbol of
kallsyms, because there is no map starting from zero. This mismatch is
incorrrect.

Fix by just ignoring these symbols before kernel start.

Signed-off-by: Song Shan Gong <gongss@xxxxxxxxxxxxxxxxxx>
---
tools/perf/tests/vmlinux-kallsyms.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index e63abab..6766006 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -28,6 +28,7 @@ int test__vmlinux_matches_kallsyms(int subtest __maybe_unused)
enum map_type type = MAP__FUNCTION;
struct maps *maps = &vmlinux.kmaps.maps[type];
u64 mem_start, mem_end;
+ u64 kernel_start;

/*
* Step 1:
@@ -75,6 +76,7 @@ int test__vmlinux_matches_kallsyms(int subtest __maybe_unused)
* same value in the vmlinux file we load.
*/
kallsyms_map = machine__kernel_map(&kallsyms);
+ kernel_start = kallsyms_map->start;

/*
* Step 5:
@@ -119,7 +121,7 @@ int test__vmlinux_matches_kallsyms(int subtest __maybe_unused)

sym = rb_entry(nd, struct symbol, rb_node);

- if (sym->start == sym->end)
+ if (sym->start == sym->end || sym->start < kernel_start)
continue;

mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
--
2.3.0