commit_impl.hh revision 7720:65d338a8dba4
17513SN/A/* 27513SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 37513SN/A * All rights reserved. 410036SAli.Saidi@ARM.com * 58835SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 610036SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 77935SN/A * met: redistributions of source code must retain the above copyright 87935SN/A * notice, this list of conditions and the following disclaimer; 97935SN/A * redistributions in binary form must reproduce the above copyright 107513SN/A * notice, this list of conditions and the following disclaimer in the 117513SN/A * documentation and/or other materials provided with the distribution; 127513SN/A * neither the name of the copyright holders nor the names of its 1310315Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 148835SAli.Saidi@ARM.com * this software without specific prior written permission. 159885Sstever@gmail.com * 169885Sstever@gmail.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1710036SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811388Ssteve.reinhardt@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 198835SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 208835SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2110315Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 228835SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310038SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249481Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259481Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 268721SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2710900Snilay@cs.wisc.edu * 2811388Ssteve.reinhardt@amd.com * Authors: Kevin Lim 298721SN/A * Korey Sewell 308835SAli.Saidi@ARM.com */ 318835SAli.Saidi@ARM.com 3211515Sandreas.sandberg@arm.com#include <algorithm> 3311515Sandreas.sandberg@arm.com#include <string> 347935SN/A 357935SN/A#include "arch/utility.hh" 367935SN/A#include "base/cp_annotate.hh" 377935SN/A#include "base/loader/symtab.hh" 387935SN/A#include "base/timebuf.hh" 397935SN/A#include "config/full_system.hh" 407935SN/A#include "config/the_isa.hh" 418893Ssaidi@eecs.umich.edu#include "config/use_checker.hh" 427513SN/A#include "cpu/exetrace.hh" 439885Sstever@gmail.com#include "cpu/o3/commit.hh" 449885Sstever@gmail.com#include "cpu/o3/thread_state.hh" 459885Sstever@gmail.com#include "params/DerivO3CPU.hh" 4610315Snilay@cs.wisc.edu 4710036SAli.Saidi@ARM.com#if USE_CHECKER 4810315Snilay@cs.wisc.edu#include "cpu/checker/cpu.hh" 499885Sstever@gmail.com#endif 509885Sstever@gmail.com 517513SN/Ausing namespace std; 527513SN/A 5310038SAli.Saidi@ARM.comtemplate <class Impl> 5410315Snilay@cs.wisc.eduDefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 557513SN/A ThreadID _tid) 569885Sstever@gmail.com : Event(CPU_Tick_Pri), commit(_commit), tid(_tid) 577513SN/A{ 587513SN/A this->setFlags(AutoDelete); 598835SAli.Saidi@ARM.com} 607513SN/A 6110038SAli.Saidi@ARM.comtemplate <class Impl> 627513SN/Avoid 6310036SAli.Saidi@ARM.comDefaultCommit<Impl>::TrapEvent::process() 647513SN/A{ 657513SN/A // This will get reset by commit if it was switched out at the 668835SAli.Saidi@ARM.com // time of this event processing. 679481Snilay@cs.wisc.edu commit->trapSquash[tid] = true; 6810038SAli.Saidi@ARM.com} 697513SN/A 707513SN/Atemplate <class Impl> 717513SN/Aconst char * 727513SN/ADefaultCommit<Impl>::TrapEvent::description() const 737513SN/A{ 747513SN/A return "Trap"; 758835SAli.Saidi@ARM.com} 767513SN/A 779885Sstever@gmail.comtemplate <class Impl> 7810315Snilay@cs.wisc.eduDefaultCommit<Impl>::DefaultCommit(O3CPU *_cpu, DerivO3CPUParams *params) 799481Snilay@cs.wisc.edu : cpu(_cpu), 807513SN/A squashCounter(0), 817513SN/A iewToCommitDelay(params->iewToCommitDelay), 827513SN/A commitToIEWDelay(params->commitToIEWDelay), 837513SN/A renameToROBDelay(params->renameToROBDelay), 847513SN/A fetchToCommitDelay(params->commitToFetchDelay), 857513SN/A renameWidth(params->renameWidth), 867513SN/A commitWidth(params->commitWidth), 8711103Snilay@cs.wisc.edu numThreads(params->numThreads), 889885Sstever@gmail.com drainPending(false), 898893Ssaidi@eecs.umich.edu switchedOut(false), 907513SN/A trapLatency(params->trapLatency) 919885Sstever@gmail.com{ 9211388Ssteve.reinhardt@amd.com _status = Active; 9310900Snilay@cs.wisc.edu _nextStatus = Inactive; 9410036SAli.Saidi@ARM.com std::string policy = params->smtCommitPolicy; 959481Snilay@cs.wisc.edu 9610900Snilay@cs.wisc.edu //Convert string to lowercase 977513SN/A std::transform(policy.begin(), policy.end(), policy.begin(), 989481Snilay@cs.wisc.edu (int(*)(int)) tolower); 997513SN/A 1008835SAli.Saidi@ARM.com //Assign commit policy 1019481Snilay@cs.wisc.edu if (policy == "aggressive"){ 10210036SAli.Saidi@ARM.com commitPolicy = Aggressive; 1037513SN/A 1048835SAli.Saidi@ARM.com DPRINTF(Commit,"Commit Policy set to Aggressive."); 1059885Sstever@gmail.com } else if (policy == "roundrobin"){ 1069481Snilay@cs.wisc.edu commitPolicy = RoundRobin; 1077513SN/A 10811388Ssteve.reinhardt@amd.com //Set-Up Priority List 1097513SN/A for (ThreadID tid = 0; tid < numThreads; tid++) { 1108893Ssaidi@eecs.umich.edu priority_list.push_back(tid); 1117513SN/A } 1129885Sstever@gmail.com 1139885Sstever@gmail.com DPRINTF(Commit,"Commit Policy set to Round Robin."); 1149885Sstever@gmail.com } else if (policy == "oldestready"){ 1159885Sstever@gmail.com commitPolicy = OldestReady; 1169885Sstever@gmail.com 11710036SAli.Saidi@ARM.com DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1189885Sstever@gmail.com } else { 11910036SAli.Saidi@ARM.com assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1209885Sstever@gmail.com "RoundRobin,OldestReady}"); 1219885Sstever@gmail.com } 12210038SAli.Saidi@ARM.com 12310038SAli.Saidi@ARM.com for (ThreadID tid = 0; tid < numThreads; tid++) { 12410038SAli.Saidi@ARM.com commitStatus[tid] = Idle; 12510038SAli.Saidi@ARM.com changedROBNumEntries[tid] = false; 12610038SAli.Saidi@ARM.com checkEmptyROB[tid] = false; 12710900Snilay@cs.wisc.edu trapInFlight[tid] = false; 12810038SAli.Saidi@ARM.com committedStores[tid] = false; 12910038SAli.Saidi@ARM.com trapSquash[tid] = false; 13010038SAli.Saidi@ARM.com tcSquash[tid] = false; 13110038SAli.Saidi@ARM.com pc[tid].set(0); 13210038SAli.Saidi@ARM.com } 13310038SAli.Saidi@ARM.com#if FULL_SYSTEM 13410038SAli.Saidi@ARM.com interrupt = NoFault; 13510038SAli.Saidi@ARM.com#endif 13610038SAli.Saidi@ARM.com} 13710038SAli.Saidi@ARM.com 13810038SAli.Saidi@ARM.comtemplate <class Impl> 13910038SAli.Saidi@ARM.comstd::string 14010038SAli.Saidi@ARM.comDefaultCommit<Impl>::name() const 14110038SAli.Saidi@ARM.com{ 14210038SAli.Saidi@ARM.com return cpu->name() + ".commit"; 14310038SAli.Saidi@ARM.com} 14410038SAli.Saidi@ARM.com 14510038SAli.Saidi@ARM.comtemplate <class Impl> 1467513SN/Avoid 1477513SN/ADefaultCommit<Impl>::regStats() 1488835SAli.Saidi@ARM.com{ 14910036SAli.Saidi@ARM.com using namespace Stats; 15010038SAli.Saidi@ARM.com commitCommittedInsts 1517513SN/A .name(name() + ".commitCommittedInsts") 1528835SAli.Saidi@ARM.com .desc("The number of committed instructions") 1538835SAli.Saidi@ARM.com .prereq(commitCommittedInsts); 1548835SAli.Saidi@ARM.com commitSquashedInsts 1558835SAli.Saidi@ARM.com .name(name() + ".commitSquashedInsts") 1569885Sstever@gmail.com .desc("The number of squashed insts skipped by commit") 15710036SAli.Saidi@ARM.com .prereq(commitSquashedInsts); 15810038SAli.Saidi@ARM.com commitSquashEvents 1599265SAli.Saidi@ARM.com .name(name() + ".commitSquashEvents") 1608835SAli.Saidi@ARM.com .desc("The number of times commit is told to squash") 1618893Ssaidi@eecs.umich.edu .prereq(commitSquashEvents); 1627513SN/A commitNonSpecStalls 1637513SN/A .name(name() + ".commitNonSpecStalls") 16411103Snilay@cs.wisc.edu .desc("The number of times commit has been forced to stall to " 1659885Sstever@gmail.com "communicate backwards") 1668893Ssaidi@eecs.umich.edu .prereq(commitNonSpecStalls); 1677513SN/A branchMispredicts 1689885Sstever@gmail.com .name(name() + ".branchMispredicts") 16911388Ssteve.reinhardt@amd.com .desc("The number of times a branch was mispredicted") 17010900Snilay@cs.wisc.edu .prereq(branchMispredicts); 17110036SAli.Saidi@ARM.com numCommittedDist 1729481Snilay@cs.wisc.edu .init(0,commitWidth,1) 17310900Snilay@cs.wisc.edu .name(name() + ".COM:committed_per_cycle") 1747513SN/A .desc("Number of insts commited each cycle") 1759481Snilay@cs.wisc.edu .flags(Stats::pdf) 1767513SN/A ; 1778835SAli.Saidi@ARM.com 1789481Snilay@cs.wisc.edu statComInst 17910036SAli.Saidi@ARM.com .init(cpu->numThreads) 1807513SN/A .name(name() + ".COM:count") 1818835SAli.Saidi@ARM.com .desc("Number of instructions committed") 1829885Sstever@gmail.com .flags(total) 1839481Snilay@cs.wisc.edu ; 1847513SN/A 18511388Ssteve.reinhardt@amd.com statComSwp 1867513SN/A .init(cpu->numThreads) 1878893Ssaidi@eecs.umich.edu .name(name() + ".COM:swp_count") 1887513SN/A .desc("Number of s/w prefetches committed") 1899885Sstever@gmail.com .flags(total) 1909885Sstever@gmail.com ; 1919885Sstever@gmail.com 1929885Sstever@gmail.com statComRefs 1939885Sstever@gmail.com .init(cpu->numThreads) 19410036SAli.Saidi@ARM.com .name(name() + ".COM:refs") 1959885Sstever@gmail.com .desc("Number of memory references committed") 19610036SAli.Saidi@ARM.com .flags(total) 1979885Sstever@gmail.com ; 1989885Sstever@gmail.com 1998835SAli.Saidi@ARM.com statComLoads 2008835SAli.Saidi@ARM.com .init(cpu->numThreads) 20110036SAli.Saidi@ARM.com .name(name() + ".COM:loads") 2028835SAli.Saidi@ARM.com .desc("Number of loads committed") 2039481Snilay@cs.wisc.edu .flags(total) 2049481Snilay@cs.wisc.edu ; 20511388Ssteve.reinhardt@amd.com 20610036SAli.Saidi@ARM.com statComMembars 2079481Snilay@cs.wisc.edu .init(cpu->numThreads) 20810038SAli.Saidi@ARM.com .name(name() + ".COM:membars") 20910038SAli.Saidi@ARM.com .desc("Number of memory barriers committed") 21010038SAli.Saidi@ARM.com .flags(total) 21110038SAli.Saidi@ARM.com ; 21210038SAli.Saidi@ARM.com 21310038SAli.Saidi@ARM.com statComBranches 21410038SAli.Saidi@ARM.com .init(cpu->numThreads) 21510038SAli.Saidi@ARM.com .name(name() + ".COM:branches") 21610038SAli.Saidi@ARM.com .desc("Number of branches committed") 21710038SAli.Saidi@ARM.com .flags(total) 2189481Snilay@cs.wisc.edu ; 2199481Snilay@cs.wisc.edu 2209481Snilay@cs.wisc.edu commitEligible 2219481Snilay@cs.wisc.edu .init(cpu->numThreads) 2229481Snilay@cs.wisc.edu .name(name() + ".COM:bw_limited") 2239481Snilay@cs.wisc.edu .desc("number of insts not committed due to BW limits") 22410038SAli.Saidi@ARM.com .flags(total) 2259481Snilay@cs.wisc.edu ; 2269481Snilay@cs.wisc.edu 22710038SAli.Saidi@ARM.com commitEligibleSamples 2289481Snilay@cs.wisc.edu .name(name() + ".COM:bw_lim_events") 22910038SAli.Saidi@ARM.com .desc("number cycles where commit BW limit reached") 23010038SAli.Saidi@ARM.com ; 23110900Snilay@cs.wisc.edu} 23210038SAli.Saidi@ARM.com 23310038SAli.Saidi@ARM.comtemplate <class Impl> 23410038SAli.Saidi@ARM.comvoid 23510038SAli.Saidi@ARM.comDefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 23610038SAli.Saidi@ARM.com{ 23710038SAli.Saidi@ARM.com thread = threads; 23810038SAli.Saidi@ARM.com} 23910900Snilay@cs.wisc.edu 24010038SAli.Saidi@ARM.comtemplate <class Impl> 24110038SAli.Saidi@ARM.comvoid 24210038SAli.Saidi@ARM.comDefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 24310038SAli.Saidi@ARM.com{ 24410038SAli.Saidi@ARM.com timeBuffer = tb_ptr; 24510038SAli.Saidi@ARM.com 24610038SAli.Saidi@ARM.com // Setup wire to send information back to IEW. 24710038SAli.Saidi@ARM.com toIEW = timeBuffer->getWire(0); 24810038SAli.Saidi@ARM.com 24910038SAli.Saidi@ARM.com // Setup wire to read data from IEW (for the ROB). 25010038SAli.Saidi@ARM.com robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 25110038SAli.Saidi@ARM.com} 25210038SAli.Saidi@ARM.com 25310038SAli.Saidi@ARM.comtemplate <class Impl> 25410038SAli.Saidi@ARM.comvoid 25510038SAli.Saidi@ARM.comDefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 25610038SAli.Saidi@ARM.com{ 2579481Snilay@cs.wisc.edu fetchQueue = fq_ptr; 2587513SN/A 2597513SN/A // Setup wire to get instructions from rename (for the ROB). 2608835SAli.Saidi@ARM.com fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 26110036SAli.Saidi@ARM.com} 26210038SAli.Saidi@ARM.com 2637513SN/Atemplate <class Impl> 2648835SAli.Saidi@ARM.comvoid 2658835SAli.Saidi@ARM.comDefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 2668835SAli.Saidi@ARM.com{ 2678835SAli.Saidi@ARM.com renameQueue = rq_ptr; 2689885Sstever@gmail.com 26910036SAli.Saidi@ARM.com // Setup wire to get instructions from rename (for the ROB). 27010038SAli.Saidi@ARM.com fromRename = renameQueue->getWire(-renameToROBDelay); 2719265SAli.Saidi@ARM.com} 2728835SAli.Saidi@ARM.com 2738893Ssaidi@eecs.umich.edutemplate <class Impl> 2747513SN/Avoid 2757513SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 27611103Snilay@cs.wisc.edu{ 2779885Sstever@gmail.com iewQueue = iq_ptr; 2788893Ssaidi@eecs.umich.edu 2799481Snilay@cs.wisc.edu // Setup wire to get instructions from IEW. 2809885Sstever@gmail.com fromIEW = iewQueue->getWire(-iewToCommitDelay); 28111388Ssteve.reinhardt@amd.com} 28210900Snilay@cs.wisc.edu 28310036SAli.Saidi@ARM.comtemplate <class Impl> 2849481Snilay@cs.wisc.eduvoid 28510900Snilay@cs.wisc.eduDefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 2867513SN/A{ 2879481Snilay@cs.wisc.edu iewStage = iew_stage; 2887513SN/A} 2898835SAli.Saidi@ARM.com 2909481Snilay@cs.wisc.edutemplate<class Impl> 29110036SAli.Saidi@ARM.comvoid 2927513SN/ADefaultCommit<Impl>::setActiveThreads(list<ThreadID> *at_ptr) 2938835SAli.Saidi@ARM.com{ 2949885Sstever@gmail.com activeThreads = at_ptr; 2959481Snilay@cs.wisc.edu} 2967513SN/A 29711388Ssteve.reinhardt@amd.comtemplate <class Impl> 2988893Ssaidi@eecs.umich.eduvoid 2998893Ssaidi@eecs.umich.eduDefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3007513SN/A{ 3019885Sstever@gmail.com for (ThreadID tid = 0; tid < numThreads; tid++) 3029885Sstever@gmail.com renameMap[tid] = &rm_ptr[tid]; 3039885Sstever@gmail.com} 3049885Sstever@gmail.com 3059885Sstever@gmail.comtemplate <class Impl> 30610036SAli.Saidi@ARM.comvoid 3079885Sstever@gmail.comDefaultCommit<Impl>::setROB(ROB *rob_ptr) 30810036SAli.Saidi@ARM.com{ 3099885Sstever@gmail.com rob = rob_ptr; 3109885Sstever@gmail.com} 3117513SN/A 31210451Snilay@cs.wisc.edutemplate <class Impl> 31311388Ssteve.reinhardt@amd.comvoid 3149885Sstever@gmail.comDefaultCommit<Impl>::initStage() 31510036SAli.Saidi@ARM.com{ 31610900Snilay@cs.wisc.edu rob->setActiveThreads(activeThreads); 31710900Snilay@cs.wisc.edu rob->resetEntries(); 31811388Ssteve.reinhardt@amd.com 31910900Snilay@cs.wisc.edu // Broadcast the number of free entries. 32011388Ssteve.reinhardt@amd.com for (ThreadID tid = 0; tid < numThreads; tid++) { 32110900Snilay@cs.wisc.edu toIEW->commitInfo[tid].usedROB = true; 3229885Sstever@gmail.com toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 3237524SN/A toIEW->commitInfo[tid].emptyROB = true; 3249481Snilay@cs.wisc.edu } 3258893Ssaidi@eecs.umich.edu 32610900Snilay@cs.wisc.edu // Commit must broadcast the number of free entries it has at the 3277513SN/A // start of the simulation, so it starts as active. 32811388Ssteve.reinhardt@amd.com cpu->activateStage(O3CPU::CommitIdx); 32911388Ssteve.reinhardt@amd.com 33011388Ssteve.reinhardt@amd.com cpu->activityThisCycle(); 33111388Ssteve.reinhardt@amd.com trapLatency = cpu->ticks(trapLatency); 33211388Ssteve.reinhardt@amd.com} 33311388Ssteve.reinhardt@amd.com 33411388Ssteve.reinhardt@amd.comtemplate <class Impl> 3357513SN/Abool 3367513SN/ADefaultCommit<Impl>::drain() 33710036SAli.Saidi@ARM.com{ 3387513SN/A drainPending = true; 3397513SN/A 3407513SN/A return false; 3417513SN/A} 3429265SAli.Saidi@ARM.com 34310900Snilay@cs.wisc.edutemplate <class Impl> 3447513SN/Avoid 3457513SN/ADefaultCommit<Impl>::switchOut() 3467513SN/A{ 3477513SN/A switchedOut = true; 34810036SAli.Saidi@ARM.com drainPending = false; 34911388Ssteve.reinhardt@amd.com rob->switchOut(); 3507513SN/A} 3517513SN/A 35210900Snilay@cs.wisc.edutemplate <class Impl> 3537513SN/Avoid 3547513SN/ADefaultCommit<Impl>::resume() 3557513SN/A{ 3567513SN/A drainPending = false; 3577513SN/A} 3587513SN/A 3597513SN/Atemplate <class Impl> 36010451Snilay@cs.wisc.eduvoid 3617513SN/ADefaultCommit<Impl>::takeOverFrom() 3629885Sstever@gmail.com{ 3639885Sstever@gmail.com switchedOut = false; 3649885Sstever@gmail.com _status = Active; 36510315Snilay@cs.wisc.edu _nextStatus = Inactive; 36610036SAli.Saidi@ARM.com for (ThreadID tid = 0; tid < numThreads; tid++) { 36710315Snilay@cs.wisc.edu commitStatus[tid] = Idle; 3689885Sstever@gmail.com changedROBNumEntries[tid] = false; 3699885Sstever@gmail.com trapSquash[tid] = false; 37010315Snilay@cs.wisc.edu tcSquash[tid] = false; 37110315Snilay@cs.wisc.edu } 37210315Snilay@cs.wisc.edu squashCounter = 0; 37310315Snilay@cs.wisc.edu rob->takeOverFrom(); 37410315Snilay@cs.wisc.edu} 37510315Snilay@cs.wisc.edu 37610315Snilay@cs.wisc.edutemplate <class Impl> 37710315Snilay@cs.wisc.eduvoid 3787513SN/ADefaultCommit<Impl>::updateStatus() 37910451Snilay@cs.wisc.edu{ 3809885Sstever@gmail.com // reset ROB changed variable 38110036SAli.Saidi@ARM.com list<ThreadID>::iterator threads = activeThreads->begin(); 38210900Snilay@cs.wisc.edu list<ThreadID>::iterator end = activeThreads->end(); 38310900Snilay@cs.wisc.edu 38411388Ssteve.reinhardt@amd.com while (threads != end) { 38510900Snilay@cs.wisc.edu ThreadID tid = *threads++; 38610451Snilay@cs.wisc.edu 38710900Snilay@cs.wisc.edu changedROBNumEntries[tid] = false; 3889885Sstever@gmail.com 3897524SN/A // Also check if any of the threads has a trap pending 39010900Snilay@cs.wisc.edu if (commitStatus[tid] == TrapPending || 3919265SAli.Saidi@ARM.com commitStatus[tid] == FetchTrapPending) { 3928893Ssaidi@eecs.umich.edu _nextStatus = Active; 3937513SN/A } 3947513SN/A } 3958983Snate@binkert.org 3969265SAli.Saidi@ARM.com if (_nextStatus == Inactive && _status == Active) { 3979885Sstever@gmail.com DPRINTF(Activity, "Deactivating stage.\n"); 3989885Sstever@gmail.com cpu->deactivateStage(O3CPU::CommitIdx); 39910036SAli.Saidi@ARM.com } else if (_nextStatus == Active && _status == Inactive) { 4008983Snate@binkert.org DPRINTF(Activity, "Activating stage.\n"); 4017513SN/A cpu->activateStage(O3CPU::CommitIdx); 4027513SN/A } 4037513SN/A 4047513SN/A _status = _nextStatus; 4058893Ssaidi@eecs.umich.edu} 4067513SN/A 4079885Sstever@gmail.comtemplate <class Impl> 4089885Sstever@gmail.comvoid 40910036SAli.Saidi@ARM.comDefaultCommit<Impl>::setNextStatus() 4109885Sstever@gmail.com{ 4119885Sstever@gmail.com int squashes = 0; 412 413 list<ThreadID>::iterator threads = activeThreads->begin(); 414 list<ThreadID>::iterator end = activeThreads->end(); 415 416 while (threads != end) { 417 ThreadID tid = *threads++; 418 419 if (commitStatus[tid] == ROBSquashing) { 420 squashes++; 421 } 422 } 423 424 squashCounter = squashes; 425 426 // If commit is currently squashing, then it will have activity for the 427 // next cycle. Set its next status as active. 428 if (squashCounter) { 429 _nextStatus = Active; 430 } 431} 432 433template <class Impl> 434bool 435DefaultCommit<Impl>::changedROBEntries() 436{ 437 list<ThreadID>::iterator threads = activeThreads->begin(); 438 list<ThreadID>::iterator end = activeThreads->end(); 439 440 while (threads != end) { 441 ThreadID tid = *threads++; 442 443 if (changedROBNumEntries[tid]) { 444 return true; 445 } 446 } 447 448 return false; 449} 450 451template <class Impl> 452size_t 453DefaultCommit<Impl>::numROBFreeEntries(ThreadID tid) 454{ 455 return rob->numFreeEntries(tid); 456} 457 458template <class Impl> 459void 460DefaultCommit<Impl>::generateTrapEvent(ThreadID tid) 461{ 462 DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 463 464 TrapEvent *trap = new TrapEvent(this, tid); 465 466 cpu->schedule(trap, curTick + trapLatency); 467 trapInFlight[tid] = true; 468} 469 470template <class Impl> 471void 472DefaultCommit<Impl>::generateTCEvent(ThreadID tid) 473{ 474 assert(!trapInFlight[tid]); 475 DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 476 477 tcSquash[tid] = true; 478} 479 480template <class Impl> 481void 482DefaultCommit<Impl>::squashAll(ThreadID tid) 483{ 484 // If we want to include the squashing instruction in the squash, 485 // then use one older sequence number. 486 // Hopefully this doesn't mess things up. Basically I want to squash 487 // all instructions of this thread. 488 InstSeqNum squashed_inst = rob->isEmpty() ? 489 0 : rob->readHeadInst(tid)->seqNum - 1; 490 491 // All younger instructions will be squashed. Set the sequence 492 // number as the youngest instruction in the ROB (0 in this case. 493 // Hopefully nothing breaks.) 494 youngestSeqNum[tid] = 0; 495 496 rob->squash(squashed_inst, tid); 497 changedROBNumEntries[tid] = true; 498 499 // Send back the sequence number of the squashed instruction. 500 toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 501 502 // Send back the squash signal to tell stages that they should 503 // squash. 504 toIEW->commitInfo[tid].squash = true; 505 506 // Send back the rob squashing signal so other stages know that 507 // the ROB is in the process of squashing. 508 toIEW->commitInfo[tid].robSquashing = true; 509 510 toIEW->commitInfo[tid].branchMispredict = false; 511 512 toIEW->commitInfo[tid].pc = pc[tid]; 513} 514 515template <class Impl> 516void 517DefaultCommit<Impl>::squashFromTrap(ThreadID tid) 518{ 519 squashAll(tid); 520 521 DPRINTF(Commit, "Squashing from trap, restarting at PC %s\n", pc[tid]); 522 523 thread[tid]->trapPending = false; 524 thread[tid]->inSyscall = false; 525 trapInFlight[tid] = false; 526 527 trapSquash[tid] = false; 528 529 commitStatus[tid] = ROBSquashing; 530 cpu->activityThisCycle(); 531} 532 533template <class Impl> 534void 535DefaultCommit<Impl>::squashFromTC(ThreadID tid) 536{ 537 squashAll(tid); 538 539 DPRINTF(Commit, "Squashing from TC, restarting at PC %s\n", pc[tid]); 540 541 thread[tid]->inSyscall = false; 542 assert(!thread[tid]->trapPending); 543 544 commitStatus[tid] = ROBSquashing; 545 cpu->activityThisCycle(); 546 547 tcSquash[tid] = false; 548} 549 550template <class Impl> 551void 552DefaultCommit<Impl>::tick() 553{ 554 wroteToTimeBuffer = false; 555 _nextStatus = Inactive; 556 557 if (drainPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 558 cpu->signalDrained(); 559 drainPending = false; 560 return; 561 } 562 563 if (activeThreads->empty()) 564 return; 565 566 list<ThreadID>::iterator threads = activeThreads->begin(); 567 list<ThreadID>::iterator end = activeThreads->end(); 568 569 // Check if any of the threads are done squashing. Change the 570 // status if they are done. 571 while (threads != end) { 572 ThreadID tid = *threads++; 573 574 // Clear the bit saying if the thread has committed stores 575 // this cycle. 576 committedStores[tid] = false; 577 578 if (commitStatus[tid] == ROBSquashing) { 579 580 if (rob->isDoneSquashing(tid)) { 581 commitStatus[tid] = Running; 582 } else { 583 DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 584 " insts this cycle.\n", tid); 585 rob->doSquash(tid); 586 toIEW->commitInfo[tid].robSquashing = true; 587 wroteToTimeBuffer = true; 588 } 589 } 590 } 591 592 commit(); 593 594 markCompletedInsts(); 595 596 threads = activeThreads->begin(); 597 598 while (threads != end) { 599 ThreadID tid = *threads++; 600 601 if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 602 // The ROB has more instructions it can commit. Its next status 603 // will be active. 604 _nextStatus = Active; 605 606 DynInstPtr inst = rob->readHeadInst(tid); 607 608 DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %s is head of" 609 " ROB and ready to commit\n", 610 tid, inst->seqNum, inst->pcState()); 611 612 } else if (!rob->isEmpty(tid)) { 613 DynInstPtr inst = rob->readHeadInst(tid); 614 615 DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 616 "%s is head of ROB and not ready\n", 617 tid, inst->seqNum, inst->pcState()); 618 } 619 620 DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 621 tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 622 } 623 624 625 if (wroteToTimeBuffer) { 626 DPRINTF(Activity, "Activity This Cycle.\n"); 627 cpu->activityThisCycle(); 628 } 629 630 updateStatus(); 631} 632 633#if FULL_SYSTEM 634template <class Impl> 635void 636DefaultCommit<Impl>::handleInterrupt() 637{ 638 if (interrupt != NoFault) { 639 // Wait until the ROB is empty and all stores have drained in 640 // order to enter the interrupt. 641 if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 642 // Squash or record that I need to squash this cycle if 643 // an interrupt needed to be handled. 644 DPRINTF(Commit, "Interrupt detected.\n"); 645 646 // Clear the interrupt now that it's going to be handled 647 toIEW->commitInfo[0].clearInterrupt = true; 648 649 assert(!thread[0]->inSyscall); 650 thread[0]->inSyscall = true; 651 652 // CPU will handle interrupt. 653 cpu->processInterrupts(interrupt); 654 655 thread[0]->inSyscall = false; 656 657 commitStatus[0] = TrapPending; 658 659 // Generate trap squash event. 660 generateTrapEvent(0); 661 662 interrupt = NoFault; 663 } else { 664 DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 665 } 666 } else if (commitStatus[0] != TrapPending && 667 cpu->checkInterrupts(cpu->tcBase(0)) && 668 !trapSquash[0] && 669 !tcSquash[0]) { 670 // Process interrupts if interrupts are enabled, not in PAL 671 // mode, and no other traps or external squashes are currently 672 // pending. 673 // @todo: Allow other threads to handle interrupts. 674 675 // Get any interrupt that happened 676 interrupt = cpu->getInterrupts(); 677 678 if (interrupt != NoFault) { 679 // Tell fetch that there is an interrupt pending. This 680 // will make fetch wait until it sees a non PAL-mode PC, 681 // at which point it stops fetching instructions. 682 toIEW->commitInfo[0].interruptPending = true; 683 } 684 } 685} 686#endif // FULL_SYSTEM 687 688template <class Impl> 689void 690DefaultCommit<Impl>::commit() 691{ 692 693#if FULL_SYSTEM 694 // Check for any interrupt, and start processing it. Or if we 695 // have an outstanding interrupt and are at a point when it is 696 // valid to take an interrupt, process it. 697 if (cpu->checkInterrupts(cpu->tcBase(0))) { 698 handleInterrupt(); 699 } 700#endif // FULL_SYSTEM 701 702 //////////////////////////////////// 703 // Check for any possible squashes, handle them first 704 //////////////////////////////////// 705 list<ThreadID>::iterator threads = activeThreads->begin(); 706 list<ThreadID>::iterator end = activeThreads->end(); 707 708 while (threads != end) { 709 ThreadID tid = *threads++; 710 711 // Not sure which one takes priority. I think if we have 712 // both, that's a bad sign. 713 if (trapSquash[tid] == true) { 714 assert(!tcSquash[tid]); 715 squashFromTrap(tid); 716 } else if (tcSquash[tid] == true) { 717 assert(commitStatus[tid] != TrapPending); 718 squashFromTC(tid); 719 } 720 721 // Squashed sequence number must be older than youngest valid 722 // instruction in the ROB. This prevents squashes from younger 723 // instructions overriding squashes from older instructions. 724 if (fromIEW->squash[tid] && 725 commitStatus[tid] != TrapPending && 726 fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 727 728 DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n", 729 tid, 730 fromIEW->mispredPC[tid], 731 fromIEW->squashedSeqNum[tid]); 732 733 DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 734 tid, 735 fromIEW->pc[tid].nextInstAddr()); 736 737 commitStatus[tid] = ROBSquashing; 738 739 // If we want to include the squashing instruction in the squash, 740 // then use one older sequence number. 741 InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 742 743 if (fromIEW->includeSquashInst[tid] == true) { 744 squashed_inst--; 745 } 746 747 // All younger instructions will be squashed. Set the sequence 748 // number as the youngest instruction in the ROB. 749 youngestSeqNum[tid] = squashed_inst; 750 751 rob->squash(squashed_inst, tid); 752 changedROBNumEntries[tid] = true; 753 754 toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 755 756 toIEW->commitInfo[tid].squash = true; 757 758 // Send back the rob squashing signal so other stages know that 759 // the ROB is in the process of squashing. 760 toIEW->commitInfo[tid].robSquashing = true; 761 762 toIEW->commitInfo[tid].branchMispredict = 763 fromIEW->branchMispredict[tid]; 764 765 toIEW->commitInfo[tid].branchTaken = 766 fromIEW->branchTaken[tid]; 767 768 toIEW->commitInfo[tid].pc = fromIEW->pc[tid]; 769 770 toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid]; 771 772 if (toIEW->commitInfo[tid].branchMispredict) { 773 ++branchMispredicts; 774 } 775 } 776 777 } 778 779 setNextStatus(); 780 781 if (squashCounter != numThreads) { 782 // If we're not currently squashing, then get instructions. 783 getInsts(); 784 785 // Try to commit any instructions. 786 commitInsts(); 787 } 788 789 //Check for any activity 790 threads = activeThreads->begin(); 791 792 while (threads != end) { 793 ThreadID tid = *threads++; 794 795 if (changedROBNumEntries[tid]) { 796 toIEW->commitInfo[tid].usedROB = true; 797 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 798 799 wroteToTimeBuffer = true; 800 changedROBNumEntries[tid] = false; 801 if (rob->isEmpty(tid)) 802 checkEmptyROB[tid] = true; 803 } 804 805 // ROB is only considered "empty" for previous stages if: a) 806 // ROB is empty, b) there are no outstanding stores, c) IEW 807 // stage has received any information regarding stores that 808 // committed. 809 // c) is checked by making sure to not consider the ROB empty 810 // on the same cycle as when stores have been committed. 811 // @todo: Make this handle multi-cycle communication between 812 // commit and IEW. 813 if (checkEmptyROB[tid] && rob->isEmpty(tid) && 814 !iewStage->hasStoresToWB(tid) && !committedStores[tid]) { 815 checkEmptyROB[tid] = false; 816 toIEW->commitInfo[tid].usedROB = true; 817 toIEW->commitInfo[tid].emptyROB = true; 818 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 819 wroteToTimeBuffer = true; 820 } 821 822 } 823} 824 825template <class Impl> 826void 827DefaultCommit<Impl>::commitInsts() 828{ 829 //////////////////////////////////// 830 // Handle commit 831 // Note that commit will be handled prior to putting new 832 // instructions in the ROB so that the ROB only tries to commit 833 // instructions it has in this current cycle, and not instructions 834 // it is writing in during this cycle. Can't commit and squash 835 // things at the same time... 836 //////////////////////////////////// 837 838 DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 839 840 unsigned num_committed = 0; 841 842 DynInstPtr head_inst; 843 844 // Commit as many instructions as possible until the commit bandwidth 845 // limit is reached, or it becomes impossible to commit any more. 846 while (num_committed < commitWidth) { 847 int commit_thread = getCommittingThread(); 848 849 if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 850 break; 851 852 head_inst = rob->readHeadInst(commit_thread); 853 854 ThreadID tid = head_inst->threadNumber; 855 856 assert(tid == commit_thread); 857 858 DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 859 head_inst->seqNum, tid); 860 861 // If the head instruction is squashed, it is ready to retire 862 // (be removed from the ROB) at any time. 863 if (head_inst->isSquashed()) { 864 865 DPRINTF(Commit, "Retiring squashed instruction from " 866 "ROB.\n"); 867 868 rob->retireHead(commit_thread); 869 870 ++commitSquashedInsts; 871 872 // Record that the number of ROB entries has changed. 873 changedROBNumEntries[tid] = true; 874 } else { 875 pc[tid] = head_inst->pcState(); 876 877 // Increment the total number of non-speculative instructions 878 // executed. 879 // Hack for now: it really shouldn't happen until after the 880 // commit is deemed to be successful, but this count is needed 881 // for syscalls. 882 thread[tid]->funcExeInst++; 883 884 // Try to commit the head instruction. 885 bool commit_success = commitHead(head_inst, num_committed); 886 887 if (commit_success) { 888 ++num_committed; 889 890 changedROBNumEntries[tid] = true; 891 892 // Set the doneSeqNum to the youngest committed instruction. 893 toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 894 895 ++commitCommittedInsts; 896 897 // To match the old model, don't count nops and instruction 898 // prefetches towards the total commit count. 899 if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 900 cpu->instDone(tid); 901 } 902 903 TheISA::advancePC(pc[tid], head_inst->staticInst); 904 905 int count = 0; 906 Addr oldpc; 907 // Debug statement. Checks to make sure we're not 908 // currently updating state while handling PC events. 909 assert(!thread[tid]->inSyscall && !thread[tid]->trapPending); 910 do { 911 oldpc = pc[tid].instAddr(); 912 cpu->system->pcEventQueue.service(thread[tid]->getTC()); 913 count++; 914 } while (oldpc != pc[tid].instAddr()); 915 if (count > 1) { 916 DPRINTF(Commit, 917 "PC skip function event, stopping commit\n"); 918 break; 919 } 920 } else { 921 DPRINTF(Commit, "Unable to commit head instruction PC:%s " 922 "[tid:%i] [sn:%i].\n", 923 head_inst->pcState(), tid ,head_inst->seqNum); 924 break; 925 } 926 } 927 } 928 929 DPRINTF(CommitRate, "%i\n", num_committed); 930 numCommittedDist.sample(num_committed); 931 932 if (num_committed == commitWidth) { 933 commitEligibleSamples++; 934 } 935} 936 937template <class Impl> 938bool 939DefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 940{ 941 assert(head_inst); 942 943 ThreadID tid = head_inst->threadNumber; 944 945 // If the instruction is not executed yet, then it will need extra 946 // handling. Signal backwards that it should be executed. 947 if (!head_inst->isExecuted()) { 948 // Keep this number correct. We have not yet actually executed 949 // and committed this instruction. 950 thread[tid]->funcExeInst--; 951 952 if (head_inst->isNonSpeculative() || 953 head_inst->isStoreConditional() || 954 head_inst->isMemBarrier() || 955 head_inst->isWriteBarrier()) { 956 957 DPRINTF(Commit, "Encountered a barrier or non-speculative " 958 "instruction [sn:%lli] at the head of the ROB, PC %s.\n", 959 head_inst->seqNum, head_inst->pcState()); 960 961 if (inst_num > 0 || iewStage->hasStoresToWB(tid)) { 962 DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 963 return false; 964 } 965 966 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 967 968 // Change the instruction so it won't try to commit again until 969 // it is executed. 970 head_inst->clearCanCommit(); 971 972 ++commitNonSpecStalls; 973 974 return false; 975 } else if (head_inst->isLoad()) { 976 if (inst_num > 0 || iewStage->hasStoresToWB(tid)) { 977 DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 978 return false; 979 } 980 981 assert(head_inst->uncacheable()); 982 DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %s.\n", 983 head_inst->seqNum, head_inst->pcState()); 984 985 // Send back the non-speculative instruction's sequence 986 // number. Tell the lsq to re-execute the load. 987 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 988 toIEW->commitInfo[tid].uncached = true; 989 toIEW->commitInfo[tid].uncachedLoad = head_inst; 990 991 head_inst->clearCanCommit(); 992 993 return false; 994 } else { 995 panic("Trying to commit un-executed instruction " 996 "of unknown type!\n"); 997 } 998 } 999 1000 if (head_inst->isThreadSync()) { 1001 // Not handled for now. 1002 panic("Thread sync instructions are not handled yet.\n"); 1003 } 1004 1005 // Check if the instruction caused a fault. If so, trap. 1006 Fault inst_fault = head_inst->getFault(); 1007 1008 // Stores mark themselves as completed. 1009 if (!head_inst->isStore() && inst_fault == NoFault) { 1010 head_inst->setCompleted(); 1011 } 1012 1013#if USE_CHECKER 1014 // Use checker prior to updating anything due to traps or PC 1015 // based events. 1016 if (cpu->checker) { 1017 cpu->checker->verify(head_inst); 1018 } 1019#endif 1020 1021 if (inst_fault != NoFault) { 1022 DPRINTF(Commit, "Inst [sn:%lli] PC %s has a fault\n", 1023 head_inst->seqNum, head_inst->pcState()); 1024 1025 if (iewStage->hasStoresToWB(tid) || inst_num > 0) { 1026 DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 1027 return false; 1028 } 1029 1030 head_inst->setCompleted(); 1031 1032#if USE_CHECKER 1033 if (cpu->checker && head_inst->isStore()) { 1034 cpu->checker->verify(head_inst); 1035 } 1036#endif 1037 1038 assert(!thread[tid]->inSyscall); 1039 1040 // Mark that we're in state update mode so that the trap's 1041 // execution doesn't generate extra squashes. 1042 thread[tid]->inSyscall = true; 1043 1044 // Execute the trap. Although it's slightly unrealistic in 1045 // terms of timing (as it doesn't wait for the full timing of 1046 // the trap event to complete before updating state), it's 1047 // needed to update the state as soon as possible. This 1048 // prevents external agents from changing any specific state 1049 // that the trap need. 1050 cpu->trap(inst_fault, tid, head_inst->staticInst); 1051 1052 // Exit state update mode to avoid accidental updating. 1053 thread[tid]->inSyscall = false; 1054 1055 commitStatus[tid] = TrapPending; 1056 1057 if (head_inst->traceData) { 1058 if (DTRACE(ExecFaulting)) { 1059 head_inst->traceData->setFetchSeq(head_inst->seqNum); 1060 head_inst->traceData->setCPSeq(thread[tid]->numInst); 1061 head_inst->traceData->dump(); 1062 } 1063 delete head_inst->traceData; 1064 head_inst->traceData = NULL; 1065 } 1066 1067 // Generate trap squash event. 1068 generateTrapEvent(tid); 1069 return false; 1070 } 1071 1072 updateComInstStats(head_inst); 1073 1074#if FULL_SYSTEM 1075 if (thread[tid]->profile) { 1076 thread[tid]->profilePC = head_inst->instAddr(); 1077 ProfileNode *node = thread[tid]->profile->consume(thread[tid]->getTC(), 1078 head_inst->staticInst); 1079 1080 if (node) 1081 thread[tid]->profileNode = node; 1082 } 1083 if (CPA::available()) { 1084 if (head_inst->isControl()) { 1085 ThreadContext *tc = thread[tid]->getTC(); 1086 CPA::cpa()->swAutoBegin(tc, head_inst->nextInstAddr()); 1087 } 1088 } 1089#endif 1090 1091 if (head_inst->traceData) { 1092 head_inst->traceData->setFetchSeq(head_inst->seqNum); 1093 head_inst->traceData->setCPSeq(thread[tid]->numInst); 1094 head_inst->traceData->dump(); 1095 delete head_inst->traceData; 1096 head_inst->traceData = NULL; 1097 } 1098 1099 // Update the commit rename map 1100 for (int i = 0; i < head_inst->numDestRegs(); i++) { 1101 renameMap[tid]->setEntry(head_inst->flattenedDestRegIdx(i), 1102 head_inst->renamedDestRegIdx(i)); 1103 } 1104 1105 if (head_inst->isCopy()) 1106 panic("Should not commit any copy instructions!"); 1107 1108 // Finally clear the head ROB entry. 1109 rob->retireHead(tid); 1110 1111 // If this was a store, record it for this cycle. 1112 if (head_inst->isStore()) 1113 committedStores[tid] = true; 1114 1115 // Return true to indicate that we have committed an instruction. 1116 return true; 1117} 1118 1119template <class Impl> 1120void 1121DefaultCommit<Impl>::getInsts() 1122{ 1123 DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 1124 1125 // Read any renamed instructions and place them into the ROB. 1126 int insts_to_process = std::min((int)renameWidth, fromRename->size); 1127 1128 for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 1129 DynInstPtr inst; 1130 1131 inst = fromRename->insts[inst_num]; 1132 ThreadID tid = inst->threadNumber; 1133 1134 if (!inst->isSquashed() && 1135 commitStatus[tid] != ROBSquashing && 1136 commitStatus[tid] != TrapPending) { 1137 changedROBNumEntries[tid] = true; 1138 1139 DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ROB.\n", 1140 inst->pcState(), inst->seqNum, tid); 1141 1142 rob->insertInst(inst); 1143 1144 assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 1145 1146 youngestSeqNum[tid] = inst->seqNum; 1147 } else { 1148 DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 1149 "squashed, skipping.\n", 1150 inst->pcState(), inst->seqNum, tid); 1151 } 1152 } 1153} 1154 1155template <class Impl> 1156void 1157DefaultCommit<Impl>::skidInsert() 1158{ 1159 DPRINTF(Commit, "Attempting to any instructions from rename into " 1160 "skidBuffer.\n"); 1161 1162 for (int inst_num = 0; inst_num < fromRename->size; ++inst_num) { 1163 DynInstPtr inst = fromRename->insts[inst_num]; 1164 1165 if (!inst->isSquashed()) { 1166 DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ", 1167 "skidBuffer.\n", inst->pcState(), inst->seqNum, 1168 inst->threadNumber); 1169 skidBuffer.push(inst); 1170 } else { 1171 DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 1172 "squashed, skipping.\n", 1173 inst->pcState(), inst->seqNum, inst->threadNumber); 1174 } 1175 } 1176} 1177 1178template <class Impl> 1179void 1180DefaultCommit<Impl>::markCompletedInsts() 1181{ 1182 // Grab completed insts out of the IEW instruction queue, and mark 1183 // instructions completed within the ROB. 1184 for (int inst_num = 0; 1185 inst_num < fromIEW->size && fromIEW->insts[inst_num]; 1186 ++inst_num) 1187 { 1188 if (!fromIEW->insts[inst_num]->isSquashed()) { 1189 DPRINTF(Commit, "[tid:%i]: Marking PC %s, [sn:%lli] ready " 1190 "within ROB.\n", 1191 fromIEW->insts[inst_num]->threadNumber, 1192 fromIEW->insts[inst_num]->pcState(), 1193 fromIEW->insts[inst_num]->seqNum); 1194 1195 // Mark the instruction as ready to commit. 1196 fromIEW->insts[inst_num]->setCanCommit(); 1197 } 1198 } 1199} 1200 1201template <class Impl> 1202bool 1203DefaultCommit<Impl>::robDoneSquashing() 1204{ 1205 list<ThreadID>::iterator threads = activeThreads->begin(); 1206 list<ThreadID>::iterator end = activeThreads->end(); 1207 1208 while (threads != end) { 1209 ThreadID tid = *threads++; 1210 1211 if (!rob->isDoneSquashing(tid)) 1212 return false; 1213 } 1214 1215 return true; 1216} 1217 1218template <class Impl> 1219void 1220DefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 1221{ 1222 ThreadID tid = inst->threadNumber; 1223 1224 // 1225 // Pick off the software prefetches 1226 // 1227#ifdef TARGET_ALPHA 1228 if (inst->isDataPrefetch()) { 1229 statComSwp[tid]++; 1230 } else { 1231 statComInst[tid]++; 1232 } 1233#else 1234 statComInst[tid]++; 1235#endif 1236 1237 // 1238 // Control Instructions 1239 // 1240 if (inst->isControl()) 1241 statComBranches[tid]++; 1242 1243 // 1244 // Memory references 1245 // 1246 if (inst->isMemRef()) { 1247 statComRefs[tid]++; 1248 1249 if (inst->isLoad()) { 1250 statComLoads[tid]++; 1251 } 1252 } 1253 1254 if (inst->isMemBarrier()) { 1255 statComMembars[tid]++; 1256 } 1257} 1258 1259//////////////////////////////////////// 1260// // 1261// SMT COMMIT POLICY MAINTAINED HERE // 1262// // 1263//////////////////////////////////////// 1264template <class Impl> 1265ThreadID 1266DefaultCommit<Impl>::getCommittingThread() 1267{ 1268 if (numThreads > 1) { 1269 switch (commitPolicy) { 1270 1271 case Aggressive: 1272 //If Policy is Aggressive, commit will call 1273 //this function multiple times per 1274 //cycle 1275 return oldestReady(); 1276 1277 case RoundRobin: 1278 return roundRobin(); 1279 1280 case OldestReady: 1281 return oldestReady(); 1282 1283 default: 1284 return InvalidThreadID; 1285 } 1286 } else { 1287 assert(!activeThreads->empty()); 1288 ThreadID tid = activeThreads->front(); 1289 1290 if (commitStatus[tid] == Running || 1291 commitStatus[tid] == Idle || 1292 commitStatus[tid] == FetchTrapPending) { 1293 return tid; 1294 } else { 1295 return InvalidThreadID; 1296 } 1297 } 1298} 1299 1300template<class Impl> 1301ThreadID 1302DefaultCommit<Impl>::roundRobin() 1303{ 1304 list<ThreadID>::iterator pri_iter = priority_list.begin(); 1305 list<ThreadID>::iterator end = priority_list.end(); 1306 1307 while (pri_iter != end) { 1308 ThreadID tid = *pri_iter; 1309 1310 if (commitStatus[tid] == Running || 1311 commitStatus[tid] == Idle || 1312 commitStatus[tid] == FetchTrapPending) { 1313 1314 if (rob->isHeadReady(tid)) { 1315 priority_list.erase(pri_iter); 1316 priority_list.push_back(tid); 1317 1318 return tid; 1319 } 1320 } 1321 1322 pri_iter++; 1323 } 1324 1325 return InvalidThreadID; 1326} 1327 1328template<class Impl> 1329ThreadID 1330DefaultCommit<Impl>::oldestReady() 1331{ 1332 unsigned oldest = 0; 1333 bool first = true; 1334 1335 list<ThreadID>::iterator threads = activeThreads->begin(); 1336 list<ThreadID>::iterator end = activeThreads->end(); 1337 1338 while (threads != end) { 1339 ThreadID tid = *threads++; 1340 1341 if (!rob->isEmpty(tid) && 1342 (commitStatus[tid] == Running || 1343 commitStatus[tid] == Idle || 1344 commitStatus[tid] == FetchTrapPending)) { 1345 1346 if (rob->isHeadReady(tid)) { 1347 1348 DynInstPtr head_inst = rob->readHeadInst(tid); 1349 1350 if (first) { 1351 oldest = tid; 1352 first = false; 1353 } else if (head_inst->seqNum < oldest) { 1354 oldest = tid; 1355 } 1356 } 1357 } 1358 } 1359 1360 if (!first) { 1361 return oldest; 1362 } else { 1363 return InvalidThreadID; 1364 } 1365} 1366