4.2 Interrupt Handling, Priority Arbitration & Daisy Chaining
💡 Core Intuition:
🍳 The Everyday Analogy:
Imagine you are baking a cake while cooking dinner:
- The Polling (Programmed I/O) Approach: Every 10 seconds, you stop chopping vegetables, walk over to the oven, open the door, and check if the cake is golden brown. Because the cake takes 45 minutes to bake, you inspect the oven 270 times. During 269 of those checks, the cake is not ready. You waste nearly all your productive culinary energy simply checking status.
- The Interrupt-Driven Approach: You put the cake in the oven and set a loud electronic timer. Now, you chop vegetables, simmer sauce, and prepare salad with 100% of your attention. When the timer chimes, the auditory alarm interrupts your train of thought at a natural stopping point (after finishing your current knife cut). You save your place on the cutting board, walk to the oven, retrieve the cake, and immediately resume dinner preparation right where you left off.
- The Daisy Chaining Analogy: If three guests at a conference table all raise their hands to speak into a single roving microphone, the moderator passes the microphone to Guest 1. If Guest 1 wants to speak, they grip the microphone and talk; guests further down the table must wait. If Guest 1 does not wish to speak, they hand the microphone downstream to Guest 2, who in turn can speak or pass it to Guest 3. The physical placement along the cable establishes strict, hardwired priority.
💻 Bridging to Computer Science:
In digital computer systems:
- Programmed I/O (Polling) forces the central processor to execute a tight loop reading an I/O device's status register (
STATUS_BUSY). Because human keystrokes or mechanical disk seeks are orders of magnitude slower than gigahertz CPU clocks, polling wastes millions of clock cycles doing zero useful compute. - Interrupt-Driven I/O frees the processor from waiting. The CPU commands an I/O peripheral to initiate a task and immediately switches to other computing work. When the peripheral finishes or requires attention, its hardware interface asserts an electrical voltage on the processor's Interrupt Request () pin.
- The processor finishes executing its current instruction, pushes its return address (Program Counter) and status flags (Program Status Word) onto the stack, acknowledges the interrupt via the Interrupt Acknowledge () signal, fetches the starting address of the corresponding Interrupt Service Routine (ISR) from an Interrupt Vector Table (IVT), and executes the handler.
- When multiple peripherals assert simultaneously, hardware arbiters—such as Daisy Chaining (serial priority grant) or Parallel Priority Encoders—resolve contention deterministically.
📑Table of Contents
- Programmed I/O vs. Interrupt-Driven I/O
- The Hardware Interrupt Lifecycle & State Transitions
- Vectored vs. Non-Vectored Interrupts
- Hardware Priority Arbitration: Daisy Chaining (Serial Priority)
- Parallel Priority Arbiters & Priority Encoders
- 🏭 Real-World Production Context: Linux Kernel & Modern PCIe MSI-X
- 📐 Numerical Applications & Worked Examples
- 🎯 Exam & Interview Pitfall Check
Programmed I/O vs. Interrupt-Driven I/O
The transfer of data between the central processor and external peripherals fundamentally dictates system throughput. Early computer architectures relied entirely on software-driven synchronization.
Programmed I/O vs. Interrupt-Driven I/O Architectural Comparison
The fundamental trade-off between processor-bound polling and asynchronous event-driven hardware signaling
Polling / Busy-Waiting
- •CPU repeatedly executes instructions to read device Status Register until Ready bit is asserted.
- •CPU is 100% monopolized in a tight spin-lock loop during slow peripheral operations.
- •Extremely high CPU overhead; throughput collapses when multiple slow devices are attached.
- •Deterministic latency: response time is tightly bounded by loop iteration time.
Asynchronous Hardware Signaling
- •CPU issues start command and immediately context-switches to execute user processes.
- •Peripheral asserts physical INTR pin when its data buffer is filled or ready.
- •CPU overhead is strictly limited to the ISR execution time and context save/restore.
- •Enables true concurrency between CPU instruction execution and I/O peripheral operations.
The Cost of Polling: A Mathematical Breakdown
Consider a high-speed optical scanner that transfers data at () to a processor running at (). The device transfers data one byte at a time.
- Between successive bytes, the time elapsed is:
- In , a CPU can execute:
- Under Programmed I/O: The processor executes a 4-instruction status polling loop ( per iteration) times while waiting for each byte. Over of CPU execution capacity is completely destroyed by spin-locking.
- Under Interrupt-Driven I/O: The CPU spends 10,000 clock cycles running productive user application threads. When the byte arrives, an interrupt triggers an ISR that takes only to read the byte and update pointers, consuming less than of processor bandwidth.
The Hardware Interrupt Lifecycle & State Transitions
An interrupt is an asynchronous signal generated by external hardware to halt the normal execution flow of the processor. To guarantee architectural correctness, the CPU hardware must handle interrupts through a deterministic multi-stage protocol.
The Sacred Rule of Instruction Boundaries
[!IMPORTANT] Interrupts are NEVER serviced in the middle of standard instruction execution.
An instruction is atomic in nature. The processor evaluates its hardware interrupt lines only at the completion of the current instruction execution phase (at the instruction boundary), immediately before fetching the next instruction. Servicing an interrupt mid-instruction would leave internal ALU flags, register write-backs, and pipeline stages in an undefined, corrupted state.
The 4-Phase Hardware Interrupt Dispatch Sequence
Micro-architectural execution from physical assertion through context switch and ISR return
Boundary Check
CPU finishes executing current instruction and samples internal Interrupt Request Register (IRR).
Context Push
CPU decrements SP and pushes Program Counter (PC) and Program Status Word (PSW) onto the stack.
Vector Retrieval
CPU asserts active-low INTA pulse on bus; peripheral responds by driving Vector Address (V) onto data bus.
Branch & ISR
CPU loads PC from Vector Table and begins fetching instructions from the registered ISR handler.
Step-by-Step Micro-Operation Breakdown
When the CPU acknowledges an interrupt, it suspends the current program sequence through the following hardware micro-operations:
- Instruction Completion: The processor finishes the execution phase () and write-back phase () of the current instruction . The Program Counter () holds the address of the next unexecuted instruction, .
- Hardware State Preservation:
- Memory stack push:
- Status flags push:
- Interrupt Acknowledgment (): The CPU generates one or two pulses on the control bus. This informs all attached interfaces that their interrupt request is being accepted.
- Vector Address Fetch: The interrupting interface decodes the pulse and places an 8-bit or 16-bit Vector Address or Vector Index onto the system data bus.
- PC Redirection: The CPU reads the vector and sets:
- Execution of ISR: The CPU executes the software instructions inside the ISR. If the ISR requires additional registers (e.g., ), the software routine pushes them onto the stack at entry and pops them before exit.
- Return from Interrupt (
IRET/RETI): The final instruction of the ISR is an atomicIRET. The CPU executes: The interrupted process resumes execution at instruction with zero knowledge that an interruption ever took place.
Vectored vs. Non-Vectored Interrupts
A fundamental design decision in processor architecture is how the CPU discovers the memory location of the appropriate ISR.
Vectored vs Non-Vectored Interrupt Architectures
Comparing hardwired single-handler architectures with dynamic vector address bus protocols
Vectored Interrupts
Dynamic Hardware Addressing- The interrupting peripheral supplies the vector address or interrupt vector number directly to the CPU over the data bus during the INTA cycle.
- The CPU uses this vector as an offset into a dedicated memory table (Interrupt Vector Table / IDT).
- Direct branch: Zero CPU software polling is required to determine which device requested service.
- Highly scalable; supports hundreds of independent device drivers with minimal dispatch latency.
Non-Vectored Interrupts
Fixed Hardware Branch- The CPU always branches to a single, predetermined, hardwired memory address (e.g., 0x0008 or 0x0018) regardless of which device triggered the interrupt.
- The code located at that fixed address is a generic dispatcher routine.
- The dispatcher must sequentially read the status registers of all connected peripherals (Software Polling) to discover who fired the interrupt.
- Low hardware complexity, but introduces significant software latency for low-priority peripherals.
Interrupt Vector Table (IVT) Mechanics
In a vectored system, a reserved block of low physical memory (or an address referenced by a dedicated Interrupt Vector Base Register (VBR / IDTR)) contains pointers to each routine:
If the Interrupt Vector Table starts at base address , each vector table entry is wide, and the interrupting device supplies vector number :
For example, in x86 real-mode architecture:
- Each entry is ()
- For Interrupt Vector (System Timer):
The CPU loads the 4 bytes at physical address
0x00020intoCS:IP.
Hardware Priority Arbitration: Daisy Chaining (Serial Priority)
When multiple peripherals share a single processor interrupt line, a conflict arises if two or more devices request service simultaneously. The system requires an arbitration mechanism to decide which peripheral gets serviced first.
Arbitration can be implemented in Software (sequential polling) or Hardware (serial or parallel). The standard serial hardware method is Daisy Chaining.
Daisy Chain Circuit Architecture
In a daisy-chained system:
- All devices share a single, common active-low Interrupt Request () line wired in an open-collector (wired-OR) configuration with a pull-up resistor to .
- The processor's Interrupt Acknowledge () signal is connected exclusively to the Priority-In () pin of the first physical device (Device 1).
- The Priority-Out () pin of Device 1 is connected to the pin of Device 2, and this chain cascades sequentially down to Device .
- Physical Placement Dictates Priority: Device 1 (closest to the CPU) has the highest priority. Device (farthest from the CPU) has the lowest priority.
Daisy Chaining Priority Interrupt Hardware Architecture
Textbook hardware standard (Morris Mano Fig 11-12) showing serial INTA grant propagation and common wired-OR /INTR bus
Daisy Chaining Serial Priority Execution Flow
Serial grant propagation cascading from highest-priority interface to lowest
Common INTR Assert
Any requesting peripheral pulls the shared wired-OR INTR line low.
Grant Evaluation (Dev 1)
CPU drives INTA into PI1. If Dev 1 is requesting, it seizes the bus and forces PO1 = 0.
Grant Forwarding (Dev 2)
If Dev 1 is idle, it asserts PO1 = 1, passing the grant token to Dev 2 PI2.
Tail Service (Dev N)
Dev N is serviced only if all upstream interfaces are completely idle.
Internal Logic Gate Operation Inside Each Interface
Each device interface contains dedicated combinatorial logic to evaluate whether to consume the acknowledge token or pass it along:
Let be the internal interrupt request flag of Device ( if requesting, otherwise).
Let be the Priority-In signal entering Device .
Let be the Priority-Out signal generated by Device for Device .
Let be the vector enable line placing the device's vector address onto the data bus.
The internal logic is governed by:
- Case 1: Device requested an interrupt () and receives :
- : Device pulls low, blocking all downstream devices ().
- : Device enables its tri-state bus transceivers and drives its vector address onto the data bus.
- Case 2: Device does NOT want an interrupt () and receives :
- : The grant token passes cleanly through to Device .
- : Device leaves the data bus in high-impedance () state.
- Case 3: Device receives (an upstream device intercepted the grant):
- : The grant is blocked.
- : No vector is driven.
Mathematical Analysis of Daisy Chain Propagation Delay
While daisy chaining requires minimal wiring (only one and one looped wire), its primary disadvantage is linear propagation latency.
If a daisy-chained system connects peripheral devices, and each interface introduces an internal gate propagation delay of :
Where is the bus settling and transceiver enable time.
To ensure correct vector latching without bus timing violations, the processor's pulse width must satisfy:
Engineering Consequence: If the number of devices is large, the processor must inject bus wait-states during the interrupt acknowledge cycle, severely capping the maximum allowable bus clock frequency.
Parallel Priority Arbiters & Priority Encoders
To eliminate the propagation delay of serial daisy chains, high-performance systems employ Parallel Priority Arbiters using combinational priority encoders.
Functional Building Blocks
A parallel arbiter consists of four hardware stages implemented inside a specialized peripheral controller (such as the classic Intel 8259A PIC or modern APIC):
Internal Architecture of Parallel Priority Arbiter
Hardware subsystems of an O(1) combinational interrupt controller
Interrupt Request Register (IRR)
Asynchronous Latch- Latches incoming interrupt request levels from peripheral pins (IR0 to IR7).
- Preserves pending requests even if peripheral line pulses transiently.
- Bit i is set when device i asserts its request line.
Interrupt Mask Register (IMR)
Software Masking- 8-bit programmable register configured by CPU I/O write instructions.
- Bit i = 1 disables (masks) the corresponding interrupt level.
- Bitwise AND with IRR produces active, unmasked candidates.
8-to-3 Priority Encoder
O(1) Resolution Logic- Combinational gate network evaluating all active lines in parallel.
- Directly outputs 3-bit binary index (Y2, Y1, Y0) of highest-priority input.
- Zero sequential latency: resolves contention in ~2 to 3 ns gate delay.
In-Service Register (ISR)
Preemption Tracking- Stores the priority level currently being serviced by the CPU core.
- Allows higher-priority interrupts to preempt the current ISR (nesting).
- Cleared by End-of-Interrupt (EOI) command on ISR exit.
8-to-3 Truth Table & Logic Equations
Assuming has the highest priority and has the lowest:
| Valid () | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | X | X | X | 0 |
| 1 | X | X | X | X | X | X | X | 0 | 0 | 0 | 1 |
| 0 | 1 | X | X | X | X | X | X | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | X | X | X | X | X | 0 | 1 | 0 | 1 |
| 0 | 0 | 0 | 1 | X | X | X | X | 0 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 1 | X | X | X | 1 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 1 | X | X | 1 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | X | 1 | 1 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
The output lines are fed to an internal adder that adds an architectural base offset (e.g., in x86 PC systems) to generate the final vector number transmitted on the data bus.
🏭 Real-World Production Context: Linux Kernel & Modern PCIe MSI-X
Understanding how physical interrupt arbitration maps into modern production systems reveals why hardware-software co-design is critical.
Linux HardIRQ vs. SoftIRQ (Top-Half & Bottom-Half Split)
When a network card generates an interrupt, servicing the entire packet inside the hardware ISR would lock the processor and drop incoming packets. The Linux kernel solves this via a two-phase architecture:
Linux Kernel Two-Phase Interrupt Architecture
De-coupling urgent hardware acknowledgment from deferred processing
NIC asserts MSI-X vector. CPU finishes instruction, pushes PC/PSW onto stack, and jumps to registered HardIRQ handler.
MSI-X Vector WriteRuns with interrupts disabled. Acknowledges hardware, enqueues descriptor into DMA ring, schedules SoftIRQ, and exits immediately (< 5 µs).
napi_schedule()Runs asynchronously with interrupts re-enabled. NAPI poller parses TCP/IP frames, performs checksums, and routes to socket queue.
net_rx_action()User application thread blocked on epoll_wait() or read() wakes up with verified payload ready in memory.
epoll_wait() -> payloadModern PCIe: Message Signaled Interrupts (MSI & MSI-X)
In legacy PCI architectures, physical motherboards routed 4 physical interrupt wires (INTA#, INTB#, INTC#, INTD#) back to the central interrupt controller. In modern servers with 64 CPU cores and dozens of PCIe NVMe drives, physical wires create routing bottlenecks and pin count explosions.
PCIe replaces physical wires with Message Signaled Interrupts (MSI-X):
- A PCIe device does not assert any physical voltage pin.
- When the device needs service, it issues an inbound 32-bit Memory Write transaction across the high-speed serial PCIe fabric directly to a memory-mapped architectural register inside the processor's Local APIC.
- The payload of this memory write contains the vector number (), and the address specifies the target CPU core.
- Advantage: An NVMe drive or NIC can have up to distinct interrupt vectors, allowing each CPU core to service its own dedicated I/O queue with zero cross-core locking or bus contention!
📐 Numerical Applications & Worked Examples
Example 1: CPU Overhead Comparison (Programmed vs. Interrupt-Driven)
Problem Statement:
A peripheral device with a continuous data transfer rate of () is connected to a CPU operating at a clock frequency of . Data is transferred byte-by-byte.
- In Programmed I/O mode, the CPU executes a polling loop that takes per iteration to check the device status register.
- In Interrupt-Driven mode, each byte transfer incurs an interrupt hardware context-save overhead of , an ISR body execution time of , and an
IRETcontext-restore time of .
Calculate:
- The percentage of CPU time consumed under Programmed I/O mode.
- The percentage of CPU time consumed under Interrupt-Driven mode.
- The overall speedup / performance factor gained by operating in interrupt mode.
Step-by-Step Solution:
-
Calculate Basic Timing Parameters:
- CPU Clock Period:
- Time interval between successive byte arrivals from the device:
- Total CPU cycles available per byte interval:
-
Calculate Overhead for Programmed I/O:
- In programmed I/O, the processor spends the entire waiting window executing the polling loop until the byte arrives.
- Number of polling loops executed per byte:
- Because the CPU cannot do any other work during this time:
-
Calculate Overhead for Interrupt-Driven I/O:
- Total clock cycles required to service one interrupt:
- Time spent servicing the interrupt per byte:
- Percentage of CPU time consumed:
-
Calculate Productive CPU Time & Performance Gain:
- Under Programmed I/O, available user compute capacity = .
- Under Interrupt-Driven I/O, available user compute capacity = .
- If comparing the total processor time dedicated to I/O:
Example 2: Daisy Chain Timing, Starvation & Clock Constraints
Problem Statement:
An array of 12 peripheral interfaces are connected to a system bus using a Daisy Chaining priority scheme. The specifications of the system are as follows:
- Each device interface has an internal propagation delay of from its pin to its pin.
- The delay from the CPU asserting to is .
- When the lowest-priority device receives its signal, it requires to decode the signal, enable its bus drivers, and place its vector address on the data bus.
- The CPU data bus requires a setup time of prior to the trailing edge of the pulse.
Calculate:
- The minimum allowable pulse duration () that the CPU must maintain on the line to guarantee that Device 12 can be reliably serviced.
- If the CPU bus controller only supports pulse widths up to , determine the maximum number of devices that can be safely daisy-chained.
Step-by-Step Solution:
-
Calculate Minimum Pulse Duration for 12 Devices:
- The acknowledge signal must propagate through the first 11 devices to reach Device 12 ():
- Add initial bus transit time from CPU:
- Add Device 12 vector drive time:
- Add CPU bus setup time:
- Total minimum pulse width:
-
Calculate Maximum Devices for :
- Set up the inequality:
- Since must be an integer:
Example 3: Interrupt Vector Table Address Decoding
Problem Statement:
A 32-bit computer system utilizes a Vectored Interrupt Architecture with an Interrupt Vector Table (IVT) located in memory starting at physical address 0x0000_1000.
- The system architecture specifies that each vector table entry contains a 32-bit ISR Starting Address followed by a 32-bit Initial Status Register (total entry size = ).
- A hardware graphics accelerator interface is assigned Interrupt Vector Number (decimal).
- During system initialization, the graphics driver's ISR is loaded into RAM starting at physical address
0x0045_8000.
Determine:
- The hexadecimal starting physical address of the IVT entry assigned to the graphics accelerator.
- The byte layout (in Little-Endian format) that the operating system loader must write into the IVT at that entry to initialize both the ISR address (
0x0045_8000) and the default Status Register (0x0000_0200).
Step-by-Step Solution:
-
Calculate the IVT Entry Address:
- Base Address
- Vector Index
- Entry Size
- Memory Offset:
- Convert to hexadecimal:
- Target IVT Entry Address:
-
Determine Little-Endian Byte Layout:
- In Little-Endian storage, the least significant byte (LSB) is stored at the lowest memory address.
- Field 1: ISR Starting Address (
0x0045_8000) occupying addresses0x0000_1158to0x0000_115B:- Byte at
0x0000_1158:0x00(Bits 7..0) - Byte at
0x0000_1159:0x80(Bits 15..8) - Byte at
0x0000_115A:0x45(Bits 23..16) - Byte at
0x0000_115B:0x00(Bits 31..24)
- Byte at
- Field 2: Initial Status Register (
0x0000_0200) occupying addresses0x0000_115Cto0x0000_115F:- Byte at
0x0000_115C:0x00(Bits 7..0) - Byte at
0x0000_115D:0x02(Bits 15..8) - Byte at
0x0000_115E:0x00(Bits 23..16) - Byte at
0x0000_115F:0x00(Bits 31..24)
- Byte at
🎯 Exam & Interview Pitfall Check
-
Question 1: Why does a processor push both the Program Counter () and the Program Status Word () onto the stack during an interrupt, whereas a standard subroutine
CALLonly pushes the ?
Answer: A subroutineCALLis a deliberate, planned software instruction written by the programmer; the programmer or compiler knows which registers and condition codes are dirty and explicitly preserves them if necessary. In contrast, an interrupt is completely asynchronous—it can occur after any arbitrary instruction (e.g., between aCMPand a conditional jumpJNE). If the CPU does not automatically save the (which contains condition flags like Zero, Carry, Sign, and Overflow), the ISR instructions would overwrite those flags, causing the interrupted program to take the wrong branch upon return and inducing catastrophic data corruption. -
Question 2: In a daisy chain arbitration system, does physical proximity to the CPU confer an absolute advantage? What is the starvation hazard?
Answer: Yes. Device 1 is physically closest to the CPU and receives the signal first. If Device 1 generates interrupts frequently (high arrival rate), it will continuously consume the acknowledge token by setting , completely starving downstream devices (Devices 2 through ) from ever receiving the grant token. Daisy chaining provides strictly non-uniform priority. -
Question 3: What is the critical distinction between Edge-Triggered and Level-Triggered interrupts in multi-device bus sharing?
Answer: An Edge-Triggered interrupt detects a low-to-high (rising) or high-to-low (falling) voltage transition. If two devices assert an edge-triggered line simultaneously, the line transitions once; after servicing the first device, the second device's request may be lost because no new edge occurs. A Level-Triggered interrupt detects a continuous logical voltage level (e.g., ground / ). As long as any device still requires attention, the shared wired-OR line stays low, guaranteeing that the processor will re-enter the interrupt cycle at the next instruction boundary until all requesting devices have been satisfied.
-
Trap 1: Assuming the CPU Immediately Halts Current Instruction Execution When an Interrupt Occurs.
Candidates frequently assert that an interrupt causes the CPU to instantly drop what it is doing mid-cycle. This is false! Instructions are executed to completion to preserve micro-architectural atomicity. The interrupt signal is merely latched into the Interrupt Request Register (IRR) and evaluated at the end of the current instruction's write-back phase. -
Trap 2: Confusing Interrupt Service Routine (ISR) with Interrupt Vector Table (IVT).
The IVT does not contain executable program code. The IVT is simply an array of 4-byte or 8-byte memory pointers (addresses). The IVT points to the ISR, which resides in the operating system's kernel code segment. -
Trap 3: Believing Daisy Chaining Provides Uniform Priority.
Daisy chaining is intrinsically asymmetric. It can never provide uniform or round-robin priority because the grant token is wired in series. Changing priority requires physically re-cabling the bus connections or inserting complex multiplexing switches.