Linux死锁调试之hardlockup

Kernel branch: 3.0.35


概要:

hardlockup用于检测进入中断之后导致死锁的情况。

原理:
利用了NMI(非屏蔽中断)不能被屏蔽的特性,也就是说系统即使中断死锁后NMI也能被触发。
如果中断正常,hrtimer会定期被调用而去更新计数变量hrtimer_interrupts, 而NMI中断函数后
也会定期判断此值有没有变化,如果没有变化说明中断已经死掉。


code流程:
和watchdog.c公用一个文件,两个功能融合在一起,
lockup_detector_init ->    //watchdog.c
    cpu_callback ->    //action CPU_UP_PREPARE
        watchdog_prepare_cpu ->    //hrtimer对应function是watchdog_timer_fn
    cpu_callback ->
        watchdog_enable ->
            watchdog_nmi_enable     ->    //这里会开启nmi
                hw_nmi_get_sample_period    //获取nmi触发的周期
                perf_event_create_kernel_counter    //使用perf架构创建一个event,当nmi触发时,会调用watchdog_overflow_callback
            kthread_create ->    //为每个cpu创建名字叫watchdog/x的thread, x是cpu number,对应function为watchdog().
                watchdog ->    
                    hrtimer_start    //启动timer
                    watchdog_timer_fn     -> //hrtimer被触发
                        watchdog_interrupt_count    //增加hrtimer_interrupts计数。
            另一方面nmi中断也会被定期触发,调用
            watchdog_overflow_callback ->
                is_hardlockup     -> //判断hrtimer_interrupts有没有被更新,如果没有,那就说明中断死锁了。
                    WARN 打印hardlockup log

touch_softlockup_watchdog()的作用
    此函数用于禁止NMI。系统可能有特殊需求,例如使用kgdb调试的时候需要关闭NMI,否则
调试会异常。

由于我使用的IMX6DL是基于ARM Cortex-A9, 不支持NMI, 所以没办法做测试了。


参考:
http://bbs.chinaunix.net/thread-4095844-1-1.html
http://blog.csdn.net/nerdx/article/details/17005935


版权声明:本文为kris_fei原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。