0% found this document useful (0 votes)
58 views7 pages

Understanding Interrupts in Operating Systems

An interrupt is a signal emitted by a device or program that requires the operating system to stop current processes and determine the next steps. Interrupts temporarily halt processes to allow the operating system to service requests from devices or programs. There are two types of interrupts - hardware interrupts caused by external devices and software interrupts triggered by programs requesting operating system services. When an interrupt occurs, the associated interrupt service routine executes to handle the request, saving state and scheduling subsequent processes.

Uploaded by

vagigip197
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views7 pages

Understanding Interrupts in Operating Systems

An interrupt is a signal emitted by a device or program that requires the operating system to stop current processes and determine the next steps. Interrupts temporarily halt processes to allow the operating system to service requests from devices or programs. There are two types of interrupts - hardware interrupts caused by external devices and software interrupts triggered by programs requesting operating system services. When an interrupt occurs, the associated interrupt service routine executes to handle the request, saving state and scheduling subsequent processes.

Uploaded by

vagigip197
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is an interrupt?

An interrupt is a signal emitted by a device attached to a computer or from


a program within the computer. It requires the operating system (OS) to stop and
figure out what to do next. An interrupt temporarily stops or terminates a service
or a current process. Most I/O devices have a bus control line called Interrupt
Service Routine (ISR) for this purpose.

An interrupt signal might be planned (i.e., specifically requested by a program) or


