Monday, September 25, 2017

Formal Verification

Formal verification is a technique used in different stages in ASIC project life cycle like front end verification, Logic Synthesis, Post Routing Checks and also for ECOs. But when you go deep into it, the formal verification used for verifying RTLs is entirely different from others. There are different formal techniques available as follows
Formal Equivalence Checking (LEC or logic equivalence checking)
Formal Property Checking.


Formal Equivalence can be used to verify if following models are equivalent:


1) RTL Design & Synthesized Netlist (Gate level model)
2) RTL Design & Reference Model
3) Two RTL designs
4) Two Gate level models
5) Two reference models


Tool Used for formal Verification - Jasper Gold 

Friday, September 15, 2017

Setup and hold time Questionaire


Significance of negative setup and hold time
What do you mean by negative setup and hold time i.e what happens if hold time is negative or setup time is negative. Does -ve setup or hold have any advantage ?

Setup times and hold times describe the limits relative to the active clock edge of a "window" within which the input data must be valid for the data to be reliably recognized. The diagram below (you can ignore the bottom Q output part) shows the situation for assumed positive hold and setup times, but you can imagine them negative.

If setup time is negative, then the absolute latest that the data can become valid is actually after the active clock edge, Obviously the hold time must be positive and of greater magnitude or there would be no window for data validity.

If the hold time is negative, then the absolute earliest the data no longer needs to be valid is before the active clock edge, so it can change just before the clock edge and the previous value will be correctly recognized. Obviously, the setup time must be positive and of greater magnitude or there would be no window.

As to possible advantages- think about the situation where you are trying to increase clock frequency as much as possible.

For Hold Time > If the difference between the data path and the clock path is negative, then a timing violation has occurred.

For Setup Time > If the difference between the clock path and the data path is negative, then a timing violation has occurred.

By negative setup and hold times do you mean positive slack time?
Positive slack means the data arrival times are not violating the timing of the circuit. It basically tells you how much timing you have to lose and still be acceptable.

slack time, setup time, hold time

A zero setup time means that the time for the data to propagate within the component and load into the latch is less than the time for the clock to propagate and trigger the latch.

A negative setup or hold time means that there is an even larger difference in path delays, so that even if the data is sent later than the clock (for setup time), it still arrives at the latch first.

slack is different from this because it is the required time - arrival time....


Say an FF as setup time of 1ns.(positive 1ns)
Now re-design this FF, and put a buffer in the clock path with a propagation delay of 2 ns.
Now the setup time of this redesigned FF would be -1ns (negative).

So if the clock is delayed w.r.t data, then you can see negative setup times.


Re: Negative setup and hold time
Negative setup time flops are used on hard-to-meet data paths.
Negative hold time flops already have an "inbuilt hold buffer" embedded and hold closure is eased.


What is metastability?
Whenever there are setup and hold time violations in any flip-flop, it enters a state where its output is unpredictable: this state is known as metastable state (quasi stable state); at the end of metastable state, the flip-flop settles down to either '1' or '0'. This whole process is known as metastability. In the figure below Tsu is the setup time and Th is the hold time. Whenever the input signal D does not meet the Tsu and Th of the given D flip-flop, metastability occurs.

When a flip-flop is in metastable state, its output oscillate between '0' and '1' as shown in the figure below (here the flip-flop output settles down to '0') . How long it takes to settle down, depends on the technology of the flip-flop.

If we look deep inside of the flip-flop we see that the quasi-stable state is reached when the flip-flop setup and hold times are violated. Assuming the use of a positive edge triggered "D" type flip-flop, when the rising edge of the flip-flop clock occurs at a point in time when the D input to the flip-flop is causing its master latch to transition, the flip-flop is highly likely to end up in a quasi-stable state. This rising clock causes the master latch to try to capture its current value while the slave latch is opened allowing the Q output to follow the "latched" value of the master. The most perfectly "caught" quasi-stable state (on the very top of the hill) results in the longest time required for the flip-flop to resolve itself to one of the stable states.


How long does it stay in this state?
The relative stability of states shown in the figure above shows that the logic 0 and logic 1 states (being at the base of the hill) are much more stable than the somewhat stable state at the top of the hill. In theory, a flip-flop in this quasi-stable hilltop state could remain there indefinitely but in reality it won't. Just as the slightest air current would eventually cause a ball on the illustrated hill to roll down one side or the other, thermal and induced noise will jostle the state of the flip-flop causing it to move from the quasi-stable state into either the logic 0 or logic 1 state.



What are the cases in which metastability occurs?
As we have seen that whenever setup and hold violation time occurs, metastability occurs, so we have to see when signals violate this timing requirement:


