liveBook · Manning

Interrupt

As explained in Rust in Action: Systems programming concepts and techniques

A hardware interrupt is an asynchronous request from a hardware device that causes a processor to suspend or redirect its current execution to handle an event.

A hardware interrupt lets a device get the CPU’s attention when something happens, such as a key press or data arriving at a network card. It can arrive while another program is running. The CPU stops that program’s execution and jumps to an interrupt handler; the operating system usually handles the event. section 12.1 section 12.1.1

An interruption between two lines

Suppose a Rust program assigns two integers and then adds them. A keyboard interrupt could arrive just before the addition. The CPU handles the interruption, but the program still calculates the sum. What may change is how long the program takes to finish. section 12.2

Figure 12.3 How applications are notified of an interrupt generated from a hardware device. Once the OS has been notified that data is ready, it then directly communicates with the device (in this case, the keyboard) to read the data into its own memory.

Follow the notification from the device through the Programmable Interrupt Controller (PIC) to the CPU. Once notified, the operating system reads the ready data from the device into its own memory. section 12.4

Similar terms describe different layers or origins:

  • A signal is an operating-system-level notification to an application, not a hardware interrupt. An operating system can use signals when communicating with applications. section 12.1 section 12.1.1
  • An exception arises during CPU processing, such as an invalid memory access. A software interrupt is deliberately generated by a program using a CPU instruction. section 12.1.1 section 12.1

Interrupts can also let an idle CPU avoid busy-waiting. A kernel loop can issue the x86 halt instruction, `hlt`, instead of running continuously with no work to do. The CPU resumes when an interrupt calls for action. section 11.3.1

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Traces the device-to-CPU route and a control-flow example, while leaving direct kernel interrupt handling aside.
Examples
Uses a keyboard event interrupting integer addition, a device-notification diagram, and a kernel loop that halts until an interrupt.
What it assumes
Assumes only a simple Rust calculation for the control-flow example; avoids requiring direct kernel interrupt-handling work.
What you can do after
Evaluate/understand why a device event changes CPU execution without necessarily changing a program’s result.
How it connects
Distinguishes hardware interrupts from signals, software interrupts, and exceptions, and connects them to interrupt handlers and the Programmable Interrupt Controller.

Also explained in

Compare how 4 books explain interrupt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.