Interrupt handler
Encyclopedia
An interrupt handler, also known as an interrupt service routine (ISR), is a callback
Callback (computer science)
In computer programming, a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to other code. This allows a lower-level software layer to call a subroutine defined in a higher-level layer....

 subroutine in microcontroller firmware, operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 or device driver
Device driver
In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....

 whose execution is triggered by the reception of an interrupt
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....

. Interrupt handlers have a multitude of functions, which vary based on the reason the interrupt was generated and the speed at which the interrupt handler completes its task.

An interrupt handler is a low-level counterpart of event handlers. These handlers are initiated by either hardware interrupts or interrupt instructions in software, and are used for servicing hardware devices and transitions between protected modes of operation such as system calls.

Overview

In several operating systems - Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

, Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

, Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

, Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

, and some other operating systems in the past, interrupt handlers are divided into two parts: the First-Level Interrupt Handler (FLIH) and the Second-Level Interrupt Handlers (SLIH). FLIHs are also known as hard interrupt handlers or fast interrupt handlers, and SLIHs are also known as slow/soft interrupt handlers, Deferred Procedure Call
Deferred Procedure Call
A Deferred Procedure Call is a Microsoft Windows operating system mechanism which allows high-priority tasks to defer required but lower-priority tasks for later execution...

.

A FLIH implements at minimum platform-specific interrupt handling similarly to interrupt routines. In response to an interrupt, there is a context switch
Context switch
A context switch is the computing process of storing and restoring the state of a CPU so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU. The context switch is an essential feature of a multitasking operating system...

, and the code for the interrupt is loaded and executed. The job of a FLIH is to quickly service the interrupt, or to record platform-specific critical information which is only available at the time of the interrupt, and schedule
Schedule (computer science)
In the fields of databases and transaction processing , a schedule of a system is an abstract model to describe execution of transactions running in the system. Often it is a list of operations ordered by time, performed by a set of transactions that are executed together in the system...

 the execution of a SLIH for further long-lived interrupt handling.

FLIHs cause jitter
Jitter
Jitter is the undesired deviation from true periodicity of an assumed periodic signal in electronics and telecommunications, often in relation to a reference clock source. Jitter may be observed in characteristics such as the frequency of successive pulses, the signal amplitude, or phase of...

 in process execution. FLIHs also mask interrupts. Reducing the jitter is most important for real-time operating system
Real-time operating system
A real-time operating system is an operating system intended to serve real-time application requests.A key characteristic of a RTOS is the level of its consistency concerning the amount of time it takes to accept and complete an application's task; the variability is jitter...

s, since they must maintain a guarantee that execution of specific code will complete within an agreed amount of time.
To reduce jitter and to reduce the potential for losing data from masked interrupts, programmers attempt to minimize the execution time of a FLIH, moving as much as possible to the SLIH.
With the speed of modern computers, FLIHs may implement all device and platform-dependent handling, and use a SLIH for further platform-independent long-lived handling.

FLIHs which service hardware typically mask their associated interrupt (or keep it masked as the case may be) until they complete their execution. An (unusual) FLIH which unmasks its associated interrupt before it completes is called a reentrant interrupt handler. Reentrant interrupt handlers might cause a stack overflow
Stack overflow
In software, a stack overflow occurs when too much memory is used on the call stack. The call stack contains a limited amount of memory, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture,...

 from multiple preemption
Preemption (computing)
In computing, preemption is the act of temporarily interrupting a task being carried out by a computer system, without requiring its cooperation, and with the intention of resuming the task at a later time. Such a change is known as a context switch...

s by the same interrupt vector
Interrupt vector
An interrupt vector is the memory address of an interrupt handler, or an index into an array called an interrupt vector table that contains the memory addresses of interrupt handlers...

, and so they are usually avoided. In a priority interrupt
Interrupt priority level
The interrupt priority level is a part of the current system interrupt state, which indicates the interrupt requests that will currently be accepted...

 system, the FLIH also (briefly) masks other interrupts of equal or lesser priority.

A SLIH completes long interrupt processing tasks similarly to a process. SLIHs either have a dedicated kernel thread for each handler, or are executed by a pool of kernel worker threads. These threads sit on a run queue
Run queue
In modern computers many processes run at once. Active processes are placed in an array called a run queue, or runqueue. The run queue may contain priority values for each process, which will be used by the scheduler to determine which process to run next...

 in the operating system until processor time is available for them to perform processing for the interrupt. SLIHs may have a long-lived execution time, and thus are typically scheduled similarly to threads and processes.

In Linux, FLIHs are called upper half, and SLIHs are called lower half or bottom half. This is different from naming used in other Unix-like systems, where both are a part of bottom half.

Comparison Between Subroutine And ISR

  1. As discussed earlier, routine executed in response to an interrupt is called as the interrupt service routine(ISR).
  2. Subroutine
    Subroutine
    In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

     is the part of a big program which perform some specific part related to the program.
  3. Subroutine is called by the program itself. It helps to avoid complexity in the program.
  4. ISR is the code executed in response to the interrupt which may occur during the execution of a program.
  5. ISR may have nothing in common to the program which is being executed at the time of interrupt is received.
  6. In the case of subroutine, only address of next field is stored in the stack automatically when it is called while in the case of ISR, along with the address of next field, content of status register and some other registers(if required) are also stored.

