← Interview Prep

Linux Kernel — Interrupts & Exceptions

Servicing hardware and CPU events: the IDT & vectors (APIC/MSI-X/IPIs), interrupt vs fault vs trap vs abort, top-half/bottom-half split (softirq/tasklet/workqueue — which can sleep), NAPI, the can't-sleep rule, spin_lock_irqsave, and IRQ affinity.

How the CPU stops what it's doing to service hardware and CPU-detected events — and how Linux keeps interrupt handlers fast so the system stays responsive. Original, interview-focused notes.

Two families: an interrupt is asynchronous, raised by a device (a NIC has a packet); an exception is synchronous, raised by the CPU while executing an instruction (page fault, divide-by-zero, a syscall/trap). Both vector through the IDT to a handler that runs in a special context where you cannot sleep.

The dispatch: IDT & vectors

Exceptions vs interrupts vs traps

TypeSourceExample
Interrupt (IRQ)External device, asyncNIC RX, disk done, timer
FaultCPU, correctable, re-runs the instructionPage fault (map the page, retry)
TrapCPU, intentionalsyscall, breakpoint
AbortCPU, unrecoverableMachine-check

Top half & bottom half

An interrupt handler must be fast — while it runs, that interrupt (often more) is masked and no process runs on the CPU. So Linux splits the work:

MechanismRuns inNote
softirqInterrupt context (softirq)Fixed set, high-perf (e.g. NET_RX); can run concurrently on CPUs. Can't sleep.
taskletBuilt on softirqSimple deferral, serialized per tasklet.
workqueueKernel thread (process context)Can sleep — use when the deferred work may block.

NAPI is the classic example: under load the NIC switches from per-packet interrupts to polling in softirq, avoiding an interrupt storm. ksoftirqd drains softirqs when they overwhelm a CPU.

The "can't sleep" rule & concurrency

Likely interview questions

Kernel Internals series. Related: Synchronization · Memory Addressing.