gem5  v20.1.0.0
fu_pool.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include "cpu/o3/fu_pool.hh"
42 
43 #include <sstream>
44 
45 #include "cpu/func_unit.hh"
46 
47 using namespace std;
48 
50 //
51 // A pool of function units
52 //
53 
54 inline void
56 {
57  funcUnitsIdx.push_back(fu_idx);
58  ++size;
59 }
60 
61 inline int
63 {
64  int retval = funcUnitsIdx[idx++];
65 
66  if (idx == size)
67  idx = 0;
68 
69  return retval;
70 }
71 
73 {
74  fuListIterator i = funcUnits.begin();
75  fuListIterator end = funcUnits.end();
76  for (; i != end; ++i)
77  delete *i;
78 }
79 
80 
81 // Constructor
83  : SimObject(p)
84 {
85  numFU = 0;
86 
87  funcUnits.clear();
88 
89  maxOpLatencies.fill(Cycles(0));
90  pipelined.fill(true);
91 
92  //
93  // Iterate through the list of FUDescData structures
94  //
95  const vector<FUDesc *> &paramList = p->FUList;
96  for (FUDDiterator i = paramList.begin(); i != paramList.end(); ++i) {
97 
98  //
99  // Don't bother with this if we're not going to create any FU's
100  //
101  if ((*i)->number) {
102  //
103  // Create the FuncUnit object from this structure
104  // - add the capabilities listed in the FU's operation
105  // description
106  //
107  // We create the first unit, then duplicate it as needed
108  //
109  FuncUnit *fu = new FuncUnit;
110 
111  OPDDiterator j = (*i)->opDescList.begin();
112  OPDDiterator end = (*i)->opDescList.end();
113  for (; j != end; ++j) {
114  // indicate that this pool has this capability
115  capabilityList.set((*j)->opClass);
116 
117  // Add each of the FU's that will have this capability to the
118  // appropriate queue.
119  for (int k = 0; k < (*i)->number; ++k)
120  fuPerCapList[(*j)->opClass].addFU(numFU + k);
121 
122  // indicate that this FU has the capability
123  fu->addCapability((*j)->opClass, (*j)->opLat, (*j)->pipelined);
124 
125  if ((*j)->opLat > maxOpLatencies[(*j)->opClass])
126  maxOpLatencies[(*j)->opClass] = (*j)->opLat;
127 
128  if (!(*j)->pipelined)
129  pipelined[(*j)->opClass] = false;
130  }
131 
132  numFU++;
133 
134  // Add the appropriate number of copies of this FU to the list
135  fu->name = (*i)->name() + "(0)";
136  funcUnits.push_back(fu);
137 
138  for (int c = 1; c < (*i)->number; ++c) {
139  ostringstream s;
140  numFU++;
141  FuncUnit *fu2 = new FuncUnit(*fu);
142 
143  s << (*i)->name() << "(" << c << ")";
144  fu2->name = s.str();
145  funcUnits.push_back(fu2);
146  }
147  }
148  }
149 
150  unitBusy.resize(numFU);
151 
152  for (int i = 0; i < numFU; i++) {
153  unitBusy[i] = false;
154  }
155 }
156 
157 int
158 FUPool::getUnit(OpClass capability)
159 {
160  // If this pool doesn't have the specified capability,
161  // return this information to the caller
162  if (!capabilityList[capability])
163  return -2;
164 
165  int fu_idx = fuPerCapList[capability].getFU();
166  int start_idx = fu_idx;
167 
168  // Iterate through the circular queue if needed, stopping if we've reached
169  // the first element again.
170  while (unitBusy[fu_idx]) {
171  fu_idx = fuPerCapList[capability].getFU();
172  if (fu_idx == start_idx) {
173  // No FU available
174  return -1;
175  }
176  }
177 
178  assert(fu_idx < numFU);
179 
180  unitBusy[fu_idx] = true;
181 
182  return fu_idx;
183 }
184 
185 void
187 {
188  assert(unitBusy[fu_idx]);
189  unitsToBeFreed.push_back(fu_idx);
190 }
191 
192 void
194 {
195  while (!unitsToBeFreed.empty()) {
196  int fu_idx = unitsToBeFreed.back();
197  unitsToBeFreed.pop_back();
198 
199  assert(unitBusy[fu_idx]);
200 
201  unitBusy[fu_idx] = false;
202  }
203 }
204 
205 void
207 {
208  cout << "Function Unit Pool (" << name() << ")\n";
209  cout << "======================================\n";
210  cout << "Free List:\n";
211 
212  for (int i = 0; i < numFU; ++i) {
213  if (unitBusy[i]) {
214  continue;
215  }
216 
217  cout << " [" << i << "] : ";
218 
219  cout << funcUnits[i]->name << " ";
220 
221  cout << "\n";
222  }
223 
224  cout << "======================================\n";
225  cout << "Busy List:\n";
226  for (int i = 0; i < numFU; ++i) {
227  if (!unitBusy[i]) {
228  continue;
229  }
230 
231  cout << " [" << i << "] : ";
232 
233  cout << funcUnits[i]->name << " ";
234 
235  cout << "\n";
236  }
237 }
238 
239 bool
241 {
242  bool is_drained = true;
243  for (int i = 0; i < numFU; i++)
244  is_drained = is_drained && !unitBusy[i];
245 
246  return is_drained;
247 }
248 
249 //
250 
252 //
253 // The SimObjects we use to get the FU information into the simulator
254 //
256 
257 //
258 // FUPool - Contails a list of FUDesc objects to make available
259 //
260 
261 //
262 // The FuPool object
263 //
264 FUPool *
265 FUPoolParams::create()
266 {
267  return new FUPool(this);
268 }
FUPool::maxOpLatencies
std::array< Cycles, Num_OpClasses > maxOpLatencies
Maximum op execution latencies, per op class.
Definition: fu_pool.hh:73
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
FUPool::capabilityList
std::bitset< Num_OpClasses > capabilityList
Bitvector listing capabilities of this FU pool.
Definition: fu_pool.hh:78
FUPool::dump
void dump()
Debugging function used to dump FU information.
Definition: fu_pool.cc:206
FUPool::fuListIterator
std::vector< FuncUnit * >::iterator fuListIterator
Definition: fu_pool.hh:127
FUPool::getUnit
int getUnit(OpClass capability)
Gets a FU providing the requested capability.
Definition: fu_pool.cc:158
std::vector
STL vector class.
Definition: stl.hh:37
FUPool::unitBusy
std::vector< bool > unitBusy
Bitvector listing which FUs are busy.
Definition: fu_pool.hh:81
FUPool
Pool of FU's, specific to the new CPU model.
Definition: fu_pool.hh:69
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
MipsISA::k
Bitfield< 23 > k
Definition: dt_constants.hh:78
FUPool::isDrained
bool isDrained() const
Have all the FUs drained?
Definition: fu_pool.cc:240
FUPool::Params
FUPoolParams Params
Definition: fu_pool.hh:130
func_unit.hh
FUPool::FUIdxQueue::addFU
void addFU(int fu_idx)
Adds a FU to the queue.
Definition: fu_pool.cc:55
FuncUnit::name
std::string name
Definition: func_unit.hh:94
PowerISA::fu
Bitfield< 12 > fu
Definition: miscregs.hh:82
fu_pool.hh
FUPool::numFU
int numFU
Number of FUs.
Definition: fu_pool.hh:122
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
FUPool::pipelined
std::array< bool, Num_OpClasses > pipelined
Whether op is pipelined or not.
Definition: fu_pool.hh:75
FUPool::processFreeUnits
void processFreeUnits()
Frees all FUs on the list.
Definition: fu_pool.cc:193
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
FUDDiterator
std::vector< FUDesc * >::const_iterator FUDDiterator
Definition: func_unit.hh:72
FUPool::freeUnitNextCycle
void freeUnitNextCycle(int fu_idx)
Frees a FU at the end of this cycle.
Definition: fu_pool.cc:186
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
FUPool::FUIdxQueue::getFU
int getFU()
Returns the index of the FU at the head of the queue, and changes the index to the next element.
Definition: fu_pool.cc:62
FUPool::funcUnits
std::vector< FuncUnit * > funcUnits
Functional units.
Definition: fu_pool.hh:125
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
FUPool::FUPool
FUPool(const Params *p)
Constructs a FU pool.
Definition: fu_pool.cc:82
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
FUPool::unitsToBeFreed
std::vector< int > unitsToBeFreed
List of units to be freed at the end of this cycle.
Definition: fu_pool.hh:84
OPDDiterator
std::vector< OpDesc * >::const_iterator OPDDiterator
Definition: func_unit.hh:71
FuncUnit
Definition: func_unit.hh:83
FUPool::~FUPool
~FUPool()
Definition: fu_pool.cc:72
FUPool::fuPerCapList
FUIdxQueue fuPerCapList[Num_OpClasses]
Per op class queues of FUs that provide that capability.
Definition: fu_pool.hh:119
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17