fu_pool.cc revision 2327
1/* 2 * Copyright (c) 2002-2005 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. 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 unitBusy[fu_idx] = true; 187 188 return fu_idx; 189} 190 191void 192FUPool::freeUnitNextCycle(int fu_idx) 193{ 194 assert(unitBusy[fu_idx]); 195 unitsToBeFreed.push_back(fu_idx); 196} 197 198void 199FUPool::processFreeUnits() 200{ 201 while (!unitsToBeFreed.empty()) { 202 int fu_idx = unitsToBeFreed.back(); 203 unitsToBeFreed.pop_back(); 204 205 assert(unitBusy[fu_idx]); 206 207 unitBusy[fu_idx] = false; 208 } 209} 210 211void 212FUPool::dump() 213{ 214 cout << "Function Unit Pool (" << name() << ")\n"; 215 cout << "======================================\n"; 216 cout << "Free List:\n"; 217 218 for (int i = 0; i < numFU; ++i) { 219 if (unitBusy[i]) { 220 continue; 221 } 222 223 cout << " [" << i << "] : "; 224 225 cout << funcUnits[i]->name << " "; 226 227 cout << "\n"; 228 } 229 230 cout << "======================================\n"; 231 cout << "Busy List:\n"; 232 for (int i = 0; i < numFU; ++i) { 233 if (!unitBusy[i]) { 234 continue; 235 } 236 237 cout << " [" << i << "] : "; 238 239 cout << funcUnits[i]->name << " "; 240 241 cout << "\n"; 242 } 243} 244 245void 246FUPool::switchOut() 247{ 248} 249 250void 251FUPool::takeOverFrom() 252{ 253 for (int i = 0; i < numFU; i++) { 254 unitBusy[i] = false; 255 } 256 unitsToBeFreed.clear(); 257} 258 259// 260 261//////////////////////////////////////////////////////////////////////////// 262// 263// The SimObjects we use to get the FU information into the simulator 264// 265//////////////////////////////////////////////////////////////////////////// 266 267// 268// FUPool - Contails a list of FUDesc objects to make available 269// 270 271// 272// The FuPool object 273// 274 275BEGIN_DECLARE_SIM_OBJECT_PARAMS(FUPool) 276 277 SimObjectVectorParam<FUDesc *> FUList; 278 279END_DECLARE_SIM_OBJECT_PARAMS(FUPool) 280 281 282BEGIN_INIT_SIM_OBJECT_PARAMS(FUPool) 283 284 INIT_PARAM(FUList, "list of FU's for this pool") 285 286END_INIT_SIM_OBJECT_PARAMS(FUPool) 287 288 289CREATE_SIM_OBJECT(FUPool) 290{ 291 return new FUPool(getInstanceName(), FUList); 292} 293 294REGISTER_SIM_OBJECT("FUPool", FUPool) 295 296