Module 1: SystemVerilog for UVM | Beginner UVM

Interfaces and Clocking Blocks

Learn how SystemVerilog groups DUT signals into reusable interfaces and how clocking blocks make testbench timing explicit and predictable.

Learning objectives

  • Explain why SystemVerilog interfaces are useful in verification.
  • Create an interface that groups related DUT signals.
  • Understand how modports control access to interface signals.
  • Explain the purpose of a clocking block.
  • Use clocking block input and output directions correctly.
  • Understand clocking block skew and why sampling and driving timing matter.
  • Recognize how interfaces and clocking blocks connect to future UVM drivers and monitors.

Step 1: Why verification needs interfaces

A DUT rarely has only one signal. A protocol may contain a clock, reset, address, data, control signals, valid/ready handshakes, status signals, and many other signals.

Without an interface, a testbench component would need to receive many individual signal connections.

input  logic        clk,
input  logic        reset_n,
output logic        valid,
output logic [7:0]  addr,
output logic [31:0] data,
input  logic        ready

As the protocol grows, this becomes difficult to maintain.

A SystemVerilog interface allows related signals to be grouped into one reusable object-like connection.

Big idea: An interface describes the communication signals of a protocol. It creates a single connection point that can be shared by the DUT and verification components.

Step 2: Create a simple interface

Consider a simple bus with a clock, reset, address, data, and read/write control.

interface bus_if(input logic clk);

  logic        reset_n;
  logic        valid;
  logic        write;
  logic [7:0]  addr;
  logic [31:0] data;
  logic        ready;

endinterface

The interface groups all of the bus signals together.

The clock is passed into the interface through the interface declaration:

interface bus_if(input logic clk);

The interface can now be instantiated in the testbench.

Step 3: Connect the interface to the DUT

The interface instance can be connected to the DUT signals.

module tb;

  logic clk;

  bus_if bus(clk);

  my_dut dut (
    .clk     (clk),
    .reset_n (bus.reset_n),
    .valid   (bus.valid),
    .write   (bus.write),
    .addr    (bus.addr),
    .data    (bus.data),
    .ready   (bus.ready)
  );

endmodule

The important point is that the testbench now has one object, bus, containing the protocol signals.

Instead of passing every signal independently to a verification component, the interface can later be passed as a single connection.

Step 4: Why interfaces improve testbenches

Interfaces provide several important benefits:

  • Grouping: Related signals are kept together.
  • Reusability: The same interface can be used by different testbenches.
  • Maintainability: Protocol changes can be handled in one place.
  • Cleaner connections: Components can work with a protocol interface instead of dozens of individual signals.
  • Timing organization: Clocking blocks can be placed inside the interface.
Verification mindset: An interface is more than a convenient bundle of signals. It creates a reusable abstraction around a protocol connection.

Step 5: What is a modport?

An interface contains signals, but different users of the interface may need different access directions.

For example, a driver may drive addr, data, and valid, while a monitor only needs to observe them.

A modport defines how a particular user is allowed to access the interface.

interface bus_if(input logic clk);

  logic        reset_n;
  logic        valid;
  logic        write;
  logic [7:0]  addr;
  logic [31:0] data;
  logic        ready;

  modport DUT (
    input  clk,
    input  reset_n,
    input  valid,
    input  write,
    input  addr,
    input  data,
    output ready
  );

  modport DRIVER (
    input  clk,
    input  reset_n,
    input  ready,
    output valid,
    output write,
    output addr,
    output data
  );

  modport MONITOR (
    input clk,
    input reset_n,
    input valid,
    input write,
    input addr,
    input data,
    input ready
  );

endinterface

The same interface can therefore provide different views for different users.

Step 6: Why modports matter in verification

Think about three different participants:

  • The DUT consumes and produces protocol signals.
  • The driver generates stimulus.
  • The monitor observes what happened.

These participants should not necessarily have identical access to every signal.

driver   -> bus_if.DRIVER
monitor  -> bus_if.MONITOR
DUT      -> bus_if.DUT
Common mistake: Thinking that a modport creates a new interface. It does not. A modport provides a restricted view of the existing interface.

Step 7: The timing problem

Grouping signals solves one problem, but verification has another important problem: timing.

Suppose the DUT samples valid, addr, and data on the rising edge of clk.

