commit_impl.hh revision 3634
11689SN/A/* 22316SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 292965Sksewell@umich.edu * Korey Sewell 301689SN/A */ 311689SN/A 322733Sktlim@umich.edu#include "config/full_system.hh" 332733Sktlim@umich.edu#include "config/use_checker.hh" 342733Sktlim@umich.edu 352292SN/A#include <algorithm> 362329SN/A#include <string> 372292SN/A 383577Sgblack@eecs.umich.edu#include "arch/utility.hh" 392292SN/A#include "base/loader/symtab.hh" 401060SN/A#include "base/timebuf.hh" 412292SN/A#include "cpu/exetrace.hh" 421717SN/A#include "cpu/o3/commit.hh" 432292SN/A#include "cpu/o3/thread_state.hh" 442292SN/A 452790Sktlim@umich.edu#if USE_CHECKER 462790Sktlim@umich.edu#include "cpu/checker/cpu.hh" 472790Sktlim@umich.edu#endif 482790Sktlim@umich.edu 491061SN/Atemplate <class Impl> 502292SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 512292SN/A unsigned _tid) 522292SN/A : Event(&mainEventQueue, CPU_Tick_Pri), commit(_commit), tid(_tid) 531060SN/A{ 542292SN/A this->setFlags(Event::AutoDelete); 551060SN/A} 561060SN/A 571061SN/Atemplate <class Impl> 581060SN/Avoid 592292SN/ADefaultCommit<Impl>::TrapEvent::process() 601062SN/A{ 612316SN/A // This will get reset by commit if it was switched out at the 622316SN/A // time of this event processing. 632292SN/A commit->trapSquash[tid] = true; 642292SN/A} 652292SN/A 662292SN/Atemplate <class Impl> 672292SN/Aconst char * 682292SN/ADefaultCommit<Impl>::TrapEvent::description() 692292SN/A{ 702292SN/A return "Trap event"; 712292SN/A} 722292SN/A 732292SN/Atemplate <class Impl> 742292SN/ADefaultCommit<Impl>::DefaultCommit(Params *params) 752669Sktlim@umich.edu : squashCounter(0), 762292SN/A iewToCommitDelay(params->iewToCommitDelay), 772292SN/A commitToIEWDelay(params->commitToIEWDelay), 782292SN/A renameToROBDelay(params->renameToROBDelay), 792292SN/A fetchToCommitDelay(params->commitToFetchDelay), 802292SN/A renameWidth(params->renameWidth), 812292SN/A commitWidth(params->commitWidth), 822307SN/A numThreads(params->numberOfThreads), 832843Sktlim@umich.edu drainPending(false), 842316SN/A switchedOut(false), 852874Sktlim@umich.edu trapLatency(params->trapLatency) 862292SN/A{ 872292SN/A _status = Active; 882292SN/A _nextStatus = Inactive; 892980Sgblack@eecs.umich.edu std::string policy = params->smtCommitPolicy; 902292SN/A 912292SN/A //Convert string to lowercase 922292SN/A std::transform(policy.begin(), policy.end(), policy.begin(), 932292SN/A (int(*)(int)) tolower); 942292SN/A 952292SN/A //Assign commit policy 962292SN/A if (policy == "aggressive"){ 972292SN/A commitPolicy = Aggressive; 982292SN/A 992292SN/A DPRINTF(Commit,"Commit Policy set to Aggressive."); 1002292SN/A } else if (policy == "roundrobin"){ 1012292SN/A commitPolicy = RoundRobin; 1022292SN/A 1032292SN/A //Set-Up Priority List 1042292SN/A for (int tid=0; tid < numThreads; tid++) { 1052292SN/A priority_list.push_back(tid); 1062292SN/A } 1072292SN/A 1082292SN/A DPRINTF(Commit,"Commit Policy set to Round Robin."); 1092292SN/A } else if (policy == "oldestready"){ 1102292SN/A commitPolicy = OldestReady; 1112292SN/A 1122292SN/A DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1132292SN/A } else { 1142292SN/A assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1152292SN/A "RoundRobin,OldestReady}"); 1162292SN/A } 1172292SN/A 1182292SN/A for (int i=0; i < numThreads; i++) { 1192292SN/A commitStatus[i] = Idle; 1202292SN/A changedROBNumEntries[i] = false; 1212292SN/A trapSquash[i] = false; 1222680Sktlim@umich.edu tcSquash[i] = false; 1232935Sksewell@umich.edu PC[i] = nextPC[i] = nextNPC[i] = 0; 1242292SN/A } 1252292SN/A} 1262292SN/A 1272292SN/Atemplate <class Impl> 1282292SN/Astd::string 1292292SN/ADefaultCommit<Impl>::name() const 1302292SN/A{ 1312292SN/A return cpu->name() + ".commit"; 1322292SN/A} 1332292SN/A 1342292SN/Atemplate <class Impl> 1352292SN/Avoid 1362292SN/ADefaultCommit<Impl>::regStats() 1372132SN/A{ 1382301SN/A using namespace Stats; 1391062SN/A commitCommittedInsts 1401062SN/A .name(name() + ".commitCommittedInsts") 1411062SN/A .desc("The number of committed instructions") 1421062SN/A .prereq(commitCommittedInsts); 1431062SN/A commitSquashedInsts 1441062SN/A .name(name() + ".commitSquashedInsts") 1451062SN/A .desc("The number of squashed insts skipped by commit") 1461062SN/A .prereq(commitSquashedInsts); 1471062SN/A commitSquashEvents 1481062SN/A .name(name() + ".commitSquashEvents") 1491062SN/A .desc("The number of times commit is told to squash") 1501062SN/A .prereq(commitSquashEvents); 1511062SN/A commitNonSpecStalls 1521062SN/A .name(name() + ".commitNonSpecStalls") 1531062SN/A .desc("The number of times commit has been forced to stall to " 1541062SN/A "communicate backwards") 1551062SN/A .prereq(commitNonSpecStalls); 1561062SN/A branchMispredicts 1571062SN/A .name(name() + ".branchMispredicts") 1581062SN/A .desc("The number of times a branch was mispredicted") 1591062SN/A .prereq(branchMispredicts); 1602292SN/A numCommittedDist 1611062SN/A .init(0,commitWidth,1) 1621062SN/A .name(name() + ".COM:committed_per_cycle") 1631062SN/A .desc("Number of insts commited each cycle") 1641062SN/A .flags(Stats::pdf) 1651062SN/A ; 1662301SN/A 1672316SN/A statComInst 1682301SN/A .init(cpu->number_of_threads) 1692301SN/A .name(name() + ".COM:count") 1702301SN/A .desc("Number of instructions committed") 1712301SN/A .flags(total) 1722301SN/A ; 1732301SN/A 1742316SN/A statComSwp 1752301SN/A .init(cpu->number_of_threads) 1762301SN/A .name(name() + ".COM:swp_count") 1772301SN/A .desc("Number of s/w prefetches committed") 1782301SN/A .flags(total) 1792301SN/A ; 1802301SN/A 1812316SN/A statComRefs 1822301SN/A .init(cpu->number_of_threads) 1832301SN/A .name(name() + ".COM:refs") 1842301SN/A .desc("Number of memory references committed") 1852301SN/A .flags(total) 1862301SN/A ; 1872301SN/A 1882316SN/A statComLoads 1892301SN/A .init(cpu->number_of_threads) 1902301SN/A .name(name() + ".COM:loads") 1912301SN/A .desc("Number of loads committed") 1922301SN/A .flags(total) 1932301SN/A ; 1942301SN/A 1952316SN/A statComMembars 1962301SN/A .init(cpu->number_of_threads) 1972301SN/A .name(name() + ".COM:membars") 1982301SN/A .desc("Number of memory barriers committed") 1992301SN/A .flags(total) 2002301SN/A ; 2012301SN/A 2022316SN/A statComBranches 2032301SN/A .init(cpu->number_of_threads) 2042301SN/A .name(name() + ".COM:branches") 2052301SN/A .desc("Number of branches committed") 2062301SN/A .flags(total) 2072301SN/A ; 2082301SN/A 2092316SN/A commitEligible 2102301SN/A .init(cpu->number_of_threads) 2112301SN/A .name(name() + ".COM:bw_limited") 2122301SN/A .desc("number of insts not committed due to BW limits") 2132301SN/A .flags(total) 2142301SN/A ; 2152301SN/A 2162316SN/A commitEligibleSamples 2172301SN/A .name(name() + ".COM:bw_lim_events") 2182301SN/A .desc("number cycles where commit BW limit reached") 2192301SN/A ; 2201062SN/A} 2211062SN/A 2221062SN/Atemplate <class Impl> 2231062SN/Avoid 2242733Sktlim@umich.eduDefaultCommit<Impl>::setCPU(O3CPU *cpu_ptr) 2251060SN/A{ 2261060SN/A DPRINTF(Commit, "Commit: Setting CPU pointer.\n"); 2271060SN/A cpu = cpu_ptr; 2282292SN/A 2292292SN/A // Commit must broadcast the number of free entries it has at the start of 2302292SN/A // the simulation, so it starts as active. 2312733Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 2322307SN/A 2332316SN/A trapLatency = cpu->cycles(trapLatency); 2341060SN/A} 2351060SN/A 2361061SN/Atemplate <class Impl> 2371060SN/Avoid 2382980Sgblack@eecs.umich.eduDefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 2392292SN/A{ 2402292SN/A thread = threads; 2412292SN/A} 2422292SN/A 2432292SN/Atemplate <class Impl> 2442292SN/Avoid 2452292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 2461060SN/A{ 2471060SN/A DPRINTF(Commit, "Commit: Setting time buffer pointer.\n"); 2481060SN/A timeBuffer = tb_ptr; 2491060SN/A 2501060SN/A // Setup wire to send information back to IEW. 2511060SN/A toIEW = timeBuffer->getWire(0); 2521060SN/A 2531060SN/A // Setup wire to read data from IEW (for the ROB). 2541060SN/A robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 2551060SN/A} 2561060SN/A 2571061SN/Atemplate <class Impl> 2581060SN/Avoid 2592292SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 2602292SN/A{ 2612292SN/A DPRINTF(Commit, "Commit: Setting fetch queue pointer.\n"); 2622292SN/A fetchQueue = fq_ptr; 2632292SN/A 2642292SN/A // Setup wire to get instructions from rename (for the ROB). 2652292SN/A fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 2662292SN/A} 2672292SN/A 2682292SN/Atemplate <class Impl> 2692292SN/Avoid 2702292SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 2711060SN/A{ 2721060SN/A DPRINTF(Commit, "Commit: Setting rename queue pointer.\n"); 2731060SN/A renameQueue = rq_ptr; 2741060SN/A 2751060SN/A // Setup wire to get instructions from rename (for the ROB). 2761060SN/A fromRename = renameQueue->getWire(-renameToROBDelay); 2771060SN/A} 2781060SN/A 2791061SN/Atemplate <class Impl> 2801060SN/Avoid 2812292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 2821060SN/A{ 2831060SN/A DPRINTF(Commit, "Commit: Setting IEW queue pointer.\n"); 2841060SN/A iewQueue = iq_ptr; 2851060SN/A 2861060SN/A // Setup wire to get instructions from IEW. 2871060SN/A fromIEW = iewQueue->getWire(-iewToCommitDelay); 2881060SN/A} 2891060SN/A 2901061SN/Atemplate <class Impl> 2911060SN/Avoid 2922292SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 2932292SN/A{ 2942292SN/A iewStage = iew_stage; 2952292SN/A} 2962292SN/A 2972292SN/Atemplate<class Impl> 2982292SN/Avoid 2992980Sgblack@eecs.umich.eduDefaultCommit<Impl>::setActiveThreads(std::list<unsigned> *at_ptr) 3002292SN/A{ 3012292SN/A DPRINTF(Commit, "Commit: Setting active threads list pointer.\n"); 3022292SN/A activeThreads = at_ptr; 3032292SN/A} 3042292SN/A 3052292SN/Atemplate <class Impl> 3062292SN/Avoid 3072292SN/ADefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3082292SN/A{ 3092292SN/A DPRINTF(Commit, "Setting rename map pointers.\n"); 3102292SN/A 3112292SN/A for (int i=0; i < numThreads; i++) { 3122292SN/A renameMap[i] = &rm_ptr[i]; 3132292SN/A } 3142292SN/A} 3152292SN/A 3162292SN/Atemplate <class Impl> 3172292SN/Avoid 3182292SN/ADefaultCommit<Impl>::setROB(ROB *rob_ptr) 3191060SN/A{ 3201060SN/A DPRINTF(Commit, "Commit: Setting ROB pointer.\n"); 3211060SN/A rob = rob_ptr; 3221060SN/A} 3231060SN/A 3241061SN/Atemplate <class Impl> 3251060SN/Avoid 3262292SN/ADefaultCommit<Impl>::initStage() 3271060SN/A{ 3282292SN/A rob->setActiveThreads(activeThreads); 3292292SN/A rob->resetEntries(); 3301060SN/A 3312292SN/A // Broadcast the number of free entries. 3322292SN/A for (int i=0; i < numThreads; i++) { 3332292SN/A toIEW->commitInfo[i].usedROB = true; 3342292SN/A toIEW->commitInfo[i].freeROBEntries = rob->numFreeEntries(i); 3351060SN/A } 3361060SN/A 3372292SN/A cpu->activityThisCycle(); 3381060SN/A} 3391060SN/A 3401061SN/Atemplate <class Impl> 3412863Sktlim@umich.edubool 3422843Sktlim@umich.eduDefaultCommit<Impl>::drain() 3431060SN/A{ 3442843Sktlim@umich.edu drainPending = true; 3452863Sktlim@umich.edu 3462863Sktlim@umich.edu return false; 3472316SN/A} 3482316SN/A 3492316SN/Atemplate <class Impl> 3502316SN/Avoid 3512843Sktlim@umich.eduDefaultCommit<Impl>::switchOut() 3522316SN/A{ 3532316SN/A switchedOut = true; 3542843Sktlim@umich.edu drainPending = false; 3552307SN/A rob->switchOut(); 3562307SN/A} 3572307SN/A 3582307SN/Atemplate <class Impl> 3592307SN/Avoid 3602843Sktlim@umich.eduDefaultCommit<Impl>::resume() 3612843Sktlim@umich.edu{ 3622864Sktlim@umich.edu drainPending = false; 3632843Sktlim@umich.edu} 3642843Sktlim@umich.edu 3652843Sktlim@umich.edutemplate <class Impl> 3662843Sktlim@umich.eduvoid 3672307SN/ADefaultCommit<Impl>::takeOverFrom() 3682307SN/A{ 3692316SN/A switchedOut = false; 3702307SN/A _status = Active; 3712307SN/A _nextStatus = Inactive; 3722307SN/A for (int i=0; i < numThreads; i++) { 3732307SN/A commitStatus[i] = Idle; 3742307SN/A changedROBNumEntries[i] = false; 3752307SN/A trapSquash[i] = false; 3762680Sktlim@umich.edu tcSquash[i] = false; 3772307SN/A } 3782307SN/A squashCounter = 0; 3792307SN/A rob->takeOverFrom(); 3802307SN/A} 3812307SN/A 3822307SN/Atemplate <class Impl> 3832307SN/Avoid 3842292SN/ADefaultCommit<Impl>::updateStatus() 3852132SN/A{ 3862316SN/A // reset ROB changed variable 3872980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 3882316SN/A while (threads != (*activeThreads).end()) { 3892316SN/A unsigned tid = *threads++; 3902316SN/A changedROBNumEntries[tid] = false; 3912316SN/A 3922316SN/A // Also check if any of the threads has a trap pending 3932316SN/A if (commitStatus[tid] == TrapPending || 3942316SN/A commitStatus[tid] == FetchTrapPending) { 3952316SN/A _nextStatus = Active; 3962316SN/A } 3972292SN/A } 3982292SN/A 3992292SN/A if (_nextStatus == Inactive && _status == Active) { 4002292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 4012733Sktlim@umich.edu cpu->deactivateStage(O3CPU::CommitIdx); 4022292SN/A } else if (_nextStatus == Active && _status == Inactive) { 4032292SN/A DPRINTF(Activity, "Activating stage.\n"); 4042733Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 4052292SN/A } 4062292SN/A 4072292SN/A _status = _nextStatus; 4082292SN/A} 4092292SN/A 4102292SN/Atemplate <class Impl> 4112292SN/Avoid 4122292SN/ADefaultCommit<Impl>::setNextStatus() 4132292SN/A{ 4142292SN/A int squashes = 0; 4152292SN/A 4162980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 4172292SN/A 4182292SN/A while (threads != (*activeThreads).end()) { 4192292SN/A unsigned tid = *threads++; 4202292SN/A 4212292SN/A if (commitStatus[tid] == ROBSquashing) { 4222292SN/A squashes++; 4232292SN/A } 4242292SN/A } 4252292SN/A 4262702Sktlim@umich.edu squashCounter = squashes; 4272292SN/A 4282292SN/A // If commit is currently squashing, then it will have activity for the 4292292SN/A // next cycle. Set its next status as active. 4302292SN/A if (squashCounter) { 4312292SN/A _nextStatus = Active; 4322292SN/A } 4332292SN/A} 4342292SN/A 4352292SN/Atemplate <class Impl> 4362292SN/Abool 4372292SN/ADefaultCommit<Impl>::changedROBEntries() 4382292SN/A{ 4392980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 4402292SN/A 4412292SN/A while (threads != (*activeThreads).end()) { 4422292SN/A unsigned tid = *threads++; 4432292SN/A 4442292SN/A if (changedROBNumEntries[tid]) { 4452292SN/A return true; 4462292SN/A } 4472292SN/A } 4482292SN/A 4492292SN/A return false; 4502292SN/A} 4512292SN/A 4522292SN/Atemplate <class Impl> 4532292SN/Aunsigned 4542292SN/ADefaultCommit<Impl>::numROBFreeEntries(unsigned tid) 4552292SN/A{ 4562292SN/A return rob->numFreeEntries(tid); 4572292SN/A} 4582292SN/A 4592292SN/Atemplate <class Impl> 4602292SN/Avoid 4612292SN/ADefaultCommit<Impl>::generateTrapEvent(unsigned tid) 4622292SN/A{ 4632292SN/A DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 4642292SN/A 4652292SN/A TrapEvent *trap = new TrapEvent(this, tid); 4662292SN/A 4672292SN/A trap->schedule(curTick + trapLatency); 4682292SN/A 4692292SN/A thread[tid]->trapPending = true; 4702292SN/A} 4712292SN/A 4722292SN/Atemplate <class Impl> 4732292SN/Avoid 4742680Sktlim@umich.eduDefaultCommit<Impl>::generateTCEvent(unsigned tid) 4752292SN/A{ 4762680Sktlim@umich.edu DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 4772292SN/A 4782680Sktlim@umich.edu tcSquash[tid] = true; 4792292SN/A} 4802292SN/A 4812292SN/Atemplate <class Impl> 4822292SN/Avoid 4832316SN/ADefaultCommit<Impl>::squashAll(unsigned tid) 4842292SN/A{ 4852292SN/A // If we want to include the squashing instruction in the squash, 4862292SN/A // then use one older sequence number. 4872292SN/A // Hopefully this doesn't mess things up. Basically I want to squash 4882292SN/A // all instructions of this thread. 4892292SN/A InstSeqNum squashed_inst = rob->isEmpty() ? 4902292SN/A 0 : rob->readHeadInst(tid)->seqNum - 1;; 4912292SN/A 4922292SN/A // All younger instructions will be squashed. Set the sequence 4932292SN/A // number as the youngest instruction in the ROB (0 in this case. 4942292SN/A // Hopefully nothing breaks.) 4952292SN/A youngestSeqNum[tid] = 0; 4962292SN/A 4972292SN/A rob->squash(squashed_inst, tid); 4982292SN/A changedROBNumEntries[tid] = true; 4992292SN/A 5002292SN/A // Send back the sequence number of the squashed instruction. 5012292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 5022292SN/A 5032292SN/A // Send back the squash signal to tell stages that they should 5042292SN/A // squash. 5052292SN/A toIEW->commitInfo[tid].squash = true; 5062292SN/A 5072292SN/A // Send back the rob squashing signal so other stages know that 5082292SN/A // the ROB is in the process of squashing. 5092292SN/A toIEW->commitInfo[tid].robSquashing = true; 5102292SN/A 5112292SN/A toIEW->commitInfo[tid].branchMispredict = false; 5122292SN/A 5132316SN/A toIEW->commitInfo[tid].nextPC = PC[tid]; 5142316SN/A} 5152292SN/A 5162316SN/Atemplate <class Impl> 5172316SN/Avoid 5182316SN/ADefaultCommit<Impl>::squashFromTrap(unsigned tid) 5192316SN/A{ 5202316SN/A squashAll(tid); 5212316SN/A 5222316SN/A DPRINTF(Commit, "Squashing from trap, restarting at PC %#x\n", PC[tid]); 5232316SN/A 5242316SN/A thread[tid]->trapPending = false; 5252316SN/A thread[tid]->inSyscall = false; 5262316SN/A 5272316SN/A trapSquash[tid] = false; 5282316SN/A 5292316SN/A commitStatus[tid] = ROBSquashing; 5302316SN/A cpu->activityThisCycle(); 5312316SN/A} 5322316SN/A 5332316SN/Atemplate <class Impl> 5342316SN/Avoid 5352680Sktlim@umich.eduDefaultCommit<Impl>::squashFromTC(unsigned tid) 5362316SN/A{ 5372316SN/A squashAll(tid); 5382292SN/A 5392680Sktlim@umich.edu DPRINTF(Commit, "Squashing from TC, restarting at PC %#x\n", PC[tid]); 5402292SN/A 5412292SN/A thread[tid]->inSyscall = false; 5422292SN/A assert(!thread[tid]->trapPending); 5432316SN/A 5442292SN/A commitStatus[tid] = ROBSquashing; 5452292SN/A cpu->activityThisCycle(); 5462292SN/A 5472680Sktlim@umich.edu tcSquash[tid] = false; 5482292SN/A} 5492292SN/A 5502292SN/Atemplate <class Impl> 5512292SN/Avoid 5522292SN/ADefaultCommit<Impl>::tick() 5532292SN/A{ 5542292SN/A wroteToTimeBuffer = false; 5552292SN/A _nextStatus = Inactive; 5562292SN/A 5572843Sktlim@umich.edu if (drainPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 5582843Sktlim@umich.edu cpu->signalDrained(); 5592843Sktlim@umich.edu drainPending = false; 5602316SN/A return; 5612316SN/A } 5622316SN/A 5632875Sksewell@umich.edu if ((*activeThreads).size() <= 0) 5642875Sksewell@umich.edu return; 5652875Sksewell@umich.edu 5662980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 5672292SN/A 5682316SN/A // Check if any of the threads are done squashing. Change the 5692316SN/A // status if they are done. 5702292SN/A while (threads != (*activeThreads).end()) { 5712292SN/A unsigned tid = *threads++; 5722292SN/A 5732292SN/A if (commitStatus[tid] == ROBSquashing) { 5742292SN/A 5752292SN/A if (rob->isDoneSquashing(tid)) { 5762292SN/A commitStatus[tid] = Running; 5772292SN/A } else { 5782292SN/A DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 5792877Sksewell@umich.edu " insts this cycle.\n", tid); 5802702Sktlim@umich.edu rob->doSquash(tid); 5812702Sktlim@umich.edu toIEW->commitInfo[tid].robSquashing = true; 5822702Sktlim@umich.edu wroteToTimeBuffer = true; 5832292SN/A } 5842292SN/A } 5852292SN/A } 5862292SN/A 5872292SN/A commit(); 5882292SN/A 5892292SN/A markCompletedInsts(); 5902292SN/A 5912292SN/A threads = (*activeThreads).begin(); 5922292SN/A 5932292SN/A while (threads != (*activeThreads).end()) { 5942292SN/A unsigned tid = *threads++; 5952292SN/A 5962292SN/A if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 5972292SN/A // The ROB has more instructions it can commit. Its next status 5982292SN/A // will be active. 5992292SN/A _nextStatus = Active; 6002292SN/A 6012292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6022292SN/A 6032292SN/A DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %#x is head of" 6042292SN/A " ROB and ready to commit\n", 6052292SN/A tid, inst->seqNum, inst->readPC()); 6062292SN/A 6072292SN/A } else if (!rob->isEmpty(tid)) { 6082292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6092292SN/A 6102292SN/A DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 6112292SN/A "%#x is head of ROB and not ready\n", 6122292SN/A tid, inst->seqNum, inst->readPC()); 6132292SN/A } 6142292SN/A 6152292SN/A DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 6162292SN/A tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 6172292SN/A } 6182292SN/A 6192292SN/A 6202292SN/A if (wroteToTimeBuffer) { 6212316SN/A DPRINTF(Activity, "Activity This Cycle.\n"); 6222292SN/A cpu->activityThisCycle(); 6232292SN/A } 6242292SN/A 6252292SN/A updateStatus(); 6262292SN/A} 6272292SN/A 6282292SN/Atemplate <class Impl> 6292292SN/Avoid 6302292SN/ADefaultCommit<Impl>::commit() 6312292SN/A{ 6322292SN/A 6331060SN/A ////////////////////////////////////// 6341060SN/A // Check for interrupts 6351060SN/A ////////////////////////////////////// 6361060SN/A 6371858SN/A#if FULL_SYSTEM 6382316SN/A // Process interrupts if interrupts are enabled, not in PAL mode, 6392316SN/A // and no other traps or external squashes are currently pending. 6402316SN/A // @todo: Allow other threads to handle interrupts. 6412292SN/A if (cpu->checkInterrupts && 6423521Sgblack@eecs.umich.edu cpu->check_interrupts(cpu->tcBase(0)) && 6433633Sktlim@umich.edu commitStatus[0] != TrapPending && 6442292SN/A !trapSquash[0] && 6452680Sktlim@umich.edu !tcSquash[0]) { 6463633Sktlim@umich.edu 6473633Sktlim@umich.edu // Get any interrupt that happened 6483633Sktlim@umich.edu Fault intr = cpu->getInterrupts(); 6493633Sktlim@umich.edu 6503633Sktlim@umich.edu // Exit this if block if there's no fault. 6513633Sktlim@umich.edu if (intr == NoFault) { 6523633Sktlim@umich.edu goto commit_insts; 6533633Sktlim@umich.edu } 6543633Sktlim@umich.edu 6552316SN/A // Tell fetch that there is an interrupt pending. This will 6562316SN/A // make fetch wait until it sees a non PAL-mode PC, at which 6572316SN/A // point it stops fetching instructions. 6582292SN/A toIEW->commitInfo[0].interruptPending = true; 6591060SN/A 6602316SN/A // Wait until the ROB is empty and all stores have drained in 6612316SN/A // order to enter the interrupt. 6622292SN/A if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 6633633Sktlim@umich.edu // Squash or record that I need to squash this cycle if 6643633Sktlim@umich.edu // an interrupt needed to be handled. 6653633Sktlim@umich.edu DPRINTF(Commit, "Interrupt detected.\n"); 6663633Sktlim@umich.edu 6672292SN/A assert(!thread[0]->inSyscall); 6682292SN/A thread[0]->inSyscall = true; 6692292SN/A 6703633Sktlim@umich.edu // CPU will handle interrupt. 6713633Sktlim@umich.edu cpu->processInterrupts(intr); 6722292SN/A 6733633Sktlim@umich.edu thread[0]->inSyscall = false; 6743633Sktlim@umich.edu 6752292SN/A commitStatus[0] = TrapPending; 6762292SN/A 6772292SN/A // Generate trap squash event. 6782292SN/A generateTrapEvent(0); 6792292SN/A 6802292SN/A toIEW->commitInfo[0].clearInterrupt = true; 6812292SN/A } else { 6822292SN/A DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 6832292SN/A } 6841060SN/A } 6853634Sktlim@umich.edu 6863634Sktlim@umich.edu // Label for goto. Not pretty but more readable than really big 6873634Sktlim@umich.edu // if statement above. 6883634Sktlim@umich.edu commit_insts: 6891060SN/A#endif // FULL_SYSTEM 6901060SN/A 6911060SN/A //////////////////////////////////// 6922316SN/A // Check for any possible squashes, handle them first 6931060SN/A //////////////////////////////////// 6942980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 6951060SN/A 6962292SN/A while (threads != (*activeThreads).end()) { 6972292SN/A unsigned tid = *threads++; 6981060SN/A 6992292SN/A // Not sure which one takes priority. I think if we have 7002292SN/A // both, that's a bad sign. 7012292SN/A if (trapSquash[tid] == true) { 7022680Sktlim@umich.edu assert(!tcSquash[tid]); 7032292SN/A squashFromTrap(tid); 7042680Sktlim@umich.edu } else if (tcSquash[tid] == true) { 7052680Sktlim@umich.edu squashFromTC(tid); 7062292SN/A } 7071061SN/A 7082292SN/A // Squashed sequence number must be older than youngest valid 7092292SN/A // instruction in the ROB. This prevents squashes from younger 7102292SN/A // instructions overriding squashes from older instructions. 7112292SN/A if (fromIEW->squash[tid] && 7122292SN/A commitStatus[tid] != TrapPending && 7132292SN/A fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 7141061SN/A 7152292SN/A DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n", 7162292SN/A tid, 7172292SN/A fromIEW->mispredPC[tid], 7182292SN/A fromIEW->squashedSeqNum[tid]); 7191061SN/A 7202292SN/A DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 7212292SN/A tid, 7222292SN/A fromIEW->nextPC[tid]); 7231061SN/A 7242292SN/A commitStatus[tid] = ROBSquashing; 7251061SN/A 7262292SN/A // If we want to include the squashing instruction in the squash, 7272292SN/A // then use one older sequence number. 7282292SN/A InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 7291062SN/A 7303093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 7312935Sksewell@umich.edu InstSeqNum bdelay_done_seq_num; 7322935Sksewell@umich.edu bool squash_bdelay_slot; 7332935Sksewell@umich.edu 7342935Sksewell@umich.edu if (fromIEW->branchMispredict[tid]) { 7352935Sksewell@umich.edu if (fromIEW->branchTaken[tid] && 7362935Sksewell@umich.edu fromIEW->condDelaySlotBranch[tid]) { 7372935Sksewell@umich.edu DPRINTF(Commit, "[tid:%i]: Cond. delay slot branch" 7382935Sksewell@umich.edu "mispredicted as taken. Squashing after previous " 7392935Sksewell@umich.edu "inst, [sn:%i]\n", 7402935Sksewell@umich.edu tid, squashed_inst); 7412935Sksewell@umich.edu bdelay_done_seq_num = squashed_inst; 7422935Sksewell@umich.edu squash_bdelay_slot = true; 7432935Sksewell@umich.edu } else { 7442935Sksewell@umich.edu DPRINTF(Commit, "[tid:%i]: Branch Mispredict. Squashing " 7452935Sksewell@umich.edu "after delay slot [sn:%i]\n", tid, squashed_inst+1); 7462935Sksewell@umich.edu bdelay_done_seq_num = squashed_inst + 1; 7472935Sksewell@umich.edu squash_bdelay_slot = false; 7482935Sksewell@umich.edu } 7492935Sksewell@umich.edu } else { 7502935Sksewell@umich.edu bdelay_done_seq_num = squashed_inst; 7512935Sksewell@umich.edu } 7522935Sksewell@umich.edu#endif 7532935Sksewell@umich.edu 7542935Sksewell@umich.edu if (fromIEW->includeSquashInst[tid] == true) { 7552292SN/A squashed_inst--; 7563093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 7572935Sksewell@umich.edu bdelay_done_seq_num--; 7582935Sksewell@umich.edu#endif 7592935Sksewell@umich.edu } 7602292SN/A // All younger instructions will be squashed. Set the sequence 7612292SN/A // number as the youngest instruction in the ROB. 7622292SN/A youngestSeqNum[tid] = squashed_inst; 7632292SN/A 7643093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 7652935Sksewell@umich.edu rob->squash(bdelay_done_seq_num, tid); 7662935Sksewell@umich.edu toIEW->commitInfo[tid].squashDelaySlot = squash_bdelay_slot; 7672935Sksewell@umich.edu toIEW->commitInfo[tid].bdelayDoneSeqNum = bdelay_done_seq_num; 7683093Sksewell@umich.edu#else 7693093Sksewell@umich.edu rob->squash(squashed_inst, tid); 7703093Sksewell@umich.edu toIEW->commitInfo[tid].squashDelaySlot = true; 7712935Sksewell@umich.edu#endif 7722292SN/A changedROBNumEntries[tid] = true; 7732292SN/A 7742292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 7752292SN/A 7762292SN/A toIEW->commitInfo[tid].squash = true; 7772292SN/A 7782292SN/A // Send back the rob squashing signal so other stages know that 7792292SN/A // the ROB is in the process of squashing. 7802292SN/A toIEW->commitInfo[tid].robSquashing = true; 7812292SN/A 7822292SN/A toIEW->commitInfo[tid].branchMispredict = 7832292SN/A fromIEW->branchMispredict[tid]; 7842292SN/A 7852292SN/A toIEW->commitInfo[tid].branchTaken = 7862292SN/A fromIEW->branchTaken[tid]; 7872292SN/A 7882292SN/A toIEW->commitInfo[tid].nextPC = fromIEW->nextPC[tid]; 7892292SN/A 7902316SN/A toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid]; 7912292SN/A 7922292SN/A if (toIEW->commitInfo[tid].branchMispredict) { 7932292SN/A ++branchMispredicts; 7942292SN/A } 7951062SN/A } 7962292SN/A 7971060SN/A } 7981060SN/A 7992292SN/A setNextStatus(); 8002292SN/A 8012292SN/A if (squashCounter != numThreads) { 8021061SN/A // If we're not currently squashing, then get instructions. 8031060SN/A getInsts(); 8041060SN/A 8051061SN/A // Try to commit any instructions. 8061060SN/A commitInsts(); 8072965Sksewell@umich.edu } else { 8083093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 8092965Sksewell@umich.edu skidInsert(); 8102965Sksewell@umich.edu#endif 8111060SN/A } 8121060SN/A 8132292SN/A //Check for any activity 8142292SN/A threads = (*activeThreads).begin(); 8152292SN/A 8162292SN/A while (threads != (*activeThreads).end()) { 8172292SN/A unsigned tid = *threads++; 8182292SN/A 8192292SN/A if (changedROBNumEntries[tid]) { 8202292SN/A toIEW->commitInfo[tid].usedROB = true; 8212292SN/A toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 8222292SN/A 8232292SN/A if (rob->isEmpty(tid)) { 8242292SN/A toIEW->commitInfo[tid].emptyROB = true; 8252292SN/A } 8262292SN/A 8272292SN/A wroteToTimeBuffer = true; 8282292SN/A changedROBNumEntries[tid] = false; 8292292SN/A } 8301060SN/A } 8311060SN/A} 8321060SN/A 8331061SN/Atemplate <class Impl> 8341060SN/Avoid 8352292SN/ADefaultCommit<Impl>::commitInsts() 8361060SN/A{ 8371060SN/A //////////////////////////////////// 8381060SN/A // Handle commit 8392316SN/A // Note that commit will be handled prior to putting new 8402316SN/A // instructions in the ROB so that the ROB only tries to commit 8412316SN/A // instructions it has in this current cycle, and not instructions 8422316SN/A // it is writing in during this cycle. Can't commit and squash 8432316SN/A // things at the same time... 8441060SN/A //////////////////////////////////// 8451060SN/A 8462292SN/A DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 8471060SN/A 8481060SN/A unsigned num_committed = 0; 8491060SN/A 8502292SN/A DynInstPtr head_inst; 8512316SN/A 8521060SN/A // Commit as many instructions as possible until the commit bandwidth 8531060SN/A // limit is reached, or it becomes impossible to commit any more. 8542292SN/A while (num_committed < commitWidth) { 8552292SN/A int commit_thread = getCommittingThread(); 8561060SN/A 8572292SN/A if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 8582292SN/A break; 8592292SN/A 8602292SN/A head_inst = rob->readHeadInst(commit_thread); 8612292SN/A 8622292SN/A int tid = head_inst->threadNumber; 8632292SN/A 8642292SN/A assert(tid == commit_thread); 8652292SN/A 8662292SN/A DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 8672292SN/A head_inst->seqNum, tid); 8682132SN/A 8692316SN/A // If the head instruction is squashed, it is ready to retire 8702316SN/A // (be removed from the ROB) at any time. 8711060SN/A if (head_inst->isSquashed()) { 8721060SN/A 8732292SN/A DPRINTF(Commit, "Retiring squashed instruction from " 8741060SN/A "ROB.\n"); 8751060SN/A 8762292SN/A rob->retireHead(commit_thread); 8771060SN/A 8781062SN/A ++commitSquashedInsts; 8791062SN/A 8802292SN/A // Record that the number of ROB entries has changed. 8812292SN/A changedROBNumEntries[tid] = true; 8821060SN/A } else { 8832292SN/A PC[tid] = head_inst->readPC(); 8842292SN/A nextPC[tid] = head_inst->readNextPC(); 8852935Sksewell@umich.edu nextNPC[tid] = head_inst->readNextNPC(); 8862292SN/A 8871060SN/A // Increment the total number of non-speculative instructions 8881060SN/A // executed. 8891060SN/A // Hack for now: it really shouldn't happen until after the 8901061SN/A // commit is deemed to be successful, but this count is needed 8911061SN/A // for syscalls. 8922292SN/A thread[tid]->funcExeInst++; 8931060SN/A 8941060SN/A // Try to commit the head instruction. 8951060SN/A bool commit_success = commitHead(head_inst, num_committed); 8961060SN/A 8971062SN/A if (commit_success) { 8981060SN/A ++num_committed; 8991060SN/A 9002292SN/A changedROBNumEntries[tid] = true; 9012292SN/A 9022292SN/A // Set the doneSeqNum to the youngest committed instruction. 9032292SN/A toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 9041060SN/A 9051062SN/A ++commitCommittedInsts; 9061062SN/A 9072292SN/A // To match the old model, don't count nops and instruction 9082292SN/A // prefetches towards the total commit count. 9092292SN/A if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 9102292SN/A cpu->instDone(tid); 9111062SN/A } 9122292SN/A 9132292SN/A PC[tid] = nextPC[tid]; 9143093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 9152935Sksewell@umich.edu nextPC[tid] = nextNPC[tid]; 9162935Sksewell@umich.edu nextNPC[tid] = nextNPC[tid] + sizeof(TheISA::MachInst); 9173093Sksewell@umich.edu#else 9183093Sksewell@umich.edu nextPC[tid] = nextPC[tid] + sizeof(TheISA::MachInst); 9192935Sksewell@umich.edu#endif 9202935Sksewell@umich.edu 9212292SN/A#if FULL_SYSTEM 9222292SN/A int count = 0; 9232292SN/A Addr oldpc; 9242292SN/A do { 9252316SN/A // Debug statement. Checks to make sure we're not 9262316SN/A // currently updating state while handling PC events. 9272292SN/A if (count == 0) 9282316SN/A assert(!thread[tid]->inSyscall && 9292316SN/A !thread[tid]->trapPending); 9302292SN/A oldpc = PC[tid]; 9312292SN/A cpu->system->pcEventQueue.service( 9322690Sktlim@umich.edu thread[tid]->getTC()); 9332292SN/A count++; 9342292SN/A } while (oldpc != PC[tid]); 9352292SN/A if (count > 1) { 9362292SN/A DPRINTF(Commit, "PC skip function event, stopping commit\n"); 9372292SN/A break; 9382292SN/A } 9392292SN/A#endif 9401060SN/A } else { 9412292SN/A DPRINTF(Commit, "Unable to commit head instruction PC:%#x " 9422292SN/A "[tid:%i] [sn:%i].\n", 9432292SN/A head_inst->readPC(), tid ,head_inst->seqNum); 9441060SN/A break; 9451060SN/A } 9461060SN/A } 9471060SN/A } 9481062SN/A 9491063SN/A DPRINTF(CommitRate, "%i\n", num_committed); 9502292SN/A numCommittedDist.sample(num_committed); 9512307SN/A 9522307SN/A if (num_committed == commitWidth) { 9532349SN/A commitEligibleSamples++; 9542307SN/A } 9551060SN/A} 9561060SN/A 9571061SN/Atemplate <class Impl> 9581060SN/Abool 9592292SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 9601060SN/A{ 9611060SN/A assert(head_inst); 9621060SN/A 9632292SN/A int tid = head_inst->threadNumber; 9642292SN/A 9652316SN/A // If the instruction is not executed yet, then it will need extra 9662316SN/A // handling. Signal backwards that it should be executed. 9671061SN/A if (!head_inst->isExecuted()) { 9681061SN/A // Keep this number correct. We have not yet actually executed 9691061SN/A // and committed this instruction. 9702292SN/A thread[tid]->funcExeInst--; 9711062SN/A 9722731Sktlim@umich.edu head_inst->setAtCommit(); 9731060SN/A 9742292SN/A if (head_inst->isNonSpeculative() || 9752348SN/A head_inst->isStoreConditional() || 9762292SN/A head_inst->isMemBarrier() || 9772292SN/A head_inst->isWriteBarrier()) { 9782316SN/A 9792316SN/A DPRINTF(Commit, "Encountered a barrier or non-speculative " 9802316SN/A "instruction [sn:%lli] at the head of the ROB, PC %#x.\n", 9812316SN/A head_inst->seqNum, head_inst->readPC()); 9822316SN/A 9832292SN/A#if !FULL_SYSTEM 9842316SN/A // Hack to make sure syscalls/memory barriers/quiesces 9852316SN/A // aren't executed until all stores write back their data. 9862316SN/A // This direct communication shouldn't be used for 9872316SN/A // anything other than this. 9882292SN/A if (inst_num > 0 || iewStage->hasStoresToWB()) 9892292SN/A#else 9902292SN/A if ((head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 9912292SN/A head_inst->isQuiesce()) && 9922292SN/A iewStage->hasStoresToWB()) 9932292SN/A#endif 9942292SN/A { 9952292SN/A DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 9962292SN/A return false; 9972292SN/A } 9982292SN/A 9992292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 10001061SN/A 10011061SN/A // Change the instruction so it won't try to commit again until 10021061SN/A // it is executed. 10031061SN/A head_inst->clearCanCommit(); 10041061SN/A 10051062SN/A ++commitNonSpecStalls; 10061062SN/A 10071061SN/A return false; 10082292SN/A } else if (head_inst->isLoad()) { 10092292SN/A DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %#x.\n", 10102292SN/A head_inst->seqNum, head_inst->readPC()); 10112292SN/A 10122292SN/A // Send back the non-speculative instruction's sequence 10132316SN/A // number. Tell the lsq to re-execute the load. 10142292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 10152292SN/A toIEW->commitInfo[tid].uncached = true; 10162292SN/A toIEW->commitInfo[tid].uncachedLoad = head_inst; 10172292SN/A 10182292SN/A head_inst->clearCanCommit(); 10192292SN/A 10202292SN/A return false; 10211061SN/A } else { 10222292SN/A panic("Trying to commit un-executed instruction " 10231061SN/A "of unknown type!\n"); 10241061SN/A } 10251060SN/A } 10261060SN/A 10272316SN/A if (head_inst->isThreadSync()) { 10282292SN/A // Not handled for now. 10292316SN/A panic("Thread sync instructions are not handled yet.\n"); 10302132SN/A } 10312132SN/A 10322316SN/A // Stores mark themselves as completed. 10332310SN/A if (!head_inst->isStore()) { 10342310SN/A head_inst->setCompleted(); 10352310SN/A } 10362310SN/A 10372733Sktlim@umich.edu#if USE_CHECKER 10382316SN/A // Use checker prior to updating anything due to traps or PC 10392316SN/A // based events. 10402316SN/A if (cpu->checker) { 10412732Sktlim@umich.edu cpu->checker->verify(head_inst); 10421060SN/A } 10432733Sktlim@umich.edu#endif 10441060SN/A 10451060SN/A // Check if the instruction caused a fault. If so, trap. 10462132SN/A Fault inst_fault = head_inst->getFault(); 10471681SN/A 10482918Sktlim@umich.edu // DTB will sometimes need the machine instruction for when 10492918Sktlim@umich.edu // faults happen. So we will set it here, prior to the DTB 10502918Sktlim@umich.edu // possibly needing it for its fault. 10512918Sktlim@umich.edu thread[tid]->setInst( 10522918Sktlim@umich.edu static_cast<TheISA::MachInst>(head_inst->staticInst->machInst)); 10532918Sktlim@umich.edu 10542112SN/A if (inst_fault != NoFault) { 10552316SN/A head_inst->setCompleted(); 10562316SN/A DPRINTF(Commit, "Inst [sn:%lli] PC %#x has a fault\n", 10572316SN/A head_inst->seqNum, head_inst->readPC()); 10582292SN/A 10592316SN/A if (iewStage->hasStoresToWB() || inst_num > 0) { 10602316SN/A DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 10612316SN/A return false; 10622316SN/A } 10632310SN/A 10642733Sktlim@umich.edu#if USE_CHECKER 10652316SN/A if (cpu->checker && head_inst->isStore()) { 10662732Sktlim@umich.edu cpu->checker->verify(head_inst); 10672316SN/A } 10682733Sktlim@umich.edu#endif 10692292SN/A 10702316SN/A assert(!thread[tid]->inSyscall); 10712292SN/A 10722316SN/A // Mark that we're in state update mode so that the trap's 10732316SN/A // execution doesn't generate extra squashes. 10742316SN/A thread[tid]->inSyscall = true; 10752292SN/A 10762316SN/A // Execute the trap. Although it's slightly unrealistic in 10772316SN/A // terms of timing (as it doesn't wait for the full timing of 10782316SN/A // the trap event to complete before updating state), it's 10792316SN/A // needed to update the state as soon as possible. This 10802316SN/A // prevents external agents from changing any specific state 10812316SN/A // that the trap need. 10822316SN/A cpu->trap(inst_fault, tid); 10832292SN/A 10842316SN/A // Exit state update mode to avoid accidental updating. 10852316SN/A thread[tid]->inSyscall = false; 10862292SN/A 10872316SN/A commitStatus[tid] = TrapPending; 10882292SN/A 10892316SN/A // Generate trap squash event. 10902316SN/A generateTrapEvent(tid); 10912353SN/A// warn("%lli fault (%d) handled @ PC %08p", curTick, inst_fault->name(), head_inst->readPC()); 10922316SN/A return false; 10931060SN/A } 10941060SN/A 10952301SN/A updateComInstStats(head_inst); 10962132SN/A 10972362SN/A#if FULL_SYSTEM 10982362SN/A if (thread[tid]->profile) { 10993577Sgblack@eecs.umich.edu// bool usermode = TheISA::inUserMode(thread[tid]->getTC()); 11002362SN/A// thread[tid]->profilePC = usermode ? 1 : head_inst->readPC(); 11012362SN/A thread[tid]->profilePC = head_inst->readPC(); 11023126Sktlim@umich.edu ProfileNode *node = thread[tid]->profile->consume(thread[tid]->getTC(), 11032362SN/A head_inst->staticInst); 11042362SN/A 11052362SN/A if (node) 11062362SN/A thread[tid]->profileNode = node; 11072362SN/A } 11082362SN/A#endif 11092362SN/A 11102132SN/A if (head_inst->traceData) { 11112292SN/A head_inst->traceData->setFetchSeq(head_inst->seqNum); 11122292SN/A head_inst->traceData->setCPSeq(thread[tid]->numInst); 11132132SN/A head_inst->traceData->finalize(); 11142292SN/A head_inst->traceData = NULL; 11151060SN/A } 11161060SN/A 11172292SN/A // Update the commit rename map 11182292SN/A for (int i = 0; i < head_inst->numDestRegs(); i++) { 11192292SN/A renameMap[tid]->setEntry(head_inst->destRegIdx(i), 11202292SN/A head_inst->renamedDestRegIdx(i)); 11211060SN/A } 11221062SN/A 11232353SN/A if (head_inst->isCopy()) 11242353SN/A panic("Should not commit any copy instructions!"); 11252353SN/A 11262292SN/A // Finally clear the head ROB entry. 11272292SN/A rob->retireHead(tid); 11281060SN/A 11291060SN/A // Return true to indicate that we have committed an instruction. 11301060SN/A return true; 11311060SN/A} 11321060SN/A 11331061SN/Atemplate <class Impl> 11341060SN/Avoid 11352292SN/ADefaultCommit<Impl>::getInsts() 11361060SN/A{ 11372935Sksewell@umich.edu DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 11382935Sksewell@umich.edu 11393093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 11402965Sksewell@umich.edu // Read any renamed instructions and place them into the ROB. 11412980Sgblack@eecs.umich.edu int insts_to_process = std::min((int)renameWidth, 11422965Sksewell@umich.edu (int)(fromRename->size + skidBuffer.size())); 11432965Sksewell@umich.edu int rename_idx = 0; 11441061SN/A 11452965Sksewell@umich.edu DPRINTF(Commit, "%i insts available to process. Rename Insts:%i " 11462965Sksewell@umich.edu "SkidBuffer Insts:%i\n", insts_to_process, fromRename->size, 11472965Sksewell@umich.edu skidBuffer.size()); 11483093Sksewell@umich.edu#else 11493093Sksewell@umich.edu // Read any renamed instructions and place them into the ROB. 11503093Sksewell@umich.edu int insts_to_process = std::min((int)renameWidth, fromRename->size); 11512965Sksewell@umich.edu#endif 11522965Sksewell@umich.edu 11532965Sksewell@umich.edu 11542965Sksewell@umich.edu for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 11552965Sksewell@umich.edu DynInstPtr inst; 11562965Sksewell@umich.edu 11573093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 11582965Sksewell@umich.edu // Get insts from skidBuffer or from Rename 11592965Sksewell@umich.edu if (skidBuffer.size() > 0) { 11602965Sksewell@umich.edu DPRINTF(Commit, "Grabbing skidbuffer inst.\n"); 11612965Sksewell@umich.edu inst = skidBuffer.front(); 11622965Sksewell@umich.edu skidBuffer.pop(); 11632965Sksewell@umich.edu } else { 11642965Sksewell@umich.edu DPRINTF(Commit, "Grabbing rename inst.\n"); 11652965Sksewell@umich.edu inst = fromRename->insts[rename_idx++]; 11662965Sksewell@umich.edu } 11673093Sksewell@umich.edu#else 11683093Sksewell@umich.edu inst = fromRename->insts[inst_num]; 11692965Sksewell@umich.edu#endif 11702292SN/A int tid = inst->threadNumber; 11712292SN/A 11722292SN/A if (!inst->isSquashed() && 11732292SN/A commitStatus[tid] != ROBSquashing) { 11742292SN/A changedROBNumEntries[tid] = true; 11752292SN/A 11762292SN/A DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ROB.\n", 11772292SN/A inst->readPC(), inst->seqNum, tid); 11782292SN/A 11792292SN/A rob->insertInst(inst); 11802292SN/A 11812292SN/A assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 11822292SN/A 11832292SN/A youngestSeqNum[tid] = inst->seqNum; 11841061SN/A } else { 11852292SN/A DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 11861061SN/A "squashed, skipping.\n", 11872292SN/A inst->readPC(), inst->seqNum, tid); 11881061SN/A } 11891060SN/A } 11902965Sksewell@umich.edu 11913093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 11922965Sksewell@umich.edu if (rename_idx < fromRename->size) { 11932965Sksewell@umich.edu DPRINTF(Commit,"Placing Rename Insts into skidBuffer.\n"); 11942965Sksewell@umich.edu 11952965Sksewell@umich.edu for (; 11962965Sksewell@umich.edu rename_idx < fromRename->size; 11972965Sksewell@umich.edu rename_idx++) { 11982965Sksewell@umich.edu DynInstPtr inst = fromRename->insts[rename_idx]; 11992965Sksewell@umich.edu int tid = inst->threadNumber; 12002965Sksewell@umich.edu 12012965Sksewell@umich.edu if (!inst->isSquashed()) { 12022965Sksewell@umich.edu DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ", 12032965Sksewell@umich.edu "skidBuffer.\n", inst->readPC(), inst->seqNum, tid); 12042965Sksewell@umich.edu skidBuffer.push(inst); 12052965Sksewell@umich.edu } else { 12062965Sksewell@umich.edu DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 12072965Sksewell@umich.edu "squashed, skipping.\n", 12082965Sksewell@umich.edu inst->readPC(), inst->seqNum, tid); 12092965Sksewell@umich.edu } 12102965Sksewell@umich.edu } 12112965Sksewell@umich.edu } 12122965Sksewell@umich.edu#endif 12132965Sksewell@umich.edu 12142965Sksewell@umich.edu} 12152965Sksewell@umich.edu 12162965Sksewell@umich.edutemplate <class Impl> 12172965Sksewell@umich.eduvoid 12182965Sksewell@umich.eduDefaultCommit<Impl>::skidInsert() 12192965Sksewell@umich.edu{ 12202965Sksewell@umich.edu DPRINTF(Commit, "Attempting to any instructions from rename into " 12212965Sksewell@umich.edu "skidBuffer.\n"); 12222965Sksewell@umich.edu 12232965Sksewell@umich.edu for (int inst_num = 0; inst_num < fromRename->size; ++inst_num) { 12242965Sksewell@umich.edu DynInstPtr inst = fromRename->insts[inst_num]; 12252965Sksewell@umich.edu 12262965Sksewell@umich.edu if (!inst->isSquashed()) { 12272965Sksewell@umich.edu DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ", 12283221Sktlim@umich.edu "skidBuffer.\n", inst->readPC(), inst->seqNum, 12293221Sktlim@umich.edu inst->threadNumber); 12302965Sksewell@umich.edu skidBuffer.push(inst); 12312965Sksewell@umich.edu } else { 12322965Sksewell@umich.edu DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 12332965Sksewell@umich.edu "squashed, skipping.\n", 12343221Sktlim@umich.edu inst->readPC(), inst->seqNum, inst->threadNumber); 12352965Sksewell@umich.edu } 12362965Sksewell@umich.edu } 12371060SN/A} 12381060SN/A 12391061SN/Atemplate <class Impl> 12401060SN/Avoid 12412292SN/ADefaultCommit<Impl>::markCompletedInsts() 12421060SN/A{ 12431060SN/A // Grab completed insts out of the IEW instruction queue, and mark 12441060SN/A // instructions completed within the ROB. 12451060SN/A for (int inst_num = 0; 12461681SN/A inst_num < fromIEW->size && fromIEW->insts[inst_num]; 12471060SN/A ++inst_num) 12481060SN/A { 12492292SN/A if (!fromIEW->insts[inst_num]->isSquashed()) { 12502316SN/A DPRINTF(Commit, "[tid:%i]: Marking PC %#x, [sn:%lli] ready " 12512316SN/A "within ROB.\n", 12522292SN/A fromIEW->insts[inst_num]->threadNumber, 12532292SN/A fromIEW->insts[inst_num]->readPC(), 12542292SN/A fromIEW->insts[inst_num]->seqNum); 12551060SN/A 12562292SN/A // Mark the instruction as ready to commit. 12572292SN/A fromIEW->insts[inst_num]->setCanCommit(); 12582292SN/A } 12591060SN/A } 12601060SN/A} 12611060SN/A 12621061SN/Atemplate <class Impl> 12632292SN/Abool 12642292SN/ADefaultCommit<Impl>::robDoneSquashing() 12651060SN/A{ 12662980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 12672292SN/A 12682292SN/A while (threads != (*activeThreads).end()) { 12692292SN/A unsigned tid = *threads++; 12702292SN/A 12712292SN/A if (!rob->isDoneSquashing(tid)) 12722292SN/A return false; 12732292SN/A } 12742292SN/A 12752292SN/A return true; 12761060SN/A} 12772292SN/A 12782301SN/Atemplate <class Impl> 12792301SN/Avoid 12802301SN/ADefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 12812301SN/A{ 12822301SN/A unsigned thread = inst->threadNumber; 12832301SN/A 12842301SN/A // 12852301SN/A // Pick off the software prefetches 12862301SN/A // 12872301SN/A#ifdef TARGET_ALPHA 12882301SN/A if (inst->isDataPrefetch()) { 12892316SN/A statComSwp[thread]++; 12902301SN/A } else { 12912316SN/A statComInst[thread]++; 12922301SN/A } 12932301SN/A#else 12942316SN/A statComInst[thread]++; 12952301SN/A#endif 12962301SN/A 12972301SN/A // 12982301SN/A // Control Instructions 12992301SN/A // 13002301SN/A if (inst->isControl()) 13012316SN/A statComBranches[thread]++; 13022301SN/A 13032301SN/A // 13042301SN/A // Memory references 13052301SN/A // 13062301SN/A if (inst->isMemRef()) { 13072316SN/A statComRefs[thread]++; 13082301SN/A 13092301SN/A if (inst->isLoad()) { 13102316SN/A statComLoads[thread]++; 13112301SN/A } 13122301SN/A } 13132301SN/A 13142301SN/A if (inst->isMemBarrier()) { 13152316SN/A statComMembars[thread]++; 13162301SN/A } 13172301SN/A} 13182301SN/A 13192292SN/A//////////////////////////////////////// 13202292SN/A// // 13212316SN/A// SMT COMMIT POLICY MAINTAINED HERE // 13222292SN/A// // 13232292SN/A//////////////////////////////////////// 13242292SN/Atemplate <class Impl> 13252292SN/Aint 13262292SN/ADefaultCommit<Impl>::getCommittingThread() 13272292SN/A{ 13282292SN/A if (numThreads > 1) { 13292292SN/A switch (commitPolicy) { 13302292SN/A 13312292SN/A case Aggressive: 13322292SN/A //If Policy is Aggressive, commit will call 13332292SN/A //this function multiple times per 13342292SN/A //cycle 13352292SN/A return oldestReady(); 13362292SN/A 13372292SN/A case RoundRobin: 13382292SN/A return roundRobin(); 13392292SN/A 13402292SN/A case OldestReady: 13412292SN/A return oldestReady(); 13422292SN/A 13432292SN/A default: 13442292SN/A return -1; 13452292SN/A } 13462292SN/A } else { 13472292SN/A int tid = (*activeThreads).front(); 13482292SN/A 13492292SN/A if (commitStatus[tid] == Running || 13502292SN/A commitStatus[tid] == Idle || 13512292SN/A commitStatus[tid] == FetchTrapPending) { 13522292SN/A return tid; 13532292SN/A } else { 13542292SN/A return -1; 13552292SN/A } 13562292SN/A } 13572292SN/A} 13582292SN/A 13592292SN/Atemplate<class Impl> 13602292SN/Aint 13612292SN/ADefaultCommit<Impl>::roundRobin() 13622292SN/A{ 13632980Sgblack@eecs.umich.edu std::list<unsigned>::iterator pri_iter = priority_list.begin(); 13642980Sgblack@eecs.umich.edu std::list<unsigned>::iterator end = priority_list.end(); 13652292SN/A 13662292SN/A while (pri_iter != end) { 13672292SN/A unsigned tid = *pri_iter; 13682292SN/A 13692292SN/A if (commitStatus[tid] == Running || 13702831Sksewell@umich.edu commitStatus[tid] == Idle || 13712831Sksewell@umich.edu commitStatus[tid] == FetchTrapPending) { 13722292SN/A 13732292SN/A if (rob->isHeadReady(tid)) { 13742292SN/A priority_list.erase(pri_iter); 13752292SN/A priority_list.push_back(tid); 13762292SN/A 13772292SN/A return tid; 13782292SN/A } 13792292SN/A } 13802292SN/A 13812292SN/A pri_iter++; 13822292SN/A } 13832292SN/A 13842292SN/A return -1; 13852292SN/A} 13862292SN/A 13872292SN/Atemplate<class Impl> 13882292SN/Aint 13892292SN/ADefaultCommit<Impl>::oldestReady() 13902292SN/A{ 13912292SN/A unsigned oldest = 0; 13922292SN/A bool first = true; 13932292SN/A 13942980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 13952292SN/A 13962292SN/A while (threads != (*activeThreads).end()) { 13972292SN/A unsigned tid = *threads++; 13982292SN/A 13992292SN/A if (!rob->isEmpty(tid) && 14002292SN/A (commitStatus[tid] == Running || 14012292SN/A commitStatus[tid] == Idle || 14022292SN/A commitStatus[tid] == FetchTrapPending)) { 14032292SN/A 14042292SN/A if (rob->isHeadReady(tid)) { 14052292SN/A 14062292SN/A DynInstPtr head_inst = rob->readHeadInst(tid); 14072292SN/A 14082292SN/A if (first) { 14092292SN/A oldest = tid; 14102292SN/A first = false; 14112292SN/A } else if (head_inst->seqNum < oldest) { 14122292SN/A oldest = tid; 14132292SN/A } 14142292SN/A } 14152292SN/A } 14162292SN/A } 14172292SN/A 14182292SN/A if (!first) { 14192292SN/A return oldest; 14202292SN/A } else { 14212292SN/A return -1; 14222292SN/A } 14232292SN/A} 1424