You are on page 1of 19

Interrupts

By:
Mr. Irfanullah
C/NO: 14
MS (Computer Science)
University Of Peshawar

In This Demonstration
What Are Interrupts?
Why Interrupts?
Instruction Cycle And Interrupts
Difference b/w Interrupts and Exceptions
Classes Of Interrupts
How They Are Handled?
I/O Communication Techniques
Queries and Suggestions

What Are Interrupts?


A Suspension of a process such as the execution

of a computer program, caused by an event


external to that process, and performed in such a
way that the process can be resumed.
A way to improve processor utilization.

Need For Interrupts?


The OS is a reactive program
When you give some input
It will perform computations
Produces output BUT
Meanwhile you can interact with the system by
interrupting the running process or
You can stop and start another process.
This reactive ness is due to interrupts
Modern Operating Systems Are Interrupt driven

Instruction Cycle And Interrupts


Without Interrupts
Two steps ( cycles)

Instruction Fetch
Instruction Execute

Instruction Cycle And Interrupts


(Continued)

State Diagram

( Without Interrupts)

Instruction Cycle And Interrupts


(Continued)
With Interrupts

Three steps ( cycles)

Instruction Fetch
Instruction Execute
Check Interrupt

Instruction Cycle And Interrupts


(Continued)

State Diagram ( With

Interrupts)

Difference Interrupts and Exceptions


Two main types of events: interrupts and

exceptions
Exceptions

are caused by software executing

instructions

e.g., a page fault, or an attempted write to a read-only


page
an expected exception is a trap, unexpected is a
fault

Interrupts

are caused by hardware devices

e.g., device finishes I/O


e.g., timer fires

Classes Of Interrupts
Program
Generated by some condition that occurs as a result of an
instruction execution, such as arithmetic overflow, division
by zero, attempt to execute an illegal machine instruction
etc.
Timer
Generated by a timer within the processor. This allows the
operating system to perform certain functions on a regular
basis.
I/O
Generated by an I/O controller, to signal normal completion of
an operation or to signal a variety of error conditions.
Hardware failure

Generated by a failure, such as power failure or memory parity error.

How Interrupts Are Handled?


Different routines handle different interrupts

called Interrupt Service Routines (ISR).


When CPU is interrupted

It stops what it was doing, and context is saved.


A generic routine called Interrupt Handling Routine

(IHR) is run which

Examines the nature of interrupt


Calls the corresponding Interrupt Service Routine (ISR)
-- stored in lower part of memory.

After servicing the interrupt, the saved address is

loaded again to PC to resume the process again.

How Interrupts Are Handled?


(Continued)

How Interrupts Are Handled?


(Continued)

Interrupt

Processing

I/O COMMUNICATION
TECHNIQUES
Three techniques are possible for I/O operations
Programmed I/O
Interrupt-driven I/O
Direct memory access (DMA)

Programmed I/O
CPU while executing a program

encounters an I/O instruction


CPU issues I/O command to I/O
module
I/O module performs the
requested action & set status
registers
CPU is responsible to check
status registers periodically to
see if I/O operation is complete.
SO
No Interrupt to alert the
processor

Interrupt-Driven I/O
Similar to direct I/O but

processor not required


to poll device.
I/O module will interrupt
CPU for data exchange
when ready

Direct Memory Access (DMA)


I/O exchanges occur directly with

memory
Requires DMA module on
system bus
Capable of mimicking CPU and
taking over control of system
from CPU
DMA will use bus when

Processor does not require it OR


Must force processor to suspend
operation temporarily called cycle
stealing

An interrupt is sent when the task

is complete
The processor is only involved at
the beginning and end of the
transfer

Another Look at I/O


Synchronous (Programmed I/O) - control returns

to user program only upon I/O completion.


Idle

CPU until the next interrupt


wait loop (contention for memory access).
Asynchronous (Interrupt driven I/O) - control

returns to user program before I/O completion.


System

call request to the operating system to


allow user to wait for I/O completion.
Device-status table contains entry for each I/O
device indicating its type, address, and state.

Thanks
Queries
AND
Suggestions

You might also like