always_ff @(posedge clk) begin
  if (valid && ready) begin
    // DUT samples transaction
  end
end

When should the testbench drive those signals?

When should the monitor sample them?

If the testbench and DUT access the same signals at nearly the same simulation time, race conditions can occur.

Important: A testbench that only looks logically correct can still have simulation race conditions if its signal sampling and driving occur at the wrong time.

Step 8: What is a clocking block?

A clocking block defines when a testbench samples and drives signals relative to a clock.

This allows the testbench to describe its timing relationship with the DUT explicitly.

clocking cb @(posedge clk);

  input  ready;
  input  reset_n;

  output valid;
  output write;
  output addr;
  output data;

endclocking

The clocking block is synchronized to the rising edge of clk.

The signals are then accessed through the clocking block rather than directly through the interface when using clocking-block semantics.

Step 9: Clocking block inputs and outputs

The direction inside a clocking block describes the relationship between the testbench and the clocking block.

clocking cb @(posedge clk);

  input  ready;
  input  reset_n;

  output valid;
  output addr;
  output data;

endclocking

In this example:

  • input signals are sampled by the testbench through the clocking block.
  • output signals are driven by the testbench through the clocking block.
Do not confuse directions: Clocking-block directions describe the testbench's view of the signal. They are not simply the same thing as the DUT's module port directions.

Step 10: Clocking block skew

A clocking block can specify when signals are sampled or driven relative to the clock event.

clocking cb @(posedge clk);

  input  #1step ready;
  output #1step valid;

endclocking

The skew controls the timing relationship between the clock event and the signal access performed through the clocking block.

You do not need to memorize every skew rule yet. The important concept is:

Clocking blocks make testbench timing explicit. They help separate "the clock edge occurred" from exactly when the testbench samples or drives signals around that edge.

Step 11: Use a clocking block in a driver-style task

Consider a simple driver operation.

task drive_transfer(
  bit        write,
  bit [7:0]  addr,
  bit [31:0] data
);

  @(bus.cb);

  bus.cb.valid <= 1;
  bus.cb.write <= write;
  bus.cb.addr  <= addr;
  bus.cb.data  <= data;

endtask

The driver waits for the clocking event and then drives the signals through the clocking block.

This is much clearer than scattering arbitrary delays throughout the testbench.

Step 12: Use a clocking block in a monitor

A monitor can also use the clocking block to sample signals.

task monitor_transfer();

  @(bus.cb);

  if (bus.cb.valid && bus.cb.ready) begin

    $display(
      "Observed addr=%0h data=%0h",
      bus.cb.addr,
      bus.cb.data
    );

  end

endtask

The monitor waits for the clocking event and samples the protocol through the clocking block.

This creates a clean separation:

  • Interface: defines the protocol signals.
  • Clocking block: defines the testbench timing view.
  • Driver: produces stimulus.
  • Monitor: observes protocol activity.

Step 13: Put the clocking block inside the interface

A common verification pattern is to keep the clocking block inside the interface itself.

interface bus_if(input logic clk);

  logic        reset_n;
  logic        valid;
  logic        write;
  logic [7:0]  addr;
  logic [31:0] data;
  logic        ready;

  clocking cb @(posedge clk);

    input  reset_n;
    input  ready;

    output valid;
    output write;
    output addr;
    output data;

  endclocking

endinterface

Now the interface contains both:

  1. The protocol signals.
  2. The timing definition used by the testbench.

This is a powerful abstraction for verification environments.

Step 14: Interface vs. clocking block

These two concepts are related, but they solve different problems.

Concept Main purpose
Interface Groups related DUT and testbench signals.
Modport Defines a particular user's access directions.
Clocking block Defines testbench sampling and driving timing.
Clock Provides the timing reference for synchronous behavior.
Easy memory trick:
Interface = what signals exist
Modport = who can access them
Clocking block = when the testbench interacts with them

Step 15: A complete small example

Put the concepts together in a small bus interface.

interface bus_if(input logic clk);

  logic        reset_n;
  logic        valid;
  logic        write;
  logic [7:0]  addr;
  logic [31:0] data;
  logic        ready;

  clocking cb @(posedge clk);

    input  #1step reset_n;
    input  #1step ready;

    output #1step valid;
    output #1step write;
    output #1step addr;
    output #1step data;

  endclocking

  modport DRIVER (
    clocking cb
  );

  modport MONITOR (
    clocking cb
  );

