fu_pool.cc (2674:6d4afef73a20) fu_pool.cc (2689:dbf969c18a65)
1/*
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Kevin Lim
27 */
28
29#include <sstream>
30
31#include "cpu/o3/fu_pool.hh"
32#include "encumbered/cpu/full/fu_pool.hh"
33#include "sim/builder.hh"
34
35using namespace std;
36
37////////////////////////////////////////////////////////////////////////////
38//
39// A pool of function units
40//
41
42inline void
43FUPool::FUIdxQueue::addFU(int fu_idx)
44{
45 funcUnitsIdx.push_back(fu_idx);
46 ++size;
47}
48
49inline int
50FUPool::FUIdxQueue::getFU()
51{
52 int retval = funcUnitsIdx[idx++];
53
54 if (idx == size)
55 idx = 0;
56
57 return retval;
58}
59
60FUPool::~FUPool()
61{
62 fuListIterator i = funcUnits.begin();
63 fuListIterator end = funcUnits.end();
64 for (; i != end; ++i)
65 delete *i;
66}
67
68
69// Constructor
70FUPool::FUPool(string name, vector<FUDesc *> paramList)
71 : SimObject(name)
72{
73 numFU = 0;
74
75 funcUnits.clear();
76
77 for (int i = 0; i < Num_OpClasses; ++i) {
78 maxOpLatencies[i] = 0;
79 maxIssueLatencies[i] = 0;
80 }
81
82 //
83 // Iterate through the list of FUDescData structures
84 //
85 for (FUDDiterator i = paramList.begin(); i != paramList.end(); ++i) {
86
87 //
88 // Don't bother with this if we're not going to create any FU's
89 //
90 if ((*i)->number) {
91 //
92 // Create the FuncUnit object from this structure
93 // - add the capabilities listed in the FU's operation
94 // description
95 //
96 // We create the first unit, then duplicate it as needed
97 //
98 FuncUnit *fu = new FuncUnit;
99
100 OPDDiterator j = (*i)->opDescList.begin();
101 OPDDiterator end = (*i)->opDescList.end();
102 for (; j != end; ++j) {
103 // indicate that this pool has this capability
104 capabilityList.set((*j)->opClass);
105
106 // Add each of the FU's that will have this capability to the
107 // appropriate queue.
108 for (int k = 0; k < (*i)->number; ++k)
109 fuPerCapList[(*j)->opClass].addFU(numFU + k);
110
111 // indicate that this FU has the capability
112 fu->addCapability((*j)->opClass, (*j)->opLat, (*j)->issueLat);
113
114 if ((*j)->opLat > maxOpLatencies[(*j)->opClass])
115 maxOpLatencies[(*j)->opClass] = (*j)->opLat;
116
117 if ((*j)->issueLat > maxIssueLatencies[(*j)->opClass])
118 maxIssueLatencies[(*j)->opClass] = (*j)->issueLat;
119 }
120
121 numFU++;
122
123 // Add the appropriate number of copies of this FU to the list
124 ostringstream s;
125
126 s << (*i)->name() << "(0)";
127 fu->name = s.str();
128 funcUnits.push_back(fu);
129
130 for (int c = 1; c < (*i)->number; ++c) {
131 ostringstream s;
132 numFU++;
133 FuncUnit *fu2 = new FuncUnit(*fu);
134
135 s << (*i)->name() << "(" << c << ")";
136 fu2->name = s.str();
137 funcUnits.push_back(fu2);
138 }
139 }
140 }
141
142 unitBusy.resize(numFU);
143
144 for (int i = 0; i < numFU; i++) {
145 unitBusy[i] = false;
146 }
147}
148
149void
150FUPool::annotateMemoryUnits(unsigned hit_latency)
151{
152 maxOpLatencies[MemReadOp] = hit_latency;
153
154 fuListIterator i = funcUnits.begin();
155 fuListIterator iend = funcUnits.end();
156 for (; i != iend; ++i) {
157 if ((*i)->provides(MemReadOp))
158 (*i)->opLatency(MemReadOp) = hit_latency;
159
160 if ((*i)->provides(MemWriteOp))
161 (*i)->opLatency(MemWriteOp) = hit_latency;
162 }
163}
164
165int
166FUPool::getUnit(OpClass capability)
167{
168 // If this pool doesn't have the specified capability,
169 // return this information to the caller
170 if (!capabilityList[capability])
171 return -2;
172
173 int fu_idx = fuPerCapList[capability].getFU();
174 int start_idx = fu_idx;
175
176 // Iterate through the circular queue if needed, stopping if we've reached
177 // the first element again.
178 while (unitBusy[fu_idx]) {
179 fu_idx = fuPerCapList[capability].getFU();
180 if (fu_idx == start_idx) {
181 // No FU available
182 return -1;
183 }
184 }
185
186 assert(fu_idx < numFU);
187
188 unitBusy[fu_idx] = true;
189
190 return fu_idx;
191}
192
193void
194FUPool::freeUnitNextCycle(int fu_idx)
195{
196 assert(unitBusy[fu_idx]);
197 unitsToBeFreed.push_back(fu_idx);
198}
199
200void
201FUPool::processFreeUnits()
202{
203 while (!unitsToBeFreed.empty()) {
204 int fu_idx = unitsToBeFreed.back();
205 unitsToBeFreed.pop_back();
206
207 assert(unitBusy[fu_idx]);
208
209 unitBusy[fu_idx] = false;
210 }
211}
212
213void
214FUPool::dump()
215{
216 cout << "Function Unit Pool (" << name() << ")\n";
217 cout << "======================================\n";
218 cout << "Free List:\n";
219
220 for (int i = 0; i < numFU; ++i) {
221 if (unitBusy[i]) {
222 continue;
223 }
224
225 cout << " [" << i << "] : ";
226
227 cout << funcUnits[i]->name << " ";
228
229 cout << "\n";
230 }
231
232 cout << "======================================\n";
233 cout << "Busy List:\n";
234 for (int i = 0; i < numFU; ++i) {
235 if (!unitBusy[i]) {
236 continue;
237 }
238
239 cout << " [" << i << "] : ";
240
241 cout << funcUnits[i]->name << " ";
242
243 cout << "\n";
244 }
245}
246
247void
248FUPool::switchOut()
249{
250}
251
252void
253FUPool::takeOverFrom()
254{
255 for (int i = 0; i < numFU; i++) {
256 unitBusy[i] = false;
257 }
258 unitsToBeFreed.clear();
259}
260
261//
262
263////////////////////////////////////////////////////////////////////////////
264//
265// The SimObjects we use to get the FU information into the simulator
266//
267////////////////////////////////////////////////////////////////////////////
268
269//
270// FUPool - Contails a list of FUDesc objects to make available
271//
272
273//
274// The FuPool object
275//
276
277BEGIN_DECLARE_SIM_OBJECT_PARAMS(FUPool)
278
279 SimObjectVectorParam<FUDesc *> FUList;
280
281END_DECLARE_SIM_OBJECT_PARAMS(FUPool)
282
283
284BEGIN_INIT_SIM_OBJECT_PARAMS(FUPool)
285
286 INIT_PARAM(FUList, "list of FU's for this pool")
287
288END_INIT_SIM_OBJECT_PARAMS(FUPool)
289
290
291CREATE_SIM_OBJECT(FUPool)
292{
293 return new FUPool(getInstanceName(), FUList);
294}
295
296REGISTER_SIM_OBJECT("FUPool", FUPool)
297
29 */
30
31#include <sstream>
32
33#include "cpu/o3/fu_pool.hh"
34#include "encumbered/cpu/full/fu_pool.hh"
35#include "sim/builder.hh"
36
37using namespace std;
38
39////////////////////////////////////////////////////////////////////////////
40//
41// A pool of function units
42//
43
44inline void
45FUPool::FUIdxQueue::addFU(int fu_idx)
46{
47 funcUnitsIdx.push_back(fu_idx);
48 ++size;
49}
50
51inline int
52FUPool::FUIdxQueue::getFU()
53{
54 int retval = funcUnitsIdx[idx++];
55
56 if (idx == size)
57 idx = 0;
58
59 return retval;
60}
61
62FUPool::~FUPool()
63{
64 fuListIterator i = funcUnits.begin();
65 fuListIterator end = funcUnits.end();
66 for (; i != end; ++i)
67 delete *i;
68}
69
70
71// Constructor
72FUPool::FUPool(string name, vector<FUDesc *> paramList)
73 : SimObject(name)
74{
75 numFU = 0;
76
77 funcUnits.clear();
78
79 for (int i = 0; i < Num_OpClasses; ++i) {
80 maxOpLatencies[i] = 0;
81 maxIssueLatencies[i] = 0;
82 }
83
84 //
85 // Iterate through the list of FUDescData structures
86 //
87 for (FUDDiterator i = paramList.begin(); i != paramList.end(); ++i) {
88
89 //
90 // Don't bother with this if we're not going to create any FU's
91 //
92 if ((*i)->number) {
93 //
94 // Create the FuncUnit object from this structure
95 // - add the capabilities listed in the FU's operation
96 // description
97 //
98 // We create the first unit, then duplicate it as needed
99 //
100 FuncUnit *fu = new FuncUnit;
101
102 OPDDiterator j = (*i)->opDescList.begin();
103 OPDDiterator end = (*i)->opDescList.end();
104 for (; j != end; ++j) {
105 // indicate that this pool has this capability
106 capabilityList.set((*j)->opClass);
107
108 // Add each of the FU's that will have this capability to the
109 // appropriate queue.
110 for (int k = 0; k < (*i)->number; ++k)
111 fuPerCapList[(*j)->opClass].addFU(numFU + k);
112
113 // indicate that this FU has the capability
114 fu->addCapability((*j)->opClass, (*j)->opLat, (*j)->issueLat);
115
116 if ((*j)->opLat > maxOpLatencies[(*j)->opClass])
117 maxOpLatencies[(*j)->opClass] = (*j)->opLat;
118
119 if ((*j)->issueLat > maxIssueLatencies[(*j)->opClass])
120 maxIssueLatencies[(*j)->opClass] = (*j)->issueLat;
121 }
122
123 numFU++;
124
125 // Add the appropriate number of copies of this FU to the list
126 ostringstream s;
127
128 s << (*i)->name() << "(0)";
129 fu->name = s.str();
130 funcUnits.push_back(fu);
131
132 for (int c = 1; c < (*i)->number; ++c) {
133 ostringstream s;
134 numFU++;
135 FuncUnit *fu2 = new FuncUnit(*fu);
136
137 s << (*i)->name() << "(" << c << ")";
138 fu2->name = s.str();
139 funcUnits.push_back(fu2);
140 }
141 }
142 }
143
144 unitBusy.resize(numFU);
145
146 for (int i = 0; i < numFU; i++) {
147 unitBusy[i] = false;
148 }
149}
150
151void
152FUPool::annotateMemoryUnits(unsigned hit_latency)
153{
154 maxOpLatencies[MemReadOp] = hit_latency;
155
156 fuListIterator i = funcUnits.begin();
157 fuListIterator iend = funcUnits.end();
158 for (; i != iend; ++i) {
159 if ((*i)->provides(MemReadOp))
160 (*i)->opLatency(MemReadOp) = hit_latency;
161
162 if ((*i)->provides(MemWriteOp))
163 (*i)->opLatency(MemWriteOp) = hit_latency;
164 }
165}
166
167int
168FUPool::getUnit(OpClass capability)
169{
170 // If this pool doesn't have the specified capability,
171 // return this information to the caller
172 if (!capabilityList[capability])
173 return -2;
174
175 int fu_idx = fuPerCapList[capability].getFU();
176 int start_idx = fu_idx;
177
178 // Iterate through the circular queue if needed, stopping if we've reached
179 // the first element again.
180 while (unitBusy[fu_idx]) {
181 fu_idx = fuPerCapList[capability].getFU();
182 if (fu_idx == start_idx) {
183 // No FU available
184 return -1;
185 }
186 }
187
188 assert(fu_idx < numFU);
189
190 unitBusy[fu_idx] = true;
191
192 return fu_idx;
193}
194
195void
196FUPool::freeUnitNextCycle(int fu_idx)
197{
198 assert(unitBusy[fu_idx]);
199 unitsToBeFreed.push_back(fu_idx);
200}
201
202void
203FUPool::processFreeUnits()
204{
205 while (!unitsToBeFreed.empty()) {
206 int fu_idx = unitsToBeFreed.back();
207 unitsToBeFreed.pop_back();
208
209 assert(unitBusy[fu_idx]);
210
211 unitBusy[fu_idx] = false;
212 }
213}
214
215void
216FUPool::dump()
217{
218 cout << "Function Unit Pool (" << name() << ")\n";
219 cout << "======================================\n";
220 cout << "Free List:\n";
221
222 for (int i = 0; i < numFU; ++i) {
223 if (unitBusy[i]) {
224 continue;
225 }
226
227 cout << " [" << i << "] : ";
228
229 cout << funcUnits[i]->name << " ";
230
231 cout << "\n";
232 }
233
234 cout << "======================================\n";
235 cout << "Busy List:\n";
236 for (int i = 0; i < numFU; ++i) {
237 if (!unitBusy[i]) {
238 continue;
239 }
240
241 cout << " [" << i << "] : ";
242
243 cout << funcUnits[i]->name << " ";
244
245 cout << "\n";
246 }
247}
248
249void
250FUPool::switchOut()
251{
252}
253
254void
255FUPool::takeOverFrom()
256{
257 for (int i = 0; i < numFU; i++) {
258 unitBusy[i] = false;
259 }
260 unitsToBeFreed.clear();
261}
262
263//
264
265////////////////////////////////////////////////////////////////////////////
266//
267// The SimObjects we use to get the FU information into the simulator
268//
269////////////////////////////////////////////////////////////////////////////
270
271//
272// FUPool - Contails a list of FUDesc objects to make available
273//
274
275//
276// The FuPool object
277//
278
279BEGIN_DECLARE_SIM_OBJECT_PARAMS(FUPool)
280
281 SimObjectVectorParam<FUDesc *> FUList;
282
283END_DECLARE_SIM_OBJECT_PARAMS(FUPool)
284
285
286BEGIN_INIT_SIM_OBJECT_PARAMS(FUPool)
287
288 INIT_PARAM(FUList, "list of FU's for this pool")
289
290END_INIT_SIM_OBJECT_PARAMS(FUPool)
291
292
293CREATE_SIM_OBJECT(FUPool)
294{
295 return new FUPool(getInstanceName(), FUList);
296}
297
298REGISTER_SIM_OBJECT("FUPool", FUPool)
299