Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

c - How to use lockdep feature in linux kernel for deadlock detection

I have a linux kernel driver and a user app that interacts with it. The kernel driver has a deadlock in it. I came accross this feature in the linux kernel called "lockdep". I was able to configure it and recompile my kernel (and I do see the lockdep folders in /proc). But I don't know how to infer the output of this tool or how to go about debugging the driver using this tool for that matter. Any help will much appreciated. Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To enable lockdep feature, edit .config file through menuconfig:

make menuconfig

And enable following in Hacking Options:

 1. [*] Detect Hard and Soft Lockups
 2. [*] Detect Hung Tasks
 3. [*] RT Mutex debugging, deadlock detection
 4. -*- Spinlock and rw-lock debugging: basic checks
 5. -*- Mutex debugging: basic checks
 6. -*- Lock debugging: detect incorrect freeing of live locks
 7. [*] Lock debugging: prove locking correctness
 8. [*] Lock usage statistics

Recompile the kernel:

make ARCH=i386 -j4 //whatever your arch is

Now, boot the new kernel image, under /proc you should see the following new folders:

/proc/lockdep
/proc/lockdep_chains
/proc/lockdep_stat
/proc/locks
/proc/lock_stats

Now, insert the module you think that is causing the error, and access it with your user application (or whatever way you use to run your driver module). If the app deadlocks(hangs), do a:

ps -aux | grep <app_name>

you should see a +D (uninterruptible sleep) state for your app, do a:

dmesg

The log it prints will include the function/file causing the deadlock.

That's it!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...