UVM Drain Time - The Old Fashioned Way

One of the most useful additions of OVM 2.1 was the objection mechanism. You could raise an objection when starting your main traffic sequence and drop it once it was finished, thus stopping the simulation. Being done with input traffic didn't mean that nothing else would happen from that point as the DUT may have required some additional time to drain any transactions that were still being processed. Setting a drain time added an extra delay from the time that all objections were dropped to the stop of the simulation, making sure that there were no outstanding transactions at that point.

The drain time was usually set in the base test, before the run phase was started. I liked to do it in the end_of_elaboration phase, but any other phase would have worked as well:

class test_base extends ovm_test;
// ...

function void end_of_elaboration();
ovm_test_done.set_drain_time(this, 100ns);
endfunction

// ...
endclass

When UVM was released, it brought another cool addition: multiple run-time phases like reset, main, shutdown, etc. While I must admit I have never really used them myself, they do look very useful for someone doing SoC verification. Sadly, along with them my old friend, the test_done objection, was deprecated in favor of phase specific objections.

The way to do it now is to set the drain time inside the phase task by using the phase argument:

class test_base extends uvm_test;
// ...

task run_phase(uvm_phase phase);
phase.phase_done.set_drain_time(this, 5);
endfunction

// ...
endclass

I don't like this, because I can't just set the drain time in the base test anymore and forget about it. Calling super.run_phase(phase) in subclasses is out of the question for obvious reasons. One could create a dummy method and always call that first; at least this way the value of the drain time would be centralized in one location. There are however problems with this approach. We always have to call this method which means it's very easy to forget to do it. Also, if we want different drain times for each phase we would need multiple such methods. I guess it's back to the drawing board.

While looking around through the UVM base class library (BCL) I noticed that each phase has a singleton associated with it. We can get handles to these singletons in the end_of_elaboration phase and set the drain time there:

class test_base extends uvm_test;
// ...

function void end_of_elaboration_phase(uvm_phase phase);
uvm_phase run_phase = uvm_run_phase::get();
run_phase.phase_done.set_drain_time(this, 5);
endfunction

// ...
endclass

It seems that we're home free, but we're not done just yet. If we try to do the same for the main phase, after setting the drain time it just doesn't' work. After some more experimenting and asking around I found out that the objects we get returned via uvm_*_phase::get() are different that what is passed to the uvm_*_phase(...) methods as the phase argument. Here's a link to the thread in the UVM forums with the explanation - many thanks to kirloy for clearing it up. Applying what we learned gives us this:

class test_base extends uvm_test;
// ...

function void end_of_elaboration_phase(uvm_phase phase);
uvm_phase main_phase = phase.find_by_name("main", 0);
main_phase.phase_done.set_drain_time(this, 10);
endfunction

// ...
endclass

Now we're really done. As usual, the code can be found on the blog's repository. Thanks for reading and stay tuned for more!

Comments