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

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.

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.

Print the interrupt counts for every line and core
cat /proc/interrupts

To 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.

Refresh the interrupt counts every second and highlight changes
watch -d -n 1 cat /proc/interrupts

How 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.

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.

  1. Print the interrupt counts once. Read each row, and note which device owns it and which core takes most of its count.

    cat /proc/interrupts

    What 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.

  2. Refresh the counts every second. Rows whose counts moved are highlighted, so busy lines stand out.

    watch -d -n 1 cat /proc/interrupts

    What 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.