gpt4 book ai didi

linux-device-driver - 解决自旋锁问题

转载 作者:行者123 更新时间:2023-12-04 05:44:49 25 4
gpt4 key购买 nike

在 Linux 设备驱动程序中。当它引入自旋锁时,它给出了以下示例:

Your driver is executing and has just taken out a lock that controls access to its device. While the lock is held, the device issues an interrupt, which causes your interrupt handler to run. The interrupt handler, before accessing the device, must also obtain the lock. Taking out a spinlock in an interrupt handler is a legitimate thing to do; that is one of the reasons that spinlock operations do not sleep. But what happens if the interrupt routine executes in the same processor as the code that took out the lock originally? While the interrupt handler is spinning, the noninterrupt code will not be able to run to release the lock. That processor will spin forever.



如何解决这个问题?使用信号量?请帮忙。

最佳答案

您使用 spin_lock_irqsave 从非中断代码禁用当前内核上的硬件中断,或使用 中描述的任何工具“锁定的替代方案”同一章中的部分。

编辑0:

不记得那里的确切细节,但理论是:

  • 在 UP 系统上,您根本不需要自旋锁——从访问与中断处理程序共享的数据的 BH 代码中禁用中断就足够了。
  • 在 SMP 系统上,您需要一个自旋锁来防止在其他内核上执行相同的 BH 代码,并且,如果您处理硬件,您还希望禁用同一内核上的中断以避免与 IRQ 例程发生死锁。
  • 中断处理程序总是需要在持有任何锁的同时禁用中断以避免与自身发生死锁。

  • 希望这可以帮助。

    关于linux-device-driver - 解决自旋锁问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816288/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com