Wednesday, February 24, 2016

randomization int overflow

The scenario is to randomize a dynamic array with sum=10 and all the elements should be non-zero. The below code should do that but the simulator is not showing right results (i.e elements hold very high values but sum is 10).
Whereas if you use the constraint “_split_arr[i] inside {[1:init_num]};”, it is showing the right results.

module test_randomize;
int unsigned split_arr[];
  
initial begin
//  repeat(10)
  split_randomly(10,split_arr);
end
// splits a number randomly
   function split_randomly(int init_num, ref int unsigned _split_arr[]);
      int num_of_parts;
      num_of_parts = $urandom_range(6, 2);
      std::randomize(_split_arr) with {
         _split_arr.size() == num_of_parts;
         foreach(_split_arr[i]) {
            _split_arr[i] > 0;
//            _split_arr[i] inside {[1:init_num]};
         }
         _split_arr.sum()  == init_num;
      };

      $display("_split_arr.size()=%0d sum=%0d", _split_arr.size(), _split_arr.sum());
         foreach(_split_arr[i])
      $display("_split_arr[%0d]=%0d", i, _split_arr[i]);
   endfunction : split_randomly


endmodule


Results:-
Compiler version J-2014.12-SP2; Runtime version J-2014.12-SP2;  Feb 24 15:40 2016
_split_arr.size()=5 sum=10
_split_arr[0]=819246108
_split_arr[1]=2362606585
_split_arr[2]=3932011010
_split_arr[3]=3575085304
_split_arr[4]=2195952891

           V C S   S i m u l a t i o n   R e p o r t

How does it possible to have big values but their sum is 10 ?

Analysis:-
The problem is overflowing 32 bit value. Randomization adds all int value and does not check overflow, so as long as the final value's 32 bit is 10, it thinks its good and when limiting each number, it gives whats desired. 

We have to be careful with variable bit width when sum() is used in constraints. 

Wednesday, February 17, 2016

another cmdline example to avoid script


Below are the list of perf numbers for different configurations. I want to collect the numbers for 1 interface, ncb_dly 0 and sort the numbers for different pkt sizes.  Just yet another example of egrep-awk-sort together.

[tgunasekaran@cahw-vnc7 ]$ egrep "# of INTF: 1" perf_metrics_overall.csv 
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  1024, # of CQ: 1, 116.302435 , 14.197075
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  1024, # of CQ: 1, 115.146584 , 14.056803
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  128, # of CQ: 1, 79.477399 , 77.614647
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  128, # of CQ: 1, 79.264892 , 77.407122
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  1536, # of CQ: 1, 119.433400 , 9.720648
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  1536, # of CQ: 1, 119.390089 , 9.715990
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  2048, # of CQ: 1, 116.241915 , 7.095024
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  2048, # of CQ: 1, 115.647429 , 7.061334
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  256, # of CQ: 1, 97.043759 , 47.422623
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  256, # of CQ: 1, 97.059819 , 47.392490
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  4096, # of CQ: 1, 122.165888 , 3.728207
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  4096, # of CQ: 1, 121.941492 , 3.721359
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  512, # of CQ: 1, 109.078867 , 26.695706
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  512, # of CQ: 1, 109.205821 , 26.661578
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  64, # of CQ: 1, 46.763638 , 91.335230
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  64, # of CQ: 1, 46.447426 , 90.717629
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  8192, # of CQ: 1, 123.508163 , 1.884585
# of INTF: 1, NCB_DLY: 300, PKT_SZ:  8192, # of CQ: 1, 123.555021 , 1.885326

[tgunasekaran@cahw-vnc7 ]$ egrep "# of INTF: 1" perf_metrics_overall.csv | egrep "NCB_DLY: 0" 
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  1024, # of CQ: 1, 116.302435 , 14.197075
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  128, # of CQ: 1, 79.477399 , 77.614647
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  1536, # of CQ: 1, 119.433400 , 9.720648
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  2048, # of CQ: 1, 116.241915 , 7.095024
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  256, # of CQ: 1, 97.043759 , 47.422623
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  4096, # of CQ: 1, 122.165888 , 3.728207
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  512, # of CQ: 1, 109.078867 , 26.695706
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  64, # of CQ: 1, 46.763638 , 91.335230
# of INTF: 1, NCB_DLY: 0, PKT_SZ:  8192, # of CQ: 1, 123.508163 , 1.884585


