Vertical Reuse of a Block Environment

A block team's UVM environment has agents, monitors, a register model and a scoreboard. At chip level most of it comes along, but its drivers must stay behind, because the chip now drives the block. Learn what moves up, what goes passive, what is replaced, and how a virtual sequencer ties the chip's agents together.

You Will Be Able To

  • Sort the parts of a block environment into reused, reused passive, left behind and replaced.
  • Switch an agent to passive through its configuration, and say what it then builds.
  • Feed a scoreboard from a monitor so that it works at both levels.
  • Explain what a virtual sequencer holds and why a chip test needs one.
Lesson
V3.6
Time
26 min
Runs on
Your browser
Check
5 questions

Picture a UART0 environment that passed every block test. Lifted into the chip, its scoreboard reports every byte on the pad as unexpected. Nothing is wrong with the chip. The scoreboard always learned what to expect from its own driver, and at chip level that driver never runs.

A Block Environment Lifted into the ChipAt block level the agent drives the block. At chip level the chip drives it, so the driver stays behind and the monitor comes along.
  • Sequence
  • Manager
  • Peripheral
  • Test
  • Result
  • Bus
  • Control / FSM
  • Data
  • Control
A Block Environment Lifted Into the ChipAt block level the agent drives the block. At chip level the chip drives it, so the driver stays behind and the monitor comes along. sequence Block sequences write TXDATA, DIV manager Driver block level only peripheral UART0 the block test Monitor both levels result Scoreboard expects from themonitor bus Chip fabric chip level: drivesUART0 control Virtual sequencer chip level: one handleper agent block levelitemschip levelread onlytransactionschip tests
  1. sequence Block sequenceswrite TXDATA, DIV
    • items → Driver
  2. manager Driverblock level only
    • block level → UART0
  3. peripheral UART0the block
    • read only → Monitor
  4. test Monitorboth levels
    • transactions → Scoreboard
  5. bus Chip fabricchip level: drives UART0
    • chip level → UART0
  6. result Scoreboardexpects from the monitor
  7. control Virtual sequencerchip level: one handle per agent
    • chip tests → Chip fabric
  1. Block level

    The agent is active: sequences go through the driver into UART0, and the monitor watches.

  2. Chip level

    The fabric drives UART0. The agent is passive: no driver, no sequencer, the same monitor.

  3. What carries the checking

    The scoreboard takes what the monitor saw. A virtual sequencer coordinates the chip's own agents.

Read the diagram as text
  • Block sequences: write TXDATA, DIV
  • Driver: block level only
  • UART0: the block
  • Monitor: both levels
  • Scoreboard: expects from the monitor
  • Chip fabric: chip level: drives UART0
  • Virtual sequencer: chip level: one handle per agent
  • Driver → UART0: block level
  • Block sequences → Driver: items
  • Chip fabric → UART0: chip level
  • UART0 → Monitor: read only
  • Monitor → Scoreboard: transactions
  • Virtual sequencer → Chip fabric: chip tests

The pattern of the UVM Cookbook's testbench architecture, drawn for UART0 of ap_soc.

Before You Start

Read Passive Checkers: Bind and Listen first. The UVM track teaches the machinery: Active and Passive Agents and Vertical Reuse.

Five questions this page answers
Question
1Why can a block's driver not come along into the chip?
2What does a passive agent build, and how is it told to be passive?
3Where must a reused scoreboard get its expected values?
4What does a virtual sequencer hold?
5What did the chip's own UVM environment do in one run, and what did it cost to build?

The Idea: The Chip Takes the Wheel

At block level the environment is the block's whole world: its driver writes the block's registers, and its monitor watches them. At chip level the chip's fabric writes those registers, under firmware or a bus manager. A second driver on the same port would fight the fabric, so the driver must stay behind.

Everything that only watches comes along: monitors, coverage, register models, scoreboards. That is most of the value of the block team's work. It is why environments switch between active and passive with one setting.

New Words

New words on this page
WordMeaning
Vertical reuseUsing a block's verification environment again inside a larger one: a subsystem or the chip.
AgentA UVM component that bundles a driver, a sequencer and a monitor for one interface.
is_activeAn agent's setting: UVM_ACTIVE builds a driver and a sequencer, UVM_PASSIVE builds only the monitor.
Configuration databaseuvm_config_db: where a parent sets values that its children read when they are built.
ScoreboardA component that compares what should have happened with what did.
Virtual sequencerA sequencer that holds handles to other sequencers, so one sequence can drive several agents in step.

The Smallest Example: Sort the UART0 Environment

Before the chip's own environment, sort a block environment for UART0 by one question. Does the part drive the block's port?

