An interrupt is a signal to the processor that an event needs immediate attention, causing the CPU to suspend the instruction stream it is executing, save its state and run a dedicated interrupt handler in the kernel. Among OS fundamentals, the interrupt is the mechanism that lets operating systems respond to devices, timers and errors without constantly polling for them, and a hardware interrupt from a network card, disk controller or keyboard is its most familiar form.
Interrupts make multitasking and responsive input possible. The periodic timer interrupt gives the kernel regular control so the process scheduler can switch tasks, while device interrupts tell drivers that data has arrived or an operation has finished.
How an interrupt transfers control to the kernel
An interrupt works by forcing a controlled jump from whatever code is running to a handler chosen by the event’s number. The processor finishes or abandons the current instruction, saves the program counter and flags, switches to kernel mode if needed and looks up the handler address in a table the kernel prepared at boot.
On x86 systems this lookup table is the Interrupt Descriptor Table (IDT); on ARM processors it is the exception vector table. Each entry maps an interrupt vector to code in kernel space, which is why user programs can never install handlers directly.
The steps below show the usual path of a hardware interrupt on a modern system.
| Stage | What happens | Who performs it |
|---|---|---|
| Signal | Device raises an interrupt line or sends a message | Device hardware |
| Routing | Controller selects a CPU and a vector | Interrupt controller such as the APIC or GIC |
| State save | Program counter, flags and registers are stored | CPU and kernel entry code |
| Handler | Driver code acknowledges the device and queues work | Interrupt service routine |
| Return | Saved state is restored and execution resumes | Kernel exit path |
Handlers must run quickly because other interrupts may be masked while they execute. Operating systems therefore split the work into a short top half that acknowledges the device and a deferred bottom half that processes the data later, using softirqs and tasklets in Linux or deferred procedure calls in Windows.
Types of interrupts and exceptions
Interrupts are classified by where they come from and whether they are synchronous with the running instruction. Hardware interrupts arrive asynchronously from outside the CPU, while exceptions are raised by the instruction itself, and software interrupts are requested deliberately by code.
| Category | Source | Timing | Typical example |
|---|---|---|---|
| Hardware interrupt | External device or timer | Asynchronous | Network packet received |
| Exception (fault) | Current instruction | Synchronous | Page fault or division by zero |
| Software interrupt | Explicit instruction in code | Synchronous | Legacy system call entry |
| Inter-processor interrupt | Another CPU core | Asynchronous | Request to flush a TLB |
| Non-maskable interrupt | Critical hardware condition | Asynchronous | Memory parity error or watchdog |
Most interrupts are maskable, meaning the kernel can briefly disable them to protect a critical section. A non-maskable interrupt (NMI) cannot be blocked this way and is reserved for serious conditions, debugging and watchdog timers that detect a hung system.
Delivery methods have also evolved. Older PCs used dedicated IRQ lines through a programmable interrupt controller, often shared among devices. PCI Express devices now use Message Signaled Interrupts (MSI and MSI-X), which write a small message to a memory address and allow many separate vectors per device.
Interrupts compared with polling and system calls
The main alternative to interrupts is polling, in which software repeatedly checks a device register to see whether work is ready. Polling wastes CPU time when events are rare, but it can beat interrupts when events are extremely frequent, because each interrupt carries a fixed entry and exit cost.
| Mechanism | Initiated by | Best suited to | Main cost |
|---|---|---|---|
| Interrupt | Hardware or exception | Infrequent or unpredictable events | Overhead per event |
| Polling | Software loop | Very high event rates | CPU cycles spent waiting |
| System call | User program | Requesting kernel services | Mode switch per request |
| Hybrid (NAPI style) | Interrupt, then polling | Bursty network traffic | More complex driver logic |
A system call also enters the kernel, and historically it used a software interrupt instruction such as int 0x80 on Linux. Modern processors provide faster dedicated instructions like syscall, so system calls are now a separate path, although both share the idea of a controlled transition into kernel space.
An interrupt does not always cause a context switch. The handler runs on behalf of the system, and only if it wakes a higher-priority thread, or the timer signals the end of a time slice, does the scheduler choose a different process on return.
Interrupt latency and tuning
Interrupt latency is the time between a device raising an interrupt and the first instruction of its handler. On desktop systems it typically ranges from a few microseconds to tens of microseconds, depending on processor speed, masking periods and power-saving states; a real-time operating system is designed to keep the worst case bounded and predictable.
Administrators and driver developers use several techniques to balance throughput against latency. The table below lists the common ones.
| Technique | Effect | Trade-off |
|---|---|---|
| Interrupt coalescing | Device batches events into fewer interrupts | Higher latency per event |
| IRQ affinity | Pins interrupts to chosen CPU cores | Uneven load if set poorly |
| Threaded interrupts | Runs handlers as schedulable kernel threads | Slight extra overhead |
| Deep idle states | Saves power between interrupts | Longer wake-up latency |
High-speed network adapters often generate hundreds of thousands of interrupts per second without coalescing, enough to consume a whole core. Spreading them across cores with receive-side scaling and limiting their rate keeps the system responsive under load.
Failure modes and common misconceptions
Interrupt problems are hard to diagnose because they occur outside normal program flow. A buggy handler that sleeps, loops or takes a lock in the wrong order can freeze a core or trigger a kernel panic, which is why kernel rules forbid blocking operations in interrupt context.
- Interrupt storms: a device keeps asserting its line, so the CPU spends nearly all its time in handlers.
- Spurious interrupts: signals with no real cause, often from electrical noise or misconfigured controllers.
- Missed interrupts: an edge-triggered signal arrives while masked and is lost, leaving a driver waiting.
- Misconception: interrupts are always faster than polling; at very high event rates polling can win.
- Misconception: every interrupt switches processes; most return to the interrupted code unchanged.
Tools such as /proc/interrupts on Linux or performance counters on Windows show per-device interrupt counts, which quickly reveal a storm or an unbalanced distribution across cores.
In plain words
Imagine a chef cooking several dishes. Instead of walking to the front door every minute to check for deliveries, the chef relies on a doorbell. When it rings, the chef notes where they stopped, answers the door, and then returns to the exact same step.
An interrupt is that doorbell for a computer. Keyboards, network cards and timers ring it when they need attention, and the processor briefly pauses its work to handle them. This is why a computer can react to a key press instantly while still running many programs.
A real-world example
An operations engineer notices that a web server with a 25 Gb/s network card is slow under heavy traffic, although average CPU use looks moderate. Checking /proc/interrupts shows that all network interrupts land on core 0, which sits at 100 percent while the other fifteen cores are mostly idle.
The engineer enables receive-side scaling to spread the queues across eight cores, sets IRQ affinity accordingly and raises the card’s interrupt coalescing interval to about 50 microseconds. Interrupts per second fall by roughly two-thirds, core 0 is no longer saturated, and the server handles noticeably more requests with lower tail latency.