General Sequence Followed When Interrupts Occur By an External Device

  1. Interrupt request
    Interrupt request
    The computing phrase "interrupt request" is used to refer to either the act of interrupting the bus lines used to signal an interrupt, or the interrupt input lines on a Programmable Interrupt Controller...

    (IRQ) signal is sent by the device to the processor.
  2. If the interrupt line is enabled the following sequence of events occur in the system, else the interrupt is ignored. The processor completes its present instruction (if any) and pay attention to the IRQ.
  3. It stores the address of the next location and content of status register
    Status register
    A status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....

     to the stack
  4. It informs the device that its request has been granted and in response the device de-activates its IRQ.
  5. Using some suitable technique the processor loads its program counter
    Program counter
    The program counter , commonly called the instruction pointer in Intel x86 microprocessors, and sometimes called the instruction address register, or just part of the instruction sequencer in some computers, is a processor register that indicates where the computer is in its instruction sequence...

    (PC) with address of the ISR.
  6. With return statement occurring at the end of the ISR all stored content is loaded back into the respective registers and the processor resumes its suspended program.

Handling Multiple interrupting Devices

There exists four ways in which processor can control multiple interrupting devices:
  1. using multiple interrupt lines;
  2. using software polling
    Polling
    Polling is a municipality in the district of Mühldorf in Bavaria in Germany....

    ;
  3. using hardware polling (vector method);
  4. using bus
    Bus
    A bus is a road vehicle designed to carry passengers. Buses can have a capacity as high as 300 passengers. The most common type of bus is the single-decker bus, with larger loads carried by double-decker buses and articulated buses, and smaller loads carried by midibuses and minibuses; coaches are...

     arbitration.

Multiple Interrupt Lines

It is the simplest way. Here by providing separate interrupt line to each device,multiple devices are handled by the processor. Disadvantage of this method is that, this lead to the increase in the hardware structure of the processor chip. hence it becomes impractical to maintain small size of the chip and providing it access to multiple external devices.

Software Polling

Here multiple devices are connected to the processor by the common line to maintain small size. To decide which device over the common line is requesting for interrupt status of the IRQ bit
Bit
A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...

 in the status register
Status register
A status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....

 of the device is checked by the processor. After detecting the IRQ signal processor processor branches to an ISR whose job is to detect(to poll) which device has send IRQ signal.Here polling action is performed on the connected device one by one until a positive result(i.e. IRQ bit=1) is obtained. After positive result corresponding device is served. Disadvantage of the scheme is that, here time is unnecessarily wasted in checking the interrupting devices i.e. this technique is time consuming.

Hardware Polling (Vector Method)

Here wastage of time is avoided since device introduces itself to the processor after receiving acknowledgment(INTA)vice signal and processor immediately start executing the corresponding ISR. Device after receiving INTA signal send a special code to the processor. this code is used to access the memory location where starting address of he corresponding ISR is stored. Thus direct address obtained from the device act as a vector that points to the starting address of the ISR. Hence scheme is termed as vectored interrupt scheme.

Bus Arbitration

This technique also uses vectored interrupt. Here before sending IRQ device must get control over the system bus. Thus here only one module can raised the IRQ signal at a time.

Interrupt threads

Several operating systems - Solaris, NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

, Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

, WinCE and FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

, for example — use different scheme known as interrupt threads. An interrupt handler provided by the device driver is just a high-priority thread which runs with interrupts enabled and, more importantly, may block on mutex
Mutual exclusion
Mutual exclusion algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code in which a process or thread accesses a common resource...

. This greatly simplifies locking in the kernel. In addition, an interrupt thread may be preempted by some higher-priority interrupt thread.

Symbian OS

Due to (amongst other reasons) extended processing in a ISR delays the servicing of other interrupts, Symbian OS uses Delayed Function Calls (DFCs) to perform processing that would be impossible inside the ISR http://developer.symbian.com/main/downloads/papers/HWinterupt/HwInterrupt.pdf.

See also

  • Advanced Programmable Interrupt Controller
    Advanced Programmable Interrupt Controller
    In computing, an Advanced Programmable Interrupt Controller is a more complex Programmable Interrupt Controller than Intel's original types such as the 8259A...

     (APIC)
  • Inter-processor interrupt
    Inter-Processor Interrupt
    An inter-processor interrupt is a special type of interrupt by which one processor may interrupt another processor in a multiprocessor system. IPIs are typically used to implement a cache coherency synchronization point.- Windows :...

     (IPI)
  • Interrupt
    Interrupt
    In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....

  • Interrupt latency
    Interrupt latency
    In real-time operating systems, interrupt latency is the time between the generation of an interrupt by a device and the servicing of the device which generated the interrupt. For many operating systems, devices are serviced as soon as the device's interrupt handler is executed...

  • Non-maskable interrupt
    Non-Maskable interrupt
    A non-maskable interrupt is a computer processor interrupt that cannot be ignored by standard interrupt masking techniques in the system. It is typically used to signal attention for non-recoverable hardware errors...

     (NMI)
  • Programmable Interrupt Controller
    Programmable Interrupt Controller
    In computing, a programmable interrupt controller is a device that is used to combine several sources of interrupt onto one or more CPU lines, while allowing priority levels to be assigned to its interrupt outputs. When the device has multiple interrupt outputs to assert, it will assert them in...

     (PIC)
  • Red zone
    Red zone (Computing)
    Red Zone is a term designating the fixed size area in memory beyond the stack pointer that has not been "allocated". This region of memory is not to be modified by interrupt/exception/signal handlers. This allows the space to be used for temporary data without the extra overhead of modifying the...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK