EmbLogic's Blog

Interrupt and IRQ

To understand Interrupts in a general context, we can say that the Interrupts behaves same as the Signals for user space applications.
Two Types of interrupts can be generated ? one is generated by the Processor control unit while executing the instructions and the other one is generated by the other hardware device and generally called as the hardware interrupts.
As the processor receives an Interrupt, the processor stops its normal execution of the instructions and switches to the different context other than the normal process context. This code (Interrupt handler) for this context is written specially for the particular Interrupt. The interrupt handling is quite different from the process context switching. But after the execution of the interrupt handler the last process resumes to the execution.
Interrupt Handler function must not contain the sleep. Interrupt handler must execute in the minimum possible amount of time. If there is some task which as to be implemented as the interrupt arrives and this task requires some time to execute, then the code for this must be written in the bottom half. Workqueue or Softirq can be implemented in the bottom half. This should be done because while interrupt handler is running, the signals on the corresponding IRQ line are temporarily disabled. The handler also sends the acknowledgment to the Programmable Interrupt Controller that I am servicing the interrupt.
IRQ (a kernel identifier) is a interrupt request from a device. During the execution of interrupt handler for a particular IRQ, the interrupt is disabled for that IRQ. Kernel also provides the facility to disable all interrupts issued by IRQ by a function. IRQ number provides the possible interrupt source on a machine.
Most hardware controller are capable of issuing interrupt requests and these interrupt requests are fed to the Programmable Interrupt Controller. The Programmable Interrupt Controller is responsible for monitoring the IRQ lines and to inform the processor on the INTR pin of the processor.
Several devices may share the same IRQ line and the most important thing that the kernel has to discover which I/O device corresponds to the particular IRQ number before enabling the Interrupt.
The interrupt handler executes several Interrupt Service Routines. Each Interrupt Service routine is a function related to a single device sharing the IRQ lines. Hence the IRQ lines can be shared among different devices and the meaning of IRQ line becomes different for each IRQ line. The Interrupt Service Routine performs all operations that need to be executed when the device raise the interrupt. Most of the time Interrupt is  best way to avoid the polling mechanism. It is helpful to save the CPU cycles. There are priority mechanism among different interrupts.
When the device driver’s interrupt handling routine is called by the Linux kernel it must efficiently work out why it was interrupted and respond. To find the cause of the interrupt the device driver should read the status register of the device that interrupted. Hence Interrupts are mostly used in the device drivers.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>