1/* 2 * Copyright (c) 2004-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. 27 * 28 * Authors: Kevin Lim 29 * Korey Sewell 30 */ 31 32#include "config/full_system.hh" 33#include "config/use_checker.hh" 34 35#include <algorithm> 36#include <string> 37 38#include "arch/utility.hh" 39#include "base/loader/symtab.hh" 40#include "base/timebuf.hh" 41#include "cpu/exetrace.hh" 42#include "cpu/o3/commit.hh" 43#include "cpu/o3/thread_state.hh" 44 45#if USE_CHECKER 46#include "cpu/checker/cpu.hh" 47#endif 48 49template <class Impl> 50DefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 51 unsigned _tid) 52 : Event(&mainEventQueue, CPU_Tick_Pri), commit(_commit), tid(_tid) 53{ 54 this->setFlags(Event::AutoDelete); 55} 56 57template <class Impl> 58void 59DefaultCommit<Impl>::TrapEvent::process() 60{ 61 // This will get reset by commit if it was switched out at the 62 // time of this event processing. 63 commit->trapSquash[tid] = true; 64} 65 66template <class Impl> 67const char * 68DefaultCommit<Impl>::TrapEvent::description() 69{ 70 return "Trap event"; 71} 72 73template <class Impl> 74DefaultCommit<Impl>::DefaultCommit(Params *params) 75 : squashCounter(0), 76 iewToCommitDelay(params->iewToCommitDelay), 77 commitToIEWDelay(params->commitToIEWDelay), 78 renameToROBDelay(params->renameToROBDelay), 79 fetchToCommitDelay(params->commitToFetchDelay), 80 renameWidth(params->renameWidth), 81 commitWidth(params->commitWidth), 82 numThreads(params->numberOfThreads), 83 drainPending(false), 84 switchedOut(false), 85 trapLatency(params->trapLatency) 86{ 87 _status = Active; 88 _nextStatus = Inactive; 89 std::string policy = params->smtCommitPolicy; 90 91 //Convert string to lowercase 92 std::transform(policy.begin(), policy.end(), policy.begin(), 93 (int(*)(int)) tolower); 94 95 //Assign commit policy 96 if (policy == "aggressive"){ 97 commitPolicy = Aggressive; 98 99 DPRINTF(Commit,"Commit Policy set to Aggressive."); 100 } else if (policy == "roundrobin"){ 101 commitPolicy = RoundRobin; 102 103 //Set-Up Priority List 104 for (int tid=0; tid < numThreads; tid++) { 105 priority_list.push_back(tid); 106 } 107 108 DPRINTF(Commit,"Commit Policy set to Round Robin."); 109 } else if (policy == "oldestready"){ 110 commitPolicy = OldestReady; 111 112 DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 113 } else { 114 assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 115 "RoundRobin,OldestReady}"); 116 } 117 118 for (int i=0; i < numThreads; i++) { 119 commitStatus[i] = Idle; 120 changedROBNumEntries[i] = false; 121 trapSquash[i] = false; 122 tcSquash[i] = false; 123 PC[i] = nextPC[i] = nextNPC[i] = 0; 124 } 125#if FULL_SYSTEM 126 interrupt = NoFault; 127#endif 128} 129 130template <class Impl> 131std::string 132DefaultCommit<Impl>::name() const 133{ 134 return cpu->name() + ".commit"; 135} 136 137template <class Impl> 138void 139DefaultCommit<Impl>::regStats() 140{ 141 using namespace Stats; 142 commitCommittedInsts 143 .name(name() + ".commitCommittedInsts") 144 .desc("The number of committed instructions") 145 .prereq(commitCommittedInsts); 146 commitSquashedInsts 147 .name(name() + ".commitSquashedInsts") 148 .desc("The number of squashed insts skipped by commit") 149 .prereq(commitSquashedInsts); 150 commitSquashEvents 151 .name(name() + ".commitSquashEvents") 152 .desc("The number of times commit is told to squash") 153 .prereq(commitSquashEvents); 154 commitNonSpecStalls 155 .name(name() + ".commitNonSpecStalls") 156 .desc("The number of times commit has been forced to stall to " 157 "communicate backwards") 158 .prereq(commitNonSpecStalls); 159 branchMispredicts 160 .name(name() + ".branchMispredicts") 161 .desc("The number of times a branch was mispredicted") 162 .prereq(branchMispredicts); 163 numCommittedDist 164 .init(0,commitWidth,1) 165 .name(name() + ".COM:committed_per_cycle") 166 .desc("Number of insts commited each cycle") 167 .flags(Stats::pdf) 168 ; 169 170 statComInst 171 .init(cpu->number_of_threads) 172 .name(name() + ".COM:count") 173 .desc("Number of instructions committed") 174 .flags(total) 175 ; 176 177 statComSwp 178 .init(cpu->number_of_threads) 179 .name(name() + ".COM:swp_count") 180 .desc("Number of s/w prefetches committed") 181 .flags(total) 182 ; 183 184 statComRefs 185 .init(cpu->number_of_threads) 186 .name(name() + ".COM:refs") 187 .desc("Number of memory references committed") 188 .flags(total) 189 ; 190 191 statComLoads 192 .init(cpu->number_of_threads) 193 .name(name() + ".COM:loads") 194 .desc("Number of loads committed") 195 .flags(total) 196 ; 197 198 statComMembars 199 .init(cpu->number_of_threads) 200 .name(name() + ".COM:membars") 201 .desc("Number of memory barriers committed") 202 .flags(total) 203 ; 204 205 statComBranches 206 .init(cpu->number_of_threads) 207 .name(name() + ".COM:branches") 208 .desc("Number of branches committed") 209 .flags(total) 210 ; 211 212 commitEligible 213 .init(cpu->number_of_threads) 214 .name(name() + ".COM:bw_limited") 215 .desc("number of insts not committed due to BW limits") 216 .flags(total) 217 ; 218 219 commitEligibleSamples 220 .name(name() + ".COM:bw_lim_events") 221 .desc("number cycles where commit BW limit reached") 222 ; 223} 224 225template <class Impl> 226void 227DefaultCommit<Impl>::setCPU(O3CPU *cpu_ptr) 228{ 229 DPRINTF(Commit, "Commit: Setting CPU pointer.\n"); 230 cpu = cpu_ptr; 231 232 // Commit must broadcast the number of free entries it has at the start of 233 // the simulation, so it starts as active. 234 cpu->activateStage(O3CPU::CommitIdx); 235 236 trapLatency = cpu->cycles(trapLatency); 237} 238 239template <class Impl> 240void 241DefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 242{ 243 thread = threads; 244} 245 246template <class Impl> 247void 248DefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 249{ 250 DPRINTF(Commit, "Commit: Setting time buffer pointer.\n"); 251 timeBuffer = tb_ptr; 252 253 // Setup wire to send information back to IEW. 254 toIEW = timeBuffer->getWire(0); 255 256 // Setup wire to read data from IEW (for the ROB). 257 robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 258} 259 260template <class Impl> 261void 262DefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 263{ 264 DPRINTF(Commit, "Commit: Setting fetch queue pointer.\n"); 265 fetchQueue = fq_ptr; 266 267 // Setup wire to get instructions from rename (for the ROB). 268 fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 269} 270 271template <class Impl> 272void 273DefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 274{ 275 DPRINTF(Commit, "Commit: Setting rename queue pointer.\n"); 276 renameQueue = rq_ptr; 277 278 // Setup wire to get instructions from rename (for the ROB). 279 fromRename = renameQueue->getWire(-renameToROBDelay); 280} 281 282template <class Impl> 283void 284DefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 285{ 286 DPRINTF(Commit, "Commit: Setting IEW queue pointer.\n"); 287 iewQueue = iq_ptr; 288 289 // Setup wire to get instructions from IEW. 290 fromIEW = iewQueue->getWire(-iewToCommitDelay); 291} 292 293template <class Impl> 294void 295DefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 296{ 297 iewStage = iew_stage; 298} 299 300template<class Impl> 301void 302DefaultCommit<Impl>::setActiveThreads(std::list<unsigned> *at_ptr) 303{ 304 DPRINTF(Commit, "Commit: Setting active threads list pointer.\n"); 305 activeThreads = at_ptr; 306} 307 308template <class Impl> 309void 310DefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 311{ 312 DPRINTF(Commit, "Setting rename map pointers.\n"); 313 314 for (int i=0; i < numThreads; i++) { 315 renameMap[i] = &rm_ptr[i]; 316 } 317} 318 319template <class Impl> 320void 321DefaultCommit<Impl>::setROB(ROB *rob_ptr) 322{ 323 DPRINTF(Commit, "Commit: Setting ROB pointer.\n"); 324 rob = rob_ptr; 325} 326 327template <class Impl> 328void 329DefaultCommit<Impl>::initStage() 330{ 331 rob->setActiveThreads(activeThreads); 332 rob->resetEntries(); 333 334 // Broadcast the number of free entries. 335 for (int i=0; i < numThreads; i++) { 336 toIEW->commitInfo[i].usedROB = true; 337 toIEW->commitInfo[i].freeROBEntries = rob->numFreeEntries(i); 338 } 339 340 cpu->activityThisCycle(); 341} 342 343template <class Impl> 344bool 345DefaultCommit<Impl>::drain() 346{ 347 drainPending = true; 348 349 return false; 350} 351 352template <class Impl> 353void 354DefaultCommit<Impl>::switchOut() 355{ 356 switchedOut = true; 357 drainPending = false; 358 rob->switchOut(); 359} 360 361template <class Impl> 362void 363DefaultCommit<Impl>::resume() 364{ 365 drainPending = false; 366} 367 368template <class Impl> 369void 370DefaultCommit<Impl>::takeOverFrom() 371{ 372 switchedOut = false; 373 _status = Active; 374 _nextStatus = Inactive; 375 for (int i=0; i < numThreads; i++) { 376 commitStatus[i] = Idle; 377 changedROBNumEntries[i] = false; 378 trapSquash[i] = false; 379 tcSquash[i] = false; 380 } 381 squashCounter = 0; 382 rob->takeOverFrom(); 383} 384 385template <class Impl> 386void 387DefaultCommit<Impl>::updateStatus() 388{ 389 // reset ROB changed variable
| 1/* 2 * Copyright (c) 2004-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. 27 * 28 * Authors: Kevin Lim 29 * Korey Sewell 30 */ 31 32#include "config/full_system.hh" 33#include "config/use_checker.hh" 34 35#include <algorithm> 36#include <string> 37 38#include "arch/utility.hh" 39#include "base/loader/symtab.hh" 40#include "base/timebuf.hh" 41#include "cpu/exetrace.hh" 42#include "cpu/o3/commit.hh" 43#include "cpu/o3/thread_state.hh" 44 45#if USE_CHECKER 46#include "cpu/checker/cpu.hh" 47#endif 48 49template <class Impl> 50DefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 51 unsigned _tid) 52 : Event(&mainEventQueue, CPU_Tick_Pri), commit(_commit), tid(_tid) 53{ 54 this->setFlags(Event::AutoDelete); 55} 56 57template <class Impl> 58void 59DefaultCommit<Impl>::TrapEvent::process() 60{ 61 // This will get reset by commit if it was switched out at the 62 // time of this event processing. 63 commit->trapSquash[tid] = true; 64} 65 66template <class Impl> 67const char * 68DefaultCommit<Impl>::TrapEvent::description() 69{ 70 return "Trap event"; 71} 72 73template <class Impl> 74DefaultCommit<Impl>::DefaultCommit(Params *params) 75 : squashCounter(0), 76 iewToCommitDelay(params->iewToCommitDelay), 77 commitToIEWDelay(params->commitToIEWDelay), 78 renameToROBDelay(params->renameToROBDelay), 79 fetchToCommitDelay(params->commitToFetchDelay), 80 renameWidth(params->renameWidth), 81 commitWidth(params->commitWidth), 82 numThreads(params->numberOfThreads), 83 drainPending(false), 84 switchedOut(false), 85 trapLatency(params->trapLatency) 86{ 87 _status = Active; 88 _nextStatus = Inactive; 89 std::string policy = params->smtCommitPolicy; 90 91 //Convert string to lowercase 92 std::transform(policy.begin(), policy.end(), policy.begin(), 93 (int(*)(int)) tolower); 94 95 //Assign commit policy 96 if (policy == "aggressive"){ 97 commitPolicy = Aggressive; 98 99 DPRINTF(Commit,"Commit Policy set to Aggressive."); 100 } else if (policy == "roundrobin"){ 101 commitPolicy = RoundRobin; 102 103 //Set-Up Priority List 104 for (int tid=0; tid < numThreads; tid++) { 105 priority_list.push_back(tid); 106 } 107 108 DPRINTF(Commit,"Commit Policy set to Round Robin."); 109 } else if (policy == "oldestready"){ 110 commitPolicy = OldestReady; 111 112 DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 113 } else { 114 assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 115 "RoundRobin,OldestReady}"); 116 } 117 118 for (int i=0; i < numThreads; i++) { 119 commitStatus[i] = Idle; 120 changedROBNumEntries[i] = false; 121 trapSquash[i] = false; 122 tcSquash[i] = false; 123 PC[i] = nextPC[i] = nextNPC[i] = 0; 124 } 125#if FULL_SYSTEM 126 interrupt = NoFault; 127#endif 128} 129 130template <class Impl> 131std::string 132DefaultCommit<Impl>::name() const 133{ 134 return cpu->name() + ".commit"; 135} 136 137template <class Impl> 138void 139DefaultCommit<Impl>::regStats() 140{ 141 using namespace Stats; 142 commitCommittedInsts 143 .name(name() + ".commitCommittedInsts") 144 .desc("The number of committed instructions") 145 .prereq(commitCommittedInsts); 146 commitSquashedInsts 147 .name(name() + ".commitSquashedInsts") 148 .desc("The number of squashed insts skipped by commit") 149 .prereq(commitSquashedInsts); 150 commitSquashEvents 151 .name(name() + ".commitSquashEvents") 152 .desc("The number of times commit is told to squash") 153 .prereq(commitSquashEvents); 154 commitNonSpecStalls 155 .name(name() + ".commitNonSpecStalls") 156 .desc("The number of times commit has been forced to stall to " 157 "communicate backwards") 158 .prereq(commitNonSpecStalls); 159 branchMispredicts 160 .name(name() + ".branchMispredicts") 161 .desc("The number of times a branch was mispredicted") 162 .prereq(branchMispredicts); 163 numCommittedDist 164 .init(0,commitWidth,1) 165 .name(name() + ".COM:committed_per_cycle") 166 .desc("Number of insts commited each cycle") 167 .flags(Stats::pdf) 168 ; 169 170 statComInst 171 .init(cpu->number_of_threads) 172 .name(name() + ".COM:count") 173 .desc("Number of instructions committed") 174 .flags(total) 175 ; 176 177 statComSwp 178 .init(cpu->number_of_threads) 179 .name(name() + ".COM:swp_count") 180 .desc("Number of s/w prefetches committed") 181 .flags(total) 182 ; 183 184 statComRefs 185 .init(cpu->number_of_threads) 186 .name(name() + ".COM:refs") 187 .desc("Number of memory references committed") 188 .flags(total) 189 ; 190 191 statComLoads 192 .init(cpu->number_of_threads) 193 .name(name() + ".COM:loads") 194 .desc("Number of loads committed") 195 .flags(total) 196 ; 197 198 statComMembars 199 .init(cpu->number_of_threads) 200 .name(name() + ".COM:membars") 201 .desc("Number of memory barriers committed") 202 .flags(total) 203 ; 204 205 statComBranches 206 .init(cpu->number_of_threads) 207 .name(name() + ".COM:branches") 208 .desc("Number of branches committed") 209 .flags(total) 210 ; 211 212 commitEligible 213 .init(cpu->number_of_threads) 214 .name(name() + ".COM:bw_limited") 215 .desc("number of insts not committed due to BW limits") 216 .flags(total) 217 ; 218 219 commitEligibleSamples 220 .name(name() + ".COM:bw_lim_events") 221 .desc("number cycles where commit BW limit reached") 222 ; 223} 224 225template <class Impl> 226void 227DefaultCommit<Impl>::setCPU(O3CPU *cpu_ptr) 228{ 229 DPRINTF(Commit, "Commit: Setting CPU pointer.\n"); 230 cpu = cpu_ptr; 231 232 // Commit must broadcast the number of free entries it has at the start of 233 // the simulation, so it starts as active. 234 cpu->activateStage(O3CPU::CommitIdx); 235 236 trapLatency = cpu->cycles(trapLatency); 237} 238 239template <class Impl> 240void 241DefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 242{ 243 thread = threads; 244} 245 246template <class Impl> 247void 248DefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 249{ 250 DPRINTF(Commit, "Commit: Setting time buffer pointer.\n"); 251 timeBuffer = tb_ptr; 252 253 // Setup wire to send information back to IEW. 254 toIEW = timeBuffer->getWire(0); 255 256 // Setup wire to read data from IEW (for the ROB). 257 robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 258} 259 260template <class Impl> 261void 262DefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 263{ 264 DPRINTF(Commit, "Commit: Setting fetch queue pointer.\n"); 265 fetchQueue = fq_ptr; 266 267 // Setup wire to get instructions from rename (for the ROB). 268 fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 269} 270 271template <class Impl> 272void 273DefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 274{ 275 DPRINTF(Commit, "Commit: Setting rename queue pointer.\n"); 276 renameQueue = rq_ptr; 277 278 // Setup wire to get instructions from rename (for the ROB). 279 fromRename = renameQueue->getWire(-renameToROBDelay); 280} 281 282template <class Impl> 283void 284DefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 285{ 286 DPRINTF(Commit, "Commit: Setting IEW queue pointer.\n"); 287 iewQueue = iq_ptr; 288 289 // Setup wire to get instructions from IEW. 290 fromIEW = iewQueue->getWire(-iewToCommitDelay); 291} 292 293template <class Impl> 294void 295DefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 296{ 297 iewStage = iew_stage; 298} 299 300template<class Impl> 301void 302DefaultCommit<Impl>::setActiveThreads(std::list<unsigned> *at_ptr) 303{ 304 DPRINTF(Commit, "Commit: Setting active threads list pointer.\n"); 305 activeThreads = at_ptr; 306} 307 308template <class Impl> 309void 310DefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 311{ 312 DPRINTF(Commit, "Setting rename map pointers.\n"); 313 314 for (int i=0; i < numThreads; i++) { 315 renameMap[i] = &rm_ptr[i]; 316 } 317} 318 319template <class Impl> 320void 321DefaultCommit<Impl>::setROB(ROB *rob_ptr) 322{ 323 DPRINTF(Commit, "Commit: Setting ROB pointer.\n"); 324 rob = rob_ptr; 325} 326 327template <class Impl> 328void 329DefaultCommit<Impl>::initStage() 330{ 331 rob->setActiveThreads(activeThreads); 332 rob->resetEntries(); 333 334 // Broadcast the number of free entries. 335 for (int i=0; i < numThreads; i++) { 336 toIEW->commitInfo[i].usedROB = true; 337 toIEW->commitInfo[i].freeROBEntries = rob->numFreeEntries(i); 338 } 339 340 cpu->activityThisCycle(); 341} 342 343template <class Impl> 344bool 345DefaultCommit<Impl>::drain() 346{ 347 drainPending = true; 348 349 return false; 350} 351 352template <class Impl> 353void 354DefaultCommit<Impl>::switchOut() 355{ 356 switchedOut = true; 357 drainPending = false; 358 rob->switchOut(); 359} 360 361template <class Impl> 362void 363DefaultCommit<Impl>::resume() 364{ 365 drainPending = false; 366} 367 368template <class Impl> 369void 370DefaultCommit<Impl>::takeOverFrom() 371{ 372 switchedOut = false; 373 _status = Active; 374 _nextStatus = Inactive; 375 for (int i=0; i < numThreads; i++) { 376 commitStatus[i] = Idle; 377 changedROBNumEntries[i] = false; 378 trapSquash[i] = false; 379 tcSquash[i] = false; 380 } 381 squashCounter = 0; 382 rob->takeOverFrom(); 383} 384 385template <class Impl> 386void 387DefaultCommit<Impl>::updateStatus() 388{ 389 // reset ROB changed variable
|
390 std::list<unsigned>::iterator threads = (*activeThreads).begin(); 391 while (threads != (*activeThreads).end()) {
| 390 std::list<unsigned>::iterator threads = activeThreads->begin(); 391 std::list<unsigned>::iterator end = activeThreads->end(); 392 393 while (threads != end) {
|
392 unsigned tid = *threads++;
| 394 unsigned tid = *threads++;
|
| 395
|
393 changedROBNumEntries[tid] = false; 394 395 // Also check if any of the threads has a trap pending 396 if (commitStatus[tid] == TrapPending || 397 commitStatus[tid] == FetchTrapPending) { 398 _nextStatus = Active; 399 } 400 } 401 402 if (_nextStatus == Inactive && _status == Active) { 403 DPRINTF(Activity, "Deactivating stage.\n"); 404 cpu->deactivateStage(O3CPU::CommitIdx); 405 } else if (_nextStatus == Active && _status == Inactive) { 406 DPRINTF(Activity, "Activating stage.\n"); 407 cpu->activateStage(O3CPU::CommitIdx); 408 } 409 410 _status = _nextStatus; 411} 412 413template <class Impl> 414void 415DefaultCommit<Impl>::setNextStatus() 416{ 417 int squashes = 0; 418
| 396 changedROBNumEntries[tid] = false; 397 398 // Also check if any of the threads has a trap pending 399 if (commitStatus[tid] == TrapPending || 400 commitStatus[tid] == FetchTrapPending) { 401 _nextStatus = Active; 402 } 403 } 404 405 if (_nextStatus == Inactive && _status == Active) { 406 DPRINTF(Activity, "Deactivating stage.\n"); 407 cpu->deactivateStage(O3CPU::CommitIdx); 408 } else if (_nextStatus == Active && _status == Inactive) { 409 DPRINTF(Activity, "Activating stage.\n"); 410 cpu->activateStage(O3CPU::CommitIdx); 411 } 412 413 _status = _nextStatus; 414} 415 416template <class Impl> 417void 418DefaultCommit<Impl>::setNextStatus() 419{ 420 int squashes = 0; 421
|
419 std::list<unsigned>::iterator threads = (*activeThreads).begin();
| 422 std::list<unsigned>::iterator threads = activeThreads->begin(); 423 std::list<unsigned>::iterator end = activeThreads->end();
|
420
| 424
|
421 while (threads != (*activeThreads).end()) {
| 425 while (threads != end) {
|
422 unsigned tid = *threads++; 423 424 if (commitStatus[tid] == ROBSquashing) { 425 squashes++; 426 } 427 } 428 429 squashCounter = squashes; 430 431 // If commit is currently squashing, then it will have activity for the 432 // next cycle. Set its next status as active. 433 if (squashCounter) { 434 _nextStatus = Active; 435 } 436} 437 438template <class Impl> 439bool 440DefaultCommit<Impl>::changedROBEntries() 441{
| 426 unsigned tid = *threads++; 427 428 if (commitStatus[tid] == ROBSquashing) { 429 squashes++; 430 } 431 } 432 433 squashCounter = squashes; 434 435 // If commit is currently squashing, then it will have activity for the 436 // next cycle. Set its next status as active. 437 if (squashCounter) { 438 _nextStatus = Active; 439 } 440} 441 442template <class Impl> 443bool 444DefaultCommit<Impl>::changedROBEntries() 445{
|
442 std::list<unsigned>::iterator threads = (*activeThreads).begin();
| 446 std::list<unsigned>::iterator threads = activeThreads->begin(); 447 std::list<unsigned>::iterator end = activeThreads->end();
|
443
| 448
|
444 while (threads != (*activeThreads).end()) {
| 449 while (threads != end) {
|
445 unsigned tid = *threads++; 446 447 if (changedROBNumEntries[tid]) { 448 return true; 449 } 450 } 451 452 return false; 453} 454 455template <class Impl> 456unsigned 457DefaultCommit<Impl>::numROBFreeEntries(unsigned tid) 458{ 459 return rob->numFreeEntries(tid); 460} 461 462template <class Impl> 463void 464DefaultCommit<Impl>::generateTrapEvent(unsigned tid) 465{ 466 DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 467 468 TrapEvent *trap = new TrapEvent(this, tid); 469 470 trap->schedule(curTick + trapLatency); 471 472 thread[tid]->trapPending = true; 473} 474 475template <class Impl> 476void 477DefaultCommit<Impl>::generateTCEvent(unsigned tid) 478{ 479 DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 480 481 tcSquash[tid] = true; 482} 483 484template <class Impl> 485void 486DefaultCommit<Impl>::squashAll(unsigned tid) 487{ 488 // If we want to include the squashing instruction in the squash, 489 // then use one older sequence number. 490 // Hopefully this doesn't mess things up. Basically I want to squash 491 // all instructions of this thread. 492 InstSeqNum squashed_inst = rob->isEmpty() ? 493 0 : rob->readHeadInst(tid)->seqNum - 1;; 494 495 // All younger instructions will be squashed. Set the sequence 496 // number as the youngest instruction in the ROB (0 in this case. 497 // Hopefully nothing breaks.) 498 youngestSeqNum[tid] = 0; 499 500 rob->squash(squashed_inst, tid); 501 changedROBNumEntries[tid] = true; 502 503 // Send back the sequence number of the squashed instruction. 504 toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 505 506 // Send back the squash signal to tell stages that they should 507 // squash. 508 toIEW->commitInfo[tid].squash = true; 509 510 // Send back the rob squashing signal so other stages know that 511 // the ROB is in the process of squashing. 512 toIEW->commitInfo[tid].robSquashing = true; 513 514 toIEW->commitInfo[tid].branchMispredict = false; 515 516 toIEW->commitInfo[tid].nextPC = PC[tid];
| 450 unsigned tid = *threads++; 451 452 if (changedROBNumEntries[tid]) { 453 return true; 454 } 455 } 456 457 return false; 458} 459 460template <class Impl> 461unsigned 462DefaultCommit<Impl>::numROBFreeEntries(unsigned tid) 463{ 464 return rob->numFreeEntries(tid); 465} 466 467template <class Impl> 468void 469DefaultCommit<Impl>::generateTrapEvent(unsigned tid) 470{ 471 DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 472 473 TrapEvent *trap = new TrapEvent(this, tid); 474 475 trap->schedule(curTick + trapLatency); 476 477 thread[tid]->trapPending = true; 478} 479 480template <class Impl> 481void 482DefaultCommit<Impl>::generateTCEvent(unsigned tid) 483{ 484 DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 485 486 tcSquash[tid] = true; 487} 488 489template <class Impl> 490void 491DefaultCommit<Impl>::squashAll(unsigned tid) 492{ 493 // If we want to include the squashing instruction in the squash, 494 // then use one older sequence number. 495 // Hopefully this doesn't mess things up. Basically I want to squash 496 // all instructions of this thread. 497 InstSeqNum squashed_inst = rob->isEmpty() ? 498 0 : rob->readHeadInst(tid)->seqNum - 1;; 499 500 // All younger instructions will be squashed. Set the sequence 501 // number as the youngest instruction in the ROB (0 in this case. 502 // Hopefully nothing breaks.) 503 youngestSeqNum[tid] = 0; 504 505 rob->squash(squashed_inst, tid); 506 changedROBNumEntries[tid] = true; 507 508 // Send back the sequence number of the squashed instruction. 509 toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 510 511 // Send back the squash signal to tell stages that they should 512 // squash. 513 toIEW->commitInfo[tid].squash = true; 514 515 // Send back the rob squashing signal so other stages know that 516 // the ROB is in the process of squashing. 517 toIEW->commitInfo[tid].robSquashing = true; 518 519 toIEW->commitInfo[tid].branchMispredict = false; 520 521 toIEW->commitInfo[tid].nextPC = PC[tid];
|
517 toIEW->commitInfo[tid].nextNPC = nextPC[tid];
| |
518} 519 520template <class Impl> 521void 522DefaultCommit<Impl>::squashFromTrap(unsigned tid) 523{ 524 squashAll(tid); 525 526 DPRINTF(Commit, "Squashing from trap, restarting at PC %#x\n", PC[tid]); 527 528 thread[tid]->trapPending = false; 529 thread[tid]->inSyscall = false; 530 531 trapSquash[tid] = false; 532 533 commitStatus[tid] = ROBSquashing; 534 cpu->activityThisCycle(); 535} 536 537template <class Impl> 538void 539DefaultCommit<Impl>::squashFromTC(unsigned tid) 540{ 541 squashAll(tid); 542 543 DPRINTF(Commit, "Squashing from TC, restarting at PC %#x\n", PC[tid]); 544 545 thread[tid]->inSyscall = false; 546 assert(!thread[tid]->trapPending); 547 548 commitStatus[tid] = ROBSquashing; 549 cpu->activityThisCycle(); 550 551 tcSquash[tid] = false; 552} 553 554template <class Impl> 555void 556DefaultCommit<Impl>::tick() 557{ 558 wroteToTimeBuffer = false; 559 _nextStatus = Inactive; 560 561 if (drainPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 562 cpu->signalDrained(); 563 drainPending = false; 564 return; 565 } 566
| 522} 523 524template <class Impl> 525void 526DefaultCommit<Impl>::squashFromTrap(unsigned tid) 527{ 528 squashAll(tid); 529 530 DPRINTF(Commit, "Squashing from trap, restarting at PC %#x\n", PC[tid]); 531 532 thread[tid]->trapPending = false; 533 thread[tid]->inSyscall = false; 534 535 trapSquash[tid] = false; 536 537 commitStatus[tid] = ROBSquashing; 538 cpu->activityThisCycle(); 539} 540 541template <class Impl> 542void 543DefaultCommit<Impl>::squashFromTC(unsigned tid) 544{ 545 squashAll(tid); 546 547 DPRINTF(Commit, "Squashing from TC, restarting at PC %#x\n", PC[tid]); 548 549 thread[tid]->inSyscall = false; 550 assert(!thread[tid]->trapPending); 551 552 commitStatus[tid] = ROBSquashing; 553 cpu->activityThisCycle(); 554 555 tcSquash[tid] = false; 556} 557 558template <class Impl> 559void 560DefaultCommit<Impl>::tick() 561{ 562 wroteToTimeBuffer = false; 563 _nextStatus = Inactive; 564 565 if (drainPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 566 cpu->signalDrained(); 567 drainPending = false; 568 return; 569 } 570
|
567 if ((*activeThreads).size() <= 0)
| 571 if (activeThreads->empty())
|
568 return; 569
| 572 return; 573
|
570 std::list<unsigned>::iterator threads = (*activeThreads).begin();
| 574 std::list<unsigned>::iterator threads = activeThreads->begin(); 575 std::list<unsigned>::iterator end = activeThreads->end();
|
571 572 // Check if any of the threads are done squashing. Change the 573 // status if they are done.
| 576 577 // Check if any of the threads are done squashing. Change the 578 // status if they are done.
|
574 while (threads != (*activeThreads).end()) {
| 579 while (threads != end) {
|
575 unsigned tid = *threads++; 576 577 if (commitStatus[tid] == ROBSquashing) { 578 579 if (rob->isDoneSquashing(tid)) { 580 commitStatus[tid] = Running; 581 } else { 582 DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 583 " insts this cycle.\n", tid); 584 rob->doSquash(tid); 585 toIEW->commitInfo[tid].robSquashing = true; 586 wroteToTimeBuffer = true; 587 } 588 } 589 } 590 591 commit(); 592 593 markCompletedInsts(); 594
| 580 unsigned tid = *threads++; 581 582 if (commitStatus[tid] == ROBSquashing) { 583 584 if (rob->isDoneSquashing(tid)) { 585 commitStatus[tid] = Running; 586 } else { 587 DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 588 " insts this cycle.\n", tid); 589 rob->doSquash(tid); 590 toIEW->commitInfo[tid].robSquashing = true; 591 wroteToTimeBuffer = true; 592 } 593 } 594 } 595 596 commit(); 597 598 markCompletedInsts(); 599
|
595 threads = (*activeThreads).begin();
| 600 threads = activeThreads->begin();
|
596
| 601
|
597 while (threads != (*activeThreads).end()) {
| 602 while (threads != end) {
|
598 unsigned tid = *threads++; 599 600 if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 601 // The ROB has more instructions it can commit. Its next status 602 // will be active. 603 _nextStatus = Active; 604 605 DynInstPtr inst = rob->readHeadInst(tid); 606 607 DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %#x is head of" 608 " ROB and ready to commit\n", 609 tid, inst->seqNum, inst->readPC()); 610 611 } else if (!rob->isEmpty(tid)) { 612 DynInstPtr inst = rob->readHeadInst(tid); 613 614 DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 615 "%#x is head of ROB and not ready\n", 616 tid, inst->seqNum, inst->readPC()); 617 } 618 619 DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 620 tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 621 } 622 623 624 if (wroteToTimeBuffer) { 625 DPRINTF(Activity, "Activity This Cycle.\n"); 626 cpu->activityThisCycle(); 627 } 628 629 updateStatus(); 630} 631 632template <class Impl> 633void 634DefaultCommit<Impl>::commit() 635{ 636 637 ////////////////////////////////////// 638 // Check for interrupts 639 ////////////////////////////////////// 640 641#if FULL_SYSTEM 642 if (interrupt != NoFault) { 643 // Wait until the ROB is empty and all stores have drained in 644 // order to enter the interrupt. 645 if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 646 // Squash or record that I need to squash this cycle if 647 // an interrupt needed to be handled. 648 DPRINTF(Commit, "Interrupt detected.\n"); 649 650 assert(!thread[0]->inSyscall); 651 thread[0]->inSyscall = true; 652 653 // CPU will handle interrupt. 654 cpu->processInterrupts(interrupt); 655 656 thread[0]->inSyscall = false; 657 658 commitStatus[0] = TrapPending; 659 660 // Generate trap squash event. 661 generateTrapEvent(0); 662 663 // Clear the interrupt now that it's been handled 664 toIEW->commitInfo[0].clearInterrupt = true; 665 interrupt = NoFault; 666 } else { 667 DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 668 } 669 } else if (cpu->checkInterrupts && 670 cpu->check_interrupts(cpu->tcBase(0)) && 671 commitStatus[0] != TrapPending && 672 !trapSquash[0] && 673 !tcSquash[0]) { 674 // Process interrupts if interrupts are enabled, not in PAL 675 // mode, and no other traps or external squashes are currently 676 // pending. 677 // @todo: Allow other threads to handle interrupts. 678 679 // Get any interrupt that happened 680 interrupt = cpu->getInterrupts(); 681 682 if (interrupt != NoFault) { 683 // Tell fetch that there is an interrupt pending. This 684 // will make fetch wait until it sees a non PAL-mode PC, 685 // at which point it stops fetching instructions. 686 toIEW->commitInfo[0].interruptPending = true; 687 } 688 } 689 690#endif // FULL_SYSTEM 691 692 //////////////////////////////////// 693 // Check for any possible squashes, handle them first 694 ////////////////////////////////////
| 603 unsigned tid = *threads++; 604 605 if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 606 // The ROB has more instructions it can commit. Its next status 607 // will be active. 608 _nextStatus = Active; 609 610 DynInstPtr inst = rob->readHeadInst(tid); 611 612 DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %#x is head of" 613 " ROB and ready to commit\n", 614 tid, inst->seqNum, inst->readPC()); 615 616 } else if (!rob->isEmpty(tid)) { 617 DynInstPtr inst = rob->readHeadInst(tid); 618 619 DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 620 "%#x is head of ROB and not ready\n", 621 tid, inst->seqNum, inst->readPC()); 622 } 623 624 DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 625 tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 626 } 627 628 629 if (wroteToTimeBuffer) { 630 DPRINTF(Activity, "Activity This Cycle.\n"); 631 cpu->activityThisCycle(); 632 } 633 634 updateStatus(); 635} 636 637template <class Impl> 638void 639DefaultCommit<Impl>::commit() 640{ 641 642 ////////////////////////////////////// 643 // Check for interrupts 644 ////////////////////////////////////// 645 646#if FULL_SYSTEM 647 if (interrupt != NoFault) { 648 // Wait until the ROB is empty and all stores have drained in 649 // order to enter the interrupt. 650 if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 651 // Squash or record that I need to squash this cycle if 652 // an interrupt needed to be handled. 653 DPRINTF(Commit, "Interrupt detected.\n"); 654 655 assert(!thread[0]->inSyscall); 656 thread[0]->inSyscall = true; 657 658 // CPU will handle interrupt. 659 cpu->processInterrupts(interrupt); 660 661 thread[0]->inSyscall = false; 662 663 commitStatus[0] = TrapPending; 664 665 // Generate trap squash event. 666 generateTrapEvent(0); 667 668 // Clear the interrupt now that it's been handled 669 toIEW->commitInfo[0].clearInterrupt = true; 670 interrupt = NoFault; 671 } else { 672 DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 673 } 674 } else if (cpu->checkInterrupts && 675 cpu->check_interrupts(cpu->tcBase(0)) && 676 commitStatus[0] != TrapPending && 677 !trapSquash[0] && 678 !tcSquash[0]) { 679 // Process interrupts if interrupts are enabled, not in PAL 680 // mode, and no other traps or external squashes are currently 681 // pending. 682 // @todo: Allow other threads to handle interrupts. 683 684 // Get any interrupt that happened 685 interrupt = cpu->getInterrupts(); 686 687 if (interrupt != NoFault) { 688 // Tell fetch that there is an interrupt pending. This 689 // will make fetch wait until it sees a non PAL-mode PC, 690 // at which point it stops fetching instructions. 691 toIEW->commitInfo[0].interruptPending = true; 692 } 693 } 694 695#endif // FULL_SYSTEM 696 697 //////////////////////////////////// 698 // Check for any possible squashes, handle them first 699 ////////////////////////////////////
|
695 std::list<unsigned>::iterator threads = (*activeThreads).begin();
| 700 std::list<unsigned>::iterator threads = activeThreads->begin(); 701 std::list<unsigned>::iterator end = activeThreads->end();
|
696
| 702
|
697 while (threads != (*activeThreads).end()) {
| 703 while (threads != end) {
|
698 unsigned tid = *threads++; 699 700 // Not sure which one takes priority. I think if we have 701 // both, that's a bad sign. 702 if (trapSquash[tid] == true) { 703 assert(!tcSquash[tid]); 704 squashFromTrap(tid); 705 } else if (tcSquash[tid] == true) { 706 squashFromTC(tid); 707 } 708 709 // Squashed sequence number must be older than youngest valid 710 // instruction in the ROB. This prevents squashes from younger 711 // instructions overriding squashes from older instructions. 712 if (fromIEW->squash[tid] && 713 commitStatus[tid] != TrapPending && 714 fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 715 716 DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n", 717 tid, 718 fromIEW->mispredPC[tid], 719 fromIEW->squashedSeqNum[tid]); 720 721 DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 722 tid, 723 fromIEW->nextPC[tid]); 724 725 commitStatus[tid] = ROBSquashing; 726 727 // If we want to include the squashing instruction in the squash, 728 // then use one older sequence number. 729 InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 730 731#if ISA_HAS_DELAY_SLOT
| 704 unsigned tid = *threads++; 705 706 // Not sure which one takes priority. I think if we have 707 // both, that's a bad sign. 708 if (trapSquash[tid] == true) { 709 assert(!tcSquash[tid]); 710 squashFromTrap(tid); 711 } else if (tcSquash[tid] == true) { 712 squashFromTC(tid); 713 } 714 715 // Squashed sequence number must be older than youngest valid 716 // instruction in the ROB. This prevents squashes from younger 717 // instructions overriding squashes from older instructions. 718 if (fromIEW->squash[tid] && 719 commitStatus[tid] != TrapPending && 720 fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 721 722 DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n", 723 tid, 724 fromIEW->mispredPC[tid], 725 fromIEW->squashedSeqNum[tid]); 726 727 DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 728 tid, 729 fromIEW->nextPC[tid]); 730 731 commitStatus[tid] = ROBSquashing; 732 733 // If we want to include the squashing instruction in the squash, 734 // then use one older sequence number. 735 InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 736 737#if ISA_HAS_DELAY_SLOT
|
732 InstSeqNum bdelay_done_seq_num = squashed_inst; 733 bool squash_bdelay_slot = fromIEW->squashDelaySlot[tid];
| 738 InstSeqNum bdelay_done_seq_num; 739 bool squash_bdelay_slot;
|
734
| 740
|
735 if (!squash_bdelay_slot) 736 bdelay_done_seq_num++;
| 741 if (fromIEW->branchMispredict[tid]) { 742 if (fromIEW->branchTaken[tid] && 743 fromIEW->condDelaySlotBranch[tid]) { 744 DPRINTF(Commit, "[tid:%i]: Cond. delay slot branch" 745 "mispredicted as taken. Squashing after previous " 746 "inst, [sn:%i]\n", 747 tid, squashed_inst); 748 bdelay_done_seq_num = squashed_inst; 749 squash_bdelay_slot = true; 750 } else { 751 DPRINTF(Commit, "[tid:%i]: Branch Mispredict. Squashing " 752 "after delay slot [sn:%i]\n", tid, squashed_inst+1); 753 bdelay_done_seq_num = squashed_inst + 1; 754 squash_bdelay_slot = false; 755 } 756 } else { 757 bdelay_done_seq_num = squashed_inst; 758 squash_bdelay_slot = true; 759 }
|
737#endif 738 739 if (fromIEW->includeSquashInst[tid] == true) { 740 squashed_inst--; 741#if ISA_HAS_DELAY_SLOT 742 bdelay_done_seq_num--; 743#endif 744 } 745 // All younger instructions will be squashed. Set the sequence 746 // number as the youngest instruction in the ROB. 747 youngestSeqNum[tid] = squashed_inst; 748 749#if ISA_HAS_DELAY_SLOT 750 rob->squash(bdelay_done_seq_num, tid); 751 toIEW->commitInfo[tid].squashDelaySlot = squash_bdelay_slot; 752 toIEW->commitInfo[tid].bdelayDoneSeqNum = bdelay_done_seq_num; 753#else 754 rob->squash(squashed_inst, tid); 755 toIEW->commitInfo[tid].squashDelaySlot = true; 756#endif 757 changedROBNumEntries[tid] = true; 758 759 toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 760 761 toIEW->commitInfo[tid].squash = true; 762 763 // Send back the rob squashing signal so other stages know that 764 // the ROB is in the process of squashing. 765 toIEW->commitInfo[tid].robSquashing = true; 766 767 toIEW->commitInfo[tid].branchMispredict = 768 fromIEW->branchMispredict[tid]; 769 770 toIEW->commitInfo[tid].branchTaken = 771 fromIEW->branchTaken[tid]; 772 773 toIEW->commitInfo[tid].nextPC = fromIEW->nextPC[tid];
| 760#endif 761 762 if (fromIEW->includeSquashInst[tid] == true) { 763 squashed_inst--; 764#if ISA_HAS_DELAY_SLOT 765 bdelay_done_seq_num--; 766#endif 767 } 768 // All younger instructions will be squashed. Set the sequence 769 // number as the youngest instruction in the ROB. 770 youngestSeqNum[tid] = squashed_inst; 771 772#if ISA_HAS_DELAY_SLOT 773 rob->squash(bdelay_done_seq_num, tid); 774 toIEW->commitInfo[tid].squashDelaySlot = squash_bdelay_slot; 775 toIEW->commitInfo[tid].bdelayDoneSeqNum = bdelay_done_seq_num; 776#else 777 rob->squash(squashed_inst, tid); 778 toIEW->commitInfo[tid].squashDelaySlot = true; 779#endif 780 changedROBNumEntries[tid] = true; 781 782 toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 783 784 toIEW->commitInfo[tid].squash = true; 785 786 // Send back the rob squashing signal so other stages know that 787 // the ROB is in the process of squashing. 788 toIEW->commitInfo[tid].robSquashing = true; 789 790 toIEW->commitInfo[tid].branchMispredict = 791 fromIEW->branchMispredict[tid]; 792 793 toIEW->commitInfo[tid].branchTaken = 794 fromIEW->branchTaken[tid]; 795 796 toIEW->commitInfo[tid].nextPC = fromIEW->nextPC[tid];
|
774 toIEW->commitInfo[tid].nextNPC = fromIEW->nextNPC[tid];
| |
775 776 toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid]; 777 778 if (toIEW->commitInfo[tid].branchMispredict) { 779 ++branchMispredicts; 780 } 781 } 782 783 } 784 785 setNextStatus(); 786 787 if (squashCounter != numThreads) { 788 // If we're not currently squashing, then get instructions. 789 getInsts(); 790 791 // Try to commit any instructions. 792 commitInsts(); 793 } else { 794#if ISA_HAS_DELAY_SLOT 795 skidInsert(); 796#endif 797 } 798 799 //Check for any activity
| 797 798 toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid]; 799 800 if (toIEW->commitInfo[tid].branchMispredict) { 801 ++branchMispredicts; 802 } 803 } 804 805 } 806 807 setNextStatus(); 808 809 if (squashCounter != numThreads) { 810 // If we're not currently squashing, then get instructions. 811 getInsts(); 812 813 // Try to commit any instructions. 814 commitInsts(); 815 } else { 816#if ISA_HAS_DELAY_SLOT 817 skidInsert(); 818#endif 819 } 820 821 //Check for any activity
|
800 threads = (*activeThreads).begin();
| 822 threads = activeThreads->begin();
|
801
| 823
|
802 while (threads != (*activeThreads).end()) {
| 824 while (threads != end) {
|
803 unsigned tid = *threads++; 804 805 if (changedROBNumEntries[tid]) { 806 toIEW->commitInfo[tid].usedROB = true; 807 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 808 809 if (rob->isEmpty(tid)) { 810 toIEW->commitInfo[tid].emptyROB = true; 811 } 812 813 wroteToTimeBuffer = true; 814 changedROBNumEntries[tid] = false; 815 } 816 } 817} 818 819template <class Impl> 820void 821DefaultCommit<Impl>::commitInsts() 822{ 823 //////////////////////////////////// 824 // Handle commit 825 // Note that commit will be handled prior to putting new 826 // instructions in the ROB so that the ROB only tries to commit 827 // instructions it has in this current cycle, and not instructions 828 // it is writing in during this cycle. Can't commit and squash 829 // things at the same time... 830 //////////////////////////////////// 831 832 DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 833 834 unsigned num_committed = 0; 835 836 DynInstPtr head_inst; 837 838 // Commit as many instructions as possible until the commit bandwidth 839 // limit is reached, or it becomes impossible to commit any more. 840 while (num_committed < commitWidth) { 841 int commit_thread = getCommittingThread(); 842 843 if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 844 break; 845 846 head_inst = rob->readHeadInst(commit_thread); 847 848 int tid = head_inst->threadNumber; 849 850 assert(tid == commit_thread); 851 852 DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 853 head_inst->seqNum, tid); 854 855 // If the head instruction is squashed, it is ready to retire 856 // (be removed from the ROB) at any time. 857 if (head_inst->isSquashed()) { 858 859 DPRINTF(Commit, "Retiring squashed instruction from " 860 "ROB.\n"); 861 862 rob->retireHead(commit_thread); 863 864 ++commitSquashedInsts; 865 866 // Record that the number of ROB entries has changed. 867 changedROBNumEntries[tid] = true; 868 } else { 869 PC[tid] = head_inst->readPC(); 870 nextPC[tid] = head_inst->readNextPC(); 871 nextNPC[tid] = head_inst->readNextNPC(); 872 873 // Increment the total number of non-speculative instructions 874 // executed. 875 // Hack for now: it really shouldn't happen until after the 876 // commit is deemed to be successful, but this count is needed 877 // for syscalls. 878 thread[tid]->funcExeInst++; 879 880 // Try to commit the head instruction. 881 bool commit_success = commitHead(head_inst, num_committed); 882 883 if (commit_success) { 884 ++num_committed; 885 886 changedROBNumEntries[tid] = true; 887 888 // Set the doneSeqNum to the youngest committed instruction. 889 toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 890 891 ++commitCommittedInsts; 892 893 // To match the old model, don't count nops and instruction 894 // prefetches towards the total commit count. 895 if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 896 cpu->instDone(tid); 897 } 898 899 PC[tid] = nextPC[tid]; 900#if ISA_HAS_DELAY_SLOT 901 nextPC[tid] = nextNPC[tid]; 902 nextNPC[tid] = nextNPC[tid] + sizeof(TheISA::MachInst); 903#else 904 nextPC[tid] = nextPC[tid] + sizeof(TheISA::MachInst); 905#endif 906 907#if FULL_SYSTEM 908 int count = 0; 909 Addr oldpc; 910 do { 911 // Debug statement. Checks to make sure we're not 912 // currently updating state while handling PC events. 913 if (count == 0) 914 assert(!thread[tid]->inSyscall && 915 !thread[tid]->trapPending); 916 oldpc = PC[tid]; 917 cpu->system->pcEventQueue.service( 918 thread[tid]->getTC()); 919 count++; 920 } while (oldpc != PC[tid]); 921 if (count > 1) { 922 DPRINTF(Commit, "PC skip function event, stopping commit\n"); 923 break; 924 } 925#endif 926 } else { 927 DPRINTF(Commit, "Unable to commit head instruction PC:%#x " 928 "[tid:%i] [sn:%i].\n", 929 head_inst->readPC(), tid ,head_inst->seqNum); 930 break; 931 } 932 } 933 } 934 935 DPRINTF(CommitRate, "%i\n", num_committed); 936 numCommittedDist.sample(num_committed); 937 938 if (num_committed == commitWidth) { 939 commitEligibleSamples++; 940 } 941} 942 943template <class Impl> 944bool 945DefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 946{ 947 assert(head_inst); 948 949 int tid = head_inst->threadNumber; 950 951 // If the instruction is not executed yet, then it will need extra 952 // handling. Signal backwards that it should be executed. 953 if (!head_inst->isExecuted()) { 954 // Keep this number correct. We have not yet actually executed 955 // and committed this instruction. 956 thread[tid]->funcExeInst--; 957 958 head_inst->setAtCommit(); 959 960 if (head_inst->isNonSpeculative() || 961 head_inst->isStoreConditional() || 962 head_inst->isMemBarrier() || 963 head_inst->isWriteBarrier()) { 964 965 DPRINTF(Commit, "Encountered a barrier or non-speculative " 966 "instruction [sn:%lli] at the head of the ROB, PC %#x.\n", 967 head_inst->seqNum, head_inst->readPC()); 968 969#if !FULL_SYSTEM 970 // Hack to make sure syscalls/memory barriers/quiesces 971 // aren't executed until all stores write back their data. 972 // This direct communication shouldn't be used for 973 // anything other than this. 974 if (inst_num > 0 || iewStage->hasStoresToWB()) 975#else 976 if ((head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 977 head_inst->isQuiesce()) && 978 iewStage->hasStoresToWB()) 979#endif 980 { 981 DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 982 return false; 983 } 984 985 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 986 987 // Change the instruction so it won't try to commit again until 988 // it is executed. 989 head_inst->clearCanCommit(); 990 991 ++commitNonSpecStalls; 992 993 return false; 994 } else if (head_inst->isLoad()) { 995 DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %#x.\n", 996 head_inst->seqNum, head_inst->readPC()); 997 998 // Send back the non-speculative instruction's sequence 999 // number. Tell the lsq to re-execute the load. 1000 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 1001 toIEW->commitInfo[tid].uncached = true; 1002 toIEW->commitInfo[tid].uncachedLoad = head_inst; 1003 1004 head_inst->clearCanCommit(); 1005 1006 return false; 1007 } else { 1008 panic("Trying to commit un-executed instruction " 1009 "of unknown type!\n"); 1010 } 1011 } 1012 1013 if (head_inst->isThreadSync()) { 1014 // Not handled for now. 1015 panic("Thread sync instructions are not handled yet.\n"); 1016 } 1017 1018 // Stores mark themselves as completed. 1019 if (!head_inst->isStore()) { 1020 head_inst->setCompleted(); 1021 } 1022 1023#if USE_CHECKER 1024 // Use checker prior to updating anything due to traps or PC 1025 // based events. 1026 if (cpu->checker) { 1027 cpu->checker->verify(head_inst); 1028 } 1029#endif 1030 1031 // Check if the instruction caused a fault. If so, trap. 1032 Fault inst_fault = head_inst->getFault(); 1033 1034 // DTB will sometimes need the machine instruction for when 1035 // faults happen. So we will set it here, prior to the DTB 1036 // possibly needing it for its fault. 1037 thread[tid]->setInst( 1038 static_cast<TheISA::MachInst>(head_inst->staticInst->machInst)); 1039 1040 if (inst_fault != NoFault) { 1041 head_inst->setCompleted(); 1042 DPRINTF(Commit, "Inst [sn:%lli] PC %#x has a fault\n", 1043 head_inst->seqNum, head_inst->readPC()); 1044 1045 if (iewStage->hasStoresToWB() || inst_num > 0) { 1046 DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 1047 return false; 1048 } 1049 1050#if USE_CHECKER 1051 if (cpu->checker && head_inst->isStore()) { 1052 cpu->checker->verify(head_inst); 1053 } 1054#endif 1055 1056 assert(!thread[tid]->inSyscall); 1057 1058 // Mark that we're in state update mode so that the trap's 1059 // execution doesn't generate extra squashes. 1060 thread[tid]->inSyscall = true; 1061 1062 // Execute the trap. Although it's slightly unrealistic in 1063 // terms of timing (as it doesn't wait for the full timing of 1064 // the trap event to complete before updating state), it's 1065 // needed to update the state as soon as possible. This 1066 // prevents external agents from changing any specific state 1067 // that the trap need. 1068 cpu->trap(inst_fault, tid); 1069 1070 // Exit state update mode to avoid accidental updating. 1071 thread[tid]->inSyscall = false; 1072 1073 commitStatus[tid] = TrapPending; 1074 1075 // Generate trap squash event. 1076 generateTrapEvent(tid); 1077// warn("%lli fault (%d) handled @ PC %08p", curTick, inst_fault->name(), head_inst->readPC()); 1078 return false; 1079 } 1080 1081 updateComInstStats(head_inst); 1082 1083#if FULL_SYSTEM 1084 if (thread[tid]->profile) { 1085// bool usermode = TheISA::inUserMode(thread[tid]->getTC()); 1086// thread[tid]->profilePC = usermode ? 1 : head_inst->readPC(); 1087 thread[tid]->profilePC = head_inst->readPC(); 1088 ProfileNode *node = thread[tid]->profile->consume(thread[tid]->getTC(), 1089 head_inst->staticInst); 1090 1091 if (node) 1092 thread[tid]->profileNode = node; 1093 } 1094#endif 1095 1096 if (head_inst->traceData) { 1097 head_inst->traceData->setFetchSeq(head_inst->seqNum); 1098 head_inst->traceData->setCPSeq(thread[tid]->numInst); 1099 head_inst->traceData->finalize(); 1100 head_inst->traceData = NULL; 1101 } 1102 1103 // Update the commit rename map 1104 for (int i = 0; i < head_inst->numDestRegs(); i++) {
| 825 unsigned tid = *threads++; 826 827 if (changedROBNumEntries[tid]) { 828 toIEW->commitInfo[tid].usedROB = true; 829 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 830 831 if (rob->isEmpty(tid)) { 832 toIEW->commitInfo[tid].emptyROB = true; 833 } 834 835 wroteToTimeBuffer = true; 836 changedROBNumEntries[tid] = false; 837 } 838 } 839} 840 841template <class Impl> 842void 843DefaultCommit<Impl>::commitInsts() 844{ 845 //////////////////////////////////// 846 // Handle commit 847 // Note that commit will be handled prior to putting new 848 // instructions in the ROB so that the ROB only tries to commit 849 // instructions it has in this current cycle, and not instructions 850 // it is writing in during this cycle. Can't commit and squash 851 // things at the same time... 852 //////////////////////////////////// 853 854 DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 855 856 unsigned num_committed = 0; 857 858 DynInstPtr head_inst; 859 860 // Commit as many instructions as possible until the commit bandwidth 861 // limit is reached, or it becomes impossible to commit any more. 862 while (num_committed < commitWidth) { 863 int commit_thread = getCommittingThread(); 864 865 if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 866 break; 867 868 head_inst = rob->readHeadInst(commit_thread); 869 870 int tid = head_inst->threadNumber; 871 872 assert(tid == commit_thread); 873 874 DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 875 head_inst->seqNum, tid); 876 877 // If the head instruction is squashed, it is ready to retire 878 // (be removed from the ROB) at any time. 879 if (head_inst->isSquashed()) { 880 881 DPRINTF(Commit, "Retiring squashed instruction from " 882 "ROB.\n"); 883 884 rob->retireHead(commit_thread); 885 886 ++commitSquashedInsts; 887 888 // Record that the number of ROB entries has changed. 889 changedROBNumEntries[tid] = true; 890 } else { 891 PC[tid] = head_inst->readPC(); 892 nextPC[tid] = head_inst->readNextPC(); 893 nextNPC[tid] = head_inst->readNextNPC(); 894 895 // Increment the total number of non-speculative instructions 896 // executed. 897 // Hack for now: it really shouldn't happen until after the 898 // commit is deemed to be successful, but this count is needed 899 // for syscalls. 900 thread[tid]->funcExeInst++; 901 902 // Try to commit the head instruction. 903 bool commit_success = commitHead(head_inst, num_committed); 904 905 if (commit_success) { 906 ++num_committed; 907 908 changedROBNumEntries[tid] = true; 909 910 // Set the doneSeqNum to the youngest committed instruction. 911 toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 912 913 ++commitCommittedInsts; 914 915 // To match the old model, don't count nops and instruction 916 // prefetches towards the total commit count. 917 if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 918 cpu->instDone(tid); 919 } 920 921 PC[tid] = nextPC[tid]; 922#if ISA_HAS_DELAY_SLOT 923 nextPC[tid] = nextNPC[tid]; 924 nextNPC[tid] = nextNPC[tid] + sizeof(TheISA::MachInst); 925#else 926 nextPC[tid] = nextPC[tid] + sizeof(TheISA::MachInst); 927#endif 928 929#if FULL_SYSTEM 930 int count = 0; 931 Addr oldpc; 932 do { 933 // Debug statement. Checks to make sure we're not 934 // currently updating state while handling PC events. 935 if (count == 0) 936 assert(!thread[tid]->inSyscall && 937 !thread[tid]->trapPending); 938 oldpc = PC[tid]; 939 cpu->system->pcEventQueue.service( 940 thread[tid]->getTC()); 941 count++; 942 } while (oldpc != PC[tid]); 943 if (count > 1) { 944 DPRINTF(Commit, "PC skip function event, stopping commit\n"); 945 break; 946 } 947#endif 948 } else { 949 DPRINTF(Commit, "Unable to commit head instruction PC:%#x " 950 "[tid:%i] [sn:%i].\n", 951 head_inst->readPC(), tid ,head_inst->seqNum); 952 break; 953 } 954 } 955 } 956 957 DPRINTF(CommitRate, "%i\n", num_committed); 958 numCommittedDist.sample(num_committed); 959 960 if (num_committed == commitWidth) { 961 commitEligibleSamples++; 962 } 963} 964 965template <class Impl> 966bool 967DefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 968{ 969 assert(head_inst); 970 971 int tid = head_inst->threadNumber; 972 973 // If the instruction is not executed yet, then it will need extra 974 // handling. Signal backwards that it should be executed. 975 if (!head_inst->isExecuted()) { 976 // Keep this number correct. We have not yet actually executed 977 // and committed this instruction. 978 thread[tid]->funcExeInst--; 979 980 head_inst->setAtCommit(); 981 982 if (head_inst->isNonSpeculative() || 983 head_inst->isStoreConditional() || 984 head_inst->isMemBarrier() || 985 head_inst->isWriteBarrier()) { 986 987 DPRINTF(Commit, "Encountered a barrier or non-speculative " 988 "instruction [sn:%lli] at the head of the ROB, PC %#x.\n", 989 head_inst->seqNum, head_inst->readPC()); 990 991#if !FULL_SYSTEM 992 // Hack to make sure syscalls/memory barriers/quiesces 993 // aren't executed until all stores write back their data. 994 // This direct communication shouldn't be used for 995 // anything other than this. 996 if (inst_num > 0 || iewStage->hasStoresToWB()) 997#else 998 if ((head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 999 head_inst->isQuiesce()) && 1000 iewStage->hasStoresToWB()) 1001#endif 1002 { 1003 DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 1004 return false; 1005 } 1006 1007 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 1008 1009 // Change the instruction so it won't try to commit again until 1010 // it is executed. 1011 head_inst->clearCanCommit(); 1012 1013 ++commitNonSpecStalls; 1014 1015 return false; 1016 } else if (head_inst->isLoad()) { 1017 DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %#x.\n", 1018 head_inst->seqNum, head_inst->readPC()); 1019 1020 // Send back the non-speculative instruction's sequence 1021 // number. Tell the lsq to re-execute the load. 1022 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 1023 toIEW->commitInfo[tid].uncached = true; 1024 toIEW->commitInfo[tid].uncachedLoad = head_inst; 1025 1026 head_inst->clearCanCommit(); 1027 1028 return false; 1029 } else { 1030 panic("Trying to commit un-executed instruction " 1031 "of unknown type!\n"); 1032 } 1033 } 1034 1035 if (head_inst->isThreadSync()) { 1036 // Not handled for now. 1037 panic("Thread sync instructions are not handled yet.\n"); 1038 } 1039 1040 // Stores mark themselves as completed. 1041 if (!head_inst->isStore()) { 1042 head_inst->setCompleted(); 1043 } 1044 1045#if USE_CHECKER 1046 // Use checker prior to updating anything due to traps or PC 1047 // based events. 1048 if (cpu->checker) { 1049 cpu->checker->verify(head_inst); 1050 } 1051#endif 1052 1053 // Check if the instruction caused a fault. If so, trap. 1054 Fault inst_fault = head_inst->getFault(); 1055 1056 // DTB will sometimes need the machine instruction for when 1057 // faults happen. So we will set it here, prior to the DTB 1058 // possibly needing it for its fault. 1059 thread[tid]->setInst( 1060 static_cast<TheISA::MachInst>(head_inst->staticInst->machInst)); 1061 1062 if (inst_fault != NoFault) { 1063 head_inst->setCompleted(); 1064 DPRINTF(Commit, "Inst [sn:%lli] PC %#x has a fault\n", 1065 head_inst->seqNum, head_inst->readPC()); 1066 1067 if (iewStage->hasStoresToWB() || inst_num > 0) { 1068 DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 1069 return false; 1070 } 1071 1072#if USE_CHECKER 1073 if (cpu->checker && head_inst->isStore()) { 1074 cpu->checker->verify(head_inst); 1075 } 1076#endif 1077 1078 assert(!thread[tid]->inSyscall); 1079 1080 // Mark that we're in state update mode so that the trap's 1081 // execution doesn't generate extra squashes. 1082 thread[tid]->inSyscall = true; 1083 1084 // Execute the trap. Although it's slightly unrealistic in 1085 // terms of timing (as it doesn't wait for the full timing of 1086 // the trap event to complete before updating state), it's 1087 // needed to update the state as soon as possible. This 1088 // prevents external agents from changing any specific state 1089 // that the trap need. 1090 cpu->trap(inst_fault, tid); 1091 1092 // Exit state update mode to avoid accidental updating. 1093 thread[tid]->inSyscall = false; 1094 1095 commitStatus[tid] = TrapPending; 1096 1097 // Generate trap squash event. 1098 generateTrapEvent(tid); 1099// warn("%lli fault (%d) handled @ PC %08p", curTick, inst_fault->name(), head_inst->readPC()); 1100 return false; 1101 } 1102 1103 updateComInstStats(head_inst); 1104 1105#if FULL_SYSTEM 1106 if (thread[tid]->profile) { 1107// bool usermode = TheISA::inUserMode(thread[tid]->getTC()); 1108// thread[tid]->profilePC = usermode ? 1 : head_inst->readPC(); 1109 thread[tid]->profilePC = head_inst->readPC(); 1110 ProfileNode *node = thread[tid]->profile->consume(thread[tid]->getTC(), 1111 head_inst->staticInst); 1112 1113 if (node) 1114 thread[tid]->profileNode = node; 1115 } 1116#endif 1117 1118 if (head_inst->traceData) { 1119 head_inst->traceData->setFetchSeq(head_inst->seqNum); 1120 head_inst->traceData->setCPSeq(thread[tid]->numInst); 1121 head_inst->traceData->finalize(); 1122 head_inst->traceData = NULL; 1123 } 1124 1125 // Update the commit rename map 1126 for (int i = 0; i < head_inst->numDestRegs(); i++) {
|
1105 renameMap[tid]->setEntry(head_inst->flattenedDestRegIdx(i),
| 1127 renameMap[tid]->setEntry(head_inst->destRegIdx(i),
|
1106 head_inst->renamedDestRegIdx(i)); 1107 } 1108 1109 if (head_inst->isCopy()) 1110 panic("Should not commit any copy instructions!"); 1111 1112 // Finally clear the head ROB entry. 1113 rob->retireHead(tid); 1114 1115 // Return true to indicate that we have committed an instruction. 1116 return true; 1117} 1118 1119template <class Impl> 1120void 1121DefaultCommit<Impl>::getInsts() 1122{ 1123 DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 1124 1125#if ISA_HAS_DELAY_SLOT 1126 // Read any renamed instructions and place them into the ROB. 1127 int insts_to_process = std::min((int)renameWidth, 1128 (int)(fromRename->size + skidBuffer.size())); 1129 int rename_idx = 0; 1130 1131 DPRINTF(Commit, "%i insts available to process. Rename Insts:%i " 1132 "SkidBuffer Insts:%i\n", insts_to_process, fromRename->size, 1133 skidBuffer.size()); 1134#else 1135 // Read any renamed instructions and place them into the ROB. 1136 int insts_to_process = std::min((int)renameWidth, fromRename->size); 1137#endif 1138 1139 1140 for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 1141 DynInstPtr inst; 1142 1143#if ISA_HAS_DELAY_SLOT 1144 // Get insts from skidBuffer or from Rename 1145 if (skidBuffer.size() > 0) { 1146 DPRINTF(Commit, "Grabbing skidbuffer inst.\n"); 1147 inst = skidBuffer.front(); 1148 skidBuffer.pop(); 1149 } else { 1150 DPRINTF(Commit, "Grabbing rename inst.\n"); 1151 inst = fromRename->insts[rename_idx++]; 1152 } 1153#else 1154 inst = fromRename->insts[inst_num]; 1155#endif 1156 int tid = inst->threadNumber; 1157 1158 if (!inst->isSquashed() && 1159 commitStatus[tid] != ROBSquashing) { 1160 changedROBNumEntries[tid] = true; 1161 1162 DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ROB.\n", 1163 inst->readPC(), inst->seqNum, tid); 1164 1165 rob->insertInst(inst); 1166 1167 assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 1168 1169 youngestSeqNum[tid] = inst->seqNum; 1170 } else { 1171 DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 1172 "squashed, skipping.\n", 1173 inst->readPC(), inst->seqNum, tid); 1174 } 1175 } 1176 1177#if ISA_HAS_DELAY_SLOT 1178 if (rename_idx < fromRename->size) { 1179 DPRINTF(Commit,"Placing Rename Insts into skidBuffer.\n"); 1180 1181 for (; 1182 rename_idx < fromRename->size; 1183 rename_idx++) { 1184 DynInstPtr inst = fromRename->insts[rename_idx]; 1185 1186 if (!inst->isSquashed()) { 1187 DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ", 1188 "skidBuffer.\n", inst->readPC(), inst->seqNum, 1189 inst->threadNumber); 1190 skidBuffer.push(inst); 1191 } else { 1192 DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 1193 "squashed, skipping.\n", 1194 inst->readPC(), inst->seqNum, inst->threadNumber); 1195 } 1196 } 1197 } 1198#endif 1199 1200} 1201 1202template <class Impl> 1203void 1204DefaultCommit<Impl>::skidInsert() 1205{ 1206 DPRINTF(Commit, "Attempting to any instructions from rename into " 1207 "skidBuffer.\n"); 1208 1209 for (int inst_num = 0; inst_num < fromRename->size; ++inst_num) { 1210 DynInstPtr inst = fromRename->insts[inst_num]; 1211 1212 if (!inst->isSquashed()) { 1213 DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ", 1214 "skidBuffer.\n", inst->readPC(), inst->seqNum, 1215 inst->threadNumber); 1216 skidBuffer.push(inst); 1217 } else { 1218 DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 1219 "squashed, skipping.\n", 1220 inst->readPC(), inst->seqNum, inst->threadNumber); 1221 } 1222 } 1223} 1224 1225template <class Impl> 1226void 1227DefaultCommit<Impl>::markCompletedInsts() 1228{ 1229 // Grab completed insts out of the IEW instruction queue, and mark 1230 // instructions completed within the ROB. 1231 for (int inst_num = 0; 1232 inst_num < fromIEW->size && fromIEW->insts[inst_num]; 1233 ++inst_num) 1234 { 1235 if (!fromIEW->insts[inst_num]->isSquashed()) { 1236 DPRINTF(Commit, "[tid:%i]: Marking PC %#x, [sn:%lli] ready " 1237 "within ROB.\n", 1238 fromIEW->insts[inst_num]->threadNumber, 1239 fromIEW->insts[inst_num]->readPC(), 1240 fromIEW->insts[inst_num]->seqNum); 1241 1242 // Mark the instruction as ready to commit. 1243 fromIEW->insts[inst_num]->setCanCommit(); 1244 } 1245 } 1246} 1247 1248template <class Impl> 1249bool 1250DefaultCommit<Impl>::robDoneSquashing() 1251{
| 1128 head_inst->renamedDestRegIdx(i)); 1129 } 1130 1131 if (head_inst->isCopy()) 1132 panic("Should not commit any copy instructions!"); 1133 1134 // Finally clear the head ROB entry. 1135 rob->retireHead(tid); 1136 1137 // Return true to indicate that we have committed an instruction. 1138 return true; 1139} 1140 1141template <class Impl> 1142void 1143DefaultCommit<Impl>::getInsts() 1144{ 1145 DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 1146 1147#if ISA_HAS_DELAY_SLOT 1148 // Read any renamed instructions and place them into the ROB. 1149 int insts_to_process = std::min((int)renameWidth, 1150 (int)(fromRename->size + skidBuffer.size())); 1151 int rename_idx = 0; 1152 1153 DPRINTF(Commit, "%i insts available to process. Rename Insts:%i " 1154 "SkidBuffer Insts:%i\n", insts_to_process, fromRename->size, 1155 skidBuffer.size()); 1156#else 1157 // Read any renamed instructions and place them into the ROB. 1158 int insts_to_process = std::min((int)renameWidth, fromRename->size); 1159#endif 1160 1161 1162 for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 1163 DynInstPtr inst; 1164 1165#if ISA_HAS_DELAY_SLOT 1166 // Get insts from skidBuffer or from Rename 1167 if (skidBuffer.size() > 0) { 1168 DPRINTF(Commit, "Grabbing skidbuffer inst.\n"); 1169 inst = skidBuffer.front(); 1170 skidBuffer.pop(); 1171 } else { 1172 DPRINTF(Commit, "Grabbing rename inst.\n"); 1173 inst = fromRename->insts[rename_idx++]; 1174 } 1175#else 1176 inst = fromRename->insts[inst_num]; 1177#endif 1178 int tid = inst->threadNumber; 1179 1180 if (!inst->isSquashed() && 1181 commitStatus[tid] != ROBSquashing) { 1182 changedROBNumEntries[tid] = true; 1183 1184 DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ROB.\n", 1185 inst->readPC(), inst->seqNum, tid); 1186 1187 rob->insertInst(inst); 1188 1189 assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 1190 1191 youngestSeqNum[tid] = inst->seqNum; 1192 } else { 1193 DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 1194 "squashed, skipping.\n", 1195 inst->readPC(), inst->seqNum, tid); 1196 } 1197 } 1198 1199#if ISA_HAS_DELAY_SLOT 1200 if (rename_idx < fromRename->size) { 1201 DPRINTF(Commit,"Placing Rename Insts into skidBuffer.\n"); 1202 1203 for (; 1204 rename_idx < fromRename->size; 1205 rename_idx++) { 1206 DynInstPtr inst = fromRename->insts[rename_idx]; 1207 1208 if (!inst->isSquashed()) { 1209 DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ", 1210 "skidBuffer.\n", inst->readPC(), inst->seqNum, 1211 inst->threadNumber); 1212 skidBuffer.push(inst); 1213 } else { 1214 DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 1215 "squashed, skipping.\n", 1216 inst->readPC(), inst->seqNum, inst->threadNumber); 1217 } 1218 } 1219 } 1220#endif 1221 1222} 1223 1224template <class Impl> 1225void 1226DefaultCommit<Impl>::skidInsert() 1227{ 1228 DPRINTF(Commit, "Attempting to any instructions from rename into " 1229 "skidBuffer.\n"); 1230 1231 for (int inst_num = 0; inst_num < fromRename->size; ++inst_num) { 1232 DynInstPtr inst = fromRename->insts[inst_num]; 1233 1234 if (!inst->isSquashed()) { 1235 DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ", 1236 "skidBuffer.\n", inst->readPC(), inst->seqNum, 1237 inst->threadNumber); 1238 skidBuffer.push(inst); 1239 } else { 1240 DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 1241 "squashed, skipping.\n", 1242 inst->readPC(), inst->seqNum, inst->threadNumber); 1243 } 1244 } 1245} 1246 1247template <class Impl> 1248void 1249DefaultCommit<Impl>::markCompletedInsts() 1250{ 1251 // Grab completed insts out of the IEW instruction queue, and mark 1252 // instructions completed within the ROB. 1253 for (int inst_num = 0; 1254 inst_num < fromIEW->size && fromIEW->insts[inst_num]; 1255 ++inst_num) 1256 { 1257 if (!fromIEW->insts[inst_num]->isSquashed()) { 1258 DPRINTF(Commit, "[tid:%i]: Marking PC %#x, [sn:%lli] ready " 1259 "within ROB.\n", 1260 fromIEW->insts[inst_num]->threadNumber, 1261 fromIEW->insts[inst_num]->readPC(), 1262 fromIEW->insts[inst_num]->seqNum); 1263 1264 // Mark the instruction as ready to commit. 1265 fromIEW->insts[inst_num]->setCanCommit(); 1266 } 1267 } 1268} 1269 1270template <class Impl> 1271bool 1272DefaultCommit<Impl>::robDoneSquashing() 1273{
|
1252 std::list<unsigned>::iterator threads = (*activeThreads).begin();
| 1274 std::list<unsigned>::iterator threads = activeThreads->begin(); 1275 std::list<unsigned>::iterator end = activeThreads->end();
|
1253
| 1276
|
1254 while (threads != (*activeThreads).end()) {
| 1277 while (threads != end) {
|
1255 unsigned tid = *threads++; 1256 1257 if (!rob->isDoneSquashing(tid)) 1258 return false; 1259 } 1260 1261 return true; 1262} 1263 1264template <class Impl> 1265void 1266DefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 1267{ 1268 unsigned thread = inst->threadNumber; 1269 1270 // 1271 // Pick off the software prefetches 1272 // 1273#ifdef TARGET_ALPHA 1274 if (inst->isDataPrefetch()) { 1275 statComSwp[thread]++; 1276 } else { 1277 statComInst[thread]++; 1278 } 1279#else 1280 statComInst[thread]++; 1281#endif 1282 1283 // 1284 // Control Instructions 1285 // 1286 if (inst->isControl()) 1287 statComBranches[thread]++; 1288 1289 // 1290 // Memory references 1291 // 1292 if (inst->isMemRef()) { 1293 statComRefs[thread]++; 1294 1295 if (inst->isLoad()) { 1296 statComLoads[thread]++; 1297 } 1298 } 1299 1300 if (inst->isMemBarrier()) { 1301 statComMembars[thread]++; 1302 } 1303} 1304 1305//////////////////////////////////////// 1306// // 1307// SMT COMMIT POLICY MAINTAINED HERE // 1308// // 1309//////////////////////////////////////// 1310template <class Impl> 1311int 1312DefaultCommit<Impl>::getCommittingThread() 1313{ 1314 if (numThreads > 1) { 1315 switch (commitPolicy) { 1316 1317 case Aggressive: 1318 //If Policy is Aggressive, commit will call 1319 //this function multiple times per 1320 //cycle 1321 return oldestReady(); 1322 1323 case RoundRobin: 1324 return roundRobin(); 1325 1326 case OldestReady: 1327 return oldestReady(); 1328 1329 default: 1330 return -1; 1331 } 1332 } else {
| 1278 unsigned tid = *threads++; 1279 1280 if (!rob->isDoneSquashing(tid)) 1281 return false; 1282 } 1283 1284 return true; 1285} 1286 1287template <class Impl> 1288void 1289DefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 1290{ 1291 unsigned thread = inst->threadNumber; 1292 1293 // 1294 // Pick off the software prefetches 1295 // 1296#ifdef TARGET_ALPHA 1297 if (inst->isDataPrefetch()) { 1298 statComSwp[thread]++; 1299 } else { 1300 statComInst[thread]++; 1301 } 1302#else 1303 statComInst[thread]++; 1304#endif 1305 1306 // 1307 // Control Instructions 1308 // 1309 if (inst->isControl()) 1310 statComBranches[thread]++; 1311 1312 // 1313 // Memory references 1314 // 1315 if (inst->isMemRef()) { 1316 statComRefs[thread]++; 1317 1318 if (inst->isLoad()) { 1319 statComLoads[thread]++; 1320 } 1321 } 1322 1323 if (inst->isMemBarrier()) { 1324 statComMembars[thread]++; 1325 } 1326} 1327 1328//////////////////////////////////////// 1329// // 1330// SMT COMMIT POLICY MAINTAINED HERE // 1331// // 1332//////////////////////////////////////// 1333template <class Impl> 1334int 1335DefaultCommit<Impl>::getCommittingThread() 1336{ 1337 if (numThreads > 1) { 1338 switch (commitPolicy) { 1339 1340 case Aggressive: 1341 //If Policy is Aggressive, commit will call 1342 //this function multiple times per 1343 //cycle 1344 return oldestReady(); 1345 1346 case RoundRobin: 1347 return roundRobin(); 1348 1349 case OldestReady: 1350 return oldestReady(); 1351 1352 default: 1353 return -1; 1354 } 1355 } else {
|
1333 int tid = (*activeThreads).front();
| 1356 assert(!activeThreads->empty()); 1357 int tid = activeThreads->front();
|
1334 1335 if (commitStatus[tid] == Running || 1336 commitStatus[tid] == Idle || 1337 commitStatus[tid] == FetchTrapPending) { 1338 return tid; 1339 } else { 1340 return -1; 1341 } 1342 } 1343} 1344 1345template<class Impl> 1346int 1347DefaultCommit<Impl>::roundRobin() 1348{ 1349 std::list<unsigned>::iterator pri_iter = priority_list.begin(); 1350 std::list<unsigned>::iterator end = priority_list.end(); 1351 1352 while (pri_iter != end) { 1353 unsigned tid = *pri_iter; 1354 1355 if (commitStatus[tid] == Running || 1356 commitStatus[tid] == Idle || 1357 commitStatus[tid] == FetchTrapPending) { 1358 1359 if (rob->isHeadReady(tid)) { 1360 priority_list.erase(pri_iter); 1361 priority_list.push_back(tid); 1362 1363 return tid; 1364 } 1365 } 1366 1367 pri_iter++; 1368 } 1369 1370 return -1; 1371} 1372 1373template<class Impl> 1374int 1375DefaultCommit<Impl>::oldestReady() 1376{ 1377 unsigned oldest = 0; 1378 bool first = true; 1379
| 1358 1359 if (commitStatus[tid] == Running || 1360 commitStatus[tid] == Idle || 1361 commitStatus[tid] == FetchTrapPending) { 1362 return tid; 1363 } else { 1364 return -1; 1365 } 1366 } 1367} 1368 1369template<class Impl> 1370int 1371DefaultCommit<Impl>::roundRobin() 1372{ 1373 std::list<unsigned>::iterator pri_iter = priority_list.begin(); 1374 std::list<unsigned>::iterator end = priority_list.end(); 1375 1376 while (pri_iter != end) { 1377 unsigned tid = *pri_iter; 1378 1379 if (commitStatus[tid] == Running || 1380 commitStatus[tid] == Idle || 1381 commitStatus[tid] == FetchTrapPending) { 1382 1383 if (rob->isHeadReady(tid)) { 1384 priority_list.erase(pri_iter); 1385 priority_list.push_back(tid); 1386 1387 return tid; 1388 } 1389 } 1390 1391 pri_iter++; 1392 } 1393 1394 return -1; 1395} 1396 1397template<class Impl> 1398int 1399DefaultCommit<Impl>::oldestReady() 1400{ 1401 unsigned oldest = 0; 1402 bool first = true; 1403
|
1380 std::list<unsigned>::iterator threads = (*activeThreads).begin();
| 1404 std::list<unsigned>::iterator threads = activeThreads->begin(); 1405 std::list<unsigned>::iterator end = activeThreads->end();
|
1381
| 1406
|
1382 while (threads != (*activeThreads).end()) {
| 1407 while (threads != end) {
|
1383 unsigned tid = *threads++; 1384 1385 if (!rob->isEmpty(tid) && 1386 (commitStatus[tid] == Running || 1387 commitStatus[tid] == Idle || 1388 commitStatus[tid] == FetchTrapPending)) { 1389 1390 if (rob->isHeadReady(tid)) { 1391 1392 DynInstPtr head_inst = rob->readHeadInst(tid); 1393 1394 if (first) { 1395 oldest = tid; 1396 first = false; 1397 } else if (head_inst->seqNum < oldest) { 1398 oldest = tid; 1399 } 1400 } 1401 } 1402 } 1403 1404 if (!first) { 1405 return oldest; 1406 } else { 1407 return -1; 1408 } 1409}
| 1408 unsigned tid = *threads++; 1409 1410 if (!rob->isEmpty(tid) && 1411 (commitStatus[tid] == Running || 1412 commitStatus[tid] == Idle || 1413 commitStatus[tid] == FetchTrapPending)) { 1414 1415 if (rob->isHeadReady(tid)) { 1416 1417 DynInstPtr head_inst = rob->readHeadInst(tid); 1418 1419 if (first) { 1420 oldest = tid; 1421 first = false; 1422 } else if (head_inst->seqNum < oldest) { 1423 oldest = tid; 1424 } 1425 } 1426 } 1427 } 1428 1429 if (!first) { 1430 return oldest; 1431 } else { 1432 return -1; 1433 } 1434}
|