Linux Kernel: How to debug mutex deadlock how to debug mutex deadlock

Source: Internet
Author: User

Like debugging the lock in userspace, it mainly involves:

1. Locate the lock deadlock and print out the call stack.

2. Find out who is using this mutex.

 

For example, in kernel config, enable is associated with lock/mutex, such as config_debug_mutex and config_detect_hung_tasks. In this way, when a deadlock occurs, wait for a period of time (120 seconds by default). The kernel detects the deadlock and prints the call stack. In kernel hacking, there are a large number of config files that are conducive to debugging. You can read them one by one. There is always one suitable for you.

 

For example, if config_debug_mutex is enabled, add the following code:

Show_stack (<lock>. Owner, null );

<Lock> is your mutex variable name ,. the owner is a struct task_struct *. By using the show_stack function, you can print out who occupies the mutex and the call stack when it occupies the mutex. Very cool.

In addition, you can take a look at the definition of struct mutex. There are some practical things, such as the mutex name. Struct task_struct also has some practical things, such as PID.

 

To sum up, the following can be printed in the kernel:

Dump_stack: prints the current backtrace

Show_stack: prints the backtrace of the specified task_struct.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.