Study guides · Advanced

Manage interrupt state: separate pending from active

Separate device signals from interrupt handling state, then follow acknowledgement, EOI and deactivation to explain repeated delivery.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. Goal: distinguish a waiting request from work in progress
  2. Build four states from two independent questions
  3. Acknowledgement changes state; observing pending does not
  4. With EOImode=1, separate EOI from deactivation
  5. A persistent level can request service again
  6. Keep each VM’s interrupt state with its owner
  7. Exercise: explain repeated delivery from state
  8. Ask Logeia about this articleCheck your understanding

Goal: distinguish a waiting request from work in progress

Describing an interrupt only as a bell leaves an important question unanswered: why might it arrive again after its handler ran? Track a pending request separately from an active interrupt that the CPU has acknowledged. This lesson builds on exception levels and guest entry and exit. It selects a limited GICv3 configuration with two VMs, one vCPU per VM, and one level-sensitive source. The goal is to explain transitions, rather than memorize register names.

Keep the device source condition in a separate column from the controller's pending and active state. An asserted source does not mean that a handler is currently executing. Conversely, an active interrupt can remain after the handler has cleared the device condition. Combining these facts into one busy flag loses information needed to determine the next transition. The extra state is useful because it makes a prediction testable, not because a larger diagram is inherently more accurate.

Build four states from two independent questions

Inactive means neither pending nor active. Pending means a request awaits acknowledgement. Active means an acknowledged interrupt has not yet been deactivated. Active plus pending combines an in-progress instance with a further pending condition; it does not mean that two copies of the handler execute simultaneously. Read both flags before predicting delivery. In particular, the presence of a pending flag is not by itself permission to acknowledge an interrupt already active under this selected model.

For example, a device asserts its level, the request becomes pending, and the guest acknowledges it. A source that remains asserted can leave a further pending condition while processing is active. The model exposes that condition as active plus pending. It deliberately excludes competing interrupt priorities and the full set of per-interrupt pending controls. Within that stated boundary, the important observation is that handler progress and a continuing request are different facts that can coexist.

StatependingactiveInterpretation
inactive00No request or active handling
pending10Awaiting acknowledgement
active01Acknowledged and not deactivated
active+pending11Active with a pending condition

Acknowledgement changes state; observing pending does not

A pending entry on the screen is not evidence that guest handling began. Delivery also depends on enable state, the vCPU IRQ mask, the selected recipient VM, and the running context. Acknowledgement obtains the interrupt identity and advances its handling state. It is different from inspecting a log. Compare a trace that enters the handler with one that keeps waiting: a request reaching the controller and a handler beginning execution are separate boundaries.

A normal trace asserts the device source, verifies eligibility, acknowledges the ID, and services the underlying condition. As a counterexample, enable the IRQ mask and observe that pending work remains without acknowledgement. Clearing pending merely to make the display quiet would discard the work rather than repair delivery. Change one gate at a time and check whether the request survives while blocked. This reveals whether the apparent success is actual handling or simply the disappearance of evidence.

With EOImode=1, separate EOI from deactivation

This lesson fixes EOImode to one. EOI ends the priority-related part of handling, while deactivation clears active state. Do not implement EOI as an operation that also clears the device condition and all controller state. Servicing the device, dropping priority, and deactivating are separate responsibilities in the trace. The access path for virtual interrupt registers depends on virtualization configuration; the model does not claim that each operation must trap into an EL2 software handler.

The short calculation below checks that distinction: active remains set after EOI and clears only after deactivation. It does not write actual GIC registers. Another configuration can combine priority drop and deactivation, so align the selected EOI mode before comparing two implementations. A difference in the number of operations is not enough to diagnose a defect. Write the intended postcondition of each operation beside its code and then compare the resulting state, rather than comparing names alone.

javascript
const irq = { active: true, priorityHeld: true, source: false };
function eoi() { irq.priorityHeld = false; }
function deactivate() { irq.active = false; }
eoi();
if (!irq.active || irq.priorityHeld) throw Error('EOI contract');
deactivate();
console.log(JSON.stringify(irq));

A persistent level can request service again

Imagine an expired timer or unread receive data. Completing CPU-side handling does not remove a device condition that still needs service. In the model, leave the source asserted while deactivating and observe a return to pending. Repeated delivery is then the presentation of an unresolved cause, rather than sufficient evidence of an accidental duplicate. A large interrupt count alone cannot tell you whether delivery logic or device servicing is responsible for the behavior.

For a controlled comparison, clear the source while active and then perform EOI and deactivation. An inactive result follows from resolving the source, not from renaming the end operation. Also consider a new request arriving immediately after the old condition is cleared. Ending old work must not erase new work. A useful test therefore checks both a quiet final state when appropriate and preservation of requests that should still be serviced. Silence alone is an inadequate correctness criterion.

Keep each VM’s interrupt state with its owner

If VM A is handling an interrupt when execution switches to VM B, A's active or pending state must not become B's state. An interrupt ID needs an owning virtual context; equal numeric IDs are not equal requests across VMs. The demonstration shows the recipient, running VM, and per-VM flags together. A global active flag may make the animation advance while silently delivering A's work to B, which is a failure of isolation rather than successful progress.

The model has one vCPU per VM, so it excludes distribution across several guest CPUs and interrupt migration between them. Even this small configuration benefits from explicit ownership. Check the context being saved, the context being restored, and the recipient of a device request independently. These observations separate a context error from the vague symptom of a missing interrupt. First establish that two owners do not cross; do not extend that result into a claim about every multicore delivery configuration.

Exercise: explain repeated delivery from state

In the virtual-interrupt demonstration, keep the source asserted through acknowledgement, EOI, and deactivation. Repeat after clearing the source. Record the first differing value, final pending and active flags, and recipient VM. The first trace retains a cause and becomes pending again; the second resolves the cause and can become inactive. Writing EOI twice does not explain how the device condition disappeared, so it is not a sufficient answer to this exercise.

Then compare an enabled IRQ mask with a wrong recipient VM. Both can resemble a handler that never progresses, but they require different repairs. A correct repair preserves waiting work and makes acknowledgement possible in the intended VM. Keep playback, prediction results, and successful configuration repairs as separate records. Reaching the last animation frame establishes that you viewed the trace; it does not by itself establish that you can diagnose the state transition under changed conditions.

Try the interactive model

Virtual interrupt delivery

Loading demo checkpoint…

Reading and practice are recorded separately in this browser, for each language.

Choose a learning path