Hardware Demands Attention
Imagine you are deep in thought, writing code. Suddenly, the doorbell rings. You have to stop typing, get up, answer the door to sign for a package, and then try to remember where you left off. Your train of thought is broken, your work is paused, and you pay a cost just from the interruption itself — even if the package delivery only takes five seconds.
This is exactly what an Interrupt is in computing.
Hardware devices — Network Interface Cards (NICs), keyboards, disk controllers, timers — are asynchronous. They do not wait politely for the CPU to ask "Do you have data for me?" Instead, they signal immediately when something happens: a key is pressed, a network packet arrives, a disk read completes. The mechanism they use is an electrical signal sent to a chip called the Interrupt Controller (historically the Intel 8259 PIC, now the APIC — Advanced Programmable Interrupt Controller). The Interrupt Controller receives this signal and forwards it to the CPU as an IRQ (Interrupt ReQuest).
When the CPU receives an IRQ, it:
1. Finishes the current machine instruction (not the whole task — just the single instruction).
2. Saves its current state (registers, instruction pointer) onto the kernel stack — this is the "bookmark."
3. Looks up the Interrupt Descriptor Table (IDT), a kernel data structure that maps each IRQ number to a function pointer.
4. Jumps to that function — the Interrupt Service Routine (ISR), also called an Interrupt Handler.
5. Executes the handler, then restores the saved state and resumes where it left off.
The Cost: Every interrupt forces the CPU to save and restore state — a mini context switch. A single interrupt costs hundreds of nanoseconds. A 10 Gbps network card receiving small packets can generate over one million interrupts per second. If each interrupt costs 500 ns of overhead, that is 500 ms of CPU time per second — half a core doing nothing but answering the doorbell. This is why interrupt handling efficiency is a first-class concern in high-performance systems.
Interviewers at high-frequency trading firms and cloud infrastructure companies often ask: "What happens when a network card generates more interrupts than the CPU can handle?" The answer is interrupt storm — the CPU spends 100% of its time in interrupt context, user processes starve, and the system becomes unresponsive. The follow-up is always: "How do you fix it?" — which leads to IRQ coalescing, NAPI polling, and IRQ affinity pinning, all covered in this lesson.