Interrupt Service Sequences

Serve interrupts from a sequence without losing one, without letting main traffic slip into a service, and without leaving the bus locked. The status register is the truth; the interrupt line only says "look".

You Will Be Able To

  • Wait for an interrupt as a level and explain why an edge loses interrupts.
  • Write a service sequence that grabs the bus, reads and clears status through the register model, and reads again before it leaves.
  • Choose between exclusive, ranked and nested service, and know which uvm-core rule each relies on.
  • Release the bus on every exit path and check for unserved interrupts at the end of the test.
Lesson
U17.6
Time
35 min
Runs on
Verilator with UVM
Check
4 questions

A threshold interrupt fires, and the service sequence reads STATUS; a moment later the error source fires too. If the service clears only what it read and leaves, main traffic slips in before the error is served. With an edge-triggered loop the error is never served at all. The fix is three habits: wait for a level, serve inside a grab, and read STATUS again before leaving.

The First Service of the Example: The Error Fires During It
0123456time (ns)115145175205235265295busmain DATAisr readisr writeisr readisr writeisr readmain DATASTATUS seen-1 (thr)-2 (err)-0-irqgrab held-yes-error fires at 142 nsleave only when STATUS is 0
Scroll horizontally ↔
  1. Cycle 0

    The fourth DATA write sets the threshold bit, and irq rises. That write was already on the bus, so it completes first.

  2. Cycle 1

    The service has grabbed the bus and reads STATUS: only the threshold bit. The error fires just after this read.

  3. Cycle 3

    After clearing the threshold bit, the service reads again and finds the error.

  4. Cycle 5

    STATUS reads 0, so the service ungrabs. Main traffic resumes at 295 ns.

Measured by the example below. The error waited 63 ns for service, and no main write slipped in.

Wait for the Level

An interrupt line from a design is a level. It stays high while any unmasked status bit is set, and the status register says which. A service loop that waits for an edge assumes every interrupt makes one. Two cases break that. An interrupt may already be pending when the loop starts waiting. Or a second source may keep the line high from one service into the next. Neither makes a new edge.

So wait for the level with wait (vif.irq === 1), and let the status register decide what to do. The predict question below measures the difference. A level wait started at 10 ns returns at once. An edge wait started then waits for the next rising edge, at 55 ns.

The level wait needs one more rule. After a service the loop checks the line again at once, so a service must leave the line low or deliberately masked. Otherwise the loop serves the same pending bit over and over.

The Service Sequence

One service is a short sequence on the bus agent's sequencer. It grabs the sequencer, so no other sequence gets a grant until it ungrabs. Then it reads STATUS through the register model, clears each pending bit with a write-1-to-clear, and reads again. It leaves only when STATUS reads 0.

