Module 2: TLM and Data Flow | Intermediate UVM

Latency-Aware Checking

Measure response latency, enforce timing requirements, and distinguish functional correctness from performance violations in a reusable UVM environment.

Learning objectives

  • Explain why functional correctness alone is insufficient for latency-sensitive protocols.
  • Define request-to-response latency using a precise timing reference.
  • Record request timestamps and calculate response latency in a scoreboard or monitor.
  • Check minimum, maximum, and exact latency requirements.
  • Apply latency checking to both in-order and out-of-order transactions.
  • Distinguish latency violations from functional mismatches and missing responses.
  • Design diagnostics that make timing failures easy to reproduce and debug.

Step 1: Understand what latency means

A response can be functionally correct and still violate the protocol if it arrives too early or too late.

Latency is the elapsed time between a defined request event and its corresponding response event.

Request accepted                         Response accepted
  |                                         |
  v                                         v
  +-----------------------------------------+
                latency

The first important verification decision is therefore: What exactly starts and ends the measurement?

For example, a protocol might define latency as:

  • Request handshake to response handshake.
  • Request acceptance to first response beat.
  • Request acceptance to final response beat.
  • Command issue to completion notification.
Verification principle: Never implement a latency check until the start and end events are explicitly defined by the protocol requirement.

Step 2: Functional correctness versus timing correctness

Consider a request for address 32'h1000. The DUT eventually returns the correct data, but the protocol specifies that the response must arrive within 20 clock cycles.

Expected:
request -> response within 20 cycles


Observed:
request -> response after 27 cycles

The data may be correct, but the DUT is still incorrect with respect to the timing requirement.

A production verification environment may therefore need to check:

Functional correctness
    +


Latency correctness
+
Protocol correctness

These checks should produce distinct diagnostics so that a failure immediately communicates what went wrong.

Step 3: Define a latency requirement

A latency requirement normally has one of three forms.

Requirement Meaning Example
Exact Response must occur at one specific latency Exactly 5 cycles
Maximum Response must not exceed a deadline ≤ 20 cycles
Range Response must occur inside a valid interval 5 to 20 cycles

For example:

MIN_LATENCY = 5 cycles


MAX_LATENCY = 20 cycles

Valid:
5 <= latency <= 20

Invalid:
latency < 5
latency > 20

Do not assume that faster is always better. Some protocols intentionally require a minimum latency because of pipeline, scheduling, or interface requirements.

Step 4: Choose the correct clock and sampling event

Cycle-based latency is usually measured using the clock associated with the protocol interface.

always @(posedge vif.clk) begin

if (request_accepted)
    request_cycle = cycle_count;

if (response_accepted)
    response_cycle = cycle_count;


end

A transaction should normally be timestamped when the protocol considers it accepted, not merely when a signal changes.

For a valid/ready-style handshake, for example:

request_accepted = req_valid && req_ready;


response_accepted = rsp_valid && rsp_ready;
Common mistake: Measuring latency from signal assertion instead of the protocol-defined acceptance event can produce an apparently precise but fundamentally incorrect latency measurement.

Step 5: Record request timestamps

Once the start event is defined, the environment needs to remember when each request was accepted.

For a simple in-order protocol, a queue may be sufficient:

longint request_cycle_q[$];


if (request_accepted)
request_cycle_q.push_back(cycle_count);

For an out-of-order protocol, the timestamp must be associated with the transaction identity.

longint request_cycle_by_id [bit [7:0]];


request_cycle_by_id[req.id] = cycle_count;

This connects directly to the previous lesson. The same correlation key used to match expected responses can also be used to recover the request's timing information.

Step 6: Calculate response latency

When the response arrives, retrieve the request timestamp and calculate the difference.

if (response_cycle_by_id.exists(rsp.id)) begin

longint latency;

latency =
    cycle_count - response_cycle_by_id[rsp.id];

`uvm_info("LATENCY",
  $sformatf(
    "ID=%0d latency=%0d cycles",
    rsp.id,
    latency),
  UVM_MEDIUM)


end

The fundamental calculation is:

latency = response_cycle - request_cycle;

Keep the calculation simple and explicit. The complexity should come from the protocol requirements, not from unnecessarily complicated measurement code.

Step 7: Add a maximum-latency check

A common requirement is that a response must arrive before a specified deadline.

localparam int MAX_LATENCY = 20;


if (latency > MAX_LATENCY) begin


`uvm_error("LATENCY",
  $sformatf(
    "Latency violation: ID=%0d latency=%0d cycles, maximum=%0d",
    rsp.id,
    latency,
    MAX_LATENCY))


