Interrupts: how devices get the CPU's attention
Video 031 of 140 in Virtualization Foundations, in the unit “Privilege, system calls and interrupts”. 4:21, with English and Hindi audio.
A network card receives a packet. A disk finishes a read. A key is pressed. Each event needs the processor's attention, but the processor cannot keep checking every device. The answer is the interrupt: the device signals, and the processor pauses what it was doing to handle the event. This article explains how one interrupt travels from a device to the kernel and back, why it beats constant checking, and how to read the counts that Linux keeps in /proc/interrupts.
What you will learn
- An interrupt is a device's signal that asks the processor for attention now.
- The processor saves its place, runs the kernel's handler for that device, then resumes its work.
- Linux counts every interrupt line in the interrupts file, with one count for each core.
- Too many interrupts landing on one core can crowd out other work on that core.
What happens when a device raises an interrupt
An interrupt is a signal that interrupts normal work. The device raises a line, called an IRQ, or sends a message, to say that it needs attention now. A network card, for example, raises its line when a packet has arrived.
- The processor saves its place and switches into kernel mode.
- It jumps to the handler the kernel registered for that line. The handler is the kernel's code for that device.
- The handler reads the device, takes the data or the status, and does the minimum needed at once.
- The device is acknowledged, so it stops asking. Otherwise the same signal would fire again and again.
- The processor returns to the work it had paused. Most of the time, the program never notices.
Why interrupts beat constant checking
There are two ways to learn that a device needs attention. In polling, the processor keeps asking, again and again. In an interrupt, the device calls out. Polling wastes time when nothing happens. An interrupt costs almost nothing while the device is quiet, and it is handled as soon as the signal arrives.
How to read the interrupt counts on Ubuntu 24.04
Linux keeps a count of every interrupt in a file called interrupts, under the proc folder. Each row is one interrupt line. Its counts grow whenever the line fires, and you see one count for each processor core. The last columns name the device that owns the line.
cat /proc/interruptsTo see the change live, use watch with the -d option. It highlights the counts that moved since the last refresh, so busy lines stand out.
watch -d -n 1 cat /proc/interruptsHow one busy card can flood a single core
Consider a database server whose network traffic is heavy, yet one processor core runs hot while the others sit idle. The interrupts file explains it. The network card's row grows fast, and nearly all its counts land on that one core. The team spread the card's queues, its separate lanes for packets, across several cores. Then the load came down.
- An interrupt storm: a faulty device, or a buggy driver, keeps raising its line. The processor spends its time in handlers, and little time on real work.
- A busy core: interrupts from one device land on one core, so that core cannot serve other work.
- How you notice it: high interrupt or system time in the CPU figures, and counts that climb without stopping.
Watch the interrupt counts change
You need a terminal on Ubuntu 24.04. Run the two commands, then move some network traffic or type on the keyboard to see the counts change.
Print the interrupt counts once. Read each row, and note which device owns it and which core takes most of its count.
cat /proc/interruptsWhat you should see: One row per interrupt line, with a count for each CPU core, and the device name at the end of each row.
Refresh the counts every second. Rows whose counts moved are highlighted, so busy lines stand out.
watch -d -n 1 cat /proc/interruptsWhat you should see: The screen updates each second, and the counts that changed are highlighted. Press Ctrl and C to stop it.
Terms
- Interrupt
- A signal from a device that asks the processor for attention now, so it pauses its current work.
- IRQ
- Interrupt request: a numbered line that a device uses to signal the processor.
- Handler
- The kernel's code that deals with one kind of interrupt, then returns control to the paused work.
- Polling
- Checking a device again and again to see whether it needs attention, instead of waiting for it to signal.
Check yourself
What does the processor do when an interrupt arrives?
It saves its place, switches into kernel mode, runs the handler for that device, and then returns to the paused work.
Why does the interrupts file show one count for each core?
Each row shows how many times that line fired on every core, so you can see which core takes the interrupts.
Why can one busy device hurt the whole server?
If its interrupts all land on one core, that core spends its time in handlers and cannot serve other work.
Previous: Watching system calls with strace. Next: Exceptions and faults.