Linux Kernel: Print Callee and Caller

Print the callback function name

If you cannot trace which function gets called when you call from core driver using function pointer, you can print function name using pf format specifier.
Linux maintains symbol table so based on function address, it can identify function name based on address pointed by function pointer.
e.g. Core driver calls hardware specific enable/disable functions:
core->ops->enable(). If you are not sure, which function is executed as a result of this call, you can print them using %pf or %pF:
pr_info("callee function name is: %pf,  core->ops->enable)
%pf prints without offset (e.g. foo) while %pF prints with offset (e.g. foo+0x00/0x80)
Reference: https://www.kernel.org/doc/Documentation/printk-formats.txt.
Thanks Bhargav(br13patel) for sharing this!

Print caller name

There are few ways to trace caller in Linux kernel.
  • Print stack backtrace
    • dump_stack();
      • To enable the dump_stack() function in the kernel config the following options must be set.
        1. Kernel hacking -> Kernel debugging
        2. Kernel hacking -> Verbose kernel error messages
    • WARN_ON(1);
  • Print caller name
    • pr_info(“caller function name is: %pf,  __builtin_return_address(0))

Store and Restore Sessions in VIM

Below commands once added in vimrc creates a session with F2 and restore using F3:

map <F2> :mksession! ~/vim_session <cr> " Quick write session with F2
map <F3> :source ~/vim_session <cr> " And load session with F3

You can make any number of sessions using “mksession” command and restore using “source” command from vim editor also.

Git send email

My git send-email config:

git config sendemail.smtpuser 
git config sendemail.smtpserver smtp.googlemail.com
git config sendemail.smtpencryption tls
git config sendemail.smtpserverport 587
git config sendemail.suppresscc self
git send-email --to <to_list> --in-reply-to="<message_id_of_message1>" --thread *.patch

This will generate patch in below way:
– Message 1
.           – Patch 1
.                       – Patch 2

This is how I prepared cover page followed by two patches:

git format-patch -2 --subject-prefix="PATCH v2" --cover-letter --thread=shallow
  • Here –cover-later would create a cover page. We need to modify subject and content.
  • The –thread=shallow flag specifies that all patches will be In-Reply-To your cover letter. Hence all patches would be in reply to cover page by default.
  • –subject-prefix=”PATCH v2″ would use given prefix in patch file.

This is how I sent this patches:

git send-email –to <to_id> –cc <cc_id> <patches>

The patch follows below sequence

  • Cover Page
    • Patch 1
    • Patch 2

References:
https://burzalodowa.wordpress.com/2013/10/05/how-to-send-patches-with-git-send-email/
http://git-scm.com/docs/git-send-email
example patch

Git useful commands

  • Git reset hard remote branch to specific commit
    # git reset --hard <commit-id>
    # git push -f origin <branch_name>
    
  • Add prefix in patch subject
    # git format-patch --subject-prefix=PREFIX][PATCH
    
      This will generate a patch with subject: [PREFIX] [PATCH]
  • Get list of new added files between two commits
    # git diff --name-only --diff-filter=A <old-commit-id> <new-commit-id>
  • Get list of modified files between two commits
    # git diff --name-only --diff-filter=M <old-commit-id> <new-commit-id>

Linux Useful Commands

  • List files recursively with path
    find . -name \* -print

    List txt files recursively with path

    find . -name \*.txt -print
  • Remove trailing whitespace of all files recursively
    find <dir> -type f -exec sed -i 's/ *$//' '{}' ';'

     

How to Change Linux Kernel dmesg buffer size

Printk is implemented by using a ring buffer in the kernel with a size of __LOG_BUF_LEN bytes where __LOG_BUF_LEN equals (1 << CONFIG_LOG_BUF_SHIFT).

dmesg buffer size can be changed using “CONFIG_LOG_BUF_SHIFT” Kconfig.

As per kernel source (4.1.0), default value of this config is 17 (i.e. 1 << 17 = 128KB). The range for this config is 12 to 21.

Addign  below line in defconfig sets

Note: If invalid value (out of range value) is set, default value is taken.

CONFIG_LOG_BUF_SHIFT can be changed from menuconfig or from defconfig as below:

CONFIG_LOG_BUF_SHIFT=21