Enabling and Disabling Interrupts
at Sunday, July 22, 2007
Device drivers may need to stop interrupts for some time. This can be due to various reasons. Usually, interrupts are blocked to avoid deadlocks. If an interrupt is shared, disabling interrupts are not adviced.
Linux kernel provides these functions for enabling and disabling interrupts:
void enable_irq(int irq); void disable_irq(int irq); void disable_irq_nosync(int irq);Enabling or disabling interrupts through these functions result in updating interrupt mask for the specified irq in the PIC (Programmable Interrupt Controller). This is visibile for all processors and hence can be used even in SMP. Disabling an interrupt waits for the completion of currently executing interrupt handler (if any). But disabling through disable_irq_nosync returns immediately but may result in race conditions. Enabling/disabling interrupt for the current processor Starting from Linux 2.6 kernel, interrupt handling on the current processor can be disabled. Linux kernel provides these functions for the same.
void local_irq_save(unsigned long flags); void local_irq_disable(void);Calling local_irq_save function will disable interrupt on the current processor and prior to which it saves current interrupt state into flags (passed to this function). Calling local_irq_disable function will disable interrupt on the current processor but without saving state. Thus disabled interrupts can be enabled using these functions.
void local_irq_restore(unsigned long flags); void local_irq_enable(void);local_irq_restore function enables interrupts and restores state using flags (stored by local_irq_save). The local_irq_enable function enables interrupts unconditionally. Reference: Linux Device Drivers




