Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entry and Exit prints in Linux Kernel

I want to know which all functions are executed in a particular scenario .

To be specific I want to understand MMC/SD card stack in Linux kernel.

My idea was to put prints like this :

pr_info("Entering %s\n", __func__);

pr_info("Leaving %s\n", __func__);

to all the functions present in drivers/mmc/ .

But this is a tedious task.

Is there a better method to do this ?

Note : I explored the possibility of using instrumentation functions provided by gcc __cyg_profile_func_enter and __cyg_profile_func_exit.

Those instrumentation functions work perfectly for small modules.

But can these functions be used in Linux Kernel also ? Or do we have some different method for this?

My environment : The code will be cross compiled for Cortex A7/A9.

like image 849
Leo Messi Avatar asked Mar 25 '26 05:03

Leo Messi


1 Answers

You can compile the source files you want with -finstrument-functions. Then you can implement these two functions yourself, in some file of the kernel.

Note that:

  1. You must not compile the file containing __cyg_profile_func_enter/exit with -finstrument-functions (or, you should use __attribute__((no_instrument_function))).
  2. The functions __cyg_profile_func_enter/exit must not call code compiled with -finstrument-functions - this will lead to infinite recursion. If all they do is printk, and printk and the low-level drivers it calls are not compiled this way, you're OK.
like image 110
ugoren Avatar answered Mar 27 '26 03:03

ugoren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!