Code File Location: VisualSim/actor/lib/Smart_Resource
o Used to define a queue that has a arbitration scheme to pop the next data structure out.
o Create multiple concurrent queues of type FIFO or LIFO.o Buffer to store requests or transactions from different sources or for different destinations in separate queues.
o Create rudimentary cache with equal sized data access (Read or Write).
o Priority queue reordered based on the priority of the incoming task.
o Used to define a resource as a set of Queues/FIFO.
The following is a block diagram that illustrates the operation of the Smart Resource block.
The Queues is a Queueing or static resource. This block defines multiple independent queues. Each queue orders the incoming data structures from highest to the lowest priority. The parameter- Queue_Number_Field selects the queue to place and the parameter-Priority_Field contains the priority for each transaction to reorder/reject in the Queue. The Queue_Number_Field and the Priority_Field can be a Expression, containing a fixed value, parameter, variable, incoming data structure field or RegEx. This block queues the incoming data structure or token in a FIFO or LIFO order based on the Queue_Type parameter. To remove from the queue, the user can send an integer value for the queue number to remove the head of the Queue or a two index array where index-0 is the queue number and index-1 is the position in the array. All queue can have the same depth (integer value for the Max_Queue_Length) or each queue can have a different value (integer array for the Max_Queue_Length).
The first token or Data Structure arriving at the Queue can either be sent out immediately or queued until a pop_input is received, based on the Initial_Queue_State parameter setting. If the queue is full, the incoming Data Structure or the lowest priority token is placed on the reject_output port, depending on the Queue_Reject_Mechanism parameter setting. If there are multiple tokens with the same priority, the last arriving transaction of the same priority is rejected.
The Script or Smart_Controller block is used in conjunction with this block and is normally connected to the pop_input port. The Smart_Controller is used to define the arbitartion and other management policies. This block can be used to trigger (pop) the next transaction from a Queue.
Note: In Input_Queue_State: First_Token_Flow_Through, the first transaction will always be sent out if there is nothing waiting in the queue when the transaction arrives and the previous transaction has been acknowledged with a pop.
Statistics
The statistics for the Queues are generated using the getBlockStatus RegEx function with type "length", Resource_Statistics block or Queue_Name + "_" + Length. The array lookup is significantly faster than the other two methods. The function and array lookup can be called in the Script, Smart_Controller and ExpressionList blocks.
Result_B = Queue_Length(2) where the array index starts at 1 for Queue number 1. Array Index of 0 is not used.
Statistics_A = getBlockStatus(Queue_Name,"Any Value","stats",Queue_Number,1) -> To get the statistics.
Reset_Stats_A = getBlockStatus(Smart_Resource_Name,"Any Value","stats",-(Queue_Number), 1) -> To reset the statistics.
If reset or statistics is required for all Queue, then make the Queue_Number = Number of Queues + 1.
There is a pre-created "Generator" block and is used in the Resource_Statistics Example in the BDE.
Copy_A = getBlockStatus(Smart_Resource_Name,"Any Value","copy",Queue_Number, position) -> To get copy of the Data Structure at a position in the Queue.
Length_A = getBlockStatus(Smart_Resource_Name,"Any Value","length",Queue_Number,1) -> To get the length of the selected Queue.
Remove_A = getBlockStatus(Smart_Resource_Name,"Any Value","take",Queue_Number, position) -> To remove a transaction in any position of the selected Queue. Make sure 1 is not used, else the head will be removed.
isAvailable = getBlockStatus(Smart_Resource_Name,"Any Value","array",Any Integer, Any Integer)- Returns an array of which Queue is free (true) or busy (false)
To learn about the use of the getBlockstatus, check the library example for getBlockStatus. There are a number of additional getBlockStatus settings to the list above. Also, view the getBlockStatus setting in the RegEx documentation and in the Basic Technology document.
Refer Single Smart_Resource Queue and Multiple Queues with Smart_Resource for Pop and Arbitration demo model.
Statistics Output:
Statistic Name |
Value |
Explanation |
Mathematical Equation |
Type |
Number_Entered |
100 |
Number of transactions entering the queue. |
- |
int |
Number_Exited |
25 |
Number of transactions that left the queue. |
- |
int |
Number_Rejected |
10 |
Number of transactions rejected and output to reject port. |
- |
int |
Queue_Number |
1 |
Queue Number. Queue number start at 1. |
- |
int |
Occupancy_Min |
4.0 |
Minimum queue usage during the simulation. |
If (Xn < Xn – 1) Xmin = Xn |
double |
Occupancy_Mean |
8.0 |
Mean/Average queue usage during the simulation. |
Xµ = (1 / n) * (X1 + X2 + … + Xn) |
double |
Occupancy_StDev |
3.0 |
Standard Deviation from the Mean queue size during the simulation. |
|
double |
Occupancy_Max |
25.0 |
Maximum queue size consumed during the simulation. |
If (Xn > Xn – 1) Xmax = Xn |
double |
Total_Delay_Min |
1.3 |
In seconds. Least time through the queue+server among all transactions. |
If (Xn < Xn – 1) Xmin = Xn |
double |
Total_Delay_Mean |
1.3 |
In seconds. Mean/Average time through the queue+server among all transactions. |
Xµ = (1 / n) * (X1 + X2 + … + Xn) |
double |
Total_Delay_StDev |
1.3 |
In seconds. Standard Deviation from the Mean time through the queue+server among all transactions. |
Xσ = Math.sqrt ((1 / n) * ((X1 - Xµ)2 + (X2 - Xµ)2 + … + (Xn - Xµ)2)) |
double |
Total_Delay_Max |
1.3 |
In seconds. Maximum time through the queue+server among all transactions. |
If (Xn > Xn – 1) Xmax = Xn |
double |
Utilization_Pct_Mean |
10.0 |
Utilization is not used and is not output |
0.0 |
double |
Where n is the number of samples and X is occupancy or delay.
Parameter |
Explanation |
Type |
Example |
Block_Name |
Block_Name, needs to be unique in the model. |
String |
"QueueName" |
Queue_Number_Field |
Queue_Number_Field selects the Queue number to place the incoming Data Structure. This is an expression that can contain a fixed value, parameter, variable, data structure field, RegEx and Expression. The numbering is one-based, queues selected from 1 to N, 0 will throw an exception. The field needs to be an integer, or will throw an exception. |
String |
Queue_Number_Field or 1 or irand(Var1,Var2) |
Priority_Field |
Priority_Field provides the priority number for reordering the queue. This is an expression that can contain a fixed value, parameter, variable, data structure field, RegEx and Expression. The higher number is higher priority. "None" or the default value is a valid entry. |
String |
Priority_Field or 1 or irand(Var1,Var2) |
Max_Queue_Length |
All queue will have the same depth (integer value
for the Max_Queue_Length) |
Integer |
30 |
Number_of_Queues |
Number of queues. |
Integer |
1 |
Initial_Queue_State |
Queue initial state attribute, either 'First_Token_Enqueue', or 'First_Token_Flow_Through'. The default is 'First_Token_Flow_Through'. If 'First_Token_Flow_Through' is selected then the first data token or data structure will flow through everytime the queue is empty and the last data structure output has been acknowledged on the pop port. The first transaction of the model is always sent out. If 'First_Token_Enqueue', then one must provide 'pop_input' (queue number as an integer) to obtain the first data token or data structure. |
- |
First_Token_Flow_Through |
Queue_Reject_Mechanism |
Queue reject attribute, either 'Incoming_Token_Rejected' (default), or 'Lowest_Priority_Token_Rejected'. If 'Incoming_Token_Rejected' is selected and the specific queue is full, then the incoming data structure is sent to the 'reject_output', see above. If 'Lowest_Priority_Token_Rejected' attribute is selected, and the queue is full, then the lowest priority queue element will be sent to the 'reject_output'. |
- |
Incoming_Token_Rejected |
Queue_Type |
Queue type attribute, either 'Queue_FIFO', or 'Queue_LIFO'. The default is 'Queue_FIFO'. FIFO means first-in-first-out, whereas LIFO means last-in-last-out. |
- |
FIFO |
Port |
Explanation |
input |
Input port for data tokens (numerical values) or composite data structures entering the queue. |
pop_input |
Input port receives the queue number to pop the head of a particular queue. Alternately it can receive a two value array where the first is the Queue number and the second is the position in the queue. Both values must start from one. The pop_input is received from the Smart_Controller. |
output |
Output port sending the head of the queue based on 'pop_input' port integer value, see above. The data token or data structure removed from the queue. |