SyoSil ApS UVM Scoreboard  1.0.3.0
cl_syoscb_queue_std.svh
1 /// Standard implementation of a queue. Uses a normal SystemVerilog queue as
2 /// implementation. The class implements the queue API as defined by the queue
3 /// base class.
5  //-------------------------------------
6  // Non randomizable variables
7  //-------------------------------------
8  /// Simple queue implementation with a SV queue
9  local cl_syoscb_item items[$];
10 
11  //-------------------------------------
12  // UVM Macros
13  //-------------------------------------
14  `uvm_component_utils_begin(cl_syoscb_queue_std)
15  `uvm_field_queue_object(items, UVM_DEFAULT)
16  `uvm_component_utils_end
17 
18  //-------------------------------------
19  // Constructor
20  //-------------------------------------
21  function new(string name, uvm_component parent);
22  super.new(name, parent);
23  endfunction: new
24 
25  //-------------------------------------
26  // Queue API
27  //-------------------------------------
28  // Basic queue functions
29  extern virtual function bit add_item(string producer, uvm_sequence_item item);
30  extern virtual function bit delete_item(cl_syoscb_proxy_item_base proxy_item);
31  extern virtual function cl_syoscb_item get_item(cl_syoscb_proxy_item_base proxy_item);
32  extern virtual function int unsigned get_size();
33  extern virtual function bit empty();
34  extern virtual function bit insert_item(string producer, uvm_sequence_item item, int unsigned idx);
35 
36  // Iterator support functions
37  extern virtual function cl_syoscb_queue_iterator_base create_iterator(string name = "");
38  extern virtual function bit delete_iterator(cl_syoscb_queue_iterator_base iterator);
39 
40  // Locator support function
41  extern virtual function cl_syoscb_queue_locator_base get_locator();
42 
43  //-------------------------------------
44  // Internal support functions
45  //-------------------------------------
46  extern protected virtual function void do_flush_queue();
47  extern virtual function void get_native_queue(ref cl_syoscb_item q[$]);
48 endclass: cl_syoscb_queue_std
49 
50 /// <b>Queue API:</b> See cl_syoscb_queue_base#add_item for more details
51 function bit cl_syoscb_queue_std::add_item(string producer, uvm_sequence_item item);
52  cl_syoscb_item new_item;
53 
54  //Generate scoreboard item, assign metadata
55  new_item = this.pre_add_item(producer, item);
56 
57  // Insert the item in the queue
58  this.items.push_back(new_item);
59 
60  //Perform bookkeeping on counters and shadow queue
61  this.post_add_item(new_item);
62 
63  // Signal that it worked
64  return 1;
65 endfunction: add_item
66 
67 /// <b>Queue API:</b> See cl_syoscb_queue_base#delete_item for more details
68 function bit cl_syoscb_queue_std::delete_item(cl_syoscb_proxy_item_base proxy_item);
69  cl_syoscb_proxy_item_std proxy_item_std;
70  int unsigned idx;
71 
72  if(!$cast(proxy_item_std,proxy_item)) begin
73  `uvm_fatal("Incorrect item type", $sformatf("[%s]:Proxy_item ", this.cfg.get_scb_name()));
74  return 0;
75  end else if(proxy_item == null) begin
76  `uvm_info("NULL", $sformatf("[%s] Passed null item to queue %s for deletion. Ignoring it", this.cfg.get_scb_name(), this.get_name()), UVM_DEBUG)
77  return 1'b0;
78  end
79 
80  idx = proxy_item_std.idx;
81 
82  if(idx < this.items.size()) begin
83  string producer;
84  cl_syoscb_queue_iterator_base iter[$];
85 
86  // Wait to get exclusive access to the queue
87  // if there are multiple iterators
88  while(!this.iter_sem.try_get());
89  producer = this.items[idx].get_producer();
90  this.items.delete(idx);
91 
92  // Update iterators
93  iter = this.iterators.find(x) with (x.next_index() > idx);
94  foreach(iter[i]) begin
95  void'(iter[i].previous());
96  end
97 
98  this.decr_cnt_producer(producer);
99 
100  this.iter_sem.put();
101  return 1;
102  end else begin
103  `uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Idx: %0d is not present in queue: %0s", this.cfg.get_scb_name(), idx, this.get_name()), UVM_DEBUG);
104  return 0;
105  end
106 endfunction: delete_item
107 
108 /// <b>Queue API:</b> See cl_syoscb_queue_base#get_item for more details
109 function cl_syoscb_item cl_syoscb_queue_std::get_item(cl_syoscb_proxy_item_base proxy_item);
110  cl_syoscb_proxy_item_std proxy_item_std;
111  int unsigned idx;
112 
113  if(!$cast(proxy_item_std, proxy_item)) begin
114  `uvm_fatal("Incorrect item type", $sformatf("[%s]:Proxy_item was of type %0s", this.cfg.get_scb_name(), proxy_item.get_type_name()));
115  return null;
116  end
117  idx = proxy_item_std.idx;
118 
119 
120  if(idx < this.items.size()) begin
121  return items[idx];
122  end else begin
123  `uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Idx: %0d is not present in queue: %0s", this.cfg.get_scb_name(), idx, this.get_name()), UVM_DEBUG);
124  return null;
125  end
126 endfunction: get_item
127 
128 /// <b>Queue API:</b> See cl_syoscb_queue_base#get_size for more details
129 function int unsigned cl_syoscb_queue_std::get_size();
130  return this.items.size();
131 endfunction: get_size
132 
133 /// <b>Queue API:</b> See cl_syoscb_queue_base#empty for more details
134 function bit cl_syoscb_queue_std::empty();
135  return this.get_size()==0;
136 endfunction
137 
138 /// <b>Queue API:</b> See cl_syoscb_queue_base#insert_item for more details
139 function bit cl_syoscb_queue_std::insert_item(string producer, uvm_sequence_item item, int unsigned idx);
140  cl_syoscb_item new_item;
141 
142  new_item = this.pre_add_item(producer, item);
143 
144  if(idx < this.items.size()) begin
145  cl_syoscb_queue_iterator_base iters[$];
146 
147  // Wait to get exclusive access to the queue
148  // if there are multiple iterators
149  while(!this.iter_sem.try_get());
150  this.items.insert(idx, new_item);
151 
152  // Update iterators
153  iters = this.iterators.find(x) with (x.next_index() >= idx);
154  for(int i = 0; i < iters.size(); i++) begin
155  // Call .next() blindly. This can never fail by design, since
156  // if it was pointing at the last element then it points to the second last
157  // element prior to the .next(). The .next() call will then just
158  // set the iterator to the correct index again after the insertion
159  void'(iters[i].next());
160  end
161  this.iter_sem.put();
162  end else if(idx == this.items.size()) begin
163  this.items.push_back(new_item);
164  end else begin
165  `uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Idx: %0d too large for queue %0s", this.cfg.get_scb_name(), idx, this.get_name()), UVM_DEBUG);
166  return 1'b0;
167  end
168 
169  this.post_add_item(new_item);
170  return 1'b1;
171 endfunction: insert_item
172 
173 /// <b>Queue API:</b> See cl_syoscb_queue_base#create_iterator for more details
174 function cl_syoscb_queue_iterator_base cl_syoscb_queue_std::create_iterator(string name = "");
175  cl_syoscb_queue_iterator_std result;
176  string iter_name;
177  cl_syoscb_queue_iterator_base f[$];
178 
179  // Wait to get exclusive access to the queue
180  // if there are multiple iterators
181  while(this.iter_sem.try_get() == 0);
182 
183  if(name == "") begin
184  iter_name = $sformatf("%0s_iter%0d", this.get_name(), this.num_iters_created);
185  end else begin
186  iter_name = name;
187  end
188 
189  //Check if an iterator with that name already exists
190  f = this.iterators.find_index() with (item.get_name() == name);
191  if(f.size() != 0) begin
192  `uvm_info("ITERATOR", $sformatf("[%0s] An iterator with the name %0s already exists", this.cfg.get_scb_name(), name), UVM_DEBUG)
193  this.iter_sem.put();
194  return null;
195  end
196  result = cl_syoscb_queue_iterator_std::type_id::create(iter_name);
197 
198  // No need to check return value since set_queue will issue
199  // an `uvm_error of something goes wrong
200  void'(result.set_queue(this));
201 
202  this.iterators[result] = result;
203  this.num_iters_created++;
204  this.iter_sem.put();
205 
206  return result;
207 endfunction: create_iterator
208 
209 /// <b>Queue API:</b> See cl_syoscb_queue_base#delete_iterator for more details
210 function bit cl_syoscb_queue_std::delete_iterator(cl_syoscb_queue_iterator_base iterator);
211  if(iterator == null) begin
212  `uvm_info("NULL", $sformatf("[%s]: Asked to delete null iterator from list of iterators in %s",
213  this.cfg.get_scb_name(), this.get_name()), UVM_DEBUG);
214  return 0;
215  end else begin
216  // Wait to get exclusive access to the queue
217  // if there are multiple iterators
218  while(!this.iter_sem.try_get());
219 
220  this.iterators.delete(iterator);
221  this.iter_sem.put();
222  return 1;
223  end
224 endfunction: delete_iterator
225 
226 /// <b>Queue API:</b> See cl_syoscb_queue_base#get_locator for more details
227 function cl_syoscb_queue_locator_base cl_syoscb_queue_std::get_locator();
228  cl_syoscb_queue_locator_std locator;
229 
230  locator = cl_syoscb_queue_locator_std::type_id::create($sformatf("%s_loc", this.get_name()));
231  void'(locator.set_queue(this));
232  return locator;
233 endfunction: get_locator
234 
235 /// See cl_syoscb_queue_base#do_flush_queue for more details
236 function void cl_syoscb_queue_std::do_flush_queue();
237  this.items = {};
238 endfunction: do_flush_queue
239 
240 // Returns a handle to this queue's underlying SV queue to allow locators to search through it.
241 // The returned queue should not be modified by the caller.
242 // DO NOT CALL FROM USER CODE
243 // \param q Handle to a queue where the results will be returned
244 function void cl_syoscb_queue_std::get_native_queue(ref cl_syoscb_item q[$]);
245  q = this.items;
246 endfunction: get_native_queue
virtual bit add_item(string producer, uvm_sequence_item item)
Queue API: See cl_syoscb_queue_base::add_item for more details
virtual void do_flush_queue()
See cl_syoscb_queue_base::do_flush_queue for more details.
virtual void post_add_item(cl_syoscb_item item)
Perform some basic bookkeping that is the same for all sequence items after insertion.
The UVM scoreboard item which wraps uvm_sequence_item .
virtual bit delete_item(cl_syoscb_proxy_item_base proxy_item)
Queue API: See cl_syoscb_queue_base::delete_item for more details
virtual cl_syoscb_queue_locator_base get_locator()
Queue API: See cl_syoscb_queue_base::get_locator for more details
virtual void decr_cnt_producer(string producer)
Decrement the producer counter for a given producer.
Locator base class defining the locator API used for searching in queues.
semaphore iter_sem
Semaphore guarding exclusive access to the queue when multiple iterators are in play.
Queue iterator base class defining the iterator API used for iterating over queues.
virtual cl_syoscb_item pre_add_item(string producer, uvm_sequence_item item)
Perform some basic bookkeeping that is the same for all sequence items before insertion.
virtual bit empty()
Queue API: See cl_syoscb_queue_base::empty for more details
Class which represents the base concept of a queue.
Standard implementation of a queue.
cl_syoscb_item items[$]
Simple queue implementation with a SV queue.
virtual int unsigned get_size()
Queue API: See cl_syoscb_queue_base::get_size for more details
virtual bit insert_item(string producer, uvm_sequence_item item, int unsigned idx)
Queue API: See cl_syoscb_queue_base::insert_item for more details
virtual cl_syoscb_item get_item(cl_syoscb_proxy_item_base proxy_item)
Queue API: See cl_syoscb_queue_base::get_item for more details
virtual cl_syoscb_queue_iterator_base create_iterator(string name="")
Queue API: See cl_syoscb_queue_base::create_iterator for more details
virtual bit delete_iterator(cl_syoscb_queue_iterator_base iterator)
Queue API: See cl_syoscb_queue_base::delete_iterator for more details
Proxy item implementation for standard queues.

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:39:58
Find a documentation bug? Report bugs to: scoreboard@syosil.com