如何使用linux内核中的lockdep特性进行死锁检测 [英] How to use lockdep feature in linux kernel for deadlock detection

查看:19
本文介绍了如何使用linux内核中的lockdep特性进行死锁检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 linux 内核驱动程序和一个与之交互的用户应用程序.内核驱动程序中存在死锁.我在 linux 内核中遇到了这个名为lockdep"的功能.我能够配置它并重新编译我的内核(我确实在/proc 中看到了 lockdep 文件夹).但我不知道如何推断此工具的输出或如何使用此工具调试驱动程序.任何帮助将不胜感激.谢谢!

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!

推荐答案

要启用 lockdep 功能,请通过 menuconfig 编辑 .config 文件:

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

make menuconfig

并在 Hacking Options 中启用以下内容:

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

重新编译内核:

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

现在,启动新的内核映像,在/proc 下,您应该会看到以下新文件夹:

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>

您应该会看到应用的 +D(不间断睡眠)状态,请执行以下操作:

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.

就是这样!

这篇关于如何使用linux内核中的lockdep特性进行死锁检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