ibex icon indicating copy to clipboard operation
ibex copied to clipboard

[dv] Add clocking blocks to icache UVM code

Open rswarbrick opened this issue 6 years ago • 8 comments

See discussion on PR #761, in particular these comments.

Sri and Udi have suggested that the code would be better if the interface included clocking blocks. Suggested code:

clocking driver_cb @(posedge clk_i);
  output req;
  output branch;
  output branch_addr;
  output ready;
  output enable;
  output invalidate;
endclocking

clocking monitor_cb @(posedge clk_i);
  input valid;
  input rdata;
  input addr;
  input err;
  input err_plus_2;
  input busy;
endclocking

rswarbrick avatar Apr 15 '20 09:04 rswarbrick

For example, some code in the driver currently looks like this:

    // Assert ready and then wait until valid
    cfg.vif.ready <= 1'b1;
    while (1'b1) begin
      @(posedge cfg.vif.clk);
      if (cfg.vif.valid)
        break;
    end

This reads from valid (driven by the DUT, so in monitor_cb above) and writes to ready. They share a clock. Is two clocking blocks the right way to structure this? I'd appreciate some guidance!

rswarbrick avatar Apr 15 '20 09:04 rswarbrick

@udinator, @sriyerg: Could you give me some advice about how this should look?

rswarbrick avatar Apr 15 '20 09:04 rswarbrick

Reading Cummings's paper more carefully, I think I have an idea of how this would work.

Use a single clocking block, specifying default output negedge to make it more obvious what's going on in dumped waves. The code above would be:

cfg.vif.cb.ready = 1'b1;
while (1'b1) begin
  @(cfg.vif.cb);
  if (cfg.vif.cb.valid)
    break;
end

Suppose that there's a clock with a posedge every 100ns and let's pretend that #1step is 1ns. Then I think a sample execution would look like

Time (ns) Event
0 cfg.vif.cb.ready = 1'b1 executed
51 ready = 1 actually happens
... ...
700 valid = 1 (set by an @(posedge clk) block in DUT)
799 valid sampled by cb (#1step before time step at 800ns)
800 break

Does that make sense? If so, I propose to use a single clocking block and I'll push up a PR tomorrow. If not, can you let me know what would be better?

rswarbrick avatar Apr 15 '20 11:04 rswarbrick

Also, should this be one clocking block with inout items, or two clocking blocks, one for the driver and one for the monitor? The latter means you need fewer inouts, but it feels a bit icky because the interface class then gets some monitor-specific and driver-specific code. Or is there another trick possible?

rswarbrick avatar Apr 15 '20 14:04 rswarbrick

I'll defer to Sri on the usage of default output negedge, I'm not quite sure how necessary this would be here. After looking at this a bit more, I think that using a single clocking block would be fine as well, I don't think we would need any inout signals here. If you want to enforce different timing requirements on signals in the "monitor" and "driver" set, then it's probably better to use two clocking blocks (moving valid into the driver block since it's part of the driver protocol) to have some separation between the two sets of signals, otherwise I'd be fine with just a single block. @sriyerg what do you think?

udinator avatar Apr 16 '20 02:04 udinator

  • I don't think here is any need to add extra skews to the clocking block, unless the DUT is timing sensitive.
  • Prefer N+1 clocking blocks (at least), where N is the number of flavors of drivers the agent has, and 1 for the monitor. So just 2 in your case.
  • Refrain from inouts - the purpose is to also make the port list view clear (see TileLink interface example below with 2 flavors of drivers, to mimic host or a device, in addition to the monitor's view, which is input-only).
  • I wouldn't consider clocking block as being driver code or monitor code specific, since they are just providing a view of the port list.
  • This is a very common way of writing SV interfaces.
  • Here's the TileLink interface as an example - https://github.com/lowRISC/opentitan/blob/master/hw/dv/sv/tl_agent/tl_if.sv
  • If you go one level up, there are some other agents as well.

The two clocking blocks would look something like this:

 // Used exclusively by the driver to access the port list it is driving and sampling. 
 clocking driver_cb @(posedge clk);
   output req;
   output branch;
   output branch_addr;
   output ready;
   input  valid;
   input  rdata;
   input  addr;
   input  err;
   input  err_plus2;
   output enable;
   output invalidate;
   input  busy;
 endclocking

 // Used exclusively by the monitor to access the port list it is sampling.
 clocking monitor_cb @(posedge clk);
   input  req;
   input  branch;
   input  branch_addr;
   input  ready;
   input  valid;
   input  rdata;
   input  addr;
   input  err;
   input  err_plus2;
   input  enable;
   input  invalidate;
   input  busy;
 endclocking

Yes, the full set of signals is replicated in both clocking blocks, because again, its just a view of the port list (what ports are allowed to be driven and what ports are allowed to be sampled from that clocking block). By limiting the driver and monitor to only refer to signals from clocking blocks, you also get that implicit check (for example, if driver drives an input signal accidentally, it will throw an error at compile-time).

sriyerg avatar Apr 16 '20 06:04 sriyerg

Right, understood. I'll write something for the core agent today and push it up.

rswarbrick avatar Apr 16 '20 08:04 rswarbrick

Oops, this got done with #786.

rswarbrick avatar May 12 '20 11:05 rswarbrick