Subscribers
Learn how UVM subscribers receive observed transactions and turn them into reusable measurements, logs, coverage, statistics, and lightweight checks.
Learning objectives
- Explain what a
uvm_subscriberis and when to use one. - Understand how a subscriber receives transactions through an analysis connection.
- Implement the
write()method of a subscriber. - Connect a monitor's analysis port to a subscriber.
- Distinguish a subscriber from a scoreboard.
- Use subscribers for transaction counts, statistics, logging, and coverage-related observation.
- Debug missing or unexpected transactions in a subscriber.
Step 1: What is a subscriber?
A subscriber is a UVM component designed to receive transactions published through an analysis connection and do something useful with those observations.
UVM provides a convenient base class called:
uvm_subscriber #(T)
where T is the transaction type the subscriber receives.
For example:
class bus_subscriber
extends uvm_subscriber #(bus_transaction);
A subscriber automatically gives you the basic analysis-consumer structure. Your main job is to implement:
function void write(bus_transaction t);
Step 2: Where does the transaction come from?
The transaction normally comes from a monitor.
The complete flow is:
DUT
|
v
Interface
|
v
Monitor
|
| bus_transaction
v
Analysis Port
|
v
Subscriber
|
v
Measurement / Coverage / Logging / Analysis
The monitor determines what actually happened on the DUT interface.
The subscriber receives that observation and decides what to do with it.
This continues the architecture introduced in Lessons 41–44:
- Monitor: observe and reconstruct.
- Analysis port: publish observations.
- Subscriber: consume and analyze observations.
Step 3: Build your first subscriber
Start with the smallest useful subscriber: one that counts transactions.
class bus_subscriber
extends uvm_subscriber #(bus_transaction);
`uvm_component_utils(bus_subscriber)
int transaction_count;
function new(
string name = "bus_subscriber",
uvm_component parent = null
);
super.new(name, parent);
transaction_count = 0;
endfunction
function void write(bus_transaction t);
transaction_count++;
`uvm_info("SUB",
$sformatf(
"Received transaction %0d:\n%s",
transaction_count,
t.sprint()),
UVM_MEDIUM)
endfunction
endclass
Every time the connected analysis port publishes a bus_transaction, the subscriber's write() method is called.
The subscriber therefore does not need its own loop waiting for transactions.
write(). It does not call the monitor to request them.
Step 4: Understand the write() method
The most important method in a basic subscriber is:
function void write(bus_transaction t);
The argument t is the transaction published by the producer.
Inside write(), you can:
- increment counters,
- collect statistics,
- update coverage,
- record interesting events,
- print debug information,
- perform lightweight checks.
For example, count writes separately from reads:
int write_count;
int read_count;
function void write(bus_transaction t);
if (t.write)
write_count++;
else
read_count++;
endfunction
At the end of simulation, the subscriber can report what it observed.
Step 5: Connect the subscriber
The subscriber is created during build_phase().
subscriber =
bus_subscriber::type_id::create(
"subscriber", this);
Then the monitor's analysis port is connected to the subscriber's analysis implementation.
monitor.analysis_port.connect(
subscriber.analysis_export
);
For a uvm_subscriber, the base class provides the analysis interface needed to receive transactions.
The complete environment pattern is:
class bus_env extends uvm_env;
`uvm_component_utils(bus_env)
bus_monitor monitor;
bus_subscriber subscriber;
function new(
string name = "bus_env",
uvm_component parent = null
);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
monitor =
bus_monitor::type_id::create(
"monitor", this);
subscriber =
bus_subscriber::type_id::create(
"subscriber", this);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
monitor.analysis_port.connect(
subscriber.analysis_export
);
endfunction
endclass
The architecture is now:
bus_monitor
|
| write(transaction)
v
analysis_port
|
v
bus_subscriber
|
v
write(t)
Step 6: Subscriber versus scoreboard
A subscriber and a scoreboard can both receive transactions through analysis connections, but their main purposes are different.
| Component | Main question | Typical work |
|---|---|---|
| Subscriber | What did we observe? | Counts, statistics, coverage, logging, analysis |
| Scoreboard | Was the behavior correct? | Expected-versus-actual checking |
For example, a subscriber might count:
100 total transactions
42 writes
58 reads
A scoreboard might determine:
Expected data = 8'h55
Observed data = 8'h55
PASS
Both components can receive the same observed transaction.
Monitor
|
v
Analysis Port
/ \
/ \
v v
Subscriber Scoreboard
"What happened?" "Was it correct?"
Step 7: A subscriber can collect statistics
Subscribers are useful when verification needs quantitative information about the observed traffic.
For example:
class bus_subscriber
extends uvm_subscriber #(bus_transaction);
`uvm_component_utils(bus_subscriber)
int total_count;
int write_count;
int read_count;
function new(
string name = "bus_subscriber",
uvm_component parent = null
);
super.new(name, parent);
endfunction
function void write(bus_transaction t);
total_count++;
if (t.write)
write_count++;
else
read_count++;
endfunction
function void report_phase(uvm_phase phase);
super.report_phase(phase);
`uvm_info("STATS",
$sformatf(
"Total=%0d Writes=%0d Reads=%0d",
total_count,
write_count,
read_count),
UVM_LOW)
endfunction
endclass
After the test finishes, the subscriber can provide a concise summary of the observed traffic.
This is often more useful than printing every transaction individually.
Step 8: Subscribers and coverage
A subscriber is also a convenient place to collect coverage from transactions.
For example, suppose we want to know whether the testbench observed writes to different address regions.
class bus_coverage
extends uvm_subscriber #(bus_transaction);
`uvm_component_utils(bus_coverage)
covergroup bus_cg;
cp_write : coverpoint trans.write;
cp_addr : coverpoint trans.addr {
bins low = {[8'h00:8'h3F]};
bins mid = {[8'h40:8'hBF]};
bins high = {[8'hC0:8'hFF]};
}
endgroup
bus_transaction trans;
function new(
string name = "bus_coverage",
uvm_component parent = null
);
super.new(name, parent);
bus_cg = new();
endfunction
function void write(bus_transaction t);
trans = t;
bus_cg.sample();
endfunction
endclass
The important architectural idea is more important than the exact coverage syntax:
Monitor
|
| observed transaction
v
Analysis Port
|
v
Coverage Subscriber
|
v
Coverage Model
The coverage component is measuring what the monitor actually observed, rather than what the sequence intended to generate.
Step 9: One monitor, many subscribers
Analysis ports become especially powerful when multiple subscribers need the same transaction stream.
+--> Scoreboard
|
Monitor --> Analysis Port +--> Coverage Subscriber
|
+--> Statistics Subscriber
|
+--> Logger
The monitor does not need separate protocol logic for each consumer.
It simply publishes:
analysis_port.write(observed);
Each connected component independently receives the observation.
This gives the environment a clean separation:
- The monitor knows how to observe the protocol.
- The analysis port distributes observations.
- Each subscriber specializes in a particular analysis task.
Step 10: Do subscribers change the DUT?
No.
A subscriber is a consumer of observations. It should not drive DUT interface signals.
The normal direction is:
DUT
|
| observed behavior
v
Monitor
|
| transaction
v
Subscriber
Not:
Subscriber
|
v
DUT pins
This keeps observation separate from stimulus.
Drivers generate activity. Monitors observe activity. Subscribers analyze observations.
Step 11: Debugging a subscriber
If your subscriber receives no transactions, trace the complete path.
1. Did the DUT perform a transfer?
2. Did the monitor detect it?
3. Did the monitor create a transaction?
4. Did the monitor call analysis_port.write()?
5. Is the analysis port connected?
6. Is the subscriber's write() being called?
7. Is the subscriber processing the transaction correctly?
Add a temporary message inside write():
function void write(bus_transaction t);
`uvm_info("SUB",
$sformatf(
"Subscriber received:\n%s",
t.sprint()),
UVM_MEDIUM)
endfunction
If this message never appears, investigate the producer and connection before changing subscriber logic.
If it appears with unexpected values, investigate the monitor's sampling and transaction reconstruction.
Common mistakes
- Forgetting the connection: the subscriber cannot receive transactions unless the analysis path is connected.
- Using the wrong transaction type: the subscriber must match the transaction type being published.
- Checking driver intent instead of monitor observations: use the monitor's transaction stream when measuring actual DUT behavior.
- Putting protocol sampling in the subscriber: the monitor should understand interface timing.
- Driving DUT signals from the subscriber: subscribers are consumers, not stimulus drivers.
- Using a subscriber as a full scoreboard: correctness checking may require expected-result generation, queues, ordering, or comparisons better handled by a scoreboard.
- Printing every transaction forever: useful during debug, but excessive logs can hide important failures.
- Assuming the subscriber owns the transaction: treat received transactions as observations and avoid modifying shared objects unnecessarily.
Subscriber architecture
DUT
|
v
Virtual Interface
|
v
Monitor
|
| bus_transaction
v
Analysis Port
/ | \
/ | \
v v v
Subscriber Scoreboard Subscriber
Statistics Checker Coverage
| | |
v v v
Counts PASS/FAIL Coverage
This architecture illustrates an important UVM principle:
One observed transaction can support multiple independent verification activities.
Practical design checklist
- Identify the observation you want to analyze.
- Make sure the monitor reconstructs that observation correctly.
- Create a subscriber using the correct transaction type.
- Implement the subscriber's
write()method. - Connect the monitor's analysis port in
connect_phase(). - Run a small deterministic test.
- Confirm that the subscriber receives the expected transactions.
- Add statistics, coverage, logging, or other analysis.
Start with one transaction. Once the data path works, add more sophisticated analysis.
Try it yourself
Build a subscriber that counts observed bus traffic.
- Create a
bus_subscriberextendinguvm_subscriber #(bus_transaction). - Implement
write(bus_transaction t). - Count total transactions.
- Count writes and reads separately.
- Connect the monitor's analysis port to the subscriber.
- Generate at least ten transactions.
- Print the final counts in
report_phase().
Challenge: Add coverage for at least three address regions and determine whether your stimulus actually exercises all of them.
Key takeaways
uvm_subscriberis a convenient UVM component for consuming analysis transactions.- The main subscriber callback is
write(transaction). - Subscribers normally receive observations from a monitor through an analysis connection.
- Subscribers can collect statistics, coverage, logs, and other transaction-level measurements.
- A subscriber is primarily an observation/analysis component; a scoreboard is primarily a correctness-checking component.
- One monitor can publish transactions to multiple independent consumers.
- Subscribers should not drive DUT signals or implement protocol sampling.
- When debugging, verify the monitor and analysis connection before changing subscriber logic.
- Observed transactions provide evidence of what the DUT actually experienced.
Core mental model
The monitor observes the DUT, the analysis port distributes the transaction, and the subscriber turns that observation into useful verification information.
What comes next?
A subscriber is excellent for analyzing observations, but verification eventually needs to answer a harder question:
That leads directly to the next lesson: Basic Scoreboards.
There you will learn how to compare observed transactions against expected behavior and turn those comparisons into meaningful pass/fail results.