cpu.cc revision 10407
1/* 2 * Copyright (c) 2011-2012, 2014 ARM Limited 3 * Copyright (c) 2013 Advanced Micro Devices, Inc. 4 * All rights reserved 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating 9 * to a hardware implementation of the functionality of the software 10 * licensed hereunder. You may use the software subject to the license 11 * terms below provided that you ensure that this notice is replicated 12 * unmodified and in its entirety in all distributions of the software, 13 * modified or unmodified, in source code or in binary form. 14 * 15 * Copyright (c) 2004-2006 The Regents of The University of Michigan 16 * Copyright (c) 2011 Regents of the University of California 17 * All rights reserved. 18 * 19 * Redistribution and use in source and binary forms, with or without 20 * modification, are permitted provided that the following conditions are 21 * met: redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer; 23 * redistributions in binary form must reproduce the above copyright 24 * notice, this list of conditions and the following disclaimer in the 25 * documentation and/or other materials provided with the distribution; 26 * neither the name of the copyright holders nor the names of its 27 * contributors may be used to endorse or promote products derived from 28 * this software without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 * 42 * Authors: Kevin Lim 43 * Korey Sewell 44 * Rick Strong 45 */ 46 47#include "arch/kernel_stats.hh" 48#include "config/the_isa.hh" 49#include "cpu/checker/cpu.hh" 50#include "cpu/checker/thread_context.hh" 51#include "cpu/o3/cpu.hh" 52#include "cpu/o3/isa_specific.hh" 53#include "cpu/o3/thread_context.hh" 54#include "cpu/activity.hh" 55#include "cpu/quiesce_event.hh" 56#include "cpu/simple_thread.hh" 57#include "cpu/thread_context.hh" 58#include "debug/Activity.hh" 59#include "debug/Drain.hh" 60#include "debug/O3CPU.hh" 61#include "debug/Quiesce.hh" 62#include "enums/MemoryMode.hh" 63#include "sim/core.hh" 64#include "sim/full_system.hh" 65#include "sim/process.hh" 66#include "sim/stat_control.hh" 67#include "sim/system.hh" 68 69#if THE_ISA == ALPHA_ISA 70#include "arch/alpha/osfpal.hh" 71#include "debug/Activity.hh" 72#endif 73 74struct BaseCPUParams; 75 76using namespace TheISA; 77using namespace std; 78 79BaseO3CPU::BaseO3CPU(BaseCPUParams *params) 80 : BaseCPU(params) 81{ 82} 83 84void 85BaseO3CPU::regStats() 86{ 87 BaseCPU::regStats(); 88} 89 90template<class Impl> 91bool 92FullO3CPU<Impl>::IcachePort::recvTimingResp(PacketPtr pkt) 93{ 94 DPRINTF(O3CPU, "Fetch unit received timing\n"); 95 // We shouldn't ever get a block in ownership state 96 assert(!(pkt->memInhibitAsserted() && !pkt->sharedAsserted())); 97 fetch->processCacheCompletion(pkt); 98 99 return true; 100} 101 102template<class Impl> 103void 104FullO3CPU<Impl>::IcachePort::recvRetry() 105{ 106 fetch->recvRetry(); 107} 108 109template <class Impl> 110bool 111FullO3CPU<Impl>::DcachePort::recvTimingResp(PacketPtr pkt) 112{ 113 return lsq->recvTimingResp(pkt); 114} 115 116template <class Impl> 117void 118FullO3CPU<Impl>::DcachePort::recvTimingSnoopReq(PacketPtr pkt) 119{ 120 lsq->recvTimingSnoopReq(pkt); 121} 122 123template <class Impl> 124void 125FullO3CPU<Impl>::DcachePort::recvRetry() 126{ 127 lsq->recvRetry(); 128} 129 130template <class Impl> 131FullO3CPU<Impl>::TickEvent::TickEvent(FullO3CPU<Impl> *c) 132 : Event(CPU_Tick_Pri), cpu(c) 133{ 134} 135 136template <class Impl> 137void 138FullO3CPU<Impl>::TickEvent::process() 139{ 140 cpu->tick(); 141} 142 143template <class Impl> 144const char * 145FullO3CPU<Impl>::TickEvent::description() const 146{ 147 return "FullO3CPU tick"; 148} 149 150template <class Impl> 151FullO3CPU<Impl>::FullO3CPU(DerivO3CPUParams *params) 152 : BaseO3CPU(params), 153 itb(params->itb), 154 dtb(params->dtb), 155 tickEvent(this), 156#ifndef NDEBUG 157 instcount(0), 158#endif 159 removeInstsThisCycle(false), 160 fetch(this, params), 161 decode(this, params), 162 rename(this, params), 163 iew(this, params), 164 commit(this, params), 165 166 regFile(params->numPhysIntRegs, 167 params->numPhysFloatRegs, 168 params->numPhysCCRegs), 169 170 freeList(name() + ".freelist", ®File), 171 172 rob(this, params), 173 174 scoreboard(name() + ".scoreboard", 175 regFile.totalNumPhysRegs(), TheISA::NumMiscRegs, 176 TheISA::ZeroReg, TheISA::ZeroReg), 177 178 isa(numThreads, NULL), 179 180 icachePort(&fetch, this), 181 dcachePort(&iew.ldstQueue, this), 182 183 timeBuffer(params->backComSize, params->forwardComSize), 184 fetchQueue(params->backComSize, params->forwardComSize), 185 decodeQueue(params->backComSize, params->forwardComSize), 186 renameQueue(params->backComSize, params->forwardComSize), 187 iewQueue(params->backComSize, params->forwardComSize), 188 activityRec(name(), NumStages, 189 params->backComSize + params->forwardComSize, 190 params->activity), 191 192 globalSeqNum(1), 193 system(params->system), 194 drainManager(NULL), 195 lastRunningCycle(curCycle()) 196{ 197 if (!params->switched_out) { 198 _status = Running; 199 } else { 200 _status = SwitchedOut; 201 } 202 203 if (params->checker) { 204 BaseCPU *temp_checker = params->checker; 205 checker = dynamic_cast<Checker<Impl> *>(temp_checker); 206 checker->setIcachePort(&icachePort); 207 checker->setSystem(params->system); 208 } else { 209 checker = NULL; 210 } 211 212 if (!FullSystem) { 213 thread.resize(numThreads); 214 tids.resize(numThreads); 215 } 216 217 // The stages also need their CPU pointer setup. However this 218 // must be done at the upper level CPU because they have pointers 219 // to the upper level CPU, and not this FullO3CPU. 220 221 // Set up Pointers to the activeThreads list for each stage 222 fetch.setActiveThreads(&activeThreads); 223 decode.setActiveThreads(&activeThreads); 224 rename.setActiveThreads(&activeThreads); 225 iew.setActiveThreads(&activeThreads); 226 commit.setActiveThreads(&activeThreads); 227 228 // Give each of the stages the time buffer they will use. 229 fetch.setTimeBuffer(&timeBuffer); 230 decode.setTimeBuffer(&timeBuffer); 231 rename.setTimeBuffer(&timeBuffer); 232 iew.setTimeBuffer(&timeBuffer); 233 commit.setTimeBuffer(&timeBuffer); 234 235 // Also setup each of the stages' queues. 236 fetch.setFetchQueue(&fetchQueue); 237 decode.setFetchQueue(&fetchQueue); 238 commit.setFetchQueue(&fetchQueue); 239 decode.setDecodeQueue(&decodeQueue); 240 rename.setDecodeQueue(&decodeQueue); 241 rename.setRenameQueue(&renameQueue); 242 iew.setRenameQueue(&renameQueue); 243 iew.setIEWQueue(&iewQueue); 244 commit.setIEWQueue(&iewQueue); 245 commit.setRenameQueue(&renameQueue); 246 247 commit.setIEWStage(&iew); 248 rename.setIEWStage(&iew); 249 rename.setCommitStage(&commit); 250 251 ThreadID active_threads; 252 if (FullSystem) { 253 active_threads = 1; 254 } else { 255 active_threads = params->workload.size(); 256 257 if (active_threads > Impl::MaxThreads) { 258 panic("Workload Size too large. Increase the 'MaxThreads' " 259 "constant in your O3CPU impl. file (e.g. o3/alpha/impl.hh) " 260 "or edit your workload size."); 261 } 262 } 263 264 //Make Sure That this a Valid Architeture 265 assert(params->numPhysIntRegs >= numThreads * TheISA::NumIntRegs); 266 assert(params->numPhysFloatRegs >= numThreads * TheISA::NumFloatRegs); 267 assert(params->numPhysCCRegs >= numThreads * TheISA::NumCCRegs); 268 269 rename.setScoreboard(&scoreboard); 270 iew.setScoreboard(&scoreboard); 271 272 // Setup the rename map for whichever stages need it. 273 for (ThreadID tid = 0; tid < numThreads; tid++) { 274 isa[tid] = params->isa[tid]; 275 276 // Only Alpha has an FP zero register, so for other ISAs we 277 // use an invalid FP register index to avoid special treatment 278 // of any valid FP reg. 279 RegIndex invalidFPReg = TheISA::NumFloatRegs + 1; 280 RegIndex fpZeroReg = 281 (THE_ISA == ALPHA_ISA) ? TheISA::ZeroReg : invalidFPReg; 282 283 commitRenameMap[tid].init(®File, TheISA::ZeroReg, fpZeroReg, 284 &freeList); 285 286 renameMap[tid].init(®File, TheISA::ZeroReg, fpZeroReg, 287 &freeList); 288 } 289 290 // Initialize rename map to assign physical registers to the 291 // architectural registers for active threads only. 292 for (ThreadID tid = 0; tid < active_threads; tid++) { 293 for (RegIndex ridx = 0; ridx < TheISA::NumIntRegs; ++ridx) { 294 // Note that we can't use the rename() method because we don't 295 // want special treatment for the zero register at this point 296 PhysRegIndex phys_reg = freeList.getIntReg(); 297 renameMap[tid].setIntEntry(ridx, phys_reg); 298 commitRenameMap[tid].setIntEntry(ridx, phys_reg); 299 } 300 301 for (RegIndex ridx = 0; ridx < TheISA::NumFloatRegs; ++ridx) { 302 PhysRegIndex phys_reg = freeList.getFloatReg(); 303 renameMap[tid].setFloatEntry(ridx, phys_reg); 304 commitRenameMap[tid].setFloatEntry(ridx, phys_reg); 305 } 306 307 for (RegIndex ridx = 0; ridx < TheISA::NumCCRegs; ++ridx) { 308 PhysRegIndex phys_reg = freeList.getCCReg(); 309 renameMap[tid].setCCEntry(ridx, phys_reg); 310 commitRenameMap[tid].setCCEntry(ridx, phys_reg); 311 } 312 } 313 314 rename.setRenameMap(renameMap); 315 commit.setRenameMap(commitRenameMap); 316 rename.setFreeList(&freeList); 317 318 // Setup the ROB for whichever stages need it. 319 commit.setROB(&rob); 320 321 lastActivatedCycle = 0; 322#if 0 323 // Give renameMap & rename stage access to the freeList; 324 for (ThreadID tid = 0; tid < numThreads; tid++) 325 globalSeqNum[tid] = 1; 326#endif 327 328 DPRINTF(O3CPU, "Creating O3CPU object.\n"); 329 330 // Setup any thread state. 331 this->thread.resize(this->numThreads); 332 333 for (ThreadID tid = 0; tid < this->numThreads; ++tid) { 334 if (FullSystem) { 335 // SMT is not supported in FS mode yet. 336 assert(this->numThreads == 1); 337 this->thread[tid] = new Thread(this, 0, NULL); 338 } else { 339 if (tid < params->workload.size()) { 340 DPRINTF(O3CPU, "Workload[%i] process is %#x", 341 tid, this->thread[tid]); 342 this->thread[tid] = new typename FullO3CPU<Impl>::Thread( 343 (typename Impl::O3CPU *)(this), 344 tid, params->workload[tid]); 345 346 //usedTids[tid] = true; 347 //threadMap[tid] = tid; 348 } else { 349 //Allocate Empty thread so M5 can use later 350 //when scheduling threads to CPU 351 Process* dummy_proc = NULL; 352 353 this->thread[tid] = new typename FullO3CPU<Impl>::Thread( 354 (typename Impl::O3CPU *)(this), 355 tid, dummy_proc); 356 //usedTids[tid] = false; 357 } 358 } 359 360 ThreadContext *tc; 361 362 // Setup the TC that will serve as the interface to the threads/CPU. 363 O3ThreadContext<Impl> *o3_tc = new O3ThreadContext<Impl>; 364 365 tc = o3_tc; 366 367 // If we're using a checker, then the TC should be the 368 // CheckerThreadContext. 369 if (params->checker) { 370 tc = new CheckerThreadContext<O3ThreadContext<Impl> >( 371 o3_tc, this->checker); 372 } 373 374 o3_tc->cpu = (typename Impl::O3CPU *)(this); 375 assert(o3_tc->cpu); 376 o3_tc->thread = this->thread[tid]; 377 378 if (FullSystem) { 379 // Setup quiesce event. 380 this->thread[tid]->quiesceEvent = new EndQuiesceEvent(tc); 381 } 382 // Give the thread the TC. 383 this->thread[tid]->tc = tc; 384 385 // Add the TC to the CPU's list of TC's. 386 this->threadContexts.push_back(tc); 387 } 388 389 // FullO3CPU always requires an interrupt controller. 390 if (!params->switched_out && !interrupts) { 391 fatal("FullO3CPU %s has no interrupt controller.\n" 392 "Ensure createInterruptController() is called.\n", name()); 393 } 394 395 for (ThreadID tid = 0; tid < this->numThreads; tid++) 396 this->thread[tid]->setFuncExeInst(0); 397} 398 399template <class Impl> 400FullO3CPU<Impl>::~FullO3CPU() 401{ 402} 403 404template <class Impl> 405void 406FullO3CPU<Impl>::regProbePoints() 407{ 408 ppInstAccessComplete = new ProbePointArg<PacketPtr>(getProbeManager(), "InstAccessComplete"); 409 ppDataAccessComplete = new ProbePointArg<std::pair<DynInstPtr, PacketPtr> >(getProbeManager(), "DataAccessComplete"); 410 fetch.regProbePoints(); 411 iew.regProbePoints(); 412 commit.regProbePoints(); 413} 414 415template <class Impl> 416void 417FullO3CPU<Impl>::regStats() 418{ 419 BaseO3CPU::regStats(); 420 421 // Register any of the O3CPU's stats here. 422 timesIdled 423 .name(name() + ".timesIdled") 424 .desc("Number of times that the entire CPU went into an idle state and" 425 " unscheduled itself") 426 .prereq(timesIdled); 427 428 idleCycles 429 .name(name() + ".idleCycles") 430 .desc("Total number of cycles that the CPU has spent unscheduled due " 431 "to idling") 432 .prereq(idleCycles); 433 434 quiesceCycles 435 .name(name() + ".quiesceCycles") 436 .desc("Total number of cycles that CPU has spent quiesced or waiting " 437 "for an interrupt") 438 .prereq(quiesceCycles); 439 440 // Number of Instructions simulated 441 // -------------------------------- 442 // Should probably be in Base CPU but need templated 443 // MaxThreads so put in here instead 444 committedInsts 445 .init(numThreads) 446 .name(name() + ".committedInsts") 447 .desc("Number of Instructions Simulated") 448 .flags(Stats::total); 449 450 committedOps 451 .init(numThreads) 452 .name(name() + ".committedOps") 453 .desc("Number of Ops (including micro ops) Simulated") 454 .flags(Stats::total); 455 456 cpi 457 .name(name() + ".cpi") 458 .desc("CPI: Cycles Per Instruction") 459 .precision(6); 460 cpi = numCycles / committedInsts; 461 462 totalCpi 463 .name(name() + ".cpi_total") 464 .desc("CPI: Total CPI of All Threads") 465 .precision(6); 466 totalCpi = numCycles / sum(committedInsts); 467 468 ipc 469 .name(name() + ".ipc") 470 .desc("IPC: Instructions Per Cycle") 471 .precision(6); 472 ipc = committedInsts / numCycles; 473 474 totalIpc 475 .name(name() + ".ipc_total") 476 .desc("IPC: Total IPC of All Threads") 477 .precision(6); 478 totalIpc = sum(committedInsts) / numCycles; 479 480 this->fetch.regStats(); 481 this->decode.regStats(); 482 this->rename.regStats(); 483 this->iew.regStats(); 484 this->commit.regStats(); 485 this->rob.regStats(); 486 487 intRegfileReads 488 .name(name() + ".int_regfile_reads") 489 .desc("number of integer regfile reads") 490 .prereq(intRegfileReads); 491 492 intRegfileWrites 493 .name(name() + ".int_regfile_writes") 494 .desc("number of integer regfile writes") 495 .prereq(intRegfileWrites); 496 497 fpRegfileReads 498 .name(name() + ".fp_regfile_reads") 499 .desc("number of floating regfile reads") 500 .prereq(fpRegfileReads); 501 502 fpRegfileWrites 503 .name(name() + ".fp_regfile_writes") 504 .desc("number of floating regfile writes") 505 .prereq(fpRegfileWrites); 506 507 ccRegfileReads 508 .name(name() + ".cc_regfile_reads") 509 .desc("number of cc regfile reads") 510 .prereq(ccRegfileReads); 511 512 ccRegfileWrites 513 .name(name() + ".cc_regfile_writes") 514 .desc("number of cc regfile writes") 515 .prereq(ccRegfileWrites); 516 517 miscRegfileReads 518 .name(name() + ".misc_regfile_reads") 519 .desc("number of misc regfile reads") 520 .prereq(miscRegfileReads); 521 522 miscRegfileWrites 523 .name(name() + ".misc_regfile_writes") 524 .desc("number of misc regfile writes") 525 .prereq(miscRegfileWrites); 526} 527 528template <class Impl> 529void 530FullO3CPU<Impl>::tick() 531{ 532 DPRINTF(O3CPU, "\n\nFullO3CPU: Ticking main, FullO3CPU.\n"); 533 assert(!switchedOut()); 534 assert(getDrainState() != Drainable::Drained); 535 536 ++numCycles; 537 538// activity = false; 539 540 //Tick each of the stages 541 fetch.tick(); 542 543 decode.tick(); 544 545 rename.tick(); 546 547 iew.tick(); 548 549 commit.tick(); 550 551 // Now advance the time buffers 552 timeBuffer.advance(); 553 554 fetchQueue.advance(); 555 decodeQueue.advance(); 556 renameQueue.advance(); 557 iewQueue.advance(); 558 559 activityRec.advance(); 560 561 if (removeInstsThisCycle) { 562 cleanUpRemovedInsts(); 563 } 564 565 if (!tickEvent.scheduled()) { 566 if (_status == SwitchedOut) { 567 DPRINTF(O3CPU, "Switched out!\n"); 568 // increment stat 569 lastRunningCycle = curCycle(); 570 } else if (!activityRec.active() || _status == Idle) { 571 DPRINTF(O3CPU, "Idle!\n"); 572 lastRunningCycle = curCycle(); 573 timesIdled++; 574 } else { 575 schedule(tickEvent, clockEdge(Cycles(1))); 576 DPRINTF(O3CPU, "Scheduling next tick!\n"); 577 } 578 } 579 580 if (!FullSystem) 581 updateThreadPriority(); 582 583 tryDrain(); 584} 585 586template <class Impl> 587void 588FullO3CPU<Impl>::init() 589{ 590 BaseCPU::init(); 591 592 for (ThreadID tid = 0; tid < numThreads; ++tid) { 593 // Set noSquashFromTC so that the CPU doesn't squash when initially 594 // setting up registers. 595 thread[tid]->noSquashFromTC = true; 596 // Initialise the ThreadContext's memory proxies 597 thread[tid]->initMemProxies(thread[tid]->getTC()); 598 } 599 600 if (FullSystem && !params()->switched_out) { 601 for (ThreadID tid = 0; tid < numThreads; tid++) { 602 ThreadContext *src_tc = threadContexts[tid]; 603 TheISA::initCPU(src_tc, src_tc->contextId()); 604 } 605 } 606 607 // Clear noSquashFromTC. 608 for (int tid = 0; tid < numThreads; ++tid) 609 thread[tid]->noSquashFromTC = false; 610 611 commit.setThreads(thread); 612} 613 614template <class Impl> 615void 616FullO3CPU<Impl>::startup() 617{ 618 BaseCPU::startup(); 619 for (int tid = 0; tid < numThreads; ++tid) 620 isa[tid]->startup(threadContexts[tid]); 621 622 fetch.startupStage(); 623 decode.startupStage(); 624 iew.startupStage(); 625 rename.startupStage(); 626 commit.startupStage(); 627} 628 629template <class Impl> 630void 631FullO3CPU<Impl>::activateThread(ThreadID tid) 632{ 633 list<ThreadID>::iterator isActive = 634 std::find(activeThreads.begin(), activeThreads.end(), tid); 635 636 DPRINTF(O3CPU, "[tid:%i]: Calling activate thread.\n", tid); 637 assert(!switchedOut()); 638 639 if (isActive == activeThreads.end()) { 640 DPRINTF(O3CPU, "[tid:%i]: Adding to active threads list\n", 641 tid); 642 643 activeThreads.push_back(tid); 644 } 645} 646 647template <class Impl> 648void 649FullO3CPU<Impl>::deactivateThread(ThreadID tid) 650{ 651 //Remove From Active List, if Active 652 list<ThreadID>::iterator thread_it = 653 std::find(activeThreads.begin(), activeThreads.end(), tid); 654 655 DPRINTF(O3CPU, "[tid:%i]: Calling deactivate thread.\n", tid); 656 assert(!switchedOut()); 657 658 if (thread_it != activeThreads.end()) { 659 DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n", 660 tid); 661 activeThreads.erase(thread_it); 662 } 663 664 fetch.deactivateThread(tid); 665 commit.deactivateThread(tid); 666} 667 668template <class Impl> 669Counter 670FullO3CPU<Impl>::totalInsts() const 671{ 672 Counter total(0); 673 674 ThreadID size = thread.size(); 675 for (ThreadID i = 0; i < size; i++) 676 total += thread[i]->numInst; 677 678 return total; 679} 680 681template <class Impl> 682Counter 683FullO3CPU<Impl>::totalOps() const 684{ 685 Counter total(0); 686 687 ThreadID size = thread.size(); 688 for (ThreadID i = 0; i < size; i++) 689 total += thread[i]->numOp; 690 691 return total; 692} 693 694template <class Impl> 695void 696FullO3CPU<Impl>::activateContext(ThreadID tid) 697{ 698 assert(!switchedOut()); 699 700 // Needs to set each stage to running as well. 701 activateThread(tid); 702 703 // We don't want to wake the CPU if it is drained. In that case, 704 // we just want to flag the thread as active and schedule the tick 705 // event from drainResume() instead. 706 if (getDrainState() == Drainable::Drained) 707 return; 708 709 // If we are time 0 or if the last activation time is in the past, 710 // schedule the next tick and wake up the fetch unit 711 if (lastActivatedCycle == 0 || lastActivatedCycle < curTick()) { 712 scheduleTickEvent(Cycles(0)); 713 714 // Be sure to signal that there's some activity so the CPU doesn't 715 // deschedule itself. 716 activityRec.activity(); 717 fetch.wakeFromQuiesce(); 718 719 Cycles cycles(curCycle() - lastRunningCycle); 720 // @todo: This is an oddity that is only here to match the stats 721 if (cycles != 0) 722 --cycles; 723 quiesceCycles += cycles; 724 725 lastActivatedCycle = curTick(); 726 727 _status = Running; 728 } 729} 730 731template <class Impl> 732void 733FullO3CPU<Impl>::deallocateContext(ThreadID tid, bool remove) 734{ 735 deactivateThread(tid); 736 if (remove) 737 removeThread(tid); 738} 739 740template <class Impl> 741void 742FullO3CPU<Impl>::suspendContext(ThreadID tid) 743{ 744 DPRINTF(O3CPU,"[tid: %i]: Suspending Thread Context.\n", tid); 745 assert(!switchedOut()); 746 deallocateContext(tid, false); 747 748 // If this was the last thread then unschedule the tick event. 749 if (activeThreads.size() == 0) 750 unscheduleTickEvent(); 751 752 DPRINTF(Quiesce, "Suspending Context\n"); 753 lastRunningCycle = curCycle(); 754 _status = Idle; 755} 756 757template <class Impl> 758void 759FullO3CPU<Impl>::haltContext(ThreadID tid) 760{ 761 //For now, this is the same as deallocate 762 DPRINTF(O3CPU,"[tid:%i]: Halt Context called. Deallocating", tid); 763 assert(!switchedOut()); 764 deallocateContext(tid, true); 765} 766 767template <class Impl> 768void 769FullO3CPU<Impl>::insertThread(ThreadID tid) 770{ 771 DPRINTF(O3CPU,"[tid:%i] Initializing thread into CPU"); 772 // Will change now that the PC and thread state is internal to the CPU 773 // and not in the ThreadContext. 774 ThreadContext *src_tc; 775 if (FullSystem) 776 src_tc = system->threadContexts[tid]; 777 else 778 src_tc = tcBase(tid); 779 780 //Bind Int Regs to Rename Map 781 for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) { 782 PhysRegIndex phys_reg = freeList.getIntReg(); 783 784 renameMap[tid].setEntry(ireg,phys_reg); 785 scoreboard.setReg(phys_reg); 786 } 787 788 //Bind Float Regs to Rename Map 789 int max_reg = TheISA::NumIntRegs + TheISA::NumFloatRegs; 790 for (int freg = TheISA::NumIntRegs; freg < max_reg; freg++) { 791 PhysRegIndex phys_reg = freeList.getFloatReg(); 792 793 renameMap[tid].setEntry(freg,phys_reg); 794 scoreboard.setReg(phys_reg); 795 } 796 797 //Bind condition-code Regs to Rename Map 798 max_reg = TheISA::NumIntRegs + TheISA::NumFloatRegs + TheISA::NumCCRegs; 799 for (int creg = TheISA::NumIntRegs + TheISA::NumFloatRegs; 800 creg < max_reg; creg++) { 801 PhysRegIndex phys_reg = freeList.getCCReg(); 802 803 renameMap[tid].setEntry(creg,phys_reg); 804 scoreboard.setReg(phys_reg); 805 } 806 807 //Copy Thread Data Into RegFile 808 //this->copyFromTC(tid); 809 810 //Set PC/NPC/NNPC 811 pcState(src_tc->pcState(), tid); 812 813 src_tc->setStatus(ThreadContext::Active); 814 815 activateContext(tid); 816 817 //Reset ROB/IQ/LSQ Entries 818 commit.rob->resetEntries(); 819 iew.resetEntries(); 820} 821 822template <class Impl> 823void 824FullO3CPU<Impl>::removeThread(ThreadID tid) 825{ 826 DPRINTF(O3CPU,"[tid:%i] Removing thread context from CPU.\n", tid); 827 828 // Copy Thread Data From RegFile 829 // If thread is suspended, it might be re-allocated 830 // this->copyToTC(tid); 831 832 833 // @todo: 2-27-2008: Fix how we free up rename mappings 834 // here to alleviate the case for double-freeing registers 835 // in SMT workloads. 836 837 // Unbind Int Regs from Rename Map 838 for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) { 839 PhysRegIndex phys_reg = renameMap[tid].lookup(ireg); 840 841 scoreboard.unsetReg(phys_reg); 842 freeList.addReg(phys_reg); 843 } 844 845 // Unbind Float Regs from Rename Map 846 int max_reg = TheISA::NumIntRegs + TheISA::NumFloatRegs; 847 for (int freg = TheISA::NumIntRegs; freg < max_reg; freg++) { 848 PhysRegIndex phys_reg = renameMap[tid].lookup(freg); 849 850 scoreboard.unsetReg(phys_reg); 851 freeList.addReg(phys_reg); 852 } 853 854 // Unbind condition-code Regs from Rename Map 855 max_reg = TheISA::NumIntRegs + TheISA::NumFloatRegs + TheISA::NumCCRegs; 856 for (int creg = TheISA::NumIntRegs + TheISA::NumFloatRegs; 857 creg < max_reg; creg++) { 858 PhysRegIndex phys_reg = renameMap[tid].lookup(creg); 859 860 scoreboard.unsetReg(phys_reg); 861 freeList.addReg(phys_reg); 862 } 863 864 // Squash Throughout Pipeline 865 DynInstPtr inst = commit.rob->readHeadInst(tid); 866 InstSeqNum squash_seq_num = inst->seqNum; 867 fetch.squash(0, squash_seq_num, inst, tid); 868 decode.squash(tid); 869 rename.squash(squash_seq_num, tid); 870 iew.squash(tid); 871 iew.ldstQueue.squash(squash_seq_num, tid); 872 commit.rob->squash(squash_seq_num, tid); 873 874 875 assert(iew.instQueue.getCount(tid) == 0); 876 assert(iew.ldstQueue.getCount(tid) == 0); 877 878 // Reset ROB/IQ/LSQ Entries 879 880 // Commented out for now. This should be possible to do by 881 // telling all the pipeline stages to drain first, and then 882 // checking until the drain completes. Once the pipeline is 883 // drained, call resetEntries(). - 10-09-06 ktlim 884/* 885 if (activeThreads.size() >= 1) { 886 commit.rob->resetEntries(); 887 iew.resetEntries(); 888 } 889*/ 890} 891 892template <class Impl> 893Fault 894FullO3CPU<Impl>::hwrei(ThreadID tid) 895{ 896#if THE_ISA == ALPHA_ISA 897 // Need to clear the lock flag upon returning from an interrupt. 898 this->setMiscRegNoEffect(AlphaISA::MISCREG_LOCKFLAG, false, tid); 899 900 this->thread[tid]->kernelStats->hwrei(); 901 902 // FIXME: XXX check for interrupts? XXX 903#endif 904 return NoFault; 905} 906 907template <class Impl> 908bool 909FullO3CPU<Impl>::simPalCheck(int palFunc, ThreadID tid) 910{ 911#if THE_ISA == ALPHA_ISA 912 if (this->thread[tid]->kernelStats) 913 this->thread[tid]->kernelStats->callpal(palFunc, 914 this->threadContexts[tid]); 915 916 switch (palFunc) { 917 case PAL::halt: 918 halt(); 919 if (--System::numSystemsRunning == 0) 920 exitSimLoop("all cpus halted"); 921 break; 922 923 case PAL::bpt: 924 case PAL::bugchk: 925 if (this->system->breakpoint()) 926 return false; 927 break; 928 } 929#endif 930 return true; 931} 932 933template <class Impl> 934Fault 935FullO3CPU<Impl>::getInterrupts() 936{ 937 // Check if there are any outstanding interrupts 938 return this->interrupts->getInterrupt(this->threadContexts[0]); 939} 940 941template <class Impl> 942void 943FullO3CPU<Impl>::processInterrupts(const Fault &interrupt) 944{ 945 // Check for interrupts here. For now can copy the code that 946 // exists within isa_fullsys_traits.hh. Also assume that thread 0 947 // is the one that handles the interrupts. 948 // @todo: Possibly consolidate the interrupt checking code. 949 // @todo: Allow other threads to handle interrupts. 950 951 assert(interrupt != NoFault); 952 this->interrupts->updateIntrInfo(this->threadContexts[0]); 953 954 DPRINTF(O3CPU, "Interrupt %s being handled\n", interrupt->name()); 955 this->trap(interrupt, 0, NULL); 956} 957 958template <class Impl> 959void 960FullO3CPU<Impl>::trap(const Fault &fault, ThreadID tid, StaticInstPtr inst) 961{ 962 // Pass the thread's TC into the invoke method. 963 fault->invoke(this->threadContexts[tid], inst); 964} 965 966template <class Impl> 967void 968FullO3CPU<Impl>::syscall(int64_t callnum, ThreadID tid) 969{ 970 DPRINTF(O3CPU, "[tid:%i] Executing syscall().\n\n", tid); 971 972 DPRINTF(Activity,"Activity: syscall() called.\n"); 973 974 // Temporarily increase this by one to account for the syscall 975 // instruction. 976 ++(this->thread[tid]->funcExeInst); 977 978 // Execute the actual syscall. 979 this->thread[tid]->syscall(callnum); 980 981 // Decrease funcExeInst by one as the normal commit will handle 982 // incrementing it. 983 --(this->thread[tid]->funcExeInst); 984} 985 986template <class Impl> 987void 988FullO3CPU<Impl>::serializeThread(std::ostream &os, ThreadID tid) 989{ 990 thread[tid]->serialize(os); 991} 992 993template <class Impl> 994void 995FullO3CPU<Impl>::unserializeThread(Checkpoint *cp, const std::string §ion, 996 ThreadID tid) 997{ 998 thread[tid]->unserialize(cp, section); 999} 1000 1001template <class Impl> 1002unsigned int 1003FullO3CPU<Impl>::drain(DrainManager *drain_manager) 1004{ 1005 // If the CPU isn't doing anything, then return immediately. 1006 if (switchedOut()) { 1007 setDrainState(Drainable::Drained); 1008 return 0; 1009 } 1010 1011 DPRINTF(Drain, "Draining...\n"); 1012 setDrainState(Drainable::Draining); 1013 1014 // We only need to signal a drain to the commit stage as this 1015 // initiates squashing controls the draining. Once the commit 1016 // stage commits an instruction where it is safe to stop, it'll 1017 // squash the rest of the instructions in the pipeline and force 1018 // the fetch stage to stall. The pipeline will be drained once all 1019 // in-flight instructions have retired. 1020 commit.drain(); 1021 1022 // Wake the CPU and record activity so everything can drain out if 1023 // the CPU was not able to immediately drain. 1024 if (!isDrained()) { 1025 drainManager = drain_manager; 1026 1027 wakeCPU(); 1028 activityRec.activity(); 1029 1030 DPRINTF(Drain, "CPU not drained\n"); 1031 1032 return 1; 1033 } else { 1034 setDrainState(Drainable::Drained); 1035 DPRINTF(Drain, "CPU is already drained\n"); 1036 if (tickEvent.scheduled()) 1037 deschedule(tickEvent); 1038 1039 // Flush out any old data from the time buffers. In 1040 // particular, there might be some data in flight from the 1041 // fetch stage that isn't visible in any of the CPU buffers we 1042 // test in isDrained(). 1043 for (int i = 0; i < timeBuffer.getSize(); ++i) { 1044 timeBuffer.advance(); 1045 fetchQueue.advance(); 1046 decodeQueue.advance(); 1047 renameQueue.advance(); 1048 iewQueue.advance(); 1049 } 1050 1051 drainSanityCheck(); 1052 return 0; 1053 } 1054} 1055 1056template <class Impl> 1057bool 1058FullO3CPU<Impl>::tryDrain() 1059{ 1060 if (!drainManager || !isDrained()) 1061 return false; 1062 1063 if (tickEvent.scheduled()) 1064 deschedule(tickEvent); 1065 1066 DPRINTF(Drain, "CPU done draining, processing drain event\n"); 1067 drainManager->signalDrainDone(); 1068 drainManager = NULL; 1069 1070 return true; 1071} 1072 1073template <class Impl> 1074void 1075FullO3CPU<Impl>::drainSanityCheck() const 1076{ 1077 assert(isDrained()); 1078 fetch.drainSanityCheck(); 1079 decode.drainSanityCheck(); 1080 rename.drainSanityCheck(); 1081 iew.drainSanityCheck(); 1082 commit.drainSanityCheck(); 1083} 1084 1085template <class Impl> 1086bool 1087FullO3CPU<Impl>::isDrained() const 1088{ 1089 bool drained(true); 1090 1091 if (!instList.empty() || !removeList.empty()) { 1092 DPRINTF(Drain, "Main CPU structures not drained.\n"); 1093 drained = false; 1094 } 1095 1096 if (!fetch.isDrained()) { 1097 DPRINTF(Drain, "Fetch not drained.\n"); 1098 drained = false; 1099 } 1100 1101 if (!decode.isDrained()) { 1102 DPRINTF(Drain, "Decode not drained.\n"); 1103 drained = false; 1104 } 1105 1106 if (!rename.isDrained()) { 1107 DPRINTF(Drain, "Rename not drained.\n"); 1108 drained = false; 1109 } 1110 1111 if (!iew.isDrained()) { 1112 DPRINTF(Drain, "IEW not drained.\n"); 1113 drained = false; 1114 } 1115 1116 if (!commit.isDrained()) { 1117 DPRINTF(Drain, "Commit not drained.\n"); 1118 drained = false; 1119 } 1120 1121 return drained; 1122} 1123 1124template <class Impl> 1125void 1126FullO3CPU<Impl>::commitDrained(ThreadID tid) 1127{ 1128 fetch.drainStall(tid); 1129} 1130 1131template <class Impl> 1132void 1133FullO3CPU<Impl>::drainResume() 1134{ 1135 setDrainState(Drainable::Running); 1136 if (switchedOut()) 1137 return; 1138 1139 DPRINTF(Drain, "Resuming...\n"); 1140 verifyMemoryMode(); 1141 1142 fetch.drainResume(); 1143 commit.drainResume(); 1144 1145 _status = Idle; 1146 for (ThreadID i = 0; i < thread.size(); i++) { 1147 if (thread[i]->status() == ThreadContext::Active) { 1148 DPRINTF(Drain, "Activating thread: %i\n", i); 1149 activateThread(i); 1150 _status = Running; 1151 } 1152 } 1153 1154 assert(!tickEvent.scheduled()); 1155 if (_status == Running) 1156 schedule(tickEvent, nextCycle()); 1157} 1158 1159template <class Impl> 1160void 1161FullO3CPU<Impl>::switchOut() 1162{ 1163 DPRINTF(O3CPU, "Switching out\n"); 1164 BaseCPU::switchOut(); 1165 1166 activityRec.reset(); 1167 1168 _status = SwitchedOut; 1169 1170 if (checker) 1171 checker->switchOut(); 1172} 1173 1174template <class Impl> 1175void 1176FullO3CPU<Impl>::takeOverFrom(BaseCPU *oldCPU) 1177{ 1178 BaseCPU::takeOverFrom(oldCPU); 1179 1180 fetch.takeOverFrom(); 1181 decode.takeOverFrom(); 1182 rename.takeOverFrom(); 1183 iew.takeOverFrom(); 1184 commit.takeOverFrom(); 1185 1186 assert(!tickEvent.scheduled()); 1187 1188 FullO3CPU<Impl> *oldO3CPU = dynamic_cast<FullO3CPU<Impl>*>(oldCPU); 1189 if (oldO3CPU) 1190 globalSeqNum = oldO3CPU->globalSeqNum; 1191 1192 lastRunningCycle = curCycle(); 1193 _status = Idle; 1194} 1195 1196template <class Impl> 1197void 1198FullO3CPU<Impl>::verifyMemoryMode() const 1199{ 1200 if (!system->isTimingMode()) { 1201 fatal("The O3 CPU requires the memory system to be in " 1202 "'timing' mode.\n"); 1203 } 1204} 1205 1206template <class Impl> 1207TheISA::MiscReg 1208FullO3CPU<Impl>::readMiscRegNoEffect(int misc_reg, ThreadID tid) 1209{ 1210 return this->isa[tid]->readMiscRegNoEffect(misc_reg); 1211} 1212 1213template <class Impl> 1214TheISA::MiscReg 1215FullO3CPU<Impl>::readMiscReg(int misc_reg, ThreadID tid) 1216{ 1217 miscRegfileReads++; 1218 return this->isa[tid]->readMiscReg(misc_reg, tcBase(tid)); 1219} 1220 1221template <class Impl> 1222void 1223FullO3CPU<Impl>::setMiscRegNoEffect(int misc_reg, 1224 const TheISA::MiscReg &val, ThreadID tid) 1225{ 1226 this->isa[tid]->setMiscRegNoEffect(misc_reg, val); 1227} 1228 1229template <class Impl> 1230void 1231FullO3CPU<Impl>::setMiscReg(int misc_reg, 1232 const TheISA::MiscReg &val, ThreadID tid) 1233{ 1234 miscRegfileWrites++; 1235 this->isa[tid]->setMiscReg(misc_reg, val, tcBase(tid)); 1236} 1237 1238template <class Impl> 1239uint64_t 1240FullO3CPU<Impl>::readIntReg(int reg_idx) 1241{ 1242 intRegfileReads++; 1243 return regFile.readIntReg(reg_idx); 1244} 1245 1246template <class Impl> 1247FloatReg 1248FullO3CPU<Impl>::readFloatReg(int reg_idx) 1249{ 1250 fpRegfileReads++; 1251 return regFile.readFloatReg(reg_idx); 1252} 1253 1254template <class Impl> 1255FloatRegBits 1256FullO3CPU<Impl>::readFloatRegBits(int reg_idx) 1257{ 1258 fpRegfileReads++; 1259 return regFile.readFloatRegBits(reg_idx); 1260} 1261 1262template <class Impl> 1263CCReg 1264FullO3CPU<Impl>::readCCReg(int reg_idx) 1265{ 1266 ccRegfileReads++; 1267 return regFile.readCCReg(reg_idx); 1268} 1269 1270template <class Impl> 1271void 1272FullO3CPU<Impl>::setIntReg(int reg_idx, uint64_t val) 1273{ 1274 intRegfileWrites++; 1275 regFile.setIntReg(reg_idx, val); 1276} 1277 1278template <class Impl> 1279void 1280FullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val) 1281{ 1282 fpRegfileWrites++; 1283 regFile.setFloatReg(reg_idx, val); 1284} 1285 1286template <class Impl> 1287void 1288FullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val) 1289{ 1290 fpRegfileWrites++; 1291 regFile.setFloatRegBits(reg_idx, val); 1292} 1293 1294template <class Impl> 1295void 1296FullO3CPU<Impl>::setCCReg(int reg_idx, CCReg val) 1297{ 1298 ccRegfileWrites++; 1299 regFile.setCCReg(reg_idx, val); 1300} 1301 1302template <class Impl> 1303uint64_t 1304FullO3CPU<Impl>::readArchIntReg(int reg_idx, ThreadID tid) 1305{ 1306 intRegfileReads++; 1307 PhysRegIndex phys_reg = commitRenameMap[tid].lookupInt(reg_idx); 1308 1309 return regFile.readIntReg(phys_reg); 1310} 1311 1312template <class Impl> 1313float 1314FullO3CPU<Impl>::readArchFloatReg(int reg_idx, ThreadID tid) 1315{ 1316 fpRegfileReads++; 1317 PhysRegIndex phys_reg = commitRenameMap[tid].lookupFloat(reg_idx); 1318 1319 return regFile.readFloatReg(phys_reg); 1320} 1321 1322template <class Impl> 1323uint64_t 1324FullO3CPU<Impl>::readArchFloatRegInt(int reg_idx, ThreadID tid) 1325{ 1326 fpRegfileReads++; 1327 PhysRegIndex phys_reg = commitRenameMap[tid].lookupFloat(reg_idx); 1328 1329 return regFile.readFloatRegBits(phys_reg); 1330} 1331 1332template <class Impl> 1333CCReg 1334FullO3CPU<Impl>::readArchCCReg(int reg_idx, ThreadID tid) 1335{ 1336 ccRegfileReads++; 1337 PhysRegIndex phys_reg = commitRenameMap[tid].lookupCC(reg_idx); 1338 1339 return regFile.readCCReg(phys_reg); 1340} 1341 1342template <class Impl> 1343void 1344FullO3CPU<Impl>::setArchIntReg(int reg_idx, uint64_t val, ThreadID tid) 1345{ 1346 intRegfileWrites++; 1347 PhysRegIndex phys_reg = commitRenameMap[tid].lookupInt(reg_idx); 1348 1349 regFile.setIntReg(phys_reg, val); 1350} 1351 1352template <class Impl> 1353void 1354FullO3CPU<Impl>::setArchFloatReg(int reg_idx, float val, ThreadID tid) 1355{ 1356 fpRegfileWrites++; 1357 PhysRegIndex phys_reg = commitRenameMap[tid].lookupFloat(reg_idx); 1358 1359 regFile.setFloatReg(phys_reg, val); 1360} 1361 1362template <class Impl> 1363void 1364FullO3CPU<Impl>::setArchFloatRegInt(int reg_idx, uint64_t val, ThreadID tid) 1365{ 1366 fpRegfileWrites++; 1367 PhysRegIndex phys_reg = commitRenameMap[tid].lookupFloat(reg_idx); 1368 1369 regFile.setFloatRegBits(phys_reg, val); 1370} 1371 1372template <class Impl> 1373void 1374FullO3CPU<Impl>::setArchCCReg(int reg_idx, CCReg val, ThreadID tid) 1375{ 1376 ccRegfileWrites++; 1377 PhysRegIndex phys_reg = commitRenameMap[tid].lookupCC(reg_idx); 1378 1379 regFile.setCCReg(phys_reg, val); 1380} 1381 1382template <class Impl> 1383TheISA::PCState 1384FullO3CPU<Impl>::pcState(ThreadID tid) 1385{ 1386 return commit.pcState(tid); 1387} 1388 1389template <class Impl> 1390void 1391FullO3CPU<Impl>::pcState(const TheISA::PCState &val, ThreadID tid) 1392{ 1393 commit.pcState(val, tid); 1394} 1395 1396template <class Impl> 1397Addr 1398FullO3CPU<Impl>::instAddr(ThreadID tid) 1399{ 1400 return commit.instAddr(tid); 1401} 1402 1403template <class Impl> 1404Addr 1405FullO3CPU<Impl>::nextInstAddr(ThreadID tid) 1406{ 1407 return commit.nextInstAddr(tid); 1408} 1409 1410template <class Impl> 1411MicroPC 1412FullO3CPU<Impl>::microPC(ThreadID tid) 1413{ 1414 return commit.microPC(tid); 1415} 1416 1417template <class Impl> 1418void 1419FullO3CPU<Impl>::squashFromTC(ThreadID tid) 1420{ 1421 this->thread[tid]->noSquashFromTC = true; 1422 this->commit.generateTCEvent(tid); 1423} 1424 1425template <class Impl> 1426typename FullO3CPU<Impl>::ListIt 1427FullO3CPU<Impl>::addInst(DynInstPtr &inst) 1428{ 1429 instList.push_back(inst); 1430 1431 return --(instList.end()); 1432} 1433 1434template <class Impl> 1435void 1436FullO3CPU<Impl>::instDone(ThreadID tid, DynInstPtr &inst) 1437{ 1438 // Keep an instruction count. 1439 if (!inst->isMicroop() || inst->isLastMicroop()) { 1440 thread[tid]->numInst++; 1441 thread[tid]->numInsts++; 1442 committedInsts[tid]++; 1443 } 1444 thread[tid]->numOp++; 1445 thread[tid]->numOps++; 1446 committedOps[tid]++; 1447 1448 system->totalNumInsts++; 1449 // Check for instruction-count-based events. 1450 comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst); 1451 system->instEventQueue.serviceEvents(system->totalNumInsts); 1452} 1453 1454template <class Impl> 1455void 1456FullO3CPU<Impl>::removeFrontInst(DynInstPtr &inst) 1457{ 1458 DPRINTF(O3CPU, "Removing committed instruction [tid:%i] PC %s " 1459 "[sn:%lli]\n", 1460 inst->threadNumber, inst->pcState(), inst->seqNum); 1461 1462 removeInstsThisCycle = true; 1463 1464 // Remove the front instruction. 1465 removeList.push(inst->getInstListIt()); 1466} 1467 1468template <class Impl> 1469void 1470FullO3CPU<Impl>::removeInstsNotInROB(ThreadID tid) 1471{ 1472 DPRINTF(O3CPU, "Thread %i: Deleting instructions from instruction" 1473 " list.\n", tid); 1474 1475 ListIt end_it; 1476 1477 bool rob_empty = false; 1478 1479 if (instList.empty()) { 1480 return; 1481 } else if (rob.isEmpty(tid)) { 1482 DPRINTF(O3CPU, "ROB is empty, squashing all insts.\n"); 1483 end_it = instList.begin(); 1484 rob_empty = true; 1485 } else { 1486 end_it = (rob.readTailInst(tid))->getInstListIt(); 1487 DPRINTF(O3CPU, "ROB is not empty, squashing insts not in ROB.\n"); 1488 } 1489 1490 removeInstsThisCycle = true; 1491 1492 ListIt inst_it = instList.end(); 1493 1494 inst_it--; 1495 1496 // Walk through the instruction list, removing any instructions 1497 // that were inserted after the given instruction iterator, end_it. 1498 while (inst_it != end_it) { 1499 assert(!instList.empty()); 1500 1501 squashInstIt(inst_it, tid); 1502 1503 inst_it--; 1504 } 1505 1506 // If the ROB was empty, then we actually need to remove the first 1507 // instruction as well. 1508 if (rob_empty) { 1509 squashInstIt(inst_it, tid); 1510 } 1511} 1512 1513template <class Impl> 1514void 1515FullO3CPU<Impl>::removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid) 1516{ 1517 assert(!instList.empty()); 1518 1519 removeInstsThisCycle = true; 1520 1521 ListIt inst_iter = instList.end(); 1522 1523 inst_iter--; 1524 1525 DPRINTF(O3CPU, "Deleting instructions from instruction " 1526 "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n", 1527 tid, seq_num, (*inst_iter)->seqNum); 1528 1529 while ((*inst_iter)->seqNum > seq_num) { 1530 1531 bool break_loop = (inst_iter == instList.begin()); 1532 1533 squashInstIt(inst_iter, tid); 1534 1535 inst_iter--; 1536 1537 if (break_loop) 1538 break; 1539 } 1540} 1541 1542template <class Impl> 1543inline void 1544FullO3CPU<Impl>::squashInstIt(const ListIt &instIt, ThreadID tid) 1545{ 1546 if ((*instIt)->threadNumber == tid) { 1547 DPRINTF(O3CPU, "Squashing instruction, " 1548 "[tid:%i] [sn:%lli] PC %s\n", 1549 (*instIt)->threadNumber, 1550 (*instIt)->seqNum, 1551 (*instIt)->pcState()); 1552 1553 // Mark it as squashed. 1554 (*instIt)->setSquashed(); 1555 1556 // @todo: Formulate a consistent method for deleting 1557 // instructions from the instruction list 1558 // Remove the instruction from the list. 1559 removeList.push(instIt); 1560 } 1561} 1562 1563template <class Impl> 1564void 1565FullO3CPU<Impl>::cleanUpRemovedInsts() 1566{ 1567 while (!removeList.empty()) { 1568 DPRINTF(O3CPU, "Removing instruction, " 1569 "[tid:%i] [sn:%lli] PC %s\n", 1570 (*removeList.front())->threadNumber, 1571 (*removeList.front())->seqNum, 1572 (*removeList.front())->pcState()); 1573 1574 instList.erase(removeList.front()); 1575 1576 removeList.pop(); 1577 } 1578 1579 removeInstsThisCycle = false; 1580} 1581/* 1582template <class Impl> 1583void 1584FullO3CPU<Impl>::removeAllInsts() 1585{ 1586 instList.clear(); 1587} 1588*/ 1589template <class Impl> 1590void 1591FullO3CPU<Impl>::dumpInsts() 1592{ 1593 int num = 0; 1594 1595 ListIt inst_list_it = instList.begin(); 1596 1597 cprintf("Dumping Instruction List\n"); 1598 1599 while (inst_list_it != instList.end()) { 1600 cprintf("Instruction:%i\nPC:%#x\n[tid:%i]\n[sn:%lli]\nIssued:%i\n" 1601 "Squashed:%i\n\n", 1602 num, (*inst_list_it)->instAddr(), (*inst_list_it)->threadNumber, 1603 (*inst_list_it)->seqNum, (*inst_list_it)->isIssued(), 1604 (*inst_list_it)->isSquashed()); 1605 inst_list_it++; 1606 ++num; 1607 } 1608} 1609/* 1610template <class Impl> 1611void 1612FullO3CPU<Impl>::wakeDependents(DynInstPtr &inst) 1613{ 1614 iew.wakeDependents(inst); 1615} 1616*/ 1617template <class Impl> 1618void 1619FullO3CPU<Impl>::wakeCPU() 1620{ 1621 if (activityRec.active() || tickEvent.scheduled()) { 1622 DPRINTF(Activity, "CPU already running.\n"); 1623 return; 1624 } 1625 1626 DPRINTF(Activity, "Waking up CPU\n"); 1627 1628 Cycles cycles(curCycle() - lastRunningCycle); 1629 // @todo: This is an oddity that is only here to match the stats 1630 if (cycles != 0) 1631 --cycles; 1632 idleCycles += cycles; 1633 numCycles += cycles; 1634 1635 schedule(tickEvent, clockEdge()); 1636} 1637 1638template <class Impl> 1639void 1640FullO3CPU<Impl>::wakeup() 1641{ 1642 if (this->thread[0]->status() != ThreadContext::Suspended) 1643 return; 1644 1645 this->wakeCPU(); 1646 1647 DPRINTF(Quiesce, "Suspended Processor woken\n"); 1648 this->threadContexts[0]->activate(); 1649} 1650 1651template <class Impl> 1652ThreadID 1653FullO3CPU<Impl>::getFreeTid() 1654{ 1655 for (ThreadID tid = 0; tid < numThreads; tid++) { 1656 if (!tids[tid]) { 1657 tids[tid] = true; 1658 return tid; 1659 } 1660 } 1661 1662 return InvalidThreadID; 1663} 1664 1665template <class Impl> 1666void 1667FullO3CPU<Impl>::updateThreadPriority() 1668{ 1669 if (activeThreads.size() > 1) { 1670 //DEFAULT TO ROUND ROBIN SCHEME 1671 //e.g. Move highest priority to end of thread list 1672 list<ThreadID>::iterator list_begin = activeThreads.begin(); 1673 1674 unsigned high_thread = *list_begin; 1675 1676 activeThreads.erase(list_begin); 1677 1678 activeThreads.push_back(high_thread); 1679 } 1680} 1681 1682// Forward declaration of FullO3CPU. 1683template class FullO3CPU<O3CPUImpl>; 1684