When the input signal is an asynchronous signal.
When the clock skew/slew is too much (rise and fall time are more than the tolerable values).
When interfacing two domains operating at two different frequencies or at the same frequency but with different phase.
When the combinational delay is such that flip-flop data input changes in the critical window (setup+hold window) 


What is MTBF?
MTBF is Mean time between failure, what does that mean? Well MTBF gives us information on how often a particular element will fail or in other words, it gives the average time interval between two successive failures. The figure below shows a typical MTBF of a flip-flop and also it gives the MTBF equation. I am not looking here to derive MTBF equation :-)


So how do I avoid metastability?
In reality, one cannot avoid metastability and increased clock-to-Q delays in synchronizing asynchronous inputs, without the use of tricky self-timed circuits. So a more appropriate question might be "How do I tolerate metastability?"


In the simplest case, designers can tolerate metastability by making sure the clock period is long enough to allow for the resolution of quasi-stable states and for the delay of whatever logic may be in the path to the next flip-flop. This approach, while simple, is rarely practical given the performance requirements of most modern designs.



The most common way to tolerate metastability is to add one or more successive synchronizing flip-flops to the synchronizer. This approach allows for an entire clock period (except for the setup time of the second flip-flop) for metastable events in the first synchronizing flip-flop to resolve themselves. This does, however, increase the latency in the synchronous logic's observation of input changes.


Neither of these approaches can guarantee that metastability cannot pass through the synchronizer; they simply reduce the probability to practical levels.

In quantitative terms, if the Mean Time Between Failure (MTBF) of a particular flip-flop in the context of a given clock rate and input transition rate is 33.33 seconds then the MTBF of two such flip-flops used to synchronize the input would be (33.33* 33.33) = 18.514 Minutes. Well I have taken the worst flip-flop ever designed in history of man kind :-). The figure below shows how to connect two flip-flops in series to achieve this and also the resultant MTBF.

Normally,
We can use a metastable hardened flip-flop
Cascade two or three D-Flip-Flops (two or three stages synchronizer).

Sunday, September 10, 2017

Randomizations and constraint overriding in SV : Part2

Pre_randomize and Post_randomize  :

1. Every class contains pre_randomize() and post_randomize() methods
2. which are automatically called by randomize() before and after computing new random values.
3. When randomize() is called it invokes three methods in below order :
    i. pre_randomize()
    ii. randomize()
    ii. post_randomize()


Note : post_randomize() will be only invoked if the randomize() was successful 

These methods can be used as hooks for the user to perform operations
for example : setting initial values and performing functions after assigning random variables.

///////////////////////////////////////
program pre_post_15;
class simple;
function void pre_randomize;
$display(" PRE_RANDOMIZATION ");
endfunction

function void post_randomize;
$display(" POST_RANDOMIZATION ");
endfunction

endclass
simple obj = new();
initial
void'(obj.randomize());
endprogram
////////////////////////////////////////////////////////


Output:

PRE_RANDOMIZATION
POST_RANDOMIZATION
$finish at simulation time 0
V C S S i m u l a t i o n R e p o r t

------------------------------------------------------------------------------------------------------------
NowI have changed a function with randomize in place of pre_randomize :
VCS compiler has given below error :

The user declared method 'randomize' in class 'simple' clashes with built-in
method name. Please change the name of the user declared method/identifier.

4. Overriding of pre_randomize and post_randomize functions is allowed by child class.


5. The pre_randomize() and post_randomize() methods are not virtual. However, because they are automatically called by the randomize() method, which is virtual, they appear to behave as virtual methods.


Question on constraint Overriding :

Can we override constraints of base class in extended class, by defining a new constraint with the same name in extended class.

In the code below, there are two constraint in "base" class for variable "a" & "b".

In "extended" class which is extended from base, I defined two more constraint which are in conflict with the constraint in base class. For variable "a" constraint I used the same name as in base class, and for "b" I used a different name.



When I randomized the extended class object, I expected randomization should fail for both the constraint in extended class. But the randomization only fail for the conflicting constraint with different name in base and extended class.
module junk () ;
   class base;
      rand bit [15:0] a,b;
      
      function new();
      endfunction // new
      
      constraint ct_a {a inside {[0:9]};} 
      constraint ct_b {b inside {[10:19]};}
    endclass // base
   
   class extended extends base;
      function new();
      endfunction // new

      constraint ct_a       {a inside {[10:19]};}
      constraint ct_b_new   {b inside {[0:9]};}
   endclass // extended
   
   initial begin
      extended extended_obj;
      extended_obj = new();

      if(!extended_obj.randomize()) $display("Randomization Failed");
   end
endmodule // junk


Answer :
1. That's expected as per LRM. With same names, you are "overriding" the base constraint and hence is not conflicting.