end

A useful diagnostic should identify at least:

  • Transaction ID.
  • Observed latency.
  • Allowed latency.
  • Request timestamp.
  • Response timestamp.

These details greatly reduce debug time when a regression produces hundreds or thousands of failures.

Step 8: Check a latency range

Some protocols specify both minimum and maximum latency.

localparam int MIN_LATENCY = 5;


localparam int MAX_LATENCY = 20;

if (latency < MIN_LATENCY) begin


`uvm_error("LATENCY",
  $sformatf(
    "Response too early: ID=%0d latency=%0d minimum=%0d",
    rsp.id,
    latency,
    MIN_LATENCY))


end
else if (latency > MAX_LATENCY) begin


`uvm_error("LATENCY",
  $sformatf(
    "Response too late: ID=%0d latency=%0d maximum=%0d",
    rsp.id,
    latency,
    MAX_LATENCY))


end

Notice that the two failures have different meanings. An early response may indicate a protocol sequencing problem, while a late response may indicate a performance or deadlock problem.

Step 9: Make latency checking work with out-of-order responses

This is where the previous lesson becomes important. If responses can arrive out of order, a single timestamp queue is not enough.

Request ID 10 -> cycle 100


Request ID 11 -> cycle 101
Request ID 12 -> cycle 102

Response ID 11 -> cycle 108
Response ID 12 -> cycle 115
Response ID 10 -> cycle 119

The scoreboard calculates:

ID 11: 108 - 101 = 7 cycles


ID 12: 115 - 102 = 13 cycles
ID 10: 119 - 100 = 19 cycles

Each response is checked against its own request timestamp. Response arrival order does not affect latency correctness.

Key connection: Transaction correlation answers "Which request does this response belong to?" Latency tracking answers "How long did that transaction take?"

Step 10: Handle missing responses

A response that never arrives cannot be detected by simply calculating latency when responses are observed.

The environment also needs a deadline mechanism.

Request ID 25 accepted at cycle 100


Maximum latency = 20 cycles

Deadline:
cycle 120

No response by cycle 120
|
+----> latency timeout

A practical environment can periodically examine outstanding requests or use a dedicated timeout mechanism.

if ((cycle_count - request_cycle_by_id[id]) > MAX_LATENCY) begin

`uvm_error("LATENCY",
  $sformatf(
    "Response timeout: ID=%0d outstanding for %0d cycles",
    id,
    cycle_count - request_cycle_by_id[id]))


end

This distinction is important:

  • Late response: the response eventually arrives, but violates the limit.
  • Timeout: the response has not arrived by the required deadline.

Step 11: Build a reusable latency tracker

Timing logic should not be duplicated across every scoreboard. A reusable tracker can encapsulate the bookkeeping.

class latency_tracker #(type ID_T = int);

longint start_cycle[ID_T];

function void start(ID_T id, longint cycle);

    if (start_cycle.exists(id)) begin
        `uvm_error("LATENCY",
          $sformatf(
            "Duplicate start for ID %0d", id))
    end

    start_cycle[id] = cycle;

endfunction

