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

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

问题描述

我有一个Linux内核驱动程序和一个与其交互的用户应用程序.内核驱动程序中有一个死锁.我在名为" lockdep 的linux内核中遇到此功能. .我能够配置它并重新编译内核(并且我确实在/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

并在黑客选项"中启用以下功能:

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天全站免登陆