Difficulty: Medium · Puzzle 2 of 6 · Topic: UVM Phases and Objections
UVM 1.2, timescale 1ns. The test raises an objection, sets a drain time of 50, runs 100 ns of stimulus and drops. A monitor in the same environment prints every 40 ns. At which time does run_phase end, and which monitor lines appear in the log?
class my_test extends uvm_test;
`uvm_component_utils(my_test)
function new(string name, uvm_component parent); super.new(name, parent); endfunction
task run_phase(uvm_phase phase);
phase.raise_objection(this);
phase.phase_done.set_drain_time(this, 50);
#100;
phase.drop_objection(this);
endtask
endclass
class my_mon extends uvm_monitor;
`uvm_component_utils(my_mon)
function new(string name, uvm_component parent); super.new(name, parent); endfunction
task run_phase(uvm_phase phase);
forever begin
#40;
`uvm_info("MON", "alive", UVM_LOW)
end
endtask
endclassThe drop at 100 ns does not end the phase by itself. What does the drain time add, and what happens to forever loops when the phase ends?
1) The last objection is dropped at 100 ns, so the objection count reaches zero then.
2) The 50 ns drain time delays the end of the phase: the phase may only end at 100 + 50 = 150 ns, provided nobody raises an objection again meanwhile.
3) The monitor's forever loop keeps running during the drain, so it still prints at 40, 80 and 120 ns.
4) At 150 ns the run phase ends and the monitor's thread is killed, so no line appears at 160 ns.Answer: run_phase ends at 150 ns; the monitor prints at 40, 80 and 120 ns and not at 160 ns.
Checked by running the code in Verilator 5; the printed output supports the answer above. Hand-written model of the documented UVM 1.2 behaviour in plain SystemVerilog (Verilator), not the UVM library: an objection class that waits the drain time after the count reaches zero, then ends the phase and kills the monitor loop.
The phase does not end at the drop (100 ns) and the monitor is not silent during the drain; it also is not allowed to continue past the end, because a phase ending kills any run_phase thread still running, including forever loops.
If a scoreboard raised a new objection at 130 ns (inside the drain), what happens? Model answer: the count is no longer zero, so the pending end is cancelled and the phase stays open; when that objection is dropped the drain time is applied again from that drop, which is why drain time is per last-drop, not a fixed extension.