2. if u use the same name in extended class that means you are overriding that constraint in the derived class. so the constraint in the base class no more work for the extended class. so for 'a' there is no conflict and the constraint is easily overwritten in extended class.

Note : here we are randomizing the object of extended class

where as for 'b' both the constraints are working so conflicts occurs in that case.



Monday, September 4, 2017

uvm_phases and flow - Interview Presparation

From the starting of simulation till the end of the simulation:

Why Phases Concept : 
1. In order to have a consistent Testbench flow, UVM introduces “Phases” to synchronize major functional steps a simulation runs through.
2. These steps are sequential in nature which are executed in the following order:

Build Phases:
Where the Testbench is constructed, connected and configured.
Run-time Phases:
Stimulus generation & time-consuming simulation takes place here.
Clean up Phases:
Here the Test results are collected and reported.

We’ll see more details of these 3 Phases in the upcoming section of this post.

1. We know that UVM environment is built of static components those are derived from the UVM base class i.e. uvm_component which contains a number of virtual methods. 
2. These virtual methods support the UVM Phasing mechanism,
3. So UVM phasing mechanism is only for uvm_components
4. Hence a verification component can be developed in isolation since there is an established understanding of what is expected to happen in each of the execution phases.



Diagram 1: UVM Phases

Here we can see 3 groups of Phases which are briefly described as well.
Build Phases group contains 3 sub-phases
Run Phases group contains 13 sub-phases
Cleanup Phases group comprises of 4 sub-phases
How UVM Phasing is triggered?:
1. To start a UVM Testbench, the run_test() method has to be called from the static part of the Testbench. 
2. It is usually called from within an initial block in the top level module of the Testbench.
// Top level Testbench 
module module top_tb; 
// UVM start up: 
initial begin 
uvm_config_db #(virtual bus_if)::set(null, "*", "BUS_vif" , BUS); 
run_test("bidirect_bus_test"); 
end 
endmodule: top_tb 
3. Once the run_test() method is called, it constructs the root component of the UVM environment 
4. then triggers/initiates the UVM Phasing process. 
5. The run_test() method can be passed with a string argument
6.  In the above code argument is “bidirect_bus_test”, to define the default type name which is used as the root node of the Testbench Hierarchy.
7. In addition, run_test() method also checks for a command line plusarg called UVM_TESTNAME and uses that plusarg string to lookup a factory registered uvm_component to override any default type name.
8. Hence to execute the “bidirect_bus_test” using command line plusarg, we’ve to use the following command line:
% <simulator executable> +UVM_TESTNAME=bidirect_bus_test
9. about uvm_test_top and uvm_root (to be updated)


What each of UVM Phase Performs?:
Lets detail out each of the UVM Phase/Sub-Phase with respect to the activities being performed during their execution:
1) Build Phase:
The build phases are executed at the start of the UVM Testbench simulation and their overall purpose is to construct, configure and connect the Testbench component hierarchy. 
All the build phase methods are functions and therefore execute in zero simulation time.

build:
i) Once the UVM Testbench root node component is constructed, the build phase starts to execute. 
ii) It constructs the testbench component hierarchy in a top-down manner. 
iii) During the build phase, uvm_components are indirectly constructed using the UVM factory.

connect:i) The connect phase is used to make TLM connections between components or to assign handles to testbench resources. 
ii) It has to occur after the build method so that Testbench component hierarchy could be in place and it works from the bottom-up of the hierarchy upwards.

end_of_elaboration:
i) The end_of_elaboration phase is used to make any final adjustments to the structure, configuration or connectivity of the Testbench before simulation starts. 
ii) Its implementation can assume that the Testbench component hierarchy and inter-connectivity is in place. This phase executes bottom up.

start_of_simulation:The start_of_simulation phase is a function which occurs before the time consuming part (run-phase) of the testbench begins. It is intended to be used for displaying banners; Testbench topology; or configuration information. It is called in bottom up order.

2) Run Phase:
i) The UVM Testbench stimulus is generated and executed during the run time phases. 
ii) Run phase was present in OVM as well but additional other phases were added to UVM to give finer run-time granularity for tests, scoreboard and other components.
iii) The run phase occurs after the start_of_simulation phase and is used for the stimulus generation and checking activities of the Testbench. 
iv) The run phase is implemented as a task, and all uvm_component run tasks are executed in parallel. 
v) Transactors such as driver and monitor will nearly always use this phase.

pre_reset:
pre_reset phase starts at the same time as the run phase. Its purpose is to take care of any activity that should occur before the reset. E.g. waiting for a power signal to go active.
reset:
As the name indicates, reset phase is especially for DUT or Interface specific reset behaviour. This phase would be used to generate reset to put the DUT/Interface into a default state.
post_reset:
This phase is intended for any activity required just after the reset phase.


