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

Generated on Mon May 26 2025 09:19:08 for gem5 by doxygen 1.13.2