Search code examples
linuxlinux-kernelkernelinterruptinterrupt-handling

clear pending interrupts in linux kernel


say I have some code as follows:

local_irq_disable();
...  // some interrupts come during this time
local_irq_enable();

after I called local_irq_enable(), all interrupts blocked(pending interrupts) are still there & cause the cpu to respond. Is there anything will clear pending interrupts? my code runs on an ARM aarch64 machine.


Solution

  • A typical chain is that the cpu interrupt pin is multiplexed via an interrupt controller (ex. GIC) to a set of devices.

    Disabling interrupts merely shunts the pin on the CPU, the interrupt controller still maintains the pending state. You could use a feature on the interrupt controller to mask all interrupts, which would permit you to then enable the CPU interrupts without receiving any. Not really sure the point in that, when you could just leave the CPU ignoring interrupts.

    To truly clear the pending interrupts, you need to invoke the device specific code (ie. interrupt handler) for each device with a pending interrupt. You could look through the status bits of the GIC, identify each pending interrupt, then look through the kernel's interrupt structure to determine the relevant device and invoke its handler. It is a lot easier to just turn interrupts back on.