What comes along
PartDrives the port?At chip level
APB driver and sequenceryesleft behind: the fabric drives UART0
APB monitornocomes along
UART pad agentdrives the pad, not the portcomes along: the pads are still the outside world
Register model of UART0nocomes along, mapped at UART0's base in the chip's model
Scoreboard fed by the APB driverno, but leans on the driverreplaced: feed it from the monitor
Block sequencesthrough the driverleft behind, or rewritten as chip sequences

The Rules

  1. Rule 1: Make every agent switchable.

    Build the driver and the sequencer only when is_active is UVM_ACTIVE; build the monitor always.

  2. Rule 2: Set the mode from above.

    The chip environment sets is_active for the reused agent through the configuration database before it is built.

  3. Rule 3: Check from monitors, never from drivers.

    A scoreboard fed by a monitor works at both levels; one fed by a driver goes deaf at chip level.

  4. Rule 4: Coordinate with a virtual sequencer.

    Keep one handle for each agent that still drives. Then a chip test can start traffic on the bus and the pads in step.

  5. Rule 5: Keep the build small enough to run.

    A chip-sized UVM build costs minutes; reuse at the level a test needs.

Sources for These Rules

Agents, is_active and the configuration database: IEEE 1800.2-2020 13.4 (uvm_agent) and F.2 (uvm_active_passive_enum); checked in uvm-core 2020.3.1, src/comps/uvm_agent.svh.

Vertical reuse, passive agents and virtual sequencers: UVM Cookbook, Testbench Architecture and Sequences chapters (UVM-CB).

The chip's environment: tools/soc/ap_soc/bench/soc_tb/soc_uvm/ and README.md; its build time: plan §3.10, stage E7.

The Lab: The Chip's Own UVM Environment

soc_tb has a third front end, in soc_uvm/. It has a bus agent on the core's seat and pad agents for UART, GPIO, JTAG and the flash. It also has a generated register model, a UART scoreboard and a virtual sequencer. Be clear about what it is. It was written for the chip, not lifted from a block bench. So it shows the receiving end of reuse: the parts a reused agent plugs into.

soc_env builds one agent per interface and the register model (soc_uvm_pkg.sv).
      bus = soc_bus_agent::type_id::create("bus", this);
      bus.api = api;
      uart = pad("uart"); gpio = pad("gpio"); jtag = pad("jtag"); spi = pad("spi");
      regs = soc_reg_block::type_id::create("regs");
      regs.build();
The bus agent's build_phase (soc_uvm_pkg.sv): the monitor always, the driver and sequencer only when active.
    virtual function void build_phase(uvm_phase phase);
      monitor = soc_bus_monitor::type_id::create("monitor", this);
      monitor.api = api;
      if (get_is_active() == UVM_ACTIVE) begin
        sequencer = uvm_sequencer #(soc_bus_item)::type_id::create("sequencer", this);
        driver = soc_bus_driver::type_id::create("driver", this);
        driver.api = api;
      end
    endfunction

Rule 1 at work in the bus agent. On the seat it is active, so all three parts exist. With the processor in the seat the same agent would have to be passive, and only its monitor would be built. One detail is a warning, not a model. The flash's pad agent listens only, but it decides that by its kind, not by is_active. A reusable agent should not take that shortcut.

The virtual sequencer holds one handle per agent that drives, plus the register model and the bench's doors (soc_uvm_pkg.sv).
  class soc_vsequencer extends uvm_sequencer;
    uvm_sequencer #(soc_bus_item) bus;
    uvm_sequencer #(soc_pad_item) uart, gpio, jtag;
    soc_reg_block regs;
    soc_api       api;

Rule 4 at work: a chip test starts one virtual sequence on soc_vsequencer. From there it reaches the bus agent, the UART, GPIO and JTAG agents, and the register model. The build ran once on the site's UVM engine, Verilator 5.052 with uvm-core 2020.3.1, at -O0.

That build is slow. On the development laptop, a WSL machine shared with other jobs, five builds took 49 to 134 s. Three were in the bench's own gate, and two in this module's recordings, under load.

soc_pads_test on the bus-manager seat: the result block and the UVM report counts.
soc_pads_test:
  verdict=pass
  reason=pass
  status=0000900d
  cycles=1717
  uart_bytes=2
  spi_frames=1
  jtag_scans=7
  bus_transfers=57
  checker_errors=0
  UVM_ERROR=0 UVM_FATAL=0

The test sent a byte each way on the UART pads (uart_bytes = 2) and read the flash (spi_frames = 1). It ran JTAG scans (jtag_scans = 7), all through UVM agents. It ended the way firmware does, with the pass word, under the bench's own end-of-test rules.

The same test with the board's UART at another rate than DIV.
soc_pads_test +uart_div=3:
  verdict=fail
  reason=checker
  uart_bytes=3
  checker_errors=1

