Show understanding of the purpose of interrupts
4.1 Central Processing Unit (CPU) Architecture
Interrupts: What and Why?
Interrupts are like surprise visitors that tell the CPU, “Hey, something important just happened!” Instead of the CPU constantly checking (polling) every device, it can keep working on its current task and jump to the visitor when needed. This saves time and makes the computer feel faster.
Exam Tip: Remember that interrupts are asynchronous events that can pre‑empt the CPU’s current task.
Types of Interrupts
- Hardware interrupts – e.g., keyboard, mouse, network card
- Software interrupts – e.g., system calls, exceptions
- External vs internal – external from devices, internal from the CPU itself
How Interrupts Work
- Event occurs → interrupt signal sent to the CPU.
- CPU pauses the current task and saves its state.
- CPU jumps to the interrupt handler (ISR).
- Handler processes the event.
- CPU restores the saved state and resumes the previous task.
⚡ Analogy: Imagine the CPU is a student studying. A teacher (interrupt) pops in to ask a question. The student stops studying, answers, then returns to their work.
Interrupt Priority and Masking
| Priority Level | Example |
|---|---|
| High | Keyboard input |
| Low | Timer tick |
📝 Exam Tip: Explain why interrupts are preferred over polling and how priority prevents starvation.
Interrupts in Real Systems
Modern CPUs use Interrupt Request (IRQ) lines and Interrupt Service Routines (ISR) to handle events. For example, when you press a key, the keyboard controller sends an IRQ to the CPU, which then runs the ISR to read the key code.
💡 Analogy: The keyboard controller is like a messenger delivering a note (key press) to the teacher (CPU).
Key Takeaways
- Interrupts enable efficient CPU use by avoiding constant polling.
- They are asynchronous and can be prioritized.
- Handling involves saving state, executing the ISR, and restoring state.
🚀 Exam Tip: Draw a flow diagram of interrupt handling and label each step.
Mathematically, the total time spent handling an interrupt can be expressed as:
$$T_{\text{total}} = T_{\text{handler}} + T_{\text{resume}}$$
Revision
Log in to practice.