SyoSil ApS UVM Scoreboard  1.0.3.0
cl_scb_test_benchmark.svh
1 /// Benchmark to compare performance of STD and Hash queues when executing OOO compare
2 // Additional classes defined below which actually implement the test
3 class cl_scb_test_benchmark extends cl_scb_test_single_scb;
4  //-------------------------------------
5  // Non randomizable variables
6  //-------------------------------------
7  int Nvals[] = {100, 200, 500, 1000, 5000, 10000, 20000, 50000, 100000};
8  //-------------------------------------
9  // UVM Macros
10  //-------------------------------------
11  `uvm_component_utils_begin(cl_scb_test_benchmark)
12 
13  `uvm_component_utils_end
14 
15  //-------------------------------------
16  // Constructor
17  //-------------------------------------
18  function new(string name = "cl_scb_test_benchmark", uvm_component parent = null);
19  super.new(name, parent);
20  endfunction: new
21 
22  //-------------------------------------
23  // Functions
24  //-------------------------------------
25  extern function void test(int N, string fname);
26  extern function void log_time(string fname);
27  extern function real get_time_diff(string file1, string file2);
28  extern function void pre_build();
29 endclass: cl_scb_test_benchmark
30 
31 function void cl_scb_test_benchmark::pre_build();
32  super.pre_build();
33  this.syoscb_cfgs.syoscb_cfg[0].set_compare_type(pk_syoscb::SYOSCB_COMPARE_OOO);
34  this.syoscb_cfgs.syoscb_cfg[0].set_disable_clone(1'b0);
35  void'(this.syoscb_cfgs.syoscb_cfg[0].set_primary_queue("Q2"));
36 endfunction: pre_build
37 
38 //Perform the test, generating N items and randomly inserting them in Q1 and Q2
39 //N: Number of items to generate
40 //name: File name to write results to
41 function void cl_scb_test_benchmark::test(int N, string fname);
42  cl_tb_seq_item items[];
43  real time_diff;
44  int fd;
45 
46  //Generate items
47  items = new [N];
48  foreach(items[i]) begin
49  items[i] = cl_tb_seq_item::type_id::create($sformatf("items[%0d]", i));
50  if(!items[i].randomize()) begin
51  `uvm_fatal("RAND", $sformatf("Unable to randomize items[%0d]", i))
52  end
53  end
54 
55  foreach(items[i]) begin
56  this.scb_env.syoscb[0].add_item("Q1", "P1", items[i]);
57  end
58  items.shuffle();
59 
60  this.log_time("t0");
61  foreach(items[i]) begin
62  this.scb_env.syoscb[0].add_item("Q2", "P1", items[i]);
63  end
64  this.log_time("t1");
65  time_diff = get_time_diff("t0", "t1");
66  if(this.scb_env.syoscb[0].get_total_queue_size() != 0) begin
67  `uvm_fatal("ERR", $sformatf("Total queue size was not 0, is %0d", this.scb_env.syoscb[0].get_total_queue_size()))
68  end
69 
70  fd = $fopen(fname, "a");
71  $fwrite(fd, $sformatf("%0d, %0f\n", N, time_diff));
72  $display("N: %0d, time: %0f", N, time_diff);
73  $fclose(fd);
74 endfunction: test
75 
76 //Gets current time, stores it in the file named "fname"
77 function void cl_scb_test_benchmark::log_time(string fname);
78  $system($sformatf("date -Ins > %0s.time", fname));
79 endfunction: log_time
80 
81 //Gets time difference in seconds between two timestamps
82 function real cl_scb_test_benchmark::get_time_diff(string file1, string file2);
83  int f1, f2;
84  string t1, t2, s1, s2, m1, m2, h1, h2;
85  real S1, S2, M1, M2, H1, H2;
86  real a;
87 
88  f1 = $fopen($sformatf("%0s.time", file1), "r");
89  f2 = $fopen($sformatf("%0s.time", file2), "r");
90 
91  void'($fgets(t1, f1));
92  void'($fgets(t2, f2));
93  //date -Ins returns a string of the type
94  //2022-01-24T08:48:50,131570320+0100
95  //We wish to extract hours, minutes and seconds, replace the ',' with a '.'
96  h1 = t1.substr(11, 12);
97  h2 = t2.substr(11, 12);
98  m1 = t1.substr(14, 15);
99  m2 = t2.substr(14, 15);
100  s1 = t1.substr(17, 28);
101  s2 = t2.substr(17, 28);
102 
103  s1.putc(2, ".");
104  s2.putc(2, ".");
105 
106  H1 = h1.atoreal();
107  H2 = h2.atoreal();
108  M1 = m1.atoreal();
109  M2 = m2.atoreal();
110  S1 = s1.atoreal();
111  S2 = s2.atoreal();
112 
113  a = (H2-H1)*3600 + (M2-M1)*60 + S2-S1;
114 
115  $fclose(f1);
116  $fclose(f2);
117 
118  return a;
119 endfunction: get_time_diff
120 
121 
122 // Track execution time of std queue
123 class cl_scb_test_benchmark_std extends cl_scb_test_benchmark;
124  //-------------------------------------
125  // Non randomizable variables
126  //-------------------------------------
127 
128 
129  //-------------------------------------
130  // UVM Macros
131  //-------------------------------------
132  `uvm_component_utils_begin(cl_scb_test_benchmark_std)
133 
134  `uvm_component_utils_end
135 
136  //-------------------------------------
137  // Constructor
138  //-------------------------------------
139  function new(string name = "cl_scb_test_benchmark_std", uvm_component parent = null);
140  super.new(name, parent);
141  endfunction: new
142 
143  //-------------------------------------
144  // Functions
145  //-------------------------------------
146 
147  function void pre_build();
148  super.pre_build();
149  this.syoscb_cfgs.syoscb_cfg[0].set_queue_type(pk_syoscb::SYOSCB_QUEUE_STD);
150  endfunction: pre_build
151 
152  task main_phase(uvm_phase phase);
153  int fd;
154  phase.raise_objection(this);
155  super.main_phase(phase);
156 
157  $fclose($fopen("std_log.txt", "w")); //this clears the file
158 
159  foreach(this.Nvals[i]) begin
160  this.test(this.Nvals[i], "std_log.txt");
161  end
162 
163  phase.drop_objection(this);
164  endtask: main_phase
165 endclass: cl_scb_test_benchmark_std
166 
167 
168 // Track execution time of md5 queue with ordered_next=0
169 class cl_scb_test_benchmark_md5 extends cl_scb_test_benchmark;
170  //-------------------------------------
171  // Non randomizable variables
172  //-------------------------------------
173 
174 
175  //-------------------------------------
176  // UVM Macros
177  //-------------------------------------
178  `uvm_component_utils_begin(cl_scb_test_benchmark_md5)
179 
180  `uvm_component_utils_end
181 
182  //-------------------------------------
183  // Constructor
184  //-------------------------------------
185  function new(string name = "cl_scb_test_benchmark_md5", uvm_component parent = null);
186  super.new(name, parent);
187  endfunction: new
188 
189  //-------------------------------------
190  // Functions
191  //-------------------------------------
192  function void pre_build();
193  super.pre_build();
194  this.syoscb_cfgs.syoscb_cfg[0].set_ordered_next(1'b0);
195  this.syoscb_cfgs.syoscb_cfg[0].set_queue_type(pk_syoscb::SYOSCB_QUEUE_MD5);
196  endfunction: pre_build
197 
198  task main_phase(uvm_phase phase);
199  int fd;
200  phase.raise_objection(this);
201  super.main_phase(phase);
202 
203  $fclose($fopen("md5_log.txt", "w")); //this clears the file
204  foreach(this.Nvals[i]) begin
205  this.test(this.Nvals[i], "md5_log.txt");
206  end
207 
208  phase.drop_objection(this);
209  endtask: main_phase
210 endclass: cl_scb_test_benchmark_md5
211 
212 // Track execution time of md5 queue with ordered_next=1
213 class cl_scb_test_benchmark_md5_on extends cl_scb_test_benchmark;
214  //-------------------------------------
215  // Non randomizable variables
216  //-------------------------------------
217 
218 
219  //-------------------------------------
220  // UVM Macros
221  //-------------------------------------
222  `uvm_component_utils_begin(cl_scb_test_benchmark_md5_on)
223 
224  `uvm_component_utils_end
225 
226  //-------------------------------------
227  // Constructor
228  //-------------------------------------
229  function new(string name = "cl_scb_test_benchmark_md5", uvm_component parent = null);
230  super.new(name, parent);
231  endfunction: new
232 
233  //-------------------------------------
234  // Functions
235  //-------------------------------------
236  function void pre_build();
237  super.pre_build();
238  this.syoscb_cfgs.syoscb_cfg[0].set_ordered_next(1'b1);
239  this.syoscb_cfgs.syoscb_cfg[0].set_queue_type(pk_syoscb::SYOSCB_QUEUE_MD5);
240  endfunction: pre_build
241 
242  task main_phase(uvm_phase phase);
243  int fd;
244  phase.raise_objection(this);
245  super.main_phase(phase);
246 
247  $fclose($fopen("md5_on_log.txt", "w")); //this clears the file
248  foreach(this.Nvals[i]) begin
249  this.test(this.Nvals[i], "md5_on_log.txt");
250  end
251 
252  phase.drop_objection(this);
253  endtask: main_phase
254 endclass: cl_scb_test_benchmark_md5_on
Benchmark to compare performance of STD and Hash queues when executing OOO compare.

Project: SyoSil ApS UVM Scoreboard, Revision: 1.0.3.0

Copyright 2014-2022 SyoSil ApS
All Rights Reserved Worldwide

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
doxygen
Doxygen Version: 1.8.14
Generated with IDV SV Filter Version: 2.6.3
Fri Sep 2 2022 14:36:34
Find a documentation bug? Report bugs to: scoreboard@syosil.com