| 1 |
16 |
HanySalah |
//
|
| 2 |
|
|
//------------------------------------------------------------------------------
|
| 3 |
|
|
// Copyright 2007-2010 Mentor Graphics Corporation
|
| 4 |
|
|
// Copyright 2007-2010 Cadence Design Systems, Inc.
|
| 5 |
|
|
// Copyright 2010 Synopsys, Inc.
|
| 6 |
|
|
// All Rights Reserved Worldwide
|
| 7 |
|
|
//
|
| 8 |
|
|
// Licensed under the Apache License, Version 2.0 (the
|
| 9 |
|
|
// "License"); you may not use this file except in
|
| 10 |
|
|
// compliance with the License. You may obtain a copy of
|
| 11 |
|
|
// the License at
|
| 12 |
|
|
//
|
| 13 |
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
|
|
//
|
| 15 |
|
|
// Unless required by applicable law or agreed to in
|
| 16 |
|
|
// writing, software distributed under the License is
|
| 17 |
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
| 18 |
|
|
// CONDITIONS OF ANY KIND, either express or implied. See
|
| 19 |
|
|
// the License for the specific language governing
|
| 20 |
|
|
// permissions and limitations under the License.
|
| 21 |
|
|
//------------------------------------------------------------------------------
|
| 22 |
|
|
|
| 23 |
|
|
|
| 24 |
|
|
//-----------------------------------------------------------------------------
|
| 25 |
|
|
//
|
| 26 |
|
|
// CLASS: uvm_barrier
|
| 27 |
|
|
//
|
| 28 |
|
|
// The uvm_barrier class provides a multiprocess synchronization mechanism.
|
| 29 |
|
|
// It enables a set of processes to block until the desired number of processes
|
| 30 |
|
|
// get to the synchronization point, at which time all of the processes are
|
| 31 |
|
|
// released.
|
| 32 |
|
|
//-----------------------------------------------------------------------------
|
| 33 |
|
|
|
| 34 |
|
|
class uvm_barrier extends uvm_object;
|
| 35 |
|
|
|
| 36 |
|
|
local int threshold;
|
| 37 |
|
|
local int num_waiters;
|
| 38 |
|
|
local bit at_threshold;
|
| 39 |
|
|
local bit auto_reset;
|
| 40 |
|
|
local uvm_event#(uvm_object) m_event;
|
| 41 |
|
|
|
| 42 |
|
|
|
| 43 |
|
|
// Function: new
|
| 44 |
|
|
//
|
| 45 |
|
|
// Creates a new barrier object.
|
| 46 |
|
|
|
| 47 |
|
|
function new (string name="", int threshold=0);
|
| 48 |
|
|
super.new(name);
|
| 49 |
|
|
m_event = new({"barrier_",name});
|
| 50 |
|
|
this.threshold = threshold;
|
| 51 |
|
|
num_waiters = 0;
|
| 52 |
|
|
auto_reset = 1;
|
| 53 |
|
|
at_threshold = 0;
|
| 54 |
|
|
endfunction
|
| 55 |
|
|
|
| 56 |
|
|
|
| 57 |
|
|
// Task: wait_for
|
| 58 |
|
|
//
|
| 59 |
|
|
// Waits for enough processes to reach the barrier before continuing.
|
| 60 |
|
|
//
|
| 61 |
|
|
// The number of processes to wait for is set by the method.
|
| 62 |
|
|
|
| 63 |
|
|
virtual task wait_for();
|
| 64 |
|
|
|
| 65 |
|
|
if (at_threshold)
|
| 66 |
|
|
return;
|
| 67 |
|
|
|
| 68 |
|
|
num_waiters++;
|
| 69 |
|
|
|
| 70 |
|
|
if (num_waiters >= threshold) begin
|
| 71 |
|
|
if (!auto_reset)
|
| 72 |
|
|
at_threshold=1;
|
| 73 |
|
|
m_trigger();
|
| 74 |
|
|
return;
|
| 75 |
|
|
end
|
| 76 |
|
|
|
| 77 |
|
|
m_event.wait_trigger();
|
| 78 |
|
|
|
| 79 |
|
|
endtask
|
| 80 |
|
|
|
| 81 |
|
|
|
| 82 |
|
|
// Function: reset
|
| 83 |
|
|
//
|
| 84 |
|
|
// Resets the barrier. This sets the waiter count back to zero.
|
| 85 |
|
|
//
|
| 86 |
|
|
// The threshold is unchanged. After reset, the barrier will force processes
|
| 87 |
|
|
// to wait for the threshold again.
|
| 88 |
|
|
//
|
| 89 |
|
|
// If the ~wakeup~ bit is set, any currently waiting processes will
|
| 90 |
|
|
// be activated.
|
| 91 |
|
|
|
| 92 |
|
|
virtual function void reset (bit wakeup=1);
|
| 93 |
|
|
at_threshold = 0;
|
| 94 |
|
|
if (num_waiters) begin
|
| 95 |
|
|
if (wakeup)
|
| 96 |
|
|
m_event.trigger();
|
| 97 |
|
|
else
|
| 98 |
|
|
m_event.reset();
|
| 99 |
|
|
end
|
| 100 |
|
|
num_waiters = 0;
|
| 101 |
|
|
endfunction
|
| 102 |
|
|
|
| 103 |
|
|
|
| 104 |
|
|
// Function: set_auto_reset
|
| 105 |
|
|
//
|
| 106 |
|
|
// Determines if the barrier should reset itself after the threshold is
|
| 107 |
|
|
// reached.
|
| 108 |
|
|
//
|
| 109 |
|
|
// The default is on, so when a barrier hits its threshold it will reset, and
|
| 110 |
|
|
// new processes will block until the threshold is reached again.
|
| 111 |
|
|
//
|
| 112 |
|
|
// If auto reset is off, then once the threshold is achieved, new processes
|
| 113 |
|
|
// pass through without being blocked until the barrier is reset.
|
| 114 |
|
|
|
| 115 |
|
|
virtual function void set_auto_reset (bit value=1);
|
| 116 |
|
|
at_threshold = 0;
|
| 117 |
|
|
auto_reset = value;
|
| 118 |
|
|
endfunction
|
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
// Function: set_threshold
|
| 122 |
|
|
//
|
| 123 |
|
|
// Sets the process threshold.
|
| 124 |
|
|
//
|
| 125 |
|
|
// This determines how many processes must be waiting on the barrier before
|
| 126 |
|
|
// the processes may proceed.
|
| 127 |
|
|
//
|
| 128 |
|
|
// Once the ~threshold~ is reached, all waiting processes are activated.
|
| 129 |
|
|
//
|
| 130 |
|
|
// If ~threshold~ is set to a value less than the number of currently
|
| 131 |
|
|
// waiting processes, then the barrier is reset and waiting processes are
|
| 132 |
|
|
// activated.
|
| 133 |
|
|
|
| 134 |
|
|
virtual function void set_threshold (int threshold);
|
| 135 |
|
|
this.threshold = threshold;
|
| 136 |
|
|
if (threshold <= num_waiters)
|
| 137 |
|
|
reset(1);
|
| 138 |
|
|
endfunction
|
| 139 |
|
|
|
| 140 |
|
|
|
| 141 |
|
|
// Function: get_threshold
|
| 142 |
|
|
//
|
| 143 |
|
|
// Gets the current threshold setting for the barrier.
|
| 144 |
|
|
|
| 145 |
|
|
virtual function int get_threshold ();
|
| 146 |
|
|
return threshold;
|
| 147 |
|
|
endfunction
|
| 148 |
|
|
|
| 149 |
|
|
|
| 150 |
|
|
// Function: get_num_waiters
|
| 151 |
|
|
//
|
| 152 |
|
|
// Returns the number of processes currently waiting at the barrier.
|
| 153 |
|
|
|
| 154 |
|
|
virtual function int get_num_waiters ();
|
| 155 |
|
|
return num_waiters;
|
| 156 |
|
|
endfunction
|
| 157 |
|
|
|
| 158 |
|
|
|
| 159 |
|
|
// Function: cancel
|
| 160 |
|
|
//
|
| 161 |
|
|
// Decrements the waiter count by one. This is used when a process that is
|
| 162 |
|
|
// waiting on the barrier is killed or activated by some other means.
|
| 163 |
|
|
|
| 164 |
|
|
virtual function void cancel ();
|
| 165 |
|
|
m_event.cancel();
|
| 166 |
|
|
num_waiters = m_event.get_num_waiters();
|
| 167 |
|
|
endfunction
|
| 168 |
|
|
|
| 169 |
|
|
|
| 170 |
|
|
const static string type_name = "uvm_barrier";
|
| 171 |
|
|
|
| 172 |
|
|
virtual function uvm_object create(string name="");
|
| 173 |
|
|
uvm_barrier v;
|
| 174 |
|
|
v=new(name);
|
| 175 |
|
|
return v;
|
| 176 |
|
|
endfunction
|
| 177 |
|
|
|
| 178 |
|
|
virtual function string get_type_name();
|
| 179 |
|
|
return type_name;
|
| 180 |
|
|
endfunction
|
| 181 |
|
|
|
| 182 |
|
|
local task m_trigger();
|
| 183 |
|
|
m_event.trigger();
|
| 184 |
|
|
num_waiters=0;
|
| 185 |
|
|
#0; //this process was last to wait; allow other procs to resume first
|
| 186 |
|
|
endtask
|
| 187 |
|
|
|
| 188 |
|
|
virtual function void do_print (uvm_printer printer);
|
| 189 |
|
|
printer.print_field_int("threshold", threshold, $bits(threshold), UVM_DEC, ".", "int");
|
| 190 |
|
|
printer.print_field_int("num_waiters", num_waiters, $bits(num_waiters), UVM_DEC, ".", "int");
|
| 191 |
|
|
printer.print_field_int("at_threshold", at_threshold, $bits(at_threshold), UVM_BIN, ".", "bit");
|
| 192 |
|
|
printer.print_field_int("auto_reset", auto_reset, $bits(auto_reset), UVM_BIN, ".", "bit");
|
| 193 |
|
|
endfunction
|
| 194 |
|
|
|
| 195 |
|
|
virtual function void do_copy (uvm_object rhs);
|
| 196 |
|
|
uvm_barrier b;
|
| 197 |
|
|
super.do_copy(rhs);
|
| 198 |
|
|
if(!$cast(b, rhs) || (b==null)) return;
|
| 199 |
|
|
|
| 200 |
|
|
threshold = b.threshold;
|
| 201 |
|
|
num_waiters = b.num_waiters;
|
| 202 |
|
|
at_threshold = b.at_threshold;
|
| 203 |
|
|
auto_reset = b.auto_reset;
|
| 204 |
|
|
m_event = b.m_event;
|
| 205 |
|
|
endfunction
|
| 206 |
|
|
|
| 207 |
|
|
endclass
|
| 208 |
|
|
|
| 209 |
|
|
|