[tgunasekaran@cahw-vnc7 ]$ egrep "# of INTF: 1" perf_metrics_overall.csv | egrep "NCB_DLY: 0" | awk '{print $8,$13,$15}'
1024, 116.302435 14.197075
128, 79.477399 77.614647
1536, 119.433400 9.720648
2048, 116.241915 7.095024
256, 97.043759 47.422623
4096, 122.165888 3.728207
512, 109.078867 26.695706
64, 46.763638 91.335230
8192, 123.508163 1.884585

[tgunasekaran@cahw-vnc7 ]$ egrep "# of INTF: 1" perf_metrics_overall.csv | egrep "NCB_DLY: 0" | awk '{print $8,$13,$14,$15}' | sort -n
64, 46.763638 , 91.335230
128, 79.477399 , 77.614647
256, 97.043759 , 47.422623
512, 109.078867 , 26.695706
1024, 116.302435 , 14.197075
1536, 119.433400 , 9.720648
2048, 116.241915 , 7.095024
4096, 122.165888 , 3.728207
8192, 123.508163 , 1.884585

sort -n will perform numerical sort.
awk will capture the arguments with space as delimiter.


Friday, February 12, 2016

good aliases for svn


Most of the time, we will be scrambling around the svn status and check-ins.  Below are the aliases which are good to have and it is very handy.

Below 2 are pretty common when you make local file changes.
alias unk        "svn st | grep ^\? | awk '{print $2}'"
alias mod        "svn st | grep ^M | awk '{print $2}'"


Below 2 are very interesting cmds;
'new' will list out the new files in svn database which will comes to your database if you do svn update.
alias new        "svn st -u  | grep \* | grep '            ' | awk '{print $2}'"

'old' will list out the already exisiting files which has changes in svn database.
alias old        "svn st -uv | grep \* | awk '{print $5}' | sort"


Just copy-paste these aliases and enjoy the benefits :-)

Thursday, February 11, 2016

some more useful cmds from the cmdline



1 find . -name "*.log" -exec grep pattern {} /; -print find log files and grep a pattern. 


2


uname -a  Print the system information
3 cat /proc/cpuinfo Print the CPU information

4

cat /etc/redhat-release RED Hat release info




#stock alias  to get the stock price 
alias cavm ' wget -q -O cavm "http://download.finance.yahoo.com/d/quotes.csv?s=cavm&f=l1" ; more cavm; rm cavm'

#remove all the 0 bytes files
alias fixcc 'find -L sim -name "*.o" -size 0c -print -exec rm {} \;'


If you want to create the list of files with full path.
alias pls 'ls -d -1 $PWD/**/*' 

Tuesday, February 9, 2016

split command



Split command is very useful in splitting the larger file into number of small files.


split -l 100 -a 3 edch_all_vectors.txt  edch_all_vectors

 -a, --suffix-length=N   use suffixes of length N (default 2)
  -b, --bytes=SIZE        put SIZE bytes per output file
  -C, --line-bytes=SIZE   put at most SIZE bytes of lines per output file
  -d, --numeric-suffixes  use numeric suffixes instead of alphabetic
  -l, --lines=NUMBER      put NUMBER lines per output file

The above command will split the edch_all_vectors.txt into smaller files with hundred lines in each file and filenames like edch_all_vectors_xxx (Note:- suffix 3 letters since we have -a 3).

Tuesday, February 2, 2016

uvm_report_catcher - uvm msg management across multiple envs


Typically we tend to use the common bfms/envs/vkits in many of our unit level/sub level/full chip level benches. When we use the envs from other modules, they might print lot of messages which might be unnecessary for our module. So, in order to minimize or turn off those messages, uvm_report_catcher is very useful.

Here is an example.

This class is trying to mask all the uvm messages below UVM_MEDIUM verbosity.

class logbuster_c extends uvm_report_catcher;

  function new(string name="logbuster");
    super.new(name);
  endfunction

  function action_e catch();
    if (get_verbosity() < UVM_MEDIUM)
      set_action(UVM_NO_ACTION);

    return THROW;
  endfunction
endclass



class basic_test extends uvm_test;
......
logbuster_c logbuster;

.....
virtual function void end_of_elaboration_phase(uvm_phase phase);
...
//if we want to apply for our whole env, use null
 //uvm_report_cb::add(null, logbuster);
//else use for specific component or object
         uvm_report_cb::add(env.ncb_env.drvr, logbuster);
         uvm_report_cb::add(env.ncb_env.arb_rsp_credits, logbuster);

   endfunction : end_of_elaboration_phase

endclass : basic_test