7.4 Interrupt- Driven I/O

COS2621 - Computer Organisation · 7. Input/Output

7.4 Interrupt-Driven I/O

Understanding Interrupts

An interrupt is a signal sent to the CPU to indicate that an event needs immediate attention. This event could be the completion of an I/O operation or an error condition. When an interrupt occurs, the CPU pauses its current activities, saves its state, and executes a special routine called an interrupt handler or interrupt service routine (ISR).

Types of Interrupts

There are two main types of interrupts:

  • Hardware Interrupts: Generated by hardware devices (like keyboards or disk drives) when they require CPU attention. For example, a hardware interrupt may be generated by a failure such as a power failure or a memory parity error.
  • Software Interrupts: Generated by programs when they need to request services from the operating system. An example is an interrupt generated by a condition that occurs as a result of an instruction execution.

How Interrupt-Driven I/O Works

In interrupt-driven I/O, the CPU does not need to wait for an I/O operation to complete. Instead, it can perform other tasks. Here is how the process works:

  1. The CPU sends a command to an I/O device.
  2. While the I/O device processes the command, the CPU continues executing other instructions.
  3. Once the I/O operation is complete, the device sends an interrupt signal to the CPU.
  4. The CPU stops its current task, saves its state, and executes the ISR for that interrupt.
  5. After handling the interrupt, the CPU resumes its previous task.

Example of Interrupt-Driven I/O

Consider a scenario where a CPU is reading data from a disk drive:

  1. The CPU issues a command to read data from the disk.
  2. While waiting for the disk to read the data, the CPU executes other instructions.
  3. Once the disk finishes reading the data, it sends an interrupt to the CPU.
  4. The CPU interrupts its current task, saves its state, and jumps to the ISR.
  5. The ISR processes the data read from the disk.
  6. After processing, the CPU restores its previous state and continues with its tasks.

Advantages and Disadvantages of Interrupt-Driven I/O

Interrupt-driven I/O has several advantages:

  • Efficiency: The CPU can perform other tasks while waiting for I/O operations to complete.
  • Responsiveness: The system can respond quickly to events that require immediate attention.

Watch out: A common mistake is to assume that the CPU is idle while waiting for I/O operations. In interrupt-driven I/O, the CPU is busy executing other instructions.

Despite its advantages, interrupt-driven I/O can have drawbacks:

  • Overhead: Handling interrupts incurs overhead, which can slow down the system if interrupts occur too frequently.
  • Complexity: Designing systems to handle interrupts can be more complex compared to polling methods.

Summary

Interrupt-driven I/O allows a CPU to efficiently manage I/O operations without waiting. It uses interrupts from hardware devices to signal the CPU when an operation is complete, enabling the CPU to perform other tasks in the meantime. This method improves system responsiveness but introduces complexity and overhead.

Check your understanding

  • What is the main purpose of an interrupt in a computer system?
  • Describe the difference between hardware and software interrupts.
  • What are the advantages and disadvantages of using interrupt-driven I/O?
  • Explain the basic steps involved in the interrupt-driven I/O process.

Test yourself

4 quick questions on this lesson. Pick an answer to see if you're right.

  1. 1. Which of the following is a characteristic of hardware interrupts?

  2. 2. What is the main purpose of an interrupt in a computer system?

  3. 3. In the interrupt-driven I/O process, what happens after the CPU receives an interrupt signal?

  4. 4. What is one disadvantage of using interrupt-driven I/O?