简体   繁体   English

为什么Linux内核中没有wait_event_ ... _irqsave()函数或宏?

[英]Why is there no wait_event_…_irqsave() function or macro in the Linux kernel?

In the Linux kernel the function wait_event_lock_irq(wq_head, condition, lock) is provided in include/linux/wait.h that expects lock to be held and unlocks/locks it using spin_lock_irq() and spin_unlock_irq() . 在Linux内核中,函数wait_event_lock_irq(wq_head, condition, lock)include/linux/wait.h中提供,它期望lock被保持并使用spin_lock_irq()spin_unlock_irq()解锁/锁定它。 Is there a particular reason that something along the lines of wait_event_lock_irqsave() that uses spin_lock_irqsave() / spin_lock_irqrestore() is not provided? 是否有特殊原因导致使用spin_lock_irqsave() / spin_lock_irqrestore()wait_event_lock_irqsave()行没有提供?

spin_lock_irqsave() and spin_unlock_irqrestore() save and restore the CPU's "interrupts enabled" status flags. spin_lock_irqsave()spin_unlock_irqrestore()保存并恢复CPU的“中断启用”状态标志。 If you know you are not running in an interrupt context with interrupts enabled, but need to synchonize with locks taken in interrupt context, you can use spin_lock_irq() and spin_unlock_irq() to disable and re-enable interrupts without preserving ing the "interrupts enabled" status flags. 如果您知道您没有在启用中断的中断上下文中运行,但需要与中断上下文中的锁同步,则可以使用spin_lock_irq()spin_unlock_irq()来禁用和重新启用中断,而不保留“启用中断” “状态标志。

The wait_event_...() macros should never be called from an interrupt context (because they may sleep), so it is safe for them to assume that they are not called from an interrupt context, so there is no need to preserve the CPU's "interrupts enabled" status flags. wait_event_...()永远不应该从中断上下文中调用(因为它们可能会休眠),因此它们可以安全地假设它们不是从中断上下文中调用的,因此不需要保留CPU的“中断已启用”状态标志。 The normal (non-IRQ) wait_event_...() macros should also never be called with interrupts disabled (again, because they may sleep), so it is safe for them to assume that interrupts are not disabled. 正常(非IRQ) wait_event_...()宏也应该永远禁用中断调用(再次,因为他们可能睡觉),因此它是安全的,他们认为中断未被禁用。 Of course, the wait_event_..._lock_irq() macro are called with interrupts disabled, but they assume that interrupts were enabled before the preceding call to spin_lock_irq() and that interrupts can be safely re-enabled. 当然,在禁用中断的情况下调用wait_event_..._lock_irq()宏,但是它们假定在前一次调用spin_lock_irq()之前启用了中断,并且可以安全地重新启用中断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM