gem5  v22.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 namespace gem5
48 {
49 
50 namespace o3
51 {
52 
54 //
55 // A pool of function units
56 //
57 
58 inline void
60 {
61  funcUnitsIdx.push_back(fu_idx);
62  ++size;
63 }
64 
65 inline int
67 {
68  int retval = funcUnitsIdx[idx++];
69 
70  if (idx == size)
71  idx = 0;
72 
73  return retval;
74 }
75 
77 {
78  fuListIterator i = funcUnits.begin();
79  fuListIterator end = funcUnits.end();
80  for (; i != end; ++i)
81  delete *i;
82 }
83 
84 
85 // Constructor
87  : SimObject(p)
88 {
89  numFU = 0;
90 
91  funcUnits.clear();
92 
93  maxOpLatencies.fill(Cycles(0));
94  pipelined.fill(true);
95 
96  //
97  // Iterate through the list of FUDescData structures
98  //
99  const std::vector<FUDesc *> &paramList = p.FUList;
100  for (FUDDiterator i = paramList.begin(); i != paramList.end(); ++i) {
101 
102  //
103  // Don't bother with this if we're not going to create any FU's
104  //
105  if ((*i)->number) {
106  //
107  // Create the FuncUnit object from this structure
108  // - add the capabilities listed in the FU's operation
109  // description
110  //
111  // We create the first unit, then duplicate it as needed
112  //
113  FuncUnit *fu = new FuncUnit;
114 
115  OPDDiterator j = (*i)->opDescList.begin();
116  OPDDiterator end = (*i)->opDescList.end();
117  for (; j != end; ++j) {
118  // indicate that this pool has this capability
119  capabilityList.set((*j)->opClass);
120 
121  // Add each of the FU's that will have this capability to the
122  // appropriate queue.
123  for (int k = 0; k < (*i)->number; ++k)
124  fuPerCapList[(*j)->opClass].addFU(numFU + k);
125 
126  // indicate that this FU has the capability
127  fu->addCapability((*j)->opClass, (*j)->opLat, (*j)->pipelined);
128 
129  if ((*j)->opLat > maxOpLatencies[(*j)->opClass])
130  maxOpLatencies[(*j)->opClass] = (*j)->opLat;
131 
132  if (!(*j)->pipelined)
133  pipelined[(*j)->opClass] = false;
134  }
135 
136  numFU++;
137 
138  // Add the appropriate number of copies of this FU to the list
139  fu->name = (*i)->name() + "(0)";
140  funcUnits.push_back(fu);
141 
142  for (int c = 1; c < (*i)->number; ++c) {
143  std::ostringstream s;
144  numFU++;
145  FuncUnit *fu2 = new FuncUnit(*fu);
146 
147  s << (*i)->name() << "(" << c << ")";
148  fu2->name = s.str();
149  funcUnits.push_back(fu2);
150  }
151  }
152  }
153 
154  unitBusy.resize(numFU);
155 
156  for (int i = 0; i < numFU; i++) {
157  unitBusy[i] = false;
158  }
159 }
160 
161 int
162 FUPool::getUnit(OpClass capability)
163 {
164  // If this pool doesn't have the specified capability,
165  // return this information to the caller
166  if (!capabilityList[capability])
167  return -2;
168 
169  int fu_idx = fuPerCapList[capability].getFU();
170  int start_idx = fu_idx;
171 
172  // Iterate through the circular queue if needed, stopping if we've reached
173  // the first element again.
174  while (unitBusy[fu_idx]) {
175  fu_idx = fuPerCapList[capability].getFU();
176  if (fu_idx == start_idx) {
177  // No FU available
178  return -1;
179  }
180  }
181 
182  assert(fu_idx < numFU);
183 
184  unitBusy[fu_idx] = true;
185 
186  return fu_idx;
187 }
188 
189 void
191 {
192  assert(unitBusy[fu_idx]);
193  unitsToBeFreed.push_back(fu_idx);
194 }
195 
196 void
198 {
199  while (!unitsToBeFreed.empty()) {
200  int fu_idx = unitsToBeFreed.back();
201  unitsToBeFreed.pop_back();
202 
203  assert(unitBusy[fu_idx]);
204 
205  unitBusy[fu_idx] = false;
206  }
207 }
208 
209 void
211 {
212  std::cout << "Function Unit Pool (" << name() << ")\n";
213  std::cout << "======================================\n";
214  std::cout << "Free List:\n";
215 
216  for (int i = 0; i < numFU; ++i) {
217  if (unitBusy[i]) {
218  continue;
219  }
220 
221  std::cout << " [" << i << "] : ";
222 
223  std::cout << funcUnits[i]->name << " ";
224 
225  std::cout << "\n";
226  }
227 
228  std::cout << "======================================\n";
229  std::cout << "Busy List:\n";
230  for (int i = 0; i < numFU; ++i) {
231  if (!unitBusy[i]) {
232  continue;
233  }
234 
235  std::cout << " [" << i << "] : ";
236 
237  std::cout << funcUnits[i]->name << " ";
238 
239  std::cout << "\n";
240  }
241 }
242 
243 bool
245 {
246  bool is_drained = true;
247  for (int i = 0; i < numFU; i++)
248  is_drained = is_drained && !unitBusy[i];
249 
250  return is_drained;
251 }
252 
253 } // namespace o3
254 } // namespace gem5
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
std::string name
Definition: func_unit.hh:113
virtual std::string name() const
Definition: named.hh:47
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
int size
Size of the queue.
Definition: fu_pool.hh:119
std::vector< int > funcUnitsIdx
Queue of FU indices.
Definition: fu_pool.hh:122
void addFU(int fu_idx)
Adds a FU to the queue.
Definition: fu_pool.cc:59
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:66
std::array< bool, Num_OpClasses > pipelined
Whether op is pipelined or not.
Definition: fu_pool.hh:81
FUPoolParams Params
Definition: fu_pool.hh:137
void processFreeUnits()
Frees all FUs on the list.
Definition: fu_pool.cc:197
void dump()
Debugging function used to dump FU information.
Definition: fu_pool.cc:210
FUIdxQueue fuPerCapList[Num_OpClasses]
Per op class queues of FUs that provide that capability.
Definition: fu_pool.hh:126
std::vector< bool > unitBusy
Bitvector listing which FUs are busy.
Definition: fu_pool.hh:87
FUPool(const Params &p)
Constructs a FU pool.
Definition: fu_pool.cc:86
void freeUnitNextCycle(int fu_idx)
Frees a FU at the end of this cycle.
Definition: fu_pool.cc:190
bool isDrained() const
Have all the FUs drained?
Definition: fu_pool.cc:244
int numFU
Number of FUs.
Definition: fu_pool.hh:129
int size()
Returns the total number of FUs.
Definition: fu_pool.hh:163
std::vector< FuncUnit * > funcUnits
Functional units.
Definition: fu_pool.hh:132
std::array< Cycles, Num_OpClasses > maxOpLatencies
Maximum op execution latencies, per op class.
Definition: fu_pool.hh:79
std::vector< int > unitsToBeFreed
List of units to be freed at the end of this cycle.
Definition: fu_pool.hh:90
std::vector< FuncUnit * >::iterator fuListIterator
Definition: fu_pool.hh:134
int getUnit(OpClass capability)
Gets a FU providing the requested capability.
Definition: fu_pool.cc:162
std::bitset< Num_OpClasses > capabilityList
Bitvector listing capabilities of this FU pool.
Definition: fu_pool.hh:84
STL vector class.
Definition: stl.hh:37
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 24 > j
Definition: misc_types.hh:57
Bitfield< 23 > k
Definition: dt_constants.hh:81
Bitfield< 12 > fu
Definition: misc.hh:94
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 2 > c
Definition: pagetable.hh:63
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::vector< OpDesc * >::const_iterator OPDDiterator
Definition: func_unit.hh:90
std::vector< FUDesc * >::const_iterator FUDDiterator
Definition: func_unit.hh:91

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1