Adding dynamic tracepoint through perf in Linux fo

2019-04-15 08:25发布

问题:

I am trying to trace function zap_pte_range from mm/memory.c using perf. But function is not listed in the perf probe -F. So is there a way to dynamically trace this function? I.e. with explicitly adding the tracepoint and recompiling the kernel?

perf probe -a zap_pte_range

gives:

[kernel.kallsyms] with build id 33b15ec444475ee7806331034772f61666fa6719 not found, continuing without symbols

Failed to find symbol zap_pte_range in kernel

Error: Failed to add events.

回答1:

There is no such trace point. So apparently you cannot trace it the easy way. It seems that this function was inlined by compiler (keep in mind that function also could be omitted for some optimization reasons). That's why there is no its symbol in /proc/kallsyms.

You can choose the most suitable function for you to trace. E.g. in my Debian with 4.9 kernel I can trace unmap_page_range(), which eventually "calls" the function you need. Perhaps it logically will meet your goal.

Another way is a little bit hacking. You can do something like objdump -dS memory.o | vim - (you should have binaries) and investigate where is the code you needed. Given that the chain zap_pud_range()->zap_pmd_range()->zap_pte_range() is probably inlined, you will have to investigate aforementioned unmap_page_range(). Perhaps you'll finally gain some code address for kprobes.

If you want to explicitly trace zap_pte_range() e.g. through jprobes (about args) or kretprobes (about return value), you can try to specify noinline-attribute for needed function(s), recompile Linux kernel and trace it as you want.

Guess I have no more useful ways for you.

More info: Related post, Jprobes example, Ftrace: trace your kernel functions!, Post about ftrace and systemtap, man nm