function bit finish(
    ID_T id,
    longint cycle,
    output longint latency);

    if (!start_cycle.exists(id)) begin

        `uvm_error("LATENCY",
          $sformatf(
            "Finish without start for ID %0d",
            id))

        latency = 0;
        return 0;
    end

    latency = cycle - start_cycle[id];

    start_cycle.delete(id);

    return 1;

endfunction


endclass

The scoreboard can then focus on verification intent rather than maintaining timing bookkeeping itself.

Step 12: Separate latency checking from functional checking

A production scoreboard may perform several independent checks for the same response.

Response


|
+--> Correlation check
|
+--> Functional data check
|
+--> Status/protocol check
|
+--> Latency check
|
+--> Coverage sampling

This separation is valuable because one transaction can have multiple independent problems.

For example:

ID 42


Expected data : 32'h1234
Actual data   : 32'h5678
Latency       : 37 cycles
Maximum       : 20 cycles

The transaction has both a functional mismatch and a latency violation. Do not allow one failure to hide the other.

Step 13: Measure latency distributions

A maximum-latency check answers whether the DUT violated a requirement. Coverage and statistics can answer a different question: How does the DUT normally behave?

For example, latency may be distributed like this:

Latency


5 cycles  : 120 transactions
6 cycles  : 350 transactions
7 cycles  : 420 transactions
8 cycles  : 105 transactions
9 cycles  : 5 transactions

> 20 cycles: 0 transactions

This information can reveal performance changes even when the design remains functionally correct.

Latency can therefore become both:

  • A hard correctness requirement.
  • A performance measurement and coverage dimension.

Common mistakes

  • Measuring from the wrong event: Start timing at the protocol-defined acceptance event.
  • Using one timestamp for all outstanding requests: Concurrent transactions require per-transaction timing state.
  • Ignoring transaction IDs: Out-of-order responses must use correlation information.
  • Checking only maximum latency: Some protocols also require minimum or exact latency.
  • Waiting forever for a response: Missing responses require explicit timeout detection.
  • Mixing functional and timing failures: Keep diagnostics clear enough to identify the actual failure category.
  • Using arbitrary simulation time instead of protocol cycles: Choose the timing unit that matches the specification.
  • Ignoring reset: Outstanding timestamps must be handled correctly when the protocol resets.

Debugging strategy

When a latency failure occurs, reconstruct the transaction timeline.

  1. Identify the transaction ID.
  2. Locate the request acceptance event.
  3. Record the request cycle.
  4. Locate the corresponding response acceptance event.
  5. Record the response cycle.
  6. Calculate the observed latency.
  7. Compare it with the protocol's allowed range.
  8. Check whether arbitration, backpressure, reset, or resource contention explains the delay.

A useful failure message should let you reconstruct most of this timeline without immediately opening a waveform.

UVM_ERROR [LATENCY]


ID=37
request_cycle=1204
response_cycle=1231
observed_latency=27
allowed_latency=5..20
status=TIMEOUT/LATE_RESPONSE

Connection to the next lessons

Latency-aware checking completes an important progression in the TLM and data-flow module:

  • Lesson 16 — Transaction Ordering: establishes why arrival order matters—or does not matter.
  • Lesson 17 — Transaction Correlation: provides the mechanism for matching related transactions.
  • Lesson 18 — Out-of-Order Responses: applies correlation when responses complete in a different order.
  • Lesson 19 — Latency-Aware Checking: measures whether each correlated transaction completes within its timing contract.
  • Lesson 20 — Transaction Recording: will build on this by making transaction activity and timing information easier to inspect and analyze.

Try it yourself

Build a latency-aware scoreboard for a protocol that allows up to four outstanding requests.

  1. Create requests with IDs 1, 2, 3, and 4.
  2. Record the cycle at which each request is accepted.
  3. Return responses in a different order.
  4. Calculate latency independently for every ID.
  5. Set a maximum allowed latency of 10 cycles.
  6. Verify that an 8-cycle response passes.
  7. Verify that a 12-cycle response produces a latency error.
  8. Leave one transaction outstanding and verify timeout detection.
  9. Send a response with an unknown ID and verify correlation failure.

Advanced challenge: Add a minimum latency requirement of 3 cycles. Then create scenarios that produce early, valid, and late responses. Report the three conditions differently.

Self-check

  1. What event should start a latency measurement?
  2. Why should latency normally be measured from protocol acceptance events rather than arbitrary signal transitions?
  3. Why does an out-of-order protocol require per-transaction timestamps?
  4. What is the difference between a late response and a timeout?
  5. Why might a protocol require a minimum latency?
  6. How can transaction correlation and latency tracking work together?
  7. Why should functional mismatches and latency violations be reported separately?
  8. How can latency measurements be used for performance analysis in addition to correctness checking?
Expected understanding: You should be able to define a precise latency contract, record timing for outstanding transactions, correlate responses correctly, detect timing violations and missing responses, and produce diagnostics that explain the failure without relying entirely on waveform inspection.

Key takeaways

  • Latency is a verification requirement when the protocol specifies when a response must occur.
  • Always define the precise start and end events before implementing a latency check.
  • Use protocol acceptance events and an appropriate clock or timing unit.
  • Out-of-order transactions require per-transaction timestamps associated with a correlation key.
  • Latency requirements may specify minimum, maximum, exact, or range-based limits.
  • Missing responses require timeout detection; they cannot be detected by response-based latency calculation alone.
  • Keep functional, correlation, protocol, and latency failures distinguishable in diagnostics.
  • Latency statistics can provide valuable performance information even when no correctness violation occurs.
  • Reusable timing infrastructure keeps scoreboards focused on verification intent rather than bookkeeping.