kernel-hacking-2024-linux-s.../tools/perf
Arnaldo Carvalho de Melo 56b03f3c4d perf tools: Handle relocatable kernels
DSOs don't have this problem because the kernel emits a
PERF_MMAP for each new executable mapping it performs on
monitored threads.

To fix the kernel case we simulate the same behaviour, by having
'perf record' to synthesize a PERF_MMAP for the kernel, encoded
like this:

[root@doppio ~]# perf record -a -f sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.344 MB perf.data (~15038 samples) ]
[root@doppio ~]# perf report -D | head -10

0xd0 [0x40]: event: 1
.
. ... raw event: size 64 bytes
.  0000:  01 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 ......@........
.  0010:  00 00 00 81 ff ff ff ff 00 00 00 00 00 00 00 00 ...............
.  0020:  00 00 00 00 00 00 00 00 5b 6b 65 72 6e 65 6c 2e ........  [kernel
.  0030:  6b 61 6c 6c 73 79 6d 73 2e 5f 74 65 78 74 5d 00  kallsyms._text]
.  0xd0
[0x40]: PERF_RECORD_MMAP 0/0: [0xffffffff81000000((nil)) @ (nil)]: [kernel.kallsyms._text]

I.e. we identify such event as having:

 .pid      = 0
 .filename = [kernel.kallsyms.REFNAME]
 .start    = REFNAME addr in /proc/kallsyms at 'perf record' time

and use now a hardcoded value of '.text' for REFNAME.

Then, later, in 'perf report', if there are any kernel hits and
thus we need to resolve kernel symbols, we search for REFNAME
and if its address changed, relocation happened and we thus must
change the kernel mapping routines to one that uses .pgoff as
the relocation to apply.

This way we use the same mechanism used for the other DSOs and
don't have to do a two pass in all the kernel symbols.

Reported-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
LKML-Reference: <1262717431-1246-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 10:09:11 +01:00
..
bench perf sched: Fix build failure on sparc 2009-12-14 08:59:12 +01:00
Documentation perf diff: Use perf_session__fprintf_hists just like 'perf record' 2009-12-16 16:53:37 +01:00
scripts/perl perf trace/scripting: List available scripts 2009-12-15 10:31:32 +01:00
util perf tools: Handle relocatable kernels 2010-01-13 10:09:11 +01:00
.gitignore perf tools: Add perf.data to .gitignore 2009-11-24 16:37:01 +01:00
builtin-annotate.c perf session: Remove redundant prefix & suffix from perf_event_ops 2009-12-28 09:03:35 +01:00
builtin-bench.c perf bench: Add "all" pseudo subsystem and "all" pseudo suite 2009-12-14 08:51:19 +01:00
builtin-buildid-list.c perf diff: Fix usage array, it must end with a NULL entry 2009-12-18 20:01:52 +01:00
builtin-diff.c perf diff: Fix support for all --sort combinations 2009-12-30 12:00:00 +01:00
builtin-help.c perf: Use format string of printf to align strings 2009-12-28 09:03:16 +01:00
builtin-kmem.c Merge branch 'perf/urgent' into perf/core 2010-01-13 10:08:50 +01:00
builtin-list.c perf list: Fix large list output by using the pager 2009-08-13 09:05:48 +02:00
builtin-probe.c perf session: Keep pointers to the vmlinux maps 2010-01-13 10:09:10 +01:00
builtin-record.c perf tools: Handle relocatable kernels 2010-01-13 10:09:11 +01:00
builtin-report.c perf report: Fix --no-call-chain option handling 2010-01-13 10:09:10 +01:00
builtin-sched.c perf session: Remove redundant prefix & suffix from perf_event_ops 2009-12-28 09:03:35 +01:00
builtin-stat.c perf tools: Fix --pid option for stat 2010-01-13 10:09:08 +01:00
builtin-timechart.c perf session: Remove redundant prefix & suffix from perf_event_ops 2009-12-28 09:03:35 +01:00
builtin-top.c perf symbols: Move symbol filtering to event__preprocess_sample() 2009-12-16 08:53:49 +01:00
builtin-trace.c perf session: Remove redundant prefix & suffix from perf_event_ops 2009-12-28 09:03:35 +01:00
builtin.h perf diff: Introduce tool to show performance difference 2009-12-15 08:50:29 +01:00
command-list.txt perf diff: Introduce tool to show performance difference 2009-12-15 08:50:29 +01:00
CREDITS perf_counter tools: Add CREDITS file for Git contributors 2009-06-24 19:54:29 +02:00
design.txt perf: Rename perf_event_hw_event in design document 2009-12-28 09:14:37 +01:00
Makefile Merge branch 'perf/urgent' into perf/core 2010-01-13 10:08:50 +01:00
perf.c perf tools: Mount debugfs automatically 2009-12-28 10:36:36 +01:00
perf.h perf tools: Allow building for ARM 2009-12-11 13:50:21 +01:00