endinterface

The driver and monitor now have a clearly defined timing-oriented view of the same interface.

This pattern is particularly useful when building reusable verification components.

Step 16: How this connects to UVM

You have not learned UVM drivers and monitors yet, but you now have the SystemVerilog foundation needed to understand them.

Later in the course, a UVM driver will receive a transaction object and convert it into signal-level activity.

sequence item
      |
      v
UVM driver
      |
      v
virtual interface
      |
      v
clocking block
      |
      v
DUT signals

A monitor works in the opposite direction:

DUT signals
      |
      v
clocking block
      |
      v
UVM monitor
      |
      v
transaction object
Important: You will study virtual interfaces in detail later. For now, understand the architecture: the SystemVerilog interface provides the signal-level connection, while UVM components use that connection to interact with the DUT.

Step 17: Common mistakes

Mistake 1: Treating an interface as a UVM component

An interface is a SystemVerilog construct. It is not a uvm_component and does not participate in UVM's component hierarchy.

Mistake 2: Confusing interface directions with clocking directions

A module port might say input or output from the DUT's perspective. A clocking block describes the testbench's interaction with those signals.

Mistake 3: Ignoring timing

A monitor that samples a signal at the wrong time can observe incorrect or unstable values even when the DUT itself is correct.

Mistake 4: Using arbitrary delays everywhere

Code such as #5 may appear to work, but it often hides the real protocol timing. Prefer synchronization to meaningful events such as clock edges and protocol handshakes.

Mistake 5: Making the interface too generic

An interface should represent a meaningful protocol or connection. Avoid creating one giant interface containing unrelated signals from the entire DUT.

Step 18: Debugging timing problems

When a verification environment produces unexpected results, inspect the waveform before changing the driver or monitor.

Ask these questions:

  1. At which clock edge should the DUT sample the transaction?
  2. When does the driver change the signals?
  3. When does the monitor sample the signals?
  4. Are the clocking block directions correct?
  5. Is the input/output skew appropriate?
  6. Is the monitor observing the same transaction that the DUT received?
Debugging rule: Before assuming that the DUT is wrong, verify that the testbench drove and sampled the protocol at the intended times.

Try it yourself

Build a simple SystemVerilog interface for a valid/ready protocol.

  1. Create signals for clk, reset_n, valid, ready, and data.
  2. Create a clocking block synchronized to posedge clk.
  3. Declare valid and data as clocking-block outputs.
  4. Declare ready and reset_n as clocking-block inputs.
  5. Create a driver-style task that waits for the clocking event and drives a data value.
  6. Create a monitor-style task that waits for the clocking event and prints the data when valid && ready is true.
  7. Run the testbench and inspect the waveform.

Bonus: Add DRIVER and MONITOR modports and explain what access each modport provides.

Quick check

  1. What problem does a SystemVerilog interface solve?
  2. What is the purpose of a modport?
  3. What problem does a clocking block solve?
  4. What does @(posedge clk) synchronize to?
  5. What is the difference between an interface and a clocking block?
  6. Why can a testbench have a race condition even when its logic is correct?
  7. In a clocking block, what does an input signal represent from the testbench perspective?
  8. Why are clocking blocks useful for monitors and drivers?
Show answers
  1. It groups related signals into a reusable protocol connection.
  2. It defines a particular user's access directions for an interface.
  3. It defines when the testbench samples and drives signals relative to a clock.
  4. The rising edge of clk.
  5. The interface groups and provides the signals; the clocking block defines the testbench's timing relationship with those signals.
  6. The testbench and DUT may access signals at conflicting simulation times or scheduling regions.
  7. It is a signal that the testbench samples through the clocking block.
  8. They provide a consistent and explicit timing model for driving and sampling protocol signals.

Key takeaways

  • An interface groups related DUT and testbench signals into a reusable connection.
  • A modport provides a specific access view of an interface.
  • A clocking block defines how the testbench samples and drives signals relative to a clock.
  • Correct timing is essential for reliable verification and avoiding race conditions.
  • Drivers typically drive DUT signals, while monitors observe them.
  • Interfaces and clocking blocks are SystemVerilog constructs; they are not UVM components.
  • Understanding interfaces and timing is essential before learning UVM drivers, monitors, and virtual interfaces.