The service from the example
task body();
  uvm_status_e st;
  uvm_reg_data_t v;
  grab();
  regs.status.read(st, v, .parent(this));
  while (v[1:0] != 0) begin
    if (v[1]) begin regs.status.write(st, 2'b10, .parent(this)); served_err++; end   // error first
    else      begin regs.status.write(st, 2'b01, .parent(this)); served_thr++; end
    regs.status.read(st, v, .parent(this));                                          // anything new?
  end
  ungrab();
endtask

The .parent(this) arguments matter. A register call creates its own bus item and starts it through a parent sequence. Without a parent, the register map makes a default one, which is not a child of the grabbing sequence. The sequencer blocks every sequence that is neither the grab holder nor its child. So that call would wait for ever behind the service's own grab.

Service latency is the time from the line rising to the first service transfer, here 30 ns. It is one bus transfer plus arbitration, so keep main items short if latency matters. The item in flight when the interrupt arrives is never cut off. In the example, the fourth DATA write is already on the bus when irq rises at 115 ns, so it completes first. The grab takes effect at the next arbitration, and the service's first read completes at 145 ns.

Exclusive, Ranked or Nested

There are three ways to let a service in. They differ in how they treat main traffic and other services.

StyleHowWhat it relies on in uvm-core
Exclusivegrab() around the whole serviceA grab request goes to the front of the arbitration queue; once granted, other sequences wait until ungrab
RankedService items get a higher priority under UVM_SEQ_ARB_STRICT_FIFOPriority ranks item requests; a lock or grab request ignores it (measured in U5.2)
NestedA higher-priority service starts inside a lower one's grabOnly the grab holder and its children pass a grab, so the higher service must be started as a child

Choose by what may run between the items of a service.

Within one exclusive service, rank sources by the order in which you test the status bits. The example tests the error bit first, so if both are pending the error is cleared first. With separate services per source, a second grab waits until the first ungrabs, unless it comes from a child of the first. That is a nested service that does not nest.

Masks, Stuck Bits and Stuck Lines

The MASK register decides which pending bits raise the line. A masked source still sets its STATUS bit, but the service never runs for it. The end-of-test STATUS read is the only place it shows up. Unmask in configuration, and treat a bit pending at the end as a failure unless the test masked it.

Two design faults turn a level wait into a trap. A status bit that does not clear on a write of 1 keeps the line high. The service then reads, clears and reads again for ever. A line stuck high with STATUS at 0 makes every service read nothing and leave at once. The loop then starts the next one immediately. Bound both: give up after a few attempts at one bit, report it, and mask it. When the line is high but STATUS reads 0, report that and stop serving.

Who Owns the Service Loop

The loop that waits for the interrupt belongs in the top virtual sequence or the test. That puts it next to the main traffic it competes with. It needs the interface for the line, the register model and the sequencer. Keep the service sequence itself short: read, clear, read again, leave.

A service in progress is work the test must not cut off. Raise an objection while a service runs, or let the end-of-test check wait for the line to be low. At the end of the test, read STATUS once more. A bit still set there is an interrupt nobody served.

Release the bus on every exit path. When a sequence ends while it holds a grab, uvm-core removes the grab and reports UVM_ERROR SEQFINERR (measured in U5.2). So the bus is freed, but the run fails. Worse, a service that hangs or keeps re-grabbing starves main traffic the whole time. If the service can fail, put the ungrab in one place that every path reaches.

Try It

Main traffic writes twelve bytes; every fourth one raises the threshold source. The test pulses the error source at 142 ns, just after the service has read STATUS. The service clears the threshold, reads again, finds the error, clears it, and only leaves when STATUS reads 0. Main traffic resumes at 295 ns.

Delete the last regs.status.read inside the loop, and the service leaves after one bit. The loop then serves the error in a second service. Change the wait to @(posedge vif.irq) and compare the services.

RUNVerilator + UVM 2020.3.1 · simulator service
Edit the code, then run it
Expected among the UVM messages: 115 ns main write DATA 13 115 ns irq seen 145 ns isr read STATUS 1 175 ns isr write STATUS 1 205 ns isr read STATUS 2 235 ns isr write STATUS 2 265 ns isr read STATUS 0 295 ns main write DATA 14 385 ns irq seen 475 ns isr read STATUS 0 595 ns irq seen 685 ns isr read STATUS 0 800 ns main done; 3 services: thr 3, err 1; irq now 0 UVM_ERROR : 0

Check Yourself

Predict the outputThe line goes high at 5 ns. Two processes start waiting at 10 ns: one for the level, one for the edge. What line does the $display print?
`timescale 1ns/1ns
`include "uvm_macros.svh"
import uvm_pkg::*;
class my_test extends uvm_test;
  `uvm_component_utils(my_test)
  bit irq;
  function new(string name, uvm_component parent); super.new(name, parent); endfunction
  task run_phase(uvm_phase phase);
    int by_level = -1, by_edge = -1;
    phase.raise_objection(this);
    fork
      begin #5 irq = 1; #40 irq = 0; #10 irq = 1; #20 irq = 0; end   // high 5-45 and 55-75
      begin #10 wait (irq == 1); by_level = $time; end
      begin #10 @(posedge irq); by_edge = $time; end
    join
    $display("level wait returns at %0d, edge wait at %0d", by_level, by_edge);
    phase.drop_objection(this);
  endtask
endclass
module tb;
  initial run_test("my_test");
endmodule
ConceptA service sequence has grabbed the sequencer and calls regs.status.read(st, v) without .parent(this). What happens?
ConceptBoth sources are pending when the service reads STATUS. The error must be served first. How does the example's service achieve that?
ConceptA design's error bit will not clear. Each service clears one bit and leaves without reading STATUS again. It gives up on a bit after three tries, counting tries within one service. What happens?

Common Mistakes

Wrong Wait for the interrupt with @(posedge vif.irq).

An interrupt already pending when the loop starts makes no new edge. Nor does one that keeps the line high into the next service, so it is never served.

Fix Wait for the level: wait (vif.irq === 1).

Before
forever begin
  @(posedge vif.irq);
  isr.start(sqr);
end
After
forever begin
  wait (vif.irq === 1);
  isr.start(sqr);
end

Wrong Leave the service after clearing the bit you read first.

A source that fired during the service waits for another service. A bit that will not clear is tried once per service. So a retry limit that counts tries within one service never trips.

Fix Read STATUS again before leaving, and loop until it reads 0.

Wrong Make register calls inside a grabbing sequence without .parent(this).

Without a parent the register item is not a child of the grabbing sequence. The sequencer blocks it behind the grab, and the service deadlocks.

Fix Pass .parent(this) to every register read and write in the service.

Wrong Return from the service on an error path before ungrab.

uvm-core removes the grab when the sequence ends, but reports UVM_ERROR SEQFINERR, so the run fails. A service that hangs or loops inside the grab starves main traffic until then.

Fix Put ungrab on every exit path, or wrap the work in one place that always releases.

Remember

  • Wait for the interrupt as a level; the status register says which sources are pending.
  • Serve inside a grab, clear with write-1-to-clear, and read STATUS again until it is 0 before you leave.
  • Register calls inside the service need .parent(this) to pass the grab.
  • A lock or grab request ignores priority in uvm-core. Rank services with item priority, or by the order you test the status bits.
  • Release the bus on every exit path, and check for pending interrupts at the end of the test.

Practice

Report a problem with this page