Interrupt

What is Interrupt

  • Hardware Interrupt — A hardware interrupt is a signal which can tell the CPU that something happen in hardware device, and should be immediately responded. A interrupt causes the processor to save its state of execution and begin execution of an interrupt service routine.
  • Software Interrupt — Software interrupt is an instruction which cause a context switch to an interrupt handler similar to a hardware interrupt. Usually it is an interrupt generated within a processor by executing an instruction. Software interrupts are often used to implement system calls.

Interrupt Latency

  • when an interrupt fires, the microprocessor executes an interrupt service routine (ISR). The amount of time that elapses between a device interrupt request and the first instruction of the corresponding ISR is known as interrupt latency.

Reduce Interrupt Latency

  • We should make all ISR as short as possible, because other ISR that has lower priority will be blocked by it.
  • If we disable interrupt in an ISR or process for protecting critical sections, we should enable it as early as possible. Once we finish the task which is non-reentrant in an ISR, its time to enable interrupt.
  • We can also reenable all ISR before the current ISR finish its non-reentrant task. Therefore, the current ISR won't degrade the latency of other ISR. However, we need to prevent interrupt overrun by setting up the corresponding mask bit or using a static to notify the ISR is currently triggered. Notice that preventing interrupt overrun means that some interrupts will miss.
  • Use inline assembly language to replace some lines of ISR code in C, and reduce some overhead introduced by C.

http://en.wikipedia.org/wiki/Interrupt

Interrupt vs Exception

The definitions are different everywhere. Here are some reasonable conclusions I made:

  • Interrupt includes hardware interrupt and software interrupt; Exception includes trap, fault, and abort.
  • Hardware interrupt is asynchronous, and others (exceptions and software interrupt) are synchronous to instructions.
  • Software interrupt are used to implement system call. In intel processor, we use INT instruction. In MIPS we use syscall.

Ex. Fork() System Call — Intel x86 & Linux

__asm__ (
    "movl $2, %%eax\n\t"           // move 2 into eax, 2 is the number for fork() system call
    "int $0x80\n\t"                   // int 0x80 execute a software interrupt that deal with system call 
    :"=a" (chPid)         // return value of Fork()
);

Ex. Open() System Call — MIPS

Void open (char *file_name) {
  asm {
      load OpenSystemCallNum, r8
      move filename, r9
      syscall       // when syscall is executed, CPU load PC with address stored in interrupt vector table
  }                      // using OpenSystemCallNum as the table index, and jump to the associated ISR
}
  • Software interrupt and trap are sometime considered as the same thing. That's why some definitions say system call is trap.

IRQ & FIQ

"IRQ is serviced at a normal priority level and FIQ is serviced at high priority level."

FIQ is the fast interrupt i.e. the latency time taken is less because in the FIQ mode (in case of ARM architecture where these modes are encountered) the mode has an additional set of 7 general purpose registers which means in case of the banked registers there is no need to store these registers into stack when the interrupt occurs.

That means only r0 to r7 need to be stored while moving from User mode to FIQ mode whereas while moving from User mode to IRQ mode r0 to r12 needs to be stored.

Reference

http://www.cs.fsu.edu/~xyuan/cop4610/lecture_2_concurrency.ppt

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License