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