How to make a linux kernel function available to ftrace function_graph tracer?
Asked Answered
J

1

12

I want to trace a function during kernel boot process with ftrace function_graph to understand what it does, but it is not available in available_filter_functions.

I tried to export it with EXPORT_SYMBOL(), guessing that it will made it available but this is not the case.

Do you have a solution ?

For information, functions I want to trace are persistent_ram_init_ringbuffer and persistent_ram_early_init in Android kernel 3.4.

I read through the documentation but found nothing on this and grep did not helped more...

Thanks

Jeopardize answered 7/3, 2013 at 12:42 Comment(3)
From my understanding of Ftrace, the dynamic tracing of functions relies on an mcount function call at the start of every kernel function. If the function you are interested in does not have that an available filter may not show up. Have you considered not using dynamic tracing? It may yield better results.Immersion
EXPORT_SYMBOL seems to have more to do with the kernel module loader resolving GPL/non-GPL licensing issues, not Ftrace.Privacy
When you list available_filter_functions does anything get listed at all? From what I can tell when you compile a kernel with CONFIG_FUNCTION_TRACER (and all the other ftrace gubbins) switched on the kernel function entry/exit tracing is implemented by setting options on the gcc command line. These options cause gcc to emit a particular function call for every function that it compiles. If I've understood that right then it means that any linux kernel function should automatically be captured by ftrace. This lead me to wonder about if anything at all was currently traceable in your kernel.Privacy
C
8

The problem is that those functions are annotated with __init and __devinit, which are black listed by ftrace function tracer.

Why? Because as module init functions (or kernel init functions) they are loaded during initialization and removed when the initialization is complete. Every function that ftrace traces is kept in a special compact table. Currently, there's no way to tell ftrace that those functions have been removed (freed) and that ftrace should remove them from its table. If we were to just ignore that, then when function tracing is enabled, ftrace will try to modify locations that no longer exist and can cause all sorts of issues (remember the e1000e bug?).

If you really want to trace them, then remove those annotations. Then they should appear in the list of functions to trace.

Corella answered 8/5, 2013 at 3:11 Comment(4)
Thank you for the answer. I was aware of notrace but not of the scope of __init and __devinit.Jeopardize
Wow....nice seeing you here Steven Rostedt. You are definitely one of the original author of the ftrace API in linux kernel.Paradisiacal
I can't trace sched_wakeup either, even if it obviously doesn't contain the __init or __devinit flags.Zaidazailer
On kernel 4.16.4, it seems not an issue any more.Aureliaaurelian

© 2022 - 2024 — McMap. All rights reserved.