The board's UART model now reads the chip's frames at the wrong bit time and counts a frame error. The bench's checker count ends the run as a fail. The scoreboard is not needed to see this: the passive parts of the bench and of the environment agree.

Why It Is Built This Way

Why not write the chip environment from scratch? Because the block team's monitors, register model and coverage already encode months of knowledge about the block. Reusing them passively costs a configuration setting; rewriting them costs the same months again, with new bugs.

Why keep the UVM practice problem small? The live server ran the chip bench about 3.5 times slower than the laptop when it was measured. Scaled by that factor, the chip environment would take an estimated 3 to 8 minutes there. One check may take 240 s. So the practice problem reuses a block environment inside a small fixture that plays the chip around it. Its page says what the fixture leaves out.

Traps

The trap of the hook is the scoreboard that listens to its driver. At block level it is a convenient shortcut: the driver knows what it sent. At chip level no driver runs, the expected queue stays empty, and every real byte looks unexpected. Worse, at block level it can hide a bus bug, because it trusts the driver's word instead of the bus.

The second trap is a build_phase that forgets its parent. uvm_agent reads is_active from the configuration database in its own build_phase. An agent whose build_phase never calls super.build_phase keeps the default, UVM_ACTIVE, and builds a driver the chip never asked for.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc's environment has one bus agent and four pad agents.

  1. Subsystem first

    Block environments are usually reused twice: into a subsystem environment, then into the chip. Each level sets its children passive.

  2. Register models in layers

    The chip's register model contains each block's model as a sub-block at its base address, generated from one register database.

  3. Emulation and silicon

    Passive monitors and scoreboards can follow the design onto an emulator; drivers are replaced by transactors or by firmware.

Try It

Run it: one agent module, instantiated twice. Active, it drives three transfers; passive, it drives nothing and the "fabric" does.

In both places the monitor sees three transfers. That is why checking hangs off the monitor.

Make the chip-level agent active as well. What happens on its bus, and why would a real chip test now be wrong?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: block level: driver on, monitor saw 3 chip level: driver off, monitor saw 3

Check Yourself

ConceptWhy must the block's APB driver stay behind at chip level?
ConceptWhat does a passive agent build?
ConceptHow does the chip environment make a reused agent passive?
ConceptIn the lab, the board's UART ran at the wrong rate. What ended the run as a fail?
Predict the outputThe toy agent runs once active and once passive. What is the last line printed?
`timescale 1ns/1ns
// An agent in plain SystemVerilog: a monitor always, a driver only when ACTIVE.
module agent #(parameter bit ACTIVE = 1) (input logic clk, inout wire valid);
  logic drive = 0;
  int seen = 0;
  assign valid = ACTIVE ? drive : 1'bz;          // a passive agent drives nothing
  always @(posedge clk) if (valid === 1'b1) seen++;
  task automatic send(input int n);
    if (ACTIVE) repeat (n) begin @(negedge clk) drive = 1; @(negedge clk) drive = 0; end
  endtask
endmodule
module tb;
  logic clk = 0;
  always #5 clk = ~clk;
  wire block_valid, chip_valid;
  logic fabric = 0;
  assign chip_valid = fabric;                    // at chip level the fabric drives the bus
  agent #(.ACTIVE(1)) at_block (.clk(clk), .valid(block_valid));
  agent #(.ACTIVE(0)) at_chip (.clk(clk), .valid(chip_valid));
  initial begin
    at_block.send(3);
    repeat (3) begin @(negedge clk) fabric = 1; @(negedge clk) fabric = 0; end
    #20;
    $display("block level: driver %s, monitor saw %0d", "on", at_block.seen);
    $display("chip level: driver %s, monitor saw %0d", "off", at_chip.seen);
    $finish;
  end
endmodule

Common Mistakes

Wrong Feed a scoreboard from the driver's announcement of what it sent.

At chip level the driver is gone, so the scoreboard expects nothing.

Fix Feed it from a monitor of the bus, which works at both levels.

Wrong Override build_phase without calling super.build_phase in an agent.

is_active is then never read, and the agent stays active.

Fix Call super.build_phase first, then test get_is_active().

Wrong Rebuild the whole chip environment for a small reuse question.

A chip-sized UVM build takes minutes; most of it is irrelevant to the question.

Fix Reuse the block environment inside the smallest fixture that plays its surroundings.

Remember

  • Monitors, coverage, register models and scoreboards come along into the chip; drivers stay behind.
  • is_active, set through the configuration database, decides what an agent builds.
  • Scoreboards must take their expectations from monitors, never from drivers.
  • A virtual sequencer holds a handle for each agent that drives; soc_vsequencer holds four, plus the register model and the bench's doors.

Practice

Report a problem with this page