All Topics  
Interrupt handler

 

   Email Print
   Bookmark   Link






 

Interrupt handler



 
 
An interrupt handler, also known as an interrupt service routine (ISR), is a callback
Callback (computer science)

In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level abstraction layer to call a subroutine defined in a higher-level layer....
 subroutine in an operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 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 communication signal from hardware 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 handler
Event handler

In computer programming, an event handler is an asynchronous callback subroutine that handles inputs received in a program. Each event is a piece of application-level information from the underlying framework, typically the GUI toolkit....
s.






Discussion
Ask a question about 'Interrupt handler'
Start a new discussion about 'Interrupt handler'
Answer questions from other users
Full Discussion Forum



Encyclopedia


An interrupt handler, also known as an interrupt service routine (ISR), is a callback
Callback (computer science)

In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level abstraction layer to call a subroutine defined in a higher-level layer....
 subroutine in an operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 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 communication signal from hardware 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 handler
Event handler

In computer programming, an event handler is an asynchronous callback subroutine that handles inputs received in a program. Each event is a piece of application-level information from the underlying framework, typically the GUI toolkit....
s. 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 modern operating systems, 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, fast interrupt handlers and top-half of interrupt, and SLIHs are also known as interrupt threads, slow interrupt handlers and bottom-half of interrupt.

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 Central processing unit such that multiple Process es can share a single CPU resource....
, 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 field of databases, a schedule is a list of actions, , from a set of Database transaction.Here is a sample schedule:In this example, Schedule D is the set of 3 transactions T1, T2, T3....
 the execution of a SLIH for further long-lived interrupt handling.

FLIHs cause jitter
Jitter

Jitter is an unwanted variation of one or more characteristics of a periodic Signalling in electronics and telecommunications. Jitter may be seen in characteristics such as the interval between successive pulses, or the amplitude, frequency, or phase of successive cycles....
 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 a Computer multitasking operating system intended for real-time computing applications. Such applications include embedded systems , industrial robots, spacecraft, industrial control , and scientific research equipment....
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. A (unusual) FLIH which unmasks its associated interrupt before it completes is called a reentrant interrupt handler. Reentrant interrupt handlers might cause a stack overflow from multiple preemption
Preemption (computing)

Preemption in computing is the act of temporarily interrupting a task being carried out by a computer, without requiring its cooperation, and with the intention of resuming the task at a later time....
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 or dispatch table....
, 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 Process run at once, to ensure each program has a fair share of resources each one is run for a period, when a program is taken out to let another run it is placed on the end of the run queue, and the program at the head of the run queue is then allowed to execute....
 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.

It is worth noting that in many systems the FLIH and SLIH are referred to as upper halves and lower halves, hardware and software interrupts, or a derivation of those names.

Interrupt threads

Several operating systems - Solaris, Mac OS X
Mac OS X

Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems....
, WinCE and FreeBSD
FreeBSD

FreeBSD is a Unix-like free software operating system descended from AT&T Unix via the Berkeley Software Distribution branch through the 386BSD and Berkeley Software Distribution#4.4BSD and descendants operating systems....
, for example - use different scheme known as interrupt threads: interrupt handler 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....
. This greatly simplifies locking in the kernel. Also, interrupt thread may be preempted by higher-priority interrupt thread.

SymbianOS

Because (amongst other reasons) extended processing in a ISR delays the servicing of other interrupts, Symbian OS
Symbian OS

Symbian OS is a proprietary software operating system designed for mobile devices, with associated Library , user interface, frameworks and reference implementations of common tools, developed by Symbian Ltd....
 uses Delayed Function Calls (DFCs) to perform processing that would be impossible inside the ISR .

See also

  • Advanced Programmable Interrupt Controller
    Advanced Programmable Interrupt Controller

    An Advanced Programmable Interrupt Controller is a more intricate Programmable Interrupt Controller containing a magnitude more outputs, much more complex priority schema, and Advanced IRQ management....
  • 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....
  • Interrupt
    Interrupt

    In computing, an interrupt is an asynchronous communication signal from hardware 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....
  • Non-Maskable Interrupt
    Non-Maskable interrupt

    A non-maskable interrupt is a computer Central processing unit interrupt that cannot be ignored by standard interrupt masking techniques in the system....
  • Programmable Interrupt Controller
    Programmable Interrupt Controller

    A programmable interrupt controller is a device which allows priority levels to be assigned to its interrupt outputs. When the device has multiple interrupt outputs to assert, it will assert them in the order of their relative priority....