fu_pool.cc (10814:46b6043bd32c) fu_pool.cc (11793:ef606668d247)
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 * Authors: Kevin Lim
41 */
42
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 * Authors: Kevin Lim
41 */
42
43#include "cpu/o3/fu_pool.hh"
44
43#include <sstream>
44
45#include <sstream>
46
45#include "cpu/o3/fu_pool.hh"
46#include "cpu/func_unit.hh"
47
48using namespace std;
49
50////////////////////////////////////////////////////////////////////////////
51//
52// A pool of function units
53//
54
55inline void
56FUPool::FUIdxQueue::addFU(int fu_idx)
57{
58 funcUnitsIdx.push_back(fu_idx);
59 ++size;
60}
61
62inline int
63FUPool::FUIdxQueue::getFU()
64{
65 int retval = funcUnitsIdx[idx++];
66
67 if (idx == size)
68 idx = 0;
69
70 return retval;
71}
72
73FUPool::~FUPool()
74{
75 fuListIterator i = funcUnits.begin();
76 fuListIterator end = funcUnits.end();
77 for (; i != end; ++i)
78 delete *i;
79}
80
81
82// Constructor
83FUPool::FUPool(const Params *p)
84 : SimObject(p)
85{
86 numFU = 0;
87
88 funcUnits.clear();
89
90 maxOpLatencies.fill(Cycles(0));
91 pipelined.fill(true);
92
93 //
94 // Iterate through the list of FUDescData structures
95 //
96 const vector<FUDesc *> &paramList = p->FUList;
97 for (FUDDiterator i = paramList.begin(); i != paramList.end(); ++i) {
98
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 OPDDiterator j = (*i)->opDescList.begin();
113 OPDDiterator end = (*i)->opDescList.end();
114 for (; j != end; ++j) {
115 // indicate that this pool has this capability
116 capabilityList.set((*j)->opClass);
117
118 // Add each of the FU's that will have this capability to the
119 // appropriate queue.
120 for (int k = 0; k < (*i)->number; ++k)
121 fuPerCapList[(*j)->opClass].addFU(numFU + k);
122
123 // indicate that this FU has the capability
124 fu->addCapability((*j)->opClass, (*j)->opLat, (*j)->pipelined);
125
126 if ((*j)->opLat > maxOpLatencies[(*j)->opClass])
127 maxOpLatencies[(*j)->opClass] = (*j)->opLat;
128
129 if (!(*j)->pipelined)
130 pipelined[(*j)->opClass] = false;
131 }
132
133 numFU++;
134
135 // Add the appropriate number of copies of this FU to the list
136 fu->name = (*i)->name() + "(0)";
137 funcUnits.push_back(fu);
138
139 for (int c = 1; c < (*i)->number; ++c) {
140 ostringstream s;
141 numFU++;
142 FuncUnit *fu2 = new FuncUnit(*fu);
143
144 s << (*i)->name() << "(" << c << ")";
145 fu2->name = s.str();
146 funcUnits.push_back(fu2);
147 }
148 }
149 }
150
151 unitBusy.resize(numFU);
152
153 for (int i = 0; i < numFU; i++) {
154 unitBusy[i] = false;
155 }
156}
157
158int
159FUPool::getUnit(OpClass capability)
160{
161 // If this pool doesn't have the specified capability,
162 // return this information to the caller
163 if (!capabilityList[capability])
164 return -2;
165
166 int fu_idx = fuPerCapList[capability].getFU();
167 int start_idx = fu_idx;
168
169 // Iterate through the circular queue if needed, stopping if we've reached
170 // the first element again.
171 while (unitBusy[fu_idx]) {
172 fu_idx = fuPerCapList[capability].getFU();
173 if (fu_idx == start_idx) {
174 // No FU available
175 return -1;
176 }
177 }
178
179 assert(fu_idx < numFU);
180
181 unitBusy[fu_idx] = true;
182
183 return fu_idx;
184}
185
186void
187FUPool::freeUnitNextCycle(int fu_idx)
188{
189 assert(unitBusy[fu_idx]);
190 unitsToBeFreed.push_back(fu_idx);
191}
192
193void
194FUPool::processFreeUnits()
195{
196 while (!unitsToBeFreed.empty()) {
197 int fu_idx = unitsToBeFreed.back();
198 unitsToBeFreed.pop_back();
199
200 assert(unitBusy[fu_idx]);
201
202 unitBusy[fu_idx] = false;
203 }
204}
205
206void
207FUPool::dump()
208{
209 cout << "Function Unit Pool (" << name() << ")\n";
210 cout << "======================================\n";
211 cout << "Free List:\n";
212
213 for (int i = 0; i < numFU; ++i) {
214 if (unitBusy[i]) {
215 continue;
216 }
217
218 cout << " [" << i << "] : ";
219
220 cout << funcUnits[i]->name << " ";
221
222 cout << "\n";
223 }
224
225 cout << "======================================\n";
226 cout << "Busy List:\n";
227 for (int i = 0; i < numFU; ++i) {
228 if (!unitBusy[i]) {
229 continue;
230 }
231
232 cout << " [" << i << "] : ";
233
234 cout << funcUnits[i]->name << " ";
235
236 cout << "\n";
237 }
238}
239
240bool
241FUPool::isDrained() const
242{
243 bool is_drained = true;
244 for (int i = 0; i < numFU; i++)
245 is_drained = is_drained && !unitBusy[i];
246
247 return is_drained;
248}
249
250//
251
252////////////////////////////////////////////////////////////////////////////
253//
254// The SimObjects we use to get the FU information into the simulator
255//
256////////////////////////////////////////////////////////////////////////////
257
258//
259// FUPool - Contails a list of FUDesc objects to make available
260//
261
262//
263// The FuPool object
264//
265FUPool *
266FUPoolParams::create()
267{
268 return new FUPool(this);
269}
47#include "cpu/func_unit.hh"
48
49using namespace std;
50
51////////////////////////////////////////////////////////////////////////////
52//
53// A pool of function units
54//
55
56inline void
57FUPool::FUIdxQueue::addFU(int fu_idx)
58{
59 funcUnitsIdx.push_back(fu_idx);
60 ++size;
61}
62
63inline int
64FUPool::FUIdxQueue::getFU()
65{
66 int retval = funcUnitsIdx[idx++];
67
68 if (idx == size)
69 idx = 0;
70
71 return retval;
72}
73
74FUPool::~FUPool()
75{
76 fuListIterator i = funcUnits.begin();
77 fuListIterator end = funcUnits.end();
78 for (; i != end; ++i)
79 delete *i;
80}
81
82
83// Constructor
84FUPool::FUPool(const Params *p)
85 : SimObject(p)
86{
87 numFU = 0;
88
89 funcUnits.clear();
90
91 maxOpLatencies.fill(Cycles(0));
92 pipelined.fill(true);
93
94 //
95 // Iterate through the list of FUDescData structures
96 //
97 const vector<FUDesc *> &paramList = p->FUList;
98 for (FUDDiterator i = paramList.begin(); i != paramList.end(); ++i) {
99
100 //
101 // Don't bother with this if we're not going to create any FU's
102 //
103 if ((*i)->number) {
104 //
105 // Create the FuncUnit object from this structure
106 // - add the capabilities listed in the FU's operation
107 // description
108 //
109 // We create the first unit, then duplicate it as needed
110 //
111 FuncUnit *fu = new FuncUnit;
112
113 OPDDiterator j = (*i)->opDescList.begin();
114 OPDDiterator end = (*i)->opDescList.end();
115 for (; j != end; ++j) {
116 // indicate that this pool has this capability
117 capabilityList.set((*j)->opClass);
118
119 // Add each of the FU's that will have this capability to the
120 // appropriate queue.
121 for (int k = 0; k < (*i)->number; ++k)
122 fuPerCapList[(*j)->opClass].addFU(numFU + k);
123
124 // indicate that this FU has the capability
125 fu->addCapability((*j)->opClass, (*j)->opLat, (*j)->pipelined);
126
127 if ((*j)->opLat > maxOpLatencies[(*j)->opClass])
128 maxOpLatencies[(*j)->opClass] = (*j)->opLat;
129
130 if (!(*j)->pipelined)
131 pipelined[(*j)->opClass] = false;
132 }
133
134 numFU++;
135
136 // Add the appropriate number of copies of this FU to the list
137 fu->name = (*i)->name() + "(0)";
138 funcUnits.push_back(fu);
139
140 for (int c = 1; c < (*i)->number; ++c) {
141 ostringstream s;
142 numFU++;
143 FuncUnit *fu2 = new FuncUnit(*fu);
144
145 s << (*i)->name() << "(" << c << ")";
146 fu2->name = s.str();
147 funcUnits.push_back(fu2);
148 }
149 }
150 }
151
152 unitBusy.resize(numFU);
153
154 for (int i = 0; i < numFU; i++) {
155 unitBusy[i] = false;
156 }
157}
158
159int
160FUPool::getUnit(OpClass capability)
161{
162 // If this pool doesn't have the specified capability,
163 // return this information to the caller
164 if (!capabilityList[capability])
165 return -2;
166
167 int fu_idx = fuPerCapList[capability].getFU();
168 int start_idx = fu_idx;
169
170 // Iterate through the circular queue if needed, stopping if we've reached
171 // the first element again.
172 while (unitBusy[fu_idx]) {
173 fu_idx = fuPerCapList[capability].getFU();
174 if (fu_idx == start_idx) {
175 // No FU available
176 return -1;
177 }
178 }
179
180 assert(fu_idx < numFU);
181
182 unitBusy[fu_idx] = true;
183
184 return fu_idx;
185}
186
187void
188FUPool::freeUnitNextCycle(int fu_idx)
189{
190 assert(unitBusy[fu_idx]);
191 unitsToBeFreed.push_back(fu_idx);
192}
193
194void
195FUPool::processFreeUnits()
196{
197 while (!unitsToBeFreed.empty()) {
198 int fu_idx = unitsToBeFreed.back();
199 unitsToBeFreed.pop_back();
200
201 assert(unitBusy[fu_idx]);
202
203 unitBusy[fu_idx] = false;
204 }
205}
206
207void
208FUPool::dump()
209{
210 cout << "Function Unit Pool (" << name() << ")\n";
211 cout << "======================================\n";
212 cout << "Free List:\n";
213
214 for (int i = 0; i < numFU; ++i) {
215 if (unitBusy[i]) {
216 continue;
217 }
218
219 cout << " [" << i << "] : ";
220
221 cout << funcUnits[i]->name << " ";
222
223 cout << "\n";
224 }
225
226 cout << "======================================\n";
227 cout << "Busy List:\n";
228 for (int i = 0; i < numFU; ++i) {
229 if (!unitBusy[i]) {
230 continue;
231 }
232
233 cout << " [" << i << "] : ";
234
235 cout << funcUnits[i]->name << " ";
236
237 cout << "\n";
238 }
239}
240
241bool
242FUPool::isDrained() const
243{
244 bool is_drained = true;
245 for (int i = 0; i < numFU; i++)
246 is_drained = is_drained && !unitBusy[i];
247
248 return is_drained;
249}
250
251//
252
253////////////////////////////////////////////////////////////////////////////
254//
255// The SimObjects we use to get the FU information into the simulator
256//
257////////////////////////////////////////////////////////////////////////////
258
259//
260// FUPool - Contails a list of FUDesc objects to make available
261//
262
263//
264// The FuPool object
265//
266FUPool *
267FUPoolParams::create()
268{
269 return new FUPool(this);
270}