pre_configure:
This phase is intended for anything that is required to prepare for the DUT configuration process after the DUT is out of reset.
configure:
configure phase is used to put the DUT into a known state before the stimulus could be applied to the DUT. For example – programming the control registers of the device for a particular test scenario.
post_configure:
This phase is intended to wait for the effect of the configuration to propagate through the DUT.
pre_main:pre_main is used to ensure that all the components needed to generate the stimulus are ready to do so.
main:
the main phase is where the stimulus specified by the Test case is generated and applied to the DUT. It completes in two conditions: One is the stimulus gets exhausted and another is when a timeout occurs. Sequences are started in this phase to generate the stimulus.
post_main:
Used for any final act after the main phase.
pre_shutdown: This phase acts as a buffer to apply any stimulus before the shutdown phase starts.
shutdown:
The shutdown phase is to ensure that the effect of stimulus generated during the main phase has propagated through the DUT and that the resultant data has drained away. It might also be used to execute the time-consuming sequences that read status registers.
post_shutdown:
post_shutdown is intended for any final activity before exiting the run phase. After this, UVM Testbench starts the cleanup phase.

3) Clean up Phase:
The cleanup phases are used to extract information from Scoreboards and Functional Coverage Monitors to determine whether the test case has passed and/or reached its coverage goals. The cleanup phases are implemented as functions and therefore take zero time to execute. They work from the bottom to the top of the component hierarchy.

extract:
The extract phase is used to retrieve and process information from Scoreboards and Functional Coverage Monitors. This may include the calculation of statistical information used by the report phase. This phase is usually used by Analysis side components.
check:
This phase is also used by the Analysis Components. This phase is used to check if the DUT behaved correctly and to find any error that may have occurred during the stimulus execution.
report:
The report phase is used to display the results of the simulation to the standard output or to write the results to file. This phase is usually used by Analysis Components.
final:
The final phase is used to complete any other outstanding actions that the Testbench has not already completed.

So these are all the different phases through which a Standard UVM Testbench runs through to generate a reset, doing configuration, stimulus generation & performing simulation and finally report generation.
so these were all different phases a UVM static component like Driver or Monitor etc. & dynamic component like Sequences goes through during life time of UVM Simulation.

//more about dynamic and static components (to be updated)






Short Notes :
1. build - Depending on configuration and factory settings, create and configure additional component hierarchies.
2. connect - Connect ports, exports, and implementations (imps), TLM ports connection
3. end_of_elaboration - Perform final configuration, topology, connection,
and other integrity checks.
4. start_of_simulation - Do pre-run activities such as printing banners, pre-loading memories, etc.
5. run - Most verification is done in this time-consuming phase. May fork other processes. Phase ends when global_stop_request is called explicitly or using phase drop objection mechanism
i) Time-consuming phase, so we can use task here
ii) run tasks are executed in parallel
iii) 12 sub-phases added in parallel with run_phase
iv) driver and monitor use run_phase for sure
6. extract - Collect information from the run in preparation for checking
7. check - Check simulation results against expected outcome.
8. report - Report simulation results.

uvm_phase is a base class which defines everything about the phase like behavior, state or context.

uvm_void > uvm_object > uvm_phase (class hierarchy)

Constructor : new, get_phase_type


UVM flow :
  1. We call run_test in tb_top, which calls the run_test task of the uvm_root class.
  2. The uvm_root calls the m_run_phases task of the uvm_phase class.
  3. For each phase, the execute_phase task is called.
  4. If the phase is a top-down or bottom-up phase, exec_func is called for each component.
  5. For example, the exec_func calls the build_phase function of each component.
  6. If the phase is a task phase, exec_task is called for each component.
  7. For example, the exec_task calls the main_phase task of each component.
  8. The uvm_phase checks if any objections are raised by the components. The phase_done is the uvm_objection object that the uvm_phase keeps track of the number of objections with. When we called phase.raise_objection() from inside the run_phase of the test phase_done.raise_objection() is called in the uvm_phase under the hood.
  9. If no objection is raised, all the processes started by the exec_task are killed. In other words, unless an objection is raised, the phase is immediately killed!
  10. The steps 3 to 9 repeat until all phases are executed.
check for more details :
http://cluelogic.com/2014/08/uvm-tutorial-for-candy-lovers-phasing/



Thanks!  feedback/suggestions/edit_suggestions are most welcome

source of info: http://www.learnuvmverification.com/index.php/2016/04/29/uvm-phasing and uvm class reference manual and my understanding.




Ethernet and more

Ethernet is a protocol under IEEE 802.33 standard User Datagram Protocol (UDP) UDP is a connectionless transport protocol. I...