commit_impl.hh revision 2669
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. 271689SN/A */ 281689SN/A 292292SN/A#include <algorithm> 302329SN/A#include <string> 312292SN/A 322292SN/A#include "base/loader/symtab.hh" 331060SN/A#include "base/timebuf.hh" 342316SN/A#include "cpu/checker/cpu.hh" 352292SN/A#include "cpu/exetrace.hh" 361717SN/A#include "cpu/o3/commit.hh" 372292SN/A#include "cpu/o3/thread_state.hh" 382292SN/A 392292SN/Ausing namespace std; 401060SN/A 411061SN/Atemplate <class Impl> 422292SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 432292SN/A unsigned _tid) 442292SN/A : Event(&mainEventQueue, CPU_Tick_Pri), commit(_commit), tid(_tid) 451060SN/A{ 462292SN/A this->setFlags(Event::AutoDelete); 471060SN/A} 481060SN/A 491061SN/Atemplate <class Impl> 501060SN/Avoid 512292SN/ADefaultCommit<Impl>::TrapEvent::process() 521062SN/A{ 532316SN/A // This will get reset by commit if it was switched out at the 542316SN/A // time of this event processing. 552292SN/A commit->trapSquash[tid] = true; 562292SN/A} 572292SN/A 582292SN/Atemplate <class Impl> 592292SN/Aconst char * 602292SN/ADefaultCommit<Impl>::TrapEvent::description() 612292SN/A{ 622292SN/A return "Trap event"; 632292SN/A} 642292SN/A 652292SN/Atemplate <class Impl> 662292SN/ADefaultCommit<Impl>::DefaultCommit(Params *params) 672669Sktlim@umich.edu : squashCounter(0), 682292SN/A iewToCommitDelay(params->iewToCommitDelay), 692292SN/A commitToIEWDelay(params->commitToIEWDelay), 702292SN/A renameToROBDelay(params->renameToROBDelay), 712292SN/A fetchToCommitDelay(params->commitToFetchDelay), 722292SN/A renameWidth(params->renameWidth), 732292SN/A iewWidth(params->executeWidth), 742292SN/A commitWidth(params->commitWidth), 752307SN/A numThreads(params->numberOfThreads), 762316SN/A switchedOut(false), 772316SN/A trapLatency(params->trapLatency), 782316SN/A fetchTrapLatency(params->fetchTrapLatency) 792292SN/A{ 802292SN/A _status = Active; 812292SN/A _nextStatus = Inactive; 822292SN/A string policy = params->smtCommitPolicy; 832292SN/A 842292SN/A //Convert string to lowercase 852292SN/A std::transform(policy.begin(), policy.end(), policy.begin(), 862292SN/A (int(*)(int)) tolower); 872292SN/A 882292SN/A //Assign commit policy 892292SN/A if (policy == "aggressive"){ 902292SN/A commitPolicy = Aggressive; 912292SN/A 922292SN/A DPRINTF(Commit,"Commit Policy set to Aggressive."); 932292SN/A } else if (policy == "roundrobin"){ 942292SN/A commitPolicy = RoundRobin; 952292SN/A 962292SN/A //Set-Up Priority List 972292SN/A for (int tid=0; tid < numThreads; tid++) { 982292SN/A priority_list.push_back(tid); 992292SN/A } 1002292SN/A 1012292SN/A DPRINTF(Commit,"Commit Policy set to Round Robin."); 1022292SN/A } else if (policy == "oldestready"){ 1032292SN/A commitPolicy = OldestReady; 1042292SN/A 1052292SN/A DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1062292SN/A } else { 1072292SN/A assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1082292SN/A "RoundRobin,OldestReady}"); 1092292SN/A } 1102292SN/A 1112292SN/A for (int i=0; i < numThreads; i++) { 1122292SN/A commitStatus[i] = Idle; 1132292SN/A changedROBNumEntries[i] = false; 1142292SN/A trapSquash[i] = false; 1152292SN/A xcSquash[i] = false; 1162292SN/A } 1172292SN/A 1182292SN/A fetchFaultTick = 0; 1192292SN/A fetchTrapWait = 0; 1202292SN/A} 1212292SN/A 1222292SN/Atemplate <class Impl> 1232292SN/Astd::string 1242292SN/ADefaultCommit<Impl>::name() const 1252292SN/A{ 1262292SN/A return cpu->name() + ".commit"; 1272292SN/A} 1282292SN/A 1292292SN/Atemplate <class Impl> 1302292SN/Avoid 1312292SN/ADefaultCommit<Impl>::regStats() 1322132SN/A{ 1332301SN/A using namespace Stats; 1341062SN/A commitCommittedInsts 1351062SN/A .name(name() + ".commitCommittedInsts") 1361062SN/A .desc("The number of committed instructions") 1371062SN/A .prereq(commitCommittedInsts); 1381062SN/A commitSquashedInsts 1391062SN/A .name(name() + ".commitSquashedInsts") 1401062SN/A .desc("The number of squashed insts skipped by commit") 1411062SN/A .prereq(commitSquashedInsts); 1421062SN/A commitSquashEvents 1431062SN/A .name(name() + ".commitSquashEvents") 1441062SN/A .desc("The number of times commit is told to squash") 1451062SN/A .prereq(commitSquashEvents); 1461062SN/A commitNonSpecStalls 1471062SN/A .name(name() + ".commitNonSpecStalls") 1481062SN/A .desc("The number of times commit has been forced to stall to " 1491062SN/A "communicate backwards") 1501062SN/A .prereq(commitNonSpecStalls); 1511062SN/A branchMispredicts 1521062SN/A .name(name() + ".branchMispredicts") 1531062SN/A .desc("The number of times a branch was mispredicted") 1541062SN/A .prereq(branchMispredicts); 1552292SN/A numCommittedDist 1561062SN/A .init(0,commitWidth,1) 1571062SN/A .name(name() + ".COM:committed_per_cycle") 1581062SN/A .desc("Number of insts commited each cycle") 1591062SN/A .flags(Stats::pdf) 1601062SN/A ; 1612301SN/A 1622316SN/A statComInst 1632301SN/A .init(cpu->number_of_threads) 1642301SN/A .name(name() + ".COM:count") 1652301SN/A .desc("Number of instructions committed") 1662301SN/A .flags(total) 1672301SN/A ; 1682301SN/A 1692316SN/A statComSwp 1702301SN/A .init(cpu->number_of_threads) 1712301SN/A .name(name() + ".COM:swp_count") 1722301SN/A .desc("Number of s/w prefetches committed") 1732301SN/A .flags(total) 1742301SN/A ; 1752301SN/A 1762316SN/A statComRefs 1772301SN/A .init(cpu->number_of_threads) 1782301SN/A .name(name() + ".COM:refs") 1792301SN/A .desc("Number of memory references committed") 1802301SN/A .flags(total) 1812301SN/A ; 1822301SN/A 1832316SN/A statComLoads 1842301SN/A .init(cpu->number_of_threads) 1852301SN/A .name(name() + ".COM:loads") 1862301SN/A .desc("Number of loads committed") 1872301SN/A .flags(total) 1882301SN/A ; 1892301SN/A 1902316SN/A statComMembars 1912301SN/A .init(cpu->number_of_threads) 1922301SN/A .name(name() + ".COM:membars") 1932301SN/A .desc("Number of memory barriers committed") 1942301SN/A .flags(total) 1952301SN/A ; 1962301SN/A 1972316SN/A statComBranches 1982301SN/A .init(cpu->number_of_threads) 1992301SN/A .name(name() + ".COM:branches") 2002301SN/A .desc("Number of branches committed") 2012301SN/A .flags(total) 2022301SN/A ; 2032301SN/A 2042301SN/A // 2052301SN/A // Commit-Eligible instructions... 2062301SN/A // 2072301SN/A // -> The number of instructions eligible to commit in those 2082301SN/A // cycles where we reached our commit BW limit (less the number 2092301SN/A // actually committed) 2102301SN/A // 2112301SN/A // -> The average value is computed over ALL CYCLES... not just 2122301SN/A // the BW limited cycles 2132301SN/A // 2142301SN/A // -> The standard deviation is computed only over cycles where 2152301SN/A // we reached the BW limit 2162301SN/A // 2172316SN/A commitEligible 2182301SN/A .init(cpu->number_of_threads) 2192301SN/A .name(name() + ".COM:bw_limited") 2202301SN/A .desc("number of insts not committed due to BW limits") 2212301SN/A .flags(total) 2222301SN/A ; 2232301SN/A 2242316SN/A commitEligibleSamples 2252301SN/A .name(name() + ".COM:bw_lim_events") 2262301SN/A .desc("number cycles where commit BW limit reached") 2272301SN/A ; 2281062SN/A} 2291062SN/A 2301062SN/Atemplate <class Impl> 2311062SN/Avoid 2322292SN/ADefaultCommit<Impl>::setCPU(FullCPU *cpu_ptr) 2331060SN/A{ 2341060SN/A DPRINTF(Commit, "Commit: Setting CPU pointer.\n"); 2351060SN/A cpu = cpu_ptr; 2362292SN/A 2372292SN/A // Commit must broadcast the number of free entries it has at the start of 2382292SN/A // the simulation, so it starts as active. 2392292SN/A cpu->activateStage(FullCPU::CommitIdx); 2402307SN/A 2412316SN/A trapLatency = cpu->cycles(trapLatency); 2422316SN/A fetchTrapLatency = cpu->cycles(fetchTrapLatency); 2431060SN/A} 2441060SN/A 2451061SN/Atemplate <class Impl> 2461060SN/Avoid 2472292SN/ADefaultCommit<Impl>::setThreads(vector<Thread *> &threads) 2482292SN/A{ 2492292SN/A thread = threads; 2502292SN/A} 2512292SN/A 2522292SN/Atemplate <class Impl> 2532292SN/Avoid 2542292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 2551060SN/A{ 2561060SN/A DPRINTF(Commit, "Commit: Setting time buffer pointer.\n"); 2571060SN/A timeBuffer = tb_ptr; 2581060SN/A 2591060SN/A // Setup wire to send information back to IEW. 2601060SN/A toIEW = timeBuffer->getWire(0); 2611060SN/A 2621060SN/A // Setup wire to read data from IEW (for the ROB). 2631060SN/A robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 2641060SN/A} 2651060SN/A 2661061SN/Atemplate <class Impl> 2671060SN/Avoid 2682292SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 2692292SN/A{ 2702292SN/A DPRINTF(Commit, "Commit: Setting fetch queue pointer.\n"); 2712292SN/A fetchQueue = fq_ptr; 2722292SN/A 2732292SN/A // Setup wire to get instructions from rename (for the ROB). 2742292SN/A fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 2752292SN/A} 2762292SN/A 2772292SN/Atemplate <class Impl> 2782292SN/Avoid 2792292SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 2801060SN/A{ 2811060SN/A DPRINTF(Commit, "Commit: Setting rename queue pointer.\n"); 2821060SN/A renameQueue = rq_ptr; 2831060SN/A 2841060SN/A // Setup wire to get instructions from rename (for the ROB). 2851060SN/A fromRename = renameQueue->getWire(-renameToROBDelay); 2861060SN/A} 2871060SN/A 2881061SN/Atemplate <class Impl> 2891060SN/Avoid 2902292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 2911060SN/A{ 2921060SN/A DPRINTF(Commit, "Commit: Setting IEW queue pointer.\n"); 2931060SN/A iewQueue = iq_ptr; 2941060SN/A 2951060SN/A // Setup wire to get instructions from IEW. 2961060SN/A fromIEW = iewQueue->getWire(-iewToCommitDelay); 2971060SN/A} 2981060SN/A 2991061SN/Atemplate <class Impl> 3001060SN/Avoid 3012316SN/ADefaultCommit<Impl>::setFetchStage(Fetch *fetch_stage) 3022316SN/A{ 3032316SN/A fetchStage = fetch_stage; 3042316SN/A} 3052316SN/A 3062316SN/Atemplate <class Impl> 3072316SN/Avoid 3082292SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 3092292SN/A{ 3102292SN/A iewStage = iew_stage; 3112292SN/A} 3122292SN/A 3132292SN/Atemplate<class Impl> 3142292SN/Avoid 3152292SN/ADefaultCommit<Impl>::setActiveThreads(list<unsigned> *at_ptr) 3162292SN/A{ 3172292SN/A DPRINTF(Commit, "Commit: Setting active threads list pointer.\n"); 3182292SN/A activeThreads = at_ptr; 3192292SN/A} 3202292SN/A 3212292SN/Atemplate <class Impl> 3222292SN/Avoid 3232292SN/ADefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3242292SN/A{ 3252292SN/A DPRINTF(Commit, "Setting rename map pointers.\n"); 3262292SN/A 3272292SN/A for (int i=0; i < numThreads; i++) { 3282292SN/A renameMap[i] = &rm_ptr[i]; 3292292SN/A } 3302292SN/A} 3312292SN/A 3322292SN/Atemplate <class Impl> 3332292SN/Avoid 3342292SN/ADefaultCommit<Impl>::setROB(ROB *rob_ptr) 3351060SN/A{ 3361060SN/A DPRINTF(Commit, "Commit: Setting ROB pointer.\n"); 3371060SN/A rob = rob_ptr; 3381060SN/A} 3391060SN/A 3401061SN/Atemplate <class Impl> 3411060SN/Avoid 3422292SN/ADefaultCommit<Impl>::initStage() 3431060SN/A{ 3442292SN/A rob->setActiveThreads(activeThreads); 3452292SN/A rob->resetEntries(); 3461060SN/A 3472292SN/A // Broadcast the number of free entries. 3482292SN/A for (int i=0; i < numThreads; i++) { 3492292SN/A toIEW->commitInfo[i].usedROB = true; 3502292SN/A toIEW->commitInfo[i].freeROBEntries = rob->numFreeEntries(i); 3511060SN/A } 3521060SN/A 3532292SN/A cpu->activityThisCycle(); 3541060SN/A} 3551060SN/A 3561061SN/Atemplate <class Impl> 3571060SN/Avoid 3582307SN/ADefaultCommit<Impl>::switchOut() 3591060SN/A{ 3602316SN/A switchPending = true; 3612316SN/A} 3622316SN/A 3632316SN/Atemplate <class Impl> 3642316SN/Avoid 3652316SN/ADefaultCommit<Impl>::doSwitchOut() 3662316SN/A{ 3672316SN/A switchedOut = true; 3682316SN/A switchPending = false; 3692307SN/A rob->switchOut(); 3702307SN/A} 3712307SN/A 3722307SN/Atemplate <class Impl> 3732307SN/Avoid 3742307SN/ADefaultCommit<Impl>::takeOverFrom() 3752307SN/A{ 3762316SN/A switchedOut = false; 3772307SN/A _status = Active; 3782307SN/A _nextStatus = Inactive; 3792307SN/A for (int i=0; i < numThreads; i++) { 3802307SN/A commitStatus[i] = Idle; 3812307SN/A changedROBNumEntries[i] = false; 3822307SN/A trapSquash[i] = false; 3832307SN/A xcSquash[i] = false; 3842307SN/A } 3852307SN/A squashCounter = 0; 3862307SN/A rob->takeOverFrom(); 3872307SN/A} 3882307SN/A 3892307SN/Atemplate <class Impl> 3902307SN/Avoid 3912292SN/ADefaultCommit<Impl>::updateStatus() 3922132SN/A{ 3932316SN/A // reset ROB changed variable 3942316SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 3952316SN/A while (threads != (*activeThreads).end()) { 3962316SN/A unsigned tid = *threads++; 3972316SN/A changedROBNumEntries[tid] = false; 3982316SN/A 3992316SN/A // Also check if any of the threads has a trap pending 4002316SN/A if (commitStatus[tid] == TrapPending || 4012316SN/A commitStatus[tid] == FetchTrapPending) { 4022316SN/A _nextStatus = Active; 4032316SN/A } 4042292SN/A } 4052292SN/A 4062292SN/A if (_nextStatus == Inactive && _status == Active) { 4072292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 4082292SN/A cpu->deactivateStage(FullCPU::CommitIdx); 4092292SN/A } else if (_nextStatus == Active && _status == Inactive) { 4102292SN/A DPRINTF(Activity, "Activating stage.\n"); 4112292SN/A cpu->activateStage(FullCPU::CommitIdx); 4122292SN/A } 4132292SN/A 4142292SN/A _status = _nextStatus; 4152292SN/A} 4162292SN/A 4172292SN/Atemplate <class Impl> 4182292SN/Avoid 4192292SN/ADefaultCommit<Impl>::setNextStatus() 4202292SN/A{ 4212292SN/A int squashes = 0; 4222292SN/A 4232292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 4242292SN/A 4252292SN/A while (threads != (*activeThreads).end()) { 4262292SN/A unsigned tid = *threads++; 4272292SN/A 4282292SN/A if (commitStatus[tid] == ROBSquashing) { 4292292SN/A squashes++; 4302292SN/A } 4312292SN/A } 4322292SN/A 4332292SN/A assert(squashes == squashCounter); 4342292SN/A 4352292SN/A // If commit is currently squashing, then it will have activity for the 4362292SN/A // next cycle. Set its next status as active. 4372292SN/A if (squashCounter) { 4382292SN/A _nextStatus = Active; 4392292SN/A } 4402292SN/A} 4412292SN/A 4422292SN/Atemplate <class Impl> 4432292SN/Abool 4442292SN/ADefaultCommit<Impl>::changedROBEntries() 4452292SN/A{ 4462292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 4472292SN/A 4482292SN/A while (threads != (*activeThreads).end()) { 4492292SN/A unsigned tid = *threads++; 4502292SN/A 4512292SN/A if (changedROBNumEntries[tid]) { 4522292SN/A return true; 4532292SN/A } 4542292SN/A } 4552292SN/A 4562292SN/A return false; 4572292SN/A} 4582292SN/A 4592292SN/Atemplate <class Impl> 4602292SN/Aunsigned 4612292SN/ADefaultCommit<Impl>::numROBFreeEntries(unsigned tid) 4622292SN/A{ 4632292SN/A return rob->numFreeEntries(tid); 4642292SN/A} 4652292SN/A 4662292SN/Atemplate <class Impl> 4672292SN/Avoid 4682292SN/ADefaultCommit<Impl>::generateTrapEvent(unsigned tid) 4692292SN/A{ 4702292SN/A DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 4712292SN/A 4722292SN/A TrapEvent *trap = new TrapEvent(this, tid); 4732292SN/A 4742292SN/A trap->schedule(curTick + trapLatency); 4752292SN/A 4762292SN/A thread[tid]->trapPending = true; 4772292SN/A} 4782292SN/A 4792292SN/Atemplate <class Impl> 4802292SN/Avoid 4812292SN/ADefaultCommit<Impl>::generateXCEvent(unsigned tid) 4822292SN/A{ 4832292SN/A DPRINTF(Commit, "Generating XC squash event for [tid:%i]\n", tid); 4842292SN/A 4852292SN/A xcSquash[tid] = true; 4862292SN/A} 4872292SN/A 4882292SN/Atemplate <class Impl> 4892292SN/Avoid 4902316SN/ADefaultCommit<Impl>::squashAll(unsigned tid) 4912292SN/A{ 4922292SN/A // If we want to include the squashing instruction in the squash, 4932292SN/A // then use one older sequence number. 4942292SN/A // Hopefully this doesn't mess things up. Basically I want to squash 4952292SN/A // all instructions of this thread. 4962292SN/A InstSeqNum squashed_inst = rob->isEmpty() ? 4972292SN/A 0 : rob->readHeadInst(tid)->seqNum - 1;; 4982292SN/A 4992292SN/A // All younger instructions will be squashed. Set the sequence 5002292SN/A // number as the youngest instruction in the ROB (0 in this case. 5012292SN/A // Hopefully nothing breaks.) 5022292SN/A youngestSeqNum[tid] = 0; 5032292SN/A 5042292SN/A rob->squash(squashed_inst, tid); 5052292SN/A changedROBNumEntries[tid] = true; 5062292SN/A 5072292SN/A // Send back the sequence number of the squashed instruction. 5082292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 5092292SN/A 5102292SN/A // Send back the squash signal to tell stages that they should 5112292SN/A // squash. 5122292SN/A toIEW->commitInfo[tid].squash = true; 5132292SN/A 5142292SN/A // Send back the rob squashing signal so other stages know that 5152292SN/A // the ROB is in the process of squashing. 5162292SN/A toIEW->commitInfo[tid].robSquashing = true; 5172292SN/A 5182292SN/A toIEW->commitInfo[tid].branchMispredict = false; 5192292SN/A 5202316SN/A toIEW->commitInfo[tid].nextPC = PC[tid]; 5212316SN/A} 5222292SN/A 5232316SN/Atemplate <class Impl> 5242316SN/Avoid 5252316SN/ADefaultCommit<Impl>::squashFromTrap(unsigned tid) 5262316SN/A{ 5272316SN/A squashAll(tid); 5282316SN/A 5292316SN/A DPRINTF(Commit, "Squashing from trap, restarting at PC %#x\n", PC[tid]); 5302316SN/A 5312316SN/A thread[tid]->trapPending = false; 5322316SN/A thread[tid]->inSyscall = false; 5332316SN/A 5342316SN/A trapSquash[tid] = false; 5352316SN/A 5362316SN/A commitStatus[tid] = ROBSquashing; 5372316SN/A cpu->activityThisCycle(); 5382316SN/A 5392316SN/A ++squashCounter; 5402316SN/A} 5412316SN/A 5422316SN/Atemplate <class Impl> 5432316SN/Avoid 5442316SN/ADefaultCommit<Impl>::squashFromXC(unsigned tid) 5452316SN/A{ 5462316SN/A squashAll(tid); 5472292SN/A 5482292SN/A DPRINTF(Commit, "Squashing from XC, restarting at PC %#x\n", PC[tid]); 5492292SN/A 5502292SN/A thread[tid]->inSyscall = false; 5512292SN/A assert(!thread[tid]->trapPending); 5522316SN/A 5532292SN/A commitStatus[tid] = ROBSquashing; 5542292SN/A cpu->activityThisCycle(); 5552292SN/A 5562292SN/A xcSquash[tid] = false; 5572292SN/A 5582292SN/A ++squashCounter; 5592292SN/A} 5602292SN/A 5612292SN/Atemplate <class Impl> 5622292SN/Avoid 5632292SN/ADefaultCommit<Impl>::tick() 5642292SN/A{ 5652292SN/A wroteToTimeBuffer = false; 5662292SN/A _nextStatus = Inactive; 5672292SN/A 5682316SN/A if (switchPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 5692316SN/A cpu->signalSwitched(); 5702316SN/A return; 5712316SN/A } 5722316SN/A 5732292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 5742292SN/A 5752316SN/A // Check if any of the threads are done squashing. Change the 5762316SN/A // status if they are done. 5772292SN/A while (threads != (*activeThreads).end()) { 5782292SN/A unsigned tid = *threads++; 5792292SN/A 5802292SN/A if (commitStatus[tid] == ROBSquashing) { 5812292SN/A 5822292SN/A if (rob->isDoneSquashing(tid)) { 5832292SN/A commitStatus[tid] = Running; 5842292SN/A --squashCounter; 5852292SN/A } else { 5862292SN/A DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 5872292SN/A "insts this cycle.\n", tid); 5882292SN/A } 5892292SN/A } 5902292SN/A } 5912292SN/A 5922292SN/A commit(); 5932292SN/A 5942292SN/A markCompletedInsts(); 5952292SN/A 5962292SN/A threads = (*activeThreads).begin(); 5972292SN/A 5982292SN/A while (threads != (*activeThreads).end()) { 5992292SN/A unsigned tid = *threads++; 6002292SN/A 6012292SN/A if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 6022292SN/A // The ROB has more instructions it can commit. Its next status 6032292SN/A // will be active. 6042292SN/A _nextStatus = Active; 6052292SN/A 6062292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6072292SN/A 6082292SN/A DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %#x is head of" 6092292SN/A " ROB and ready to commit\n", 6102292SN/A tid, inst->seqNum, inst->readPC()); 6112292SN/A 6122292SN/A } else if (!rob->isEmpty(tid)) { 6132292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6142292SN/A 6152292SN/A DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 6162292SN/A "%#x is head of ROB and not ready\n", 6172292SN/A tid, inst->seqNum, inst->readPC()); 6182292SN/A } 6192292SN/A 6202292SN/A DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 6212292SN/A tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 6222292SN/A } 6232292SN/A 6242292SN/A 6252292SN/A if (wroteToTimeBuffer) { 6262316SN/A DPRINTF(Activity, "Activity This Cycle.\n"); 6272292SN/A cpu->activityThisCycle(); 6282292SN/A } 6292292SN/A 6302292SN/A updateStatus(); 6312292SN/A} 6322292SN/A 6332292SN/Atemplate <class Impl> 6342292SN/Avoid 6352292SN/ADefaultCommit<Impl>::commit() 6362292SN/A{ 6372292SN/A 6381060SN/A ////////////////////////////////////// 6391060SN/A // Check for interrupts 6401060SN/A ////////////////////////////////////// 6411060SN/A 6421858SN/A#if FULL_SYSTEM 6432316SN/A // Process interrupts if interrupts are enabled, not in PAL mode, 6442316SN/A // and no other traps or external squashes are currently pending. 6452316SN/A // @todo: Allow other threads to handle interrupts. 6462292SN/A if (cpu->checkInterrupts && 6471060SN/A cpu->check_interrupts() && 6482292SN/A !cpu->inPalMode(readPC()) && 6492292SN/A !trapSquash[0] && 6502292SN/A !xcSquash[0]) { 6512316SN/A // Tell fetch that there is an interrupt pending. This will 6522316SN/A // make fetch wait until it sees a non PAL-mode PC, at which 6532316SN/A // point it stops fetching instructions. 6542292SN/A toIEW->commitInfo[0].interruptPending = true; 6551060SN/A 6562316SN/A // Wait until the ROB is empty and all stores have drained in 6572316SN/A // order to enter the interrupt. 6582292SN/A if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 6592292SN/A // Not sure which thread should be the one to interrupt. For now 6602292SN/A // always do thread 0. 6612292SN/A assert(!thread[0]->inSyscall); 6622292SN/A thread[0]->inSyscall = true; 6632292SN/A 6642292SN/A // CPU will handle implementation of the interrupt. 6652292SN/A cpu->processInterrupts(); 6662292SN/A 6672292SN/A // Now squash or record that I need to squash this cycle. 6682292SN/A commitStatus[0] = TrapPending; 6692292SN/A 6702292SN/A // Exit state update mode to avoid accidental updating. 6712292SN/A thread[0]->inSyscall = false; 6722292SN/A 6732292SN/A // Generate trap squash event. 6742292SN/A generateTrapEvent(0); 6752292SN/A 6762292SN/A toIEW->commitInfo[0].clearInterrupt = true; 6772292SN/A 6782292SN/A DPRINTF(Commit, "Interrupt detected.\n"); 6792292SN/A } else { 6802292SN/A DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 6812292SN/A } 6821060SN/A } 6831060SN/A#endif // FULL_SYSTEM 6841060SN/A 6851060SN/A //////////////////////////////////// 6862316SN/A // Check for any possible squashes, handle them first 6871060SN/A //////////////////////////////////// 6881060SN/A 6892292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6901060SN/A 6912292SN/A while (threads != (*activeThreads).end()) { 6922292SN/A unsigned tid = *threads++; 6931060SN/A 6942307SN/A if (fromFetch->fetchFault && commitStatus[0] != TrapPending) { 6952316SN/A // Record the fault. Wait until it's empty in the ROB. 6962316SN/A // Then handle the trap. Ignore it if there's already a 6972316SN/A // trap pending as fetch will be redirected. 6982292SN/A fetchFault = fromFetch->fetchFault; 6992292SN/A fetchFaultTick = curTick + fetchTrapLatency; 7002292SN/A commitStatus[0] = FetchTrapPending; 7012292SN/A DPRINTF(Commit, "Fault from fetch recorded. Will trap if the " 7022292SN/A "ROB empties without squashing the fault.\n"); 7032292SN/A fetchTrapWait = 0; 7042292SN/A } 7051060SN/A 7062316SN/A // Fetch may tell commit to clear the trap if it's been squashed. 7072292SN/A if (fromFetch->clearFetchFault) { 7082292SN/A DPRINTF(Commit, "Received clear fetch fault signal\n"); 7092292SN/A fetchTrapWait = 0; 7102292SN/A if (commitStatus[0] == FetchTrapPending) { 7112292SN/A DPRINTF(Commit, "Clearing fault from fetch\n"); 7122292SN/A commitStatus[0] = Running; 7132292SN/A } 7142292SN/A } 7151060SN/A 7162292SN/A // Not sure which one takes priority. I think if we have 7172292SN/A // both, that's a bad sign. 7182292SN/A if (trapSquash[tid] == true) { 7192292SN/A assert(!xcSquash[tid]); 7202292SN/A squashFromTrap(tid); 7212292SN/A } else if (xcSquash[tid] == true) { 7222292SN/A squashFromXC(tid); 7232292SN/A } 7241061SN/A 7252292SN/A // Squashed sequence number must be older than youngest valid 7262292SN/A // instruction in the ROB. This prevents squashes from younger 7272292SN/A // instructions overriding squashes from older instructions. 7282292SN/A if (fromIEW->squash[tid] && 7292292SN/A commitStatus[tid] != TrapPending && 7302292SN/A fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 7311061SN/A 7322292SN/A DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n", 7332292SN/A tid, 7342292SN/A fromIEW->mispredPC[tid], 7352292SN/A fromIEW->squashedSeqNum[tid]); 7361061SN/A 7372292SN/A DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 7382292SN/A tid, 7392292SN/A fromIEW->nextPC[tid]); 7401061SN/A 7412292SN/A commitStatus[tid] = ROBSquashing; 7421061SN/A 7432292SN/A ++squashCounter; 7441061SN/A 7452292SN/A // If we want to include the squashing instruction in the squash, 7462292SN/A // then use one older sequence number. 7472292SN/A InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 7481062SN/A 7492292SN/A if (fromIEW->includeSquashInst[tid] == true) 7502292SN/A squashed_inst--; 7512292SN/A 7522292SN/A // All younger instructions will be squashed. Set the sequence 7532292SN/A // number as the youngest instruction in the ROB. 7542292SN/A youngestSeqNum[tid] = squashed_inst; 7552292SN/A 7562292SN/A rob->squash(squashed_inst, tid); 7572292SN/A changedROBNumEntries[tid] = true; 7582292SN/A 7592292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 7602292SN/A 7612292SN/A toIEW->commitInfo[tid].squash = true; 7622292SN/A 7632292SN/A // Send back the rob squashing signal so other stages know that 7642292SN/A // the ROB is in the process of squashing. 7652292SN/A toIEW->commitInfo[tid].robSquashing = true; 7662292SN/A 7672292SN/A toIEW->commitInfo[tid].branchMispredict = 7682292SN/A fromIEW->branchMispredict[tid]; 7692292SN/A 7702292SN/A toIEW->commitInfo[tid].branchTaken = 7712292SN/A fromIEW->branchTaken[tid]; 7722292SN/A 7732292SN/A toIEW->commitInfo[tid].nextPC = fromIEW->nextPC[tid]; 7742292SN/A 7752316SN/A toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid]; 7762292SN/A 7772292SN/A if (toIEW->commitInfo[tid].branchMispredict) { 7782292SN/A ++branchMispredicts; 7792292SN/A } 7801062SN/A } 7812292SN/A 7821060SN/A } 7831060SN/A 7842292SN/A setNextStatus(); 7852292SN/A 7862292SN/A if (squashCounter != numThreads) { 7871061SN/A // If we're not currently squashing, then get instructions. 7881060SN/A getInsts(); 7891060SN/A 7901061SN/A // Try to commit any instructions. 7911060SN/A commitInsts(); 7921060SN/A } 7931060SN/A 7942292SN/A //Check for any activity 7952292SN/A threads = (*activeThreads).begin(); 7962292SN/A 7972292SN/A while (threads != (*activeThreads).end()) { 7982292SN/A unsigned tid = *threads++; 7992292SN/A 8002292SN/A if (changedROBNumEntries[tid]) { 8012292SN/A toIEW->commitInfo[tid].usedROB = true; 8022292SN/A toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 8032292SN/A 8042292SN/A if (rob->isEmpty(tid)) { 8052292SN/A toIEW->commitInfo[tid].emptyROB = true; 8062292SN/A } 8072292SN/A 8082292SN/A wroteToTimeBuffer = true; 8092292SN/A changedROBNumEntries[tid] = false; 8102292SN/A } 8111060SN/A } 8121060SN/A} 8131060SN/A 8141061SN/Atemplate <class Impl> 8151060SN/Avoid 8162292SN/ADefaultCommit<Impl>::commitInsts() 8171060SN/A{ 8181060SN/A //////////////////////////////////// 8191060SN/A // Handle commit 8202316SN/A // Note that commit will be handled prior to putting new 8212316SN/A // instructions in the ROB so that the ROB only tries to commit 8222316SN/A // instructions it has in this current cycle, and not instructions 8232316SN/A // it is writing in during this cycle. Can't commit and squash 8242316SN/A // things at the same time... 8251060SN/A //////////////////////////////////// 8261060SN/A 8272292SN/A DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 8281060SN/A 8291060SN/A unsigned num_committed = 0; 8301060SN/A 8312292SN/A DynInstPtr head_inst; 8322316SN/A 8331060SN/A // Commit as many instructions as possible until the commit bandwidth 8341060SN/A // limit is reached, or it becomes impossible to commit any more. 8352292SN/A while (num_committed < commitWidth) { 8362292SN/A int commit_thread = getCommittingThread(); 8371060SN/A 8382292SN/A if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 8392292SN/A break; 8402292SN/A 8412292SN/A head_inst = rob->readHeadInst(commit_thread); 8422292SN/A 8432292SN/A int tid = head_inst->threadNumber; 8442292SN/A 8452292SN/A assert(tid == commit_thread); 8462292SN/A 8472292SN/A DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 8482292SN/A head_inst->seqNum, tid); 8492132SN/A 8502316SN/A // If the head instruction is squashed, it is ready to retire 8512316SN/A // (be removed from the ROB) at any time. 8521060SN/A if (head_inst->isSquashed()) { 8531060SN/A 8542292SN/A DPRINTF(Commit, "Retiring squashed instruction from " 8551060SN/A "ROB.\n"); 8561060SN/A 8572292SN/A rob->retireHead(commit_thread); 8581060SN/A 8591062SN/A ++commitSquashedInsts; 8601062SN/A 8612292SN/A // Record that the number of ROB entries has changed. 8622292SN/A changedROBNumEntries[tid] = true; 8631060SN/A } else { 8642292SN/A PC[tid] = head_inst->readPC(); 8652292SN/A nextPC[tid] = head_inst->readNextPC(); 8662292SN/A 8671060SN/A // Increment the total number of non-speculative instructions 8681060SN/A // executed. 8691060SN/A // Hack for now: it really shouldn't happen until after the 8701061SN/A // commit is deemed to be successful, but this count is needed 8711061SN/A // for syscalls. 8722292SN/A thread[tid]->funcExeInst++; 8731060SN/A 8741060SN/A // Try to commit the head instruction. 8751060SN/A bool commit_success = commitHead(head_inst, num_committed); 8761060SN/A 8771062SN/A if (commit_success) { 8781060SN/A ++num_committed; 8791060SN/A 8802292SN/A changedROBNumEntries[tid] = true; 8812292SN/A 8822292SN/A // Set the doneSeqNum to the youngest committed instruction. 8832292SN/A toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 8841060SN/A 8851062SN/A ++commitCommittedInsts; 8861062SN/A 8872292SN/A // To match the old model, don't count nops and instruction 8882292SN/A // prefetches towards the total commit count. 8892292SN/A if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 8902292SN/A cpu->instDone(tid); 8911062SN/A } 8922292SN/A 8932292SN/A PC[tid] = nextPC[tid]; 8942307SN/A nextPC[tid] = nextPC[tid] + sizeof(TheISA::MachInst); 8952292SN/A#if FULL_SYSTEM 8962292SN/A int count = 0; 8972292SN/A Addr oldpc; 8982292SN/A do { 8992316SN/A // Debug statement. Checks to make sure we're not 9002316SN/A // currently updating state while handling PC events. 9012292SN/A if (count == 0) 9022316SN/A assert(!thread[tid]->inSyscall && 9032316SN/A !thread[tid]->trapPending); 9042292SN/A oldpc = PC[tid]; 9052292SN/A cpu->system->pcEventQueue.service( 9062292SN/A thread[tid]->getXCProxy()); 9072292SN/A count++; 9082292SN/A } while (oldpc != PC[tid]); 9092292SN/A if (count > 1) { 9102292SN/A DPRINTF(Commit, "PC skip function event, stopping commit\n"); 9112292SN/A break; 9122292SN/A } 9132292SN/A#endif 9141060SN/A } else { 9152292SN/A DPRINTF(Commit, "Unable to commit head instruction PC:%#x " 9162292SN/A "[tid:%i] [sn:%i].\n", 9172292SN/A head_inst->readPC(), tid ,head_inst->seqNum); 9181060SN/A break; 9191060SN/A } 9201060SN/A } 9211060SN/A } 9221062SN/A 9231063SN/A DPRINTF(CommitRate, "%i\n", num_committed); 9242292SN/A numCommittedDist.sample(num_committed); 9252307SN/A 9262307SN/A if (num_committed == commitWidth) { 9272316SN/A commitEligible[0]++; 9282307SN/A } 9291060SN/A} 9301060SN/A 9311061SN/Atemplate <class Impl> 9321060SN/Abool 9332292SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 9341060SN/A{ 9351060SN/A assert(head_inst); 9361060SN/A 9372292SN/A int tid = head_inst->threadNumber; 9382292SN/A 9392316SN/A // If the instruction is not executed yet, then it will need extra 9402316SN/A // handling. Signal backwards that it should be executed. 9411061SN/A if (!head_inst->isExecuted()) { 9421061SN/A // Keep this number correct. We have not yet actually executed 9431061SN/A // and committed this instruction. 9442292SN/A thread[tid]->funcExeInst--; 9451062SN/A 9462292SN/A head_inst->reachedCommit = true; 9471060SN/A 9482292SN/A if (head_inst->isNonSpeculative() || 9492292SN/A head_inst->isMemBarrier() || 9502292SN/A head_inst->isWriteBarrier()) { 9512316SN/A 9522316SN/A DPRINTF(Commit, "Encountered a barrier or non-speculative " 9532316SN/A "instruction [sn:%lli] at the head of the ROB, PC %#x.\n", 9542316SN/A head_inst->seqNum, head_inst->readPC()); 9552316SN/A 9562292SN/A#if !FULL_SYSTEM 9572316SN/A // Hack to make sure syscalls/memory barriers/quiesces 9582316SN/A // aren't executed until all stores write back their data. 9592316SN/A // This direct communication shouldn't be used for 9602316SN/A // anything other than this. 9612292SN/A if (inst_num > 0 || iewStage->hasStoresToWB()) 9622292SN/A#else 9632292SN/A if ((head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 9642292SN/A head_inst->isQuiesce()) && 9652292SN/A iewStage->hasStoresToWB()) 9662292SN/A#endif 9672292SN/A { 9682292SN/A DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 9692292SN/A return false; 9702292SN/A } 9712292SN/A 9722292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 9731061SN/A 9741061SN/A // Change the instruction so it won't try to commit again until 9751061SN/A // it is executed. 9761061SN/A head_inst->clearCanCommit(); 9771061SN/A 9781062SN/A ++commitNonSpecStalls; 9791062SN/A 9801061SN/A return false; 9812292SN/A } else if (head_inst->isLoad()) { 9822292SN/A DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %#x.\n", 9832292SN/A head_inst->seqNum, head_inst->readPC()); 9842292SN/A 9852292SN/A // Send back the non-speculative instruction's sequence 9862316SN/A // number. Tell the lsq to re-execute the load. 9872292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 9882292SN/A toIEW->commitInfo[tid].uncached = true; 9892292SN/A toIEW->commitInfo[tid].uncachedLoad = head_inst; 9902292SN/A 9912292SN/A head_inst->clearCanCommit(); 9922292SN/A 9932292SN/A return false; 9941061SN/A } else { 9952292SN/A panic("Trying to commit un-executed instruction " 9961061SN/A "of unknown type!\n"); 9971061SN/A } 9981060SN/A } 9991060SN/A 10002316SN/A if (head_inst->isThreadSync()) { 10012292SN/A // Not handled for now. 10022316SN/A panic("Thread sync instructions are not handled yet.\n"); 10032132SN/A } 10042132SN/A 10052316SN/A // Stores mark themselves as completed. 10062310SN/A if (!head_inst->isStore()) { 10072310SN/A head_inst->setCompleted(); 10082310SN/A } 10092310SN/A 10102316SN/A // Use checker prior to updating anything due to traps or PC 10112316SN/A // based events. 10122316SN/A if (cpu->checker) { 10132316SN/A cpu->checker->tick(head_inst); 10141060SN/A } 10151060SN/A 10161060SN/A // Check if the instruction caused a fault. If so, trap. 10172132SN/A Fault inst_fault = head_inst->getFault(); 10181681SN/A 10192112SN/A if (inst_fault != NoFault) { 10202316SN/A head_inst->setCompleted(); 10211858SN/A#if FULL_SYSTEM 10222316SN/A DPRINTF(Commit, "Inst [sn:%lli] PC %#x has a fault\n", 10232316SN/A head_inst->seqNum, head_inst->readPC()); 10242292SN/A 10252316SN/A if (iewStage->hasStoresToWB() || inst_num > 0) { 10262316SN/A DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 10272316SN/A return false; 10282316SN/A } 10292310SN/A 10302316SN/A if (cpu->checker && head_inst->isStore()) { 10312316SN/A cpu->checker->tick(head_inst); 10322316SN/A } 10332292SN/A 10342316SN/A assert(!thread[tid]->inSyscall); 10352292SN/A 10362316SN/A // Mark that we're in state update mode so that the trap's 10372316SN/A // execution doesn't generate extra squashes. 10382316SN/A thread[tid]->inSyscall = true; 10392292SN/A 10402316SN/A // DTB will sometimes need the machine instruction for when 10412316SN/A // faults happen. So we will set it here, prior to the DTB 10422316SN/A // possibly needing it for its fault. 10432316SN/A thread[tid]->setInst( 10442316SN/A static_cast<TheISA::MachInst>(head_inst->staticInst->machInst)); 10452292SN/A 10462316SN/A // Execute the trap. Although it's slightly unrealistic in 10472316SN/A // terms of timing (as it doesn't wait for the full timing of 10482316SN/A // the trap event to complete before updating state), it's 10492316SN/A // needed to update the state as soon as possible. This 10502316SN/A // prevents external agents from changing any specific state 10512316SN/A // that the trap need. 10522316SN/A cpu->trap(inst_fault, tid); 10532292SN/A 10542316SN/A // Exit state update mode to avoid accidental updating. 10552316SN/A thread[tid]->inSyscall = false; 10562292SN/A 10572316SN/A commitStatus[tid] = TrapPending; 10582292SN/A 10592316SN/A // Generate trap squash event. 10602316SN/A generateTrapEvent(tid); 10612316SN/A 10622316SN/A return false; 10631060SN/A#else // !FULL_SYSTEM 10642316SN/A panic("fault (%d) detected @ PC %08p", inst_fault, 10652316SN/A head_inst->PC); 10661062SN/A#endif // FULL_SYSTEM 10671060SN/A } 10681060SN/A 10692301SN/A updateComInstStats(head_inst); 10702132SN/A 10712132SN/A if (head_inst->traceData) { 10722292SN/A head_inst->traceData->setFetchSeq(head_inst->seqNum); 10732292SN/A head_inst->traceData->setCPSeq(thread[tid]->numInst); 10742132SN/A head_inst->traceData->finalize(); 10752292SN/A head_inst->traceData = NULL; 10761060SN/A } 10771060SN/A 10782292SN/A // Update the commit rename map 10792292SN/A for (int i = 0; i < head_inst->numDestRegs(); i++) { 10802292SN/A renameMap[tid]->setEntry(head_inst->destRegIdx(i), 10812292SN/A head_inst->renamedDestRegIdx(i)); 10821060SN/A } 10831062SN/A 10842292SN/A // Finally clear the head ROB entry. 10852292SN/A rob->retireHead(tid); 10861060SN/A 10871060SN/A // Return true to indicate that we have committed an instruction. 10881060SN/A return true; 10891060SN/A} 10901060SN/A 10911061SN/Atemplate <class Impl> 10921060SN/Avoid 10932292SN/ADefaultCommit<Impl>::getInsts() 10941060SN/A{ 10952316SN/A // Read any renamed instructions and place them into the ROB. 10961061SN/A int insts_to_process = min((int)renameWidth, fromRename->size); 10971061SN/A 10982292SN/A for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) 10991060SN/A { 11002292SN/A DynInstPtr inst = fromRename->insts[inst_num]; 11012292SN/A int tid = inst->threadNumber; 11022292SN/A 11032292SN/A if (!inst->isSquashed() && 11042292SN/A commitStatus[tid] != ROBSquashing) { 11052292SN/A changedROBNumEntries[tid] = true; 11062292SN/A 11072292SN/A DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ROB.\n", 11082292SN/A inst->readPC(), inst->seqNum, tid); 11092292SN/A 11102292SN/A rob->insertInst(inst); 11112292SN/A 11122292SN/A assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 11132292SN/A 11142292SN/A youngestSeqNum[tid] = inst->seqNum; 11151061SN/A } else { 11162292SN/A DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 11171061SN/A "squashed, skipping.\n", 11182292SN/A inst->readPC(), inst->seqNum, tid); 11191061SN/A } 11201060SN/A } 11211060SN/A} 11221060SN/A 11231061SN/Atemplate <class Impl> 11241060SN/Avoid 11252292SN/ADefaultCommit<Impl>::markCompletedInsts() 11261060SN/A{ 11271060SN/A // Grab completed insts out of the IEW instruction queue, and mark 11281060SN/A // instructions completed within the ROB. 11291060SN/A for (int inst_num = 0; 11301681SN/A inst_num < fromIEW->size && fromIEW->insts[inst_num]; 11311060SN/A ++inst_num) 11321060SN/A { 11332292SN/A if (!fromIEW->insts[inst_num]->isSquashed()) { 11342316SN/A DPRINTF(Commit, "[tid:%i]: Marking PC %#x, [sn:%lli] ready " 11352316SN/A "within ROB.\n", 11362292SN/A fromIEW->insts[inst_num]->threadNumber, 11372292SN/A fromIEW->insts[inst_num]->readPC(), 11382292SN/A fromIEW->insts[inst_num]->seqNum); 11391060SN/A 11402292SN/A // Mark the instruction as ready to commit. 11412292SN/A fromIEW->insts[inst_num]->setCanCommit(); 11422292SN/A } 11431060SN/A } 11441060SN/A} 11451060SN/A 11461061SN/Atemplate <class Impl> 11472292SN/Abool 11482292SN/ADefaultCommit<Impl>::robDoneSquashing() 11491060SN/A{ 11502292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 11512292SN/A 11522292SN/A while (threads != (*activeThreads).end()) { 11532292SN/A unsigned tid = *threads++; 11542292SN/A 11552292SN/A if (!rob->isDoneSquashing(tid)) 11562292SN/A return false; 11572292SN/A } 11582292SN/A 11592292SN/A return true; 11601060SN/A} 11612292SN/A 11622301SN/Atemplate <class Impl> 11632301SN/Avoid 11642301SN/ADefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 11652301SN/A{ 11662301SN/A unsigned thread = inst->threadNumber; 11672301SN/A 11682301SN/A // 11692301SN/A // Pick off the software prefetches 11702301SN/A // 11712301SN/A#ifdef TARGET_ALPHA 11722301SN/A if (inst->isDataPrefetch()) { 11732316SN/A statComSwp[thread]++; 11742301SN/A } else { 11752316SN/A statComInst[thread]++; 11762301SN/A } 11772301SN/A#else 11782316SN/A statComInst[thread]++; 11792301SN/A#endif 11802301SN/A 11812301SN/A // 11822301SN/A // Control Instructions 11832301SN/A // 11842301SN/A if (inst->isControl()) 11852316SN/A statComBranches[thread]++; 11862301SN/A 11872301SN/A // 11882301SN/A // Memory references 11892301SN/A // 11902301SN/A if (inst->isMemRef()) { 11912316SN/A statComRefs[thread]++; 11922301SN/A 11932301SN/A if (inst->isLoad()) { 11942316SN/A statComLoads[thread]++; 11952301SN/A } 11962301SN/A } 11972301SN/A 11982301SN/A if (inst->isMemBarrier()) { 11992316SN/A statComMembars[thread]++; 12002301SN/A } 12012301SN/A} 12022301SN/A 12032292SN/A//////////////////////////////////////// 12042292SN/A// // 12052316SN/A// SMT COMMIT POLICY MAINTAINED HERE // 12062292SN/A// // 12072292SN/A//////////////////////////////////////// 12082292SN/Atemplate <class Impl> 12092292SN/Aint 12102292SN/ADefaultCommit<Impl>::getCommittingThread() 12112292SN/A{ 12122292SN/A if (numThreads > 1) { 12132292SN/A switch (commitPolicy) { 12142292SN/A 12152292SN/A case Aggressive: 12162292SN/A //If Policy is Aggressive, commit will call 12172292SN/A //this function multiple times per 12182292SN/A //cycle 12192292SN/A return oldestReady(); 12202292SN/A 12212292SN/A case RoundRobin: 12222292SN/A return roundRobin(); 12232292SN/A 12242292SN/A case OldestReady: 12252292SN/A return oldestReady(); 12262292SN/A 12272292SN/A default: 12282292SN/A return -1; 12292292SN/A } 12302292SN/A } else { 12312292SN/A int tid = (*activeThreads).front(); 12322292SN/A 12332292SN/A if (commitStatus[tid] == Running || 12342292SN/A commitStatus[tid] == Idle || 12352292SN/A commitStatus[tid] == FetchTrapPending) { 12362292SN/A return tid; 12372292SN/A } else { 12382292SN/A return -1; 12392292SN/A } 12402292SN/A } 12412292SN/A} 12422292SN/A 12432292SN/Atemplate<class Impl> 12442292SN/Aint 12452292SN/ADefaultCommit<Impl>::roundRobin() 12462292SN/A{ 12472292SN/A list<unsigned>::iterator pri_iter = priority_list.begin(); 12482292SN/A list<unsigned>::iterator end = priority_list.end(); 12492292SN/A 12502292SN/A while (pri_iter != end) { 12512292SN/A unsigned tid = *pri_iter; 12522292SN/A 12532292SN/A if (commitStatus[tid] == Running || 12542292SN/A commitStatus[tid] == Idle) { 12552292SN/A 12562292SN/A if (rob->isHeadReady(tid)) { 12572292SN/A priority_list.erase(pri_iter); 12582292SN/A priority_list.push_back(tid); 12592292SN/A 12602292SN/A return tid; 12612292SN/A } 12622292SN/A } 12632292SN/A 12642292SN/A pri_iter++; 12652292SN/A } 12662292SN/A 12672292SN/A return -1; 12682292SN/A} 12692292SN/A 12702292SN/Atemplate<class Impl> 12712292SN/Aint 12722292SN/ADefaultCommit<Impl>::oldestReady() 12732292SN/A{ 12742292SN/A unsigned oldest = 0; 12752292SN/A bool first = true; 12762292SN/A 12772292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 12782292SN/A 12792292SN/A while (threads != (*activeThreads).end()) { 12802292SN/A unsigned tid = *threads++; 12812292SN/A 12822292SN/A if (!rob->isEmpty(tid) && 12832292SN/A (commitStatus[tid] == Running || 12842292SN/A commitStatus[tid] == Idle || 12852292SN/A commitStatus[tid] == FetchTrapPending)) { 12862292SN/A 12872292SN/A if (rob->isHeadReady(tid)) { 12882292SN/A 12892292SN/A DynInstPtr head_inst = rob->readHeadInst(tid); 12902292SN/A 12912292SN/A if (first) { 12922292SN/A oldest = tid; 12932292SN/A first = false; 12942292SN/A } else if (head_inst->seqNum < oldest) { 12952292SN/A oldest = tid; 12962292SN/A } 12972292SN/A } 12982292SN/A } 12992292SN/A } 13002292SN/A 13012292SN/A if (!first) { 13022292SN/A return oldest; 13032292SN/A } else { 13042292SN/A return -1; 13052292SN/A } 13062292SN/A} 1307