Sampling Protocol Transactions
Learn how a UVM monitor determines when a protocol transaction has occurred, samples interface signals at the correct time, and reconstructs accurate transaction objects.
Learning objectives
- Explain why correct sampling timing is essential for a UVM monitor.
- Identify transaction boundaries using protocol handshakes and control signals.
- Sample signals on the correct clock edge.
- Reconstruct a transaction from multiple interface signals.
- Handle multi-cycle and response-based transactions.
- Understand how reset affects monitor sampling.
- Recognize common monitor sampling bugs and debug them systematically.
Step 1: A monitor must know when a transaction happened
In Lesson 41, you learned that a monitor observes the DUT and converts signal activity into transactions.
The next question is more precise: How does the monitor know which signal values belong to a real transaction?
The answer comes from the protocol.
A monitor must understand the rules that define a valid transfer. Those rules may involve a clock edge, enable signal, valid/ready handshake, request/response sequence, FIFO control signals, or several cycles of activity.
Step 2: Identify the transaction boundary
A transaction boundary tells the monitor when one protocol operation begins and ends.
Consider a simple valid/ready interface:
valid = 1
ready = 1
If the protocol defines a transfer whenever both signals are high on the rising clock edge, then:
transfer = valid && ready
The monitor should therefore sample the transaction on that clock edge.
@(posedge vif.clk iff
vif.valid && vif.ready);
This is fundamentally different from simply doing:
@(posedge vif.clk);
if (vif.valid) begin
// capture transaction
end
The second version ignores ready. If the protocol requires both signals,
the monitor could incorrectly report transfers that never actually occurred.
Step 3: Understand clocked sampling
Digital protocols often define valid data relative to a clock edge. The monitor therefore needs to sample at the same protocol-defined event.
For example:
Clock: __/‾\__/‾\__/‾\__/‾\__
↑ ↑
sample sample
Suppose the protocol says that a transfer occurs at the rising edge. The monitor should reconstruct the transaction from the values associated with that transfer event.
Sampling too early can capture values from the previous cycle. Sampling too late can capture values from the next cycle.
Step 4: Sample all fields belonging to the same transfer
A transaction often contains multiple fields that must be sampled together.
observed.write = vif.write;
observed.addr = vif.addr;
observed.data = vif.data;
These values should correspond to the same protocol transfer.
A common mistake is to sample control information at one point and data at another unrelated point.
For a simple single-cycle transfer, the monitor can do everything at the same protocol event:
task collect_transfer();
bus_transaction observed;
@(posedge vif.clk iff
vif.valid && vif.ready);
observed =
bus_transaction::type_id::create("observed");
observed.write = vif.write;
observed.addr = vif.addr;
observed.data = vif.data;
analysis_port.write(observed);
endtask
The resulting object represents one complete observed transfer.
Step 5: Do not confuse signal changes with transfers
A signal can change without a transaction occurring.
For example, data might change while valid is low.
If the protocol says data is meaningful only when valid && ready is true,
the monitor should ignore those changes.
Cycle valid ready data Transfer?
---
1 0 0 8'h10 No
2 1 0 8'h20 No
3 1 1 8'h20 Yes
4 0 0 8'h55 No
The monitor should publish exactly one transaction for this example.
Step 6: Reconstruct a meaningful transaction
The monitor's job is not simply to copy every signal into a class. It should reconstruct the meaningful protocol operation.
For example, an interface might contain:
valid
ready
write
addr
data
clk
reset
The transaction may only need:
write
addr
data
The clock and handshake signals determine when the transaction happened. They do not necessarily need to become transaction fields.
This reinforces an important distinction:
Interface
↓
Protocol timing + control
↓
Meaningful transaction
The transaction represents the operation, not a raw copy of every wire.
Step 7: Handle multi-cycle transactions
Not every protocol transaction fits into one clock cycle.
A transaction might contain:
Cycle 1: request
Cycle 2: address accepted
Cycle 3: wait
Cycle 4: response
Cycle 5: response data
In that situation, the monitor must understand the complete protocol sequence before publishing a transaction.
Conceptually:
Request detected
↓
Capture request information
↓
Wait for response
↓
Capture response information
↓
Build complete transaction
↓
analysis_port.write()
The exact implementation depends on the protocol, but the principle remains the same: publish a transaction when the information needed to represent that protocol operation is available.
Step 8: Example of a request/response monitor
Imagine a simple protocol where a request is accepted first and a response arrives later.
task collect_transaction();
bus_transaction observed;
// Wait for request
@(posedge vif.clk iff
vif.req_valid && vif.req_ready);
observed =
bus_transaction::type_id::create("observed");
observed.addr = vif.addr;
observed.write = vif.write;
observed.data = vif.data;
// Wait for response
@(posedge vif.clk iff vif.rsp_valid);
observed.response = vif.rsp_data;
analysis_port.write(observed);
endtask
This example illustrates an important idea: the monitor may need to maintain temporary state while a protocol transaction is in progress.
The transaction is published only after the monitor has collected the information required by the transaction model.
Step 9: Reset changes what should be sampled
Reset is another important part of protocol observation. During reset, interface signals may not represent normal transactions.
A monitor may therefore need to ignore transfers while reset is active:
wait (!vif.reset);
forever begin
@(posedge vif.clk);
if (vif.valid && vif.ready) begin
// reconstruct transaction
end
end
More complex protocols may require the monitor to clear partially collected state when reset occurs.
For example:
Request captured
↓
Reset asserted
↓
Discard incomplete transaction
↓
Wait for normal operation
↓
Start observing again
Whether an in-progress transaction is discarded, completed, or reported as aborted depends on the protocol and verification requirements.
Step 10: Publish only complete observations
Once a transaction has been reconstructed, publish it through the analysis port.
analysis_port.write(observed);
The monitor should avoid publishing partially populated objects unless the verification environment explicitly defines them as partial or intermediate observations.
For a normal transaction stream, downstream components should be able to assume:
One published object
=
One meaningful observed transaction
This makes scoreboards and coverage collectors much easier to design.
Step 11: Add useful monitor debug information
During development, print the transaction after reconstruction.
`uvm_info("MON",
$sformatf("Observed transaction:\n%s",
observed.sprint()),
UVM_MEDIUM)
You can also report important protocol events:
`uvm_info("MON",
"Valid/ready transfer detected",
UVM_LOW)
These messages can answer:
- Did the monitor detect the transfer?
- Did it sample at the expected time?
- Did it reconstruct the correct fields?
- Did it publish the transaction?
Step 12: Sampling bugs you should recognize
Monitor bugs often produce confusing scoreboard failures because the DUT may be correct while the testbench reconstructed the transaction incorrectly.
- Wrong clock edge: values from the wrong cycle are captured.
- Missing handshake condition: false transactions are reported.
- Sampling too early: newly updated values may not yet be represented correctly.
- Sampling too late: the monitor may capture the next transaction's values.
- Missing response: a multi-cycle transaction is published too early.
- Incorrect transaction boundary: one operation may be split into several transactions or several operations may be combined.
- Reset ignored: reset activity may be interpreted as normal traffic.
- Wrong interface: the monitor observes the wrong signals.
Step 13: Debug sampling systematically
When a monitor reports an incorrect transaction, do not immediately modify the scoreboard. First verify the observation itself.
- Find the protocol event: identify the exact cycle where the transfer should occur.
- Inspect the waveform: look at the clock, control, and data signals around that event.
- Check the monitor condition: confirm that the monitor recognizes the same event.
- Check sampled values: compare the transaction fields with the waveform.
- Check transaction boundaries: confirm that one object represents one intended operation.
- Check publication: verify that
analysis_port.write()is called once for each transaction.
A useful debugging table is:
| Question | Evidence |
|---|---|
| Did the DUT perform a transfer? | Protocol signals and waveform |
| Did the monitor detect it? | Monitor debug message |
| Did the monitor capture the correct values? | Observed transaction |
| Did the monitor publish it? | Analysis-port activity / subscriber |
| Did the checker receive it? | Scoreboard or subscriber log |
Step 14: A complete basic sampling monitor
Here is a compact monitor that puts the main ideas together for a simple valid/ready protocol.
class bus_monitor extends uvm_monitor;
`uvm_component_utils(bus_monitor)
virtual bus_if vif;
uvm_analysis_port #(bus_transaction) analysis_port;
function new(
string name = "bus_monitor",
uvm_component parent = null
);
super.new(name, parent);
analysis_port =
new("analysis_port", this);
endfunction
task run_phase(uvm_phase phase);
bus_transaction observed;
forever begin
@(posedge vif.clk);
if (vif.reset)
continue;
if (vif.valid && vif.ready) begin
observed =
bus_transaction::type_id::create(
"observed");
observed.write = vif.write;
observed.addr = vif.addr;
observed.data = vif.data;
`uvm_info("MON",
$sformatf(
"Observed:\n%s",
observed.sprint()),
UVM_MEDIUM)
analysis_port.write(observed);
end
end
endtask
endclass
The monitor follows a simple sequence:
Wait for clock
↓
Ignore reset
↓
Check valid && ready
↓
Create transaction
↓
Sample fields
↓
Publish transaction
For a more complicated protocol, the same architecture remains useful, but the sampling and transaction-reconstruction logic becomes more sophisticated.
Monitor sampling vs. driver driving
It is useful to compare the two components:
| Driver | Monitor |
|---|---|
| Receives transactions | Observes signals |
| Generates DUT activity | Detects DUT activity |
| Controls protocol timing | Understands protocol timing |
| Uses virtual interface to drive | Uses virtual interface to sample |
| Reports what it was asked to drive | Reports what it actually observed |
Both components understand the protocol, but they use that knowledge for opposite purposes: the driver creates activity, while the monitor recognizes activity.
Common mistakes
- Sampling every clock: not every clock represents a transaction.
- Ignoring handshake signals: this can create false transactions.
- Sampling on the wrong edge: transaction values may belong to another cycle.
- Publishing too early: multi-cycle transactions may be incomplete.
- Publishing too often: one transfer may accidentally produce multiple transaction objects.
- Ignoring reset: reset activity can become false protocol traffic.
- Copying every interface signal: the transaction should represent meaningful protocol information.
- Putting checking logic in the monitor: observation and checking should remain separate.
- Debugging the scoreboard first: verify that the monitor produced the correct observed transaction before changing the checker.
Practical debugging workflow
When a scoreboard reports an unexpected transaction, use this order:
1. Check DUT waveform
↓
2. Identify real protocol transfer
↓
3. Check monitor sampling condition
↓
4. Check observed transaction
↓
5. Check analysis-port publication
↓
6. Check scoreboard
↓
7. Only then investigate expected-result logic
This prevents a common verification mistake: fixing the checker to compensate for a broken monitor.
Try it yourself
Build a monitor for the simple valid/ready bus used in the
previous lessons.
- Wait for a rising clock edge.
- Ignore activity while reset is asserted.
- Detect a transfer only when
valid && readyis true. - Create a new observed transaction for each transfer.
- Capture
write,addr, anddata. - Print the transaction with
sprint(). - Publish it through the analysis port.
Compare the monitor's output with the waveform and verify that every published transaction corresponds to exactly one real protocol transfer.
Challenge
Extend your monitor to recognize a two-part transaction:
Request
↓
Wait one or more cycles
↓
Response
↓
Publish complete transaction
Add reset handling so that an incomplete transaction is discarded if reset occurs before the response arrives.
Then ask yourself: What evidence proves that the monitor reconstructed the transaction correctly?
Use the waveform, monitor log, and published transaction as three independent pieces of evidence.
Key takeaways
- A monitor must understand the protocol to know when meaningful transactions occur.
- Transaction boundaries are defined by protocol events, not simply by signal changes.
- Sample all transaction fields at the correct protocol-defined timing point.
- A valid/ready handshake is one common example of a transaction boundary, but protocols can be much more complex.
- Multi-cycle transactions may require the monitor to maintain state until enough information has been collected.
- Reset may require the monitor to ignore traffic or discard incomplete observations.
- One published transaction should normally represent one meaningful observed protocol operation.
- The monitor should observe and reconstruct; the scoreboard should determine correctness.
- When debugging, compare the waveform, sampling condition, observed transaction, and checker input.