it may be unplanned (i.e., caused by an event that may not be related to a
program that's currently running on the system).

Today, almost all computing systems are interrupt-driven. What this means is
that they follow the list of computer instructions in a program and run the
instructions until they get to the end or until they sense an interrupt signal. If the
latter event happens, the computer either resumes running the current program
or begins running another program. In either case, it must stop operations while
deciding on the next action. To do this and to work on other programs, the OS
uses pauses in operations.

When the device processor handles interrupts, it informs the device sending the
signal that the interrupt request (IRQ) has been recognized. Then the device
stops sending the IRQ signal.

An OS usually includes code called an interrupt handler to prioritize interrupts


and save them in a queue if more than one is waiting to be handled. It also has a
scheduler program that determines the next program that gets control.

When an interrupt occurs, the associated service may not start immediately. The
time interval between the time the interrupt occurs and the time when ISR
execution starts is called interrupt latency.
Types of interrupts
Interrupts are classified into two types:

I. Hardware interrupt
A hardware interrupt is an electronic signal from an external hardware device that
indicates it needs attention from the OS. One example of this is moving a mouse or
pressing a keyboard key. In these examples of interrupts, the processor must stop to read
the mouse position or keystroke at that instant.

In this type of interrupt, all devices are connected to the Interrupt Request Line (IRL).
Typically, a hardware IRQ has a value that associates it with a particular device. This
makes it possible for the processor to determine which device is requesting service by
raising the IRQ, and then provide service accordingly.

There are three types of hardware interrupts:

Maskable interrupts

In a processor, an internal interrupt mask register selectively enables and disables


hardware requests. When the mask bit is set, the interrupt is enabled. When it is clear, the
interrupt is disabled. Signals that are affected by the mask are maskable interrupts.

Non-maskable interrupts

In some cases, the interrupt mask cannot be disabled so it does not affect some interrupt
signals. These are non-maskable interrupts and are usually high-priority events that
cannot be ignored.

Spurious interrupts

Also known as a phantom interrupt or ghost interrupt, a spurious interrupt is a type of


hardware interrupt for which no source can be found. These interrupts are difficult to
identify if a system misbehaves. If the ISR does not account for the possibility of such
interrupts, it may result in a system deadlock.

II. Software interrupts


A software interrupt occurs when an application program terminates or requests certain
services from the OS. Usually, the processor requests a software interrupt when certain
conditions are met by executing a special instruction. This instruction invokes the
interrupt and functions like a subroutine call. Software interrupts are commonly used
when the system interacts with device drivers or when a program requests OS services.

In some cases, software interrupts may be triggered unexpectedly by program execution


errors rather than by design. These interrupts are known as exceptions or traps.

Difference between Hardware Interrupt and


Software Interrupt
1. Hardware Interrupt : Hardware Interrupt is caused by some hardware
device such as request to start an I/O, a hardware failure or something similar.
Hardware interrupts were introduced as a way to avoid wasting the processor’s
valuable time in polling loops, waiting for external events.
For example, when an I/O operation is completed such as reading some data
into the computer from a tape drive.
 An interrupt generated by a mouse when a button is clicked
 An interrupt generated by a network card when data is received
 An interrupt generated by a disk drive when a read or write operation is
completed
2. Software Interrupt : Software Interrupt is invoked by the use of INT
instruction. This event immediately stops execution of the program and passes
execution over to the INT handler. The INT handler is usually a part of the
operating system and determines the action to be taken. It occurs when an
application program terminates or requests certain services from the operating
system.
For example, output to the screen, execute file etc.
 A system call to read or write data to a file
 A division by zero exception
 A page fault exception
Difference between Hardware Interrupt and Software Interrupt :
[Link]. Hardware Interrupt Software Interrupt

Hardware interrupt is an interrupt Software interrupt is the interrupt that is


1 generated from an external device generated by any internal system of the
or hardware. computer.

It do not increment the program


2 It increment the program counter.
counter.

Hardware interrupt can be invoked


with some external device such as Software interrupt can be invoked with
3
request to start an I/O or the help of INT instruction.
occurrence of a hardware failure.

It has lowest priority than software It has highest priority among all
4
interrupts interrupts.

Hardware interrupt is triggered by Software interrupt is triggered by


external hardware and is software and considered one of the ways
5 considered one of the ways to to communicate with kernel or to trigger
communicate with the outside system calls, especially during error or
peripherals, hardware. exception handling.

6 It is an asynchronous event. It is synchronous event.

Hardware interrupts can be


Software interrupts can be classified into
classified into two types they are:
7 two types they are: 1. Normal Interrupts.
1. Maskable Interrupt. 2. Non
2. Exception
Maskable Interrupt.

Keystroke depressions and mouse


All system calls are examples of
8 movements are examples of
software interrupts
hardware interrupt.
Interrupts vs. polling
Polling is a state of continuous monitoring where a microcontroller in a computing
system continuously checks the status of all devices. The first device encountered with
the IRQ bit is serviced first and the appropriate ISR is called to service that device. The
system is easy to implement and ensures that the component that needs service gets it.

However, because the microcontroller uses all its processing time for polling, it cannot
carry out simultaneous operation. Also, a lot of time is wasted by interrogating the IRQ
bit of all devices. Interrupts provide a solution to this problem. With interrupts,
the controller does not need to regularly monitor the status of devices. Instead, it responds
only when an interrupt occurs. So, when there is an interrupt, the controller is notified
that it needs service.

What is an ISR?
An ISR is present for every interrupt. The address of each ISR is stored in a fixed
location in memory. An ISR can call for asynchronous interrupts and handle both
maskable and non-maskable interrupts.

When an interrupt occurs, the microcontroller runs the ISR. At the start of execution, the
ISR disables the interrupt services of all other devices, stopping the instruction that's
currently processing and saving its configuration in a register. Then it will load the
interrupt's program counter from a location given by the interrupt vector table. Once ISR
execution is complete, it will reinitialize all interrupt services.

The two main types of interrupt handlers:

 First-level interrupt handler (FLIH). A hard or fast interrupt handler that handles
maskable interrupts and has jitter during process execution

 Second-level interrupt handler (SLIH). A slow and soft interrupt handler with less
jitter than FLIH
Interrupt vector

Table of pointers in memory contains the addresses of interrupt service routines


at a fixed location for a given CPU.

Interrupt processing
Step 1 − First device issues interrupt to CPU.
Step 2 − Then, the CPU finishes execution of current instruction.
Step 3 − CPU tests for pending interrupt request. If there is one, it sends an
acknowledgment to the device which removes its interrupt signal.
Step 4 − CPU saves program status word onto control stack.
Step 5 − CPU loads the location of the interrupt handler into the PC register.
Step 6 − Save the contents of all registers from the control stack into memory.
Step 7 − Find out the cause of interrupt, or interrupt type or invokes
appropriate routine.
Step 8 − Restore saved registers from the stack.
Step 9 − Restore PC to dispatch the original process.

Common questions

Powered by AI

Interrupts improve the CPU's efficiency by allowing the processor to stop its current activities and prioritize the handling of input/output requests or other events. Unlike polling, where the CPU continuously checks the status of a device and potentially wastes processing time if the device does not need service, interrupts notify the CPU only when a device requires attention. This means the CPU can perform other tasks until an interrupt signal is received, thus optimizing resource utilization and reducing unnecessary load .

Polling involves the CPU continuously checking the status of an I/O device to see if it requires attention, which ensures each device is serviced in sequence. This approach is simple and predictable in behavior but can be inefficient as it uses valuable CPU time, which may be wasted when devices do not need servicing. In contrast, interrupt-driven approaches notify the CPU only when a device needs service, freeing the CPU to perform other tasks concurrently, leading to more efficient CPU utilization. However, managing interrupts can be complex, requiring more sophisticated hardware and software to prioritize and queue interrupt requests effectively. Thus, while interrupts can offer efficiency and responsiveness, they also necessitate more complex system architectures .

An interrupt vector table is a data structure that holds the addresses of interrupt service routines (ISRs) located at specific memory locations. When an interrupt occurs, the CPU uses this table to quickly find the corresponding ISR and load its address into the program counter, thus ensuring that the correct routine is executed. This mechanism helps streamline the handling process by organizing ISRs efficiently, allowing for prompt and organized responses to multiple interrupts, thereby reducing processing delays and enhancing system performance .

An Interrupt Service Routine (ISR) is a special block of code associated with an interrupt signal. When an interrupt occurs, the microcontroller calls the ISR which begins execution by saving the current state of the process, such as registers, onto a control stack. The ISR then executes its designated function which might involve reading or writing data related to the interrupt. Once the ISR completes, it restores the saved state from the control stack and allows the interrupted process to resume. This structure allows the system to manage multiple interrupts effectively by responding only when needed and ensuring no data is lost during the transition .

The ISR manages both maskable and non-maskable interrupts by executing specific routines assigned to each type. For maskable interrupts, the ISR can selectively enable or disable them using an interrupt mask register, allowing the processor to focus on higher-priority tasks if needed. For non-maskable interrupts, the ISR ensures that these are addressed immediately, given their high-priority nature, as they cannot be turned off. The address of each ISR is stored in a vector table, permitting quick access when required. This structured handling allows the system to efficiently prioritize and manage multiple interrupt signals, ensuring the highest levels of responsiveness and stability .

Non-maskable interrupts are considered high-priority because they cannot be disabled by the interrupt mask, ensuring that critical issues are addressed promptly. These interrupts are often used for serious system alerts such as hardware malfunctions that require immediate attention. If neglected, non-maskable interrupts could lead to severe system issues, potential data loss, or even complete system failure, as they often indicate critical conditions that need immediate resolution .

Hardware interrupts are generated by external devices and hardware, such as mouse clicks or keyboard strokes, and are often asynchronous. These interrupts are used to signal the CPU that a device needs processing attention. Software interrupts, on the other hand, are generated within the CPU by executing a specific instruction, such as an INT instruction, and are synchronous. They are used to handle system calls or exceptions within the operating system. Additionally, hardware interrupts do not increment the program counter and are generally lower in priority compared to software interrupts, which may increment it and are crucial for handling critical tasks or errors like page faults .

Interrupt handling begins when a device generates an interrupt signal to the CPU. The CPU completes its current instruction before checking for any pending interrupt requests. If an interrupt is detected, the CPU acknowledges it, which causes the device to cease sending the interrupt signal. The CPU then saves the current process's state onto a control stack, including program status word and registers. It then loads the ISR corresponding to the interrupt into the program counter from the interrupt vector table. After executing the ISR, which includes any required data processing, the CPU restores the previously saved state from the stack and resumes the original process by updating the program counter. This ensures that processing continues seamlessly after the interrupt has been handled .

Interrupt latency refers to the time interval between the occurrence of an interrupt and the start of the interrupt service routine's execution. It's a critical measure of performance in interrupt-driven systems since shorter latency allows the CPU to respond quickly to devices that require immediate attention, thus minimizing response delays and potential system inefficiencies. High interrupt latency can lead to missed signals or delayed data processing, which can degrade system performance and user experience. Therefore, efficient management of interrupt latency is vital to maintaining optimal system operations and ensuring timely processing .

Spurious interrupts, also known as phantom or ghost interrupts, occur without a known source, often due to hardware or signal noise. These interrupts can challenge system design and operations because they require the system to allocate resources to handle unplanned interrupts, which can disrupt normal operations or lead to deadlocks if not handled properly by the ISR. Spurious interrupts complicate both detection and correction processes. Effective system design must anticipate and mitigate these occurrences by incorporating robust error handling and diagnostic features to identify and resolve these events promptly .

You might also like