disable_irq和disable_irq_nosync的区别

来源:互联网 发布:女朋友活好体验 知乎 编辑:程序博客网 时间:2024/06/17 17:51
这两天因为disable_irq的问题,困扰好久。到头来发现原来是自己没有仔细看每个函数的用法。。。。
问题出在request_irq后,在注册的中断回调函数(handler)中调用了disable_irq。这个调用导致系统定屏,现在看来应该是死锁了。在仔细看了如下的说明后,换成disable_irq_nosync后就好了。
如果你在某处调用了disable_irq,那么这个函数会等待自己对应的handler退出(return IRQ_HANDLED)后,这个disable_irq才会返回。(这里的互斥使用自旋锁实现的)
而disable_irq_nosync则不会等待自己对应的handler返回,disable_irq_nosync会立刻返回。
因此,入过你在一个handler中调用其对应的disable_irq必然会导致死锁产生!!!,此种情况下你应该使用disable_irq_nosync !!!
/** *disable_irq_nosync - disable an irq without waiting *@irq: Interrupt to disable * *Disable the selected interrupt line.  Disables and Enables are *nested. *Unlike disable_irq(), this function does not ensure existing *instances of the IRQ handler have completed before returning. * *This function may be called from IRQ context. */void disable_irq_nosync(unsigned int irq){__disable_irq_nosync(irq);}EXPORT_SYMBOL(disable_irq_nosync);/** *disable_irq - disable an irq and wait for completion *@irq: Interrupt to disable * *Disable the selected interrupt line.  Enables and Disables are *nested. *This function waits for any pending IRQ handlers for this interrupt *to complete before returning. If you use this function while *holding a resource the IRQ handler may need you will deadlock. * *This function may be called - with care - from IRQ context. */void disable_irq(unsigned int irq){if (!__disable_irq_nosync(irq))synchronize_irq(irq);}