commit_impl.hh revision 2348
11689SN/A/* 22316SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292965Sksewell@umich.edu#include <algorithm> 301689SN/A#include <string> 311689SN/A 322733Sktlim@umich.edu#include "base/loader/symtab.hh" 332733Sktlim@umich.edu#include "base/timebuf.hh" 342733Sktlim@umich.edu#include "cpu/checker/cpu.hh" 352292SN/A#include "cpu/exetrace.hh" 362329SN/A#include "cpu/o3/commit.hh" 372292SN/A#include "cpu/o3/thread_state.hh" 383577Sgblack@eecs.umich.edu 392292SN/Ausing namespace std; 401060SN/A 412292SN/Atemplate <class Impl> 421717SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 432292SN/A unsigned _tid) 442292SN/A : Event(&mainEventQueue, CPU_Tick_Pri), commit(_commit), tid(_tid) 452790Sktlim@umich.edu{ 462790Sktlim@umich.edu this->setFlags(Event::AutoDelete); 472790Sktlim@umich.edu} 482790Sktlim@umich.edu 491061SN/Atemplate <class Impl> 502292SN/Avoid 512292SN/ADefaultCommit<Impl>::TrapEvent::process() 522292SN/A{ 531060SN/A // This will get reset by commit if it was switched out at the 542292SN/A // time of this event processing. 551060SN/A commit->trapSquash[tid] = true; 561060SN/A} 571061SN/A 581060SN/Atemplate <class Impl> 592292SN/Aconst char * 601062SN/ADefaultCommit<Impl>::TrapEvent::description() 612316SN/A{ 622316SN/A return "Trap event"; 632292SN/A} 642292SN/A 652292SN/Atemplate <class Impl> 662292SN/ADefaultCommit<Impl>::DefaultCommit(Params *params) 672292SN/A : dcacheInterface(params->dcacheInterface), 685336Shines@cs.fsu.edu squashCounter(0), 692292SN/A iewToCommitDelay(params->iewToCommitDelay), 704873Sstever@eecs.umich.edu commitToIEWDelay(params->commitToIEWDelay), 712292SN/A renameToROBDelay(params->renameToROBDelay), 722292SN/A fetchToCommitDelay(params->commitToFetchDelay), 732292SN/A renameWidth(params->renameWidth), 744329Sktlim@umich.edu iewWidth(params->executeWidth), 754329Sktlim@umich.edu commitWidth(params->commitWidth), 764329Sktlim@umich.edu numThreads(params->numberOfThreads), 772292SN/A switchedOut(false), 782292SN/A trapLatency(params->trapLatency), 792292SN/A fetchTrapLatency(params->fetchTrapLatency) 802292SN/A{ 812292SN/A _status = Active; 822292SN/A _nextStatus = Inactive; 832307SN/A string policy = params->smtCommitPolicy; 842843Sktlim@umich.edu 852316SN/A //Convert string to lowercase 862874Sktlim@umich.edu std::transform(policy.begin(), policy.end(), policy.begin(), 872292SN/A (int(*)(int)) tolower); 882292SN/A 892292SN/A //Assign commit policy 902980Sgblack@eecs.umich.edu if (policy == "aggressive"){ 912292SN/A commitPolicy = Aggressive; 922292SN/A 932292SN/A DPRINTF(Commit,"Commit Policy set to Aggressive."); 942292SN/A } else if (policy == "roundrobin"){ 952292SN/A commitPolicy = RoundRobin; 962292SN/A 972292SN/A //Set-Up Priority List 982292SN/A for (int tid=0; tid < numThreads; tid++) { 992292SN/A priority_list.push_back(tid); 1004329Sktlim@umich.edu } 1012292SN/A 1022292SN/A DPRINTF(Commit,"Commit Policy set to Round Robin."); 1032292SN/A } else if (policy == "oldestready"){ 1042292SN/A commitPolicy = OldestReady; 1052292SN/A 1062292SN/A DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1072292SN/A } else { 1082292SN/A assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1094329Sktlim@umich.edu "RoundRobin,OldestReady}"); 1102292SN/A } 1112292SN/A 1122292SN/A for (int i=0; i < numThreads; i++) { 1134329Sktlim@umich.edu commitStatus[i] = Idle; 1142292SN/A changedROBNumEntries[i] = false; 1152292SN/A trapSquash[i] = false; 1162292SN/A xcSquash[i] = false; 1172292SN/A } 1182292SN/A 1192292SN/A fetchFaultTick = 0; 1202292SN/A fetchTrapWait = 0; 1212292SN/A} 1224035Sktlim@umich.edu 1234035Sktlim@umich.edutemplate <class Impl> 1244035Sktlim@umich.edustd::string 1252292SN/ADefaultCommit<Impl>::name() const 1262680Sktlim@umich.edu{ 1274636Sgblack@eecs.umich.edu return cpu->name() + ".commit"; 1282292SN/A} 1293640Sktlim@umich.edu 1303640Sktlim@umich.edutemplate <class Impl> 1313640Sktlim@umich.eduvoid 1322292SN/ADefaultCommit<Impl>::regStats() 1332292SN/A{ 1342292SN/A using namespace Stats; 1352292SN/A commitCommittedInsts 1362292SN/A .name(name() + ".commitCommittedInsts") 1372292SN/A .desc("The number of committed instructions") 1382292SN/A .prereq(commitCommittedInsts); 1392292SN/A commitSquashedInsts 1402292SN/A .name(name() + ".commitSquashedInsts") 1412292SN/A .desc("The number of squashed insts skipped by commit") 1422292SN/A .prereq(commitSquashedInsts); 1432292SN/A commitSquashEvents 1442132SN/A .name(name() + ".commitSquashEvents") 1452301SN/A .desc("The number of times commit is told to squash") 1461062SN/A .prereq(commitSquashEvents); 1471062SN/A commitNonSpecStalls 1481062SN/A .name(name() + ".commitNonSpecStalls") 1491062SN/A .desc("The number of times commit has been forced to stall to " 1501062SN/A "communicate backwards") 1511062SN/A .prereq(commitNonSpecStalls); 1521062SN/A branchMispredicts 1531062SN/A .name(name() + ".branchMispredicts") 1541062SN/A .desc("The number of times a branch was mispredicted") 1551062SN/A .prereq(branchMispredicts); 1561062SN/A numCommittedDist 1571062SN/A .init(0,commitWidth,1) 1581062SN/A .name(name() + ".COM:committed_per_cycle") 1591062SN/A .desc("Number of insts commited each cycle") 1601062SN/A .flags(Stats::pdf) 1611062SN/A ; 1621062SN/A 1631062SN/A statComInst 1641062SN/A .init(cpu->number_of_threads) 1651062SN/A .name(name() + ".COM:count") 1661062SN/A .desc("Number of instructions committed") 1672292SN/A .flags(total) 1681062SN/A ; 1691062SN/A 1701062SN/A statComSwp 1711062SN/A .init(cpu->number_of_threads) 1721062SN/A .name(name() + ".COM:swp_count") 1732301SN/A .desc("Number of s/w prefetches committed") 1742316SN/A .flags(total) 1752301SN/A ; 1762301SN/A 1772301SN/A statComRefs 1782301SN/A .init(cpu->number_of_threads) 1792301SN/A .name(name() + ".COM:refs") 1802301SN/A .desc("Number of memory references committed") 1812316SN/A .flags(total) 1822301SN/A ; 1832301SN/A 1842301SN/A statComLoads 1852301SN/A .init(cpu->number_of_threads) 1862301SN/A .name(name() + ".COM:loads") 1872301SN/A .desc("Number of loads committed") 1882316SN/A .flags(total) 1892301SN/A ; 1902301SN/A 1912301SN/A statComMembars 1922301SN/A .init(cpu->number_of_threads) 1932301SN/A .name(name() + ".COM:membars") 1942301SN/A .desc("Number of memory barriers committed") 1952316SN/A .flags(total) 1962301SN/A ; 1972301SN/A 1982301SN/A statComBranches 1992301SN/A .init(cpu->number_of_threads) 2002301SN/A .name(name() + ".COM:branches") 2012301SN/A .desc("Number of branches committed") 2022316SN/A .flags(total) 2032301SN/A ; 2042301SN/A 2052301SN/A // 2062301SN/A // Commit-Eligible instructions... 2072301SN/A // 2082301SN/A // -> The number of instructions eligible to commit in those 2092316SN/A // cycles where we reached our commit BW limit (less the number 2102301SN/A // actually committed) 2112301SN/A // 2122301SN/A // -> The average value is computed over ALL CYCLES... not just 2132301SN/A // the BW limited cycles 2142301SN/A // 2152301SN/A // -> The standard deviation is computed only over cycles where 2162316SN/A // we reached the BW limit 2172301SN/A // 2182301SN/A commitEligible 2192301SN/A .init(cpu->number_of_threads) 2202301SN/A .name(name() + ".COM:bw_limited") 2212301SN/A .desc("number of insts not committed due to BW limits") 2222301SN/A .flags(total) 2232316SN/A ; 2242301SN/A 2252301SN/A commitEligibleSamples 2262301SN/A .name(name() + ".COM:bw_lim_events") 2271062SN/A .desc("number cycles where commit BW limit reached") 2281062SN/A ; 2291062SN/A} 2301062SN/A 2312980Sgblack@eecs.umich.edutemplate <class Impl> 2322292SN/Avoid 2332292SN/ADefaultCommit<Impl>::setCPU(FullCPU *cpu_ptr) 2342292SN/A{ 2352292SN/A DPRINTF(Commit, "Commit: Setting CPU pointer.\n"); 2362292SN/A cpu = cpu_ptr; 2372292SN/A 2382292SN/A // Commit must broadcast the number of free entries it has at the start of 2391060SN/A // the simulation, so it starts as active. 2401060SN/A cpu->activateStage(FullCPU::CommitIdx); 2411060SN/A 2421060SN/A trapLatency = cpu->cycles(trapLatency); 2431060SN/A fetchTrapLatency = cpu->cycles(fetchTrapLatency); 2441060SN/A} 2451060SN/A 2461060SN/Atemplate <class Impl> 2471060SN/Avoid 2481060SN/ADefaultCommit<Impl>::setThreads(vector<Thread *> &threads) 2491061SN/A{ 2501060SN/A thread = threads; 2512292SN/A} 2522292SN/A 2532292SN/Atemplate <class Impl> 2542292SN/Avoid 2552292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 2562292SN/A{ 2572292SN/A DPRINTF(Commit, "Commit: Setting time buffer pointer.\n"); 2582292SN/A timeBuffer = tb_ptr; 2592292SN/A 2602292SN/A // Setup wire to send information back to IEW. 2612292SN/A toIEW = timeBuffer->getWire(0); 2621060SN/A 2631060SN/A // Setup wire to read data from IEW (for the ROB). 2641060SN/A robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 2651060SN/A} 2661060SN/A 2671060SN/Atemplate <class Impl> 2681060SN/Avoid 2691061SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 2701060SN/A{ 2712292SN/A DPRINTF(Commit, "Commit: Setting fetch queue pointer.\n"); 2721060SN/A fetchQueue = fq_ptr; 2731060SN/A 2741060SN/A // Setup wire to get instructions from rename (for the ROB). 2751060SN/A fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 2761060SN/A} 2771060SN/A 2781060SN/Atemplate <class Impl> 2791061SN/Avoid 2801060SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 2812292SN/A{ 2822292SN/A DPRINTF(Commit, "Commit: Setting rename queue pointer.\n"); 2832292SN/A renameQueue = rq_ptr; 2842292SN/A 2852292SN/A // Setup wire to get instructions from rename (for the ROB). 2862292SN/A fromRename = renameQueue->getWire(-renameToROBDelay); 2872292SN/A} 2882980Sgblack@eecs.umich.edu 2892292SN/Atemplate <class Impl> 2902292SN/Avoid 2912292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 2922292SN/A{ 2932292SN/A DPRINTF(Commit, "Commit: Setting IEW queue pointer.\n"); 2942292SN/A iewQueue = iq_ptr; 2952292SN/A 2962292SN/A // Setup wire to get instructions from IEW. 2972292SN/A fromIEW = iewQueue->getWire(-iewToCommitDelay); 2982292SN/A} 2992292SN/A 3002292SN/Atemplate <class Impl> 3012292SN/Avoid 3022292SN/ADefaultCommit<Impl>::setFetchStage(Fetch *fetch_stage) 3032292SN/A{ 3042292SN/A fetchStage = fetch_stage; 3051060SN/A} 3061060SN/A 3071060SN/Atemplate <class Impl> 3081060SN/Avoid 3091061SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 3101060SN/A{ 3112292SN/A iewStage = iew_stage; 3121060SN/A} 3132292SN/A 3142292SN/Atemplate<class Impl> 3151060SN/Avoid 3162292SN/ADefaultCommit<Impl>::setActiveThreads(list<unsigned> *at_ptr) 3172292SN/A{ 3182292SN/A DPRINTF(Commit, "Commit: Setting active threads list pointer.\n"); 3192292SN/A activeThreads = at_ptr; 3204035Sktlim@umich.edu} 3211060SN/A 3221060SN/Atemplate <class Impl> 3234329Sktlim@umich.eduvoid 3244329Sktlim@umich.eduDefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3254329Sktlim@umich.edu{ 3264329Sktlim@umich.edu DPRINTF(Commit, "Setting rename map pointers.\n"); 3272292SN/A 3285100Ssaidi@eecs.umich.edu for (int i=0; i < numThreads; i++) { 3291060SN/A renameMap[i] = &rm_ptr[i]; 3301060SN/A } 3311061SN/A} 3322863Sktlim@umich.edu 3332843Sktlim@umich.edutemplate <class Impl> 3341060SN/Avoid 3352843Sktlim@umich.eduDefaultCommit<Impl>::setROB(ROB *rob_ptr) 3362863Sktlim@umich.edu{ 3372863Sktlim@umich.edu DPRINTF(Commit, "Commit: Setting ROB pointer.\n"); 3382316SN/A rob = rob_ptr; 3392316SN/A} 3402316SN/A 3412316SN/Atemplate <class Impl> 3422843Sktlim@umich.eduvoid 3432316SN/ADefaultCommit<Impl>::initStage() 3442316SN/A{ 3452843Sktlim@umich.edu rob->setActiveThreads(activeThreads); 3462307SN/A rob->resetEntries(); 3472307SN/A 3482307SN/A // Broadcast the number of free entries. 3492307SN/A for (int i=0; i < numThreads; i++) { 3502307SN/A toIEW->commitInfo[i].usedROB = true; 3512843Sktlim@umich.edu toIEW->commitInfo[i].freeROBEntries = rob->numFreeEntries(i); 3522843Sktlim@umich.edu } 3532864Sktlim@umich.edu 3542843Sktlim@umich.edu cpu->activityThisCycle(); 3552843Sktlim@umich.edu} 3562843Sktlim@umich.edu 3572843Sktlim@umich.edutemplate <class Impl> 3582307SN/Avoid 3592307SN/ADefaultCommit<Impl>::switchOut() 3602316SN/A{ 3612307SN/A switchPending = true; 3622307SN/A} 3632307SN/A 3642307SN/Atemplate <class Impl> 3652307SN/Avoid 3662307SN/ADefaultCommit<Impl>::doSwitchOut() 3672680Sktlim@umich.edu{ 3682307SN/A switchedOut = true; 3692307SN/A switchPending = false; 3702307SN/A rob->switchOut(); 3712307SN/A} 3722307SN/A 3732307SN/Atemplate <class Impl> 3742307SN/Avoid 3752292SN/ADefaultCommit<Impl>::takeOverFrom() 3762132SN/A{ 3772316SN/A switchedOut = false; 3783867Sbinkertn@umich.edu _status = Active; 3793867Sbinkertn@umich.edu _nextStatus = Inactive; 3803867Sbinkertn@umich.edu for (int i=0; i < numThreads; i++) { 3813867Sbinkertn@umich.edu commitStatus[i] = Idle; 3822316SN/A changedROBNumEntries[i] = false; 3833867Sbinkertn@umich.edu trapSquash[i] = false; 3842316SN/A xcSquash[i] = false; 3852316SN/A } 3862316SN/A squashCounter = 0; 3872316SN/A rob->takeOverFrom(); 3882316SN/A} 3892316SN/A 3902316SN/Atemplate <class Impl> 3912292SN/Avoid 3922292SN/ADefaultCommit<Impl>::updateStatus() 3932292SN/A{ 3942292SN/A // reset ROB changed variable 3952733Sktlim@umich.edu list<unsigned>::iterator threads = (*activeThreads).begin(); 3962292SN/A while (threads != (*activeThreads).end()) { 3972292SN/A unsigned tid = *threads++; 3982733Sktlim@umich.edu changedROBNumEntries[tid] = false; 3992292SN/A 4002292SN/A // Also check if any of the threads has a trap pending 4012292SN/A if (commitStatus[tid] == TrapPending || 4022292SN/A commitStatus[tid] == FetchTrapPending) { 4032292SN/A _nextStatus = Active; 4042292SN/A } 4052292SN/A } 4062292SN/A 4072292SN/A if (_nextStatus == Inactive && _status == Active) { 4082292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 4092292SN/A cpu->deactivateStage(FullCPU::CommitIdx); 4103867Sbinkertn@umich.edu } else if (_nextStatus == Active && _status == Inactive) { 4113867Sbinkertn@umich.edu DPRINTF(Activity, "Activating stage.\n"); 4122292SN/A cpu->activateStage(FullCPU::CommitIdx); 4133867Sbinkertn@umich.edu } 4142292SN/A 4152292SN/A _status = _nextStatus; 4162292SN/A} 4172292SN/A 4182292SN/Atemplate <class Impl> 4192292SN/Avoid 4202292SN/ADefaultCommit<Impl>::setNextStatus() 4212702Sktlim@umich.edu{ 4222292SN/A int squashes = 0; 4232292SN/A 4242292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 4252292SN/A 4262292SN/A while (threads != (*activeThreads).end()) { 4272292SN/A unsigned tid = *threads++; 4282292SN/A 4292292SN/A if (commitStatus[tid] == ROBSquashing) { 4302292SN/A squashes++; 4312292SN/A } 4322292SN/A } 4332292SN/A 4343867Sbinkertn@umich.edu assert(squashes == squashCounter); 4353867Sbinkertn@umich.edu 4362292SN/A // If commit is currently squashing, then it will have activity for the 4373867Sbinkertn@umich.edu // next cycle. Set its next status as active. 4382292SN/A if (squashCounter) { 4392292SN/A _nextStatus = Active; 4402292SN/A } 4412292SN/A} 4422292SN/A 4432292SN/Atemplate <class Impl> 4442292SN/Abool 4452292SN/ADefaultCommit<Impl>::changedROBEntries() 4462292SN/A{ 4472292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 4482292SN/A 4492292SN/A while (threads != (*activeThreads).end()) { 4502292SN/A unsigned tid = *threads++; 4512292SN/A 4522292SN/A if (changedROBNumEntries[tid]) { 4532292SN/A return true; 4542292SN/A } 4552292SN/A } 4562292SN/A 4572292SN/A return false; 4582292SN/A} 4592292SN/A 4602292SN/Atemplate <class Impl> 4612292SN/Aunsigned 4622292SN/ADefaultCommit<Impl>::numROBFreeEntries(unsigned tid) 4632292SN/A{ 4644035Sktlim@umich.edu return rob->numFreeEntries(tid); 4652292SN/A} 4662292SN/A 4672292SN/Atemplate <class Impl> 4682292SN/Avoid 4692680Sktlim@umich.eduDefaultCommit<Impl>::generateTrapEvent(unsigned tid) 4702292SN/A{ 4714035Sktlim@umich.edu DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 4722680Sktlim@umich.edu 4732292SN/A TrapEvent *trap = new TrapEvent(this, tid); 4742680Sktlim@umich.edu 4752292SN/A trap->schedule(curTick + trapLatency); 4762292SN/A 4772292SN/A thread[tid]->trapPending = true; 4782292SN/A} 4792316SN/A 4802292SN/Atemplate <class Impl> 4812292SN/Avoid 4822292SN/ADefaultCommit<Impl>::generateXCEvent(unsigned tid) 4832292SN/A{ 4842292SN/A DPRINTF(Commit, "Generating XC squash event for [tid:%i]\n", tid); 4852292SN/A 4864035Sktlim@umich.edu xcSquash[tid] = true; 4872292SN/A} 4882292SN/A 4892292SN/Atemplate <class Impl> 4902292SN/Avoid 4912292SN/ADefaultCommit<Impl>::squashAll(unsigned tid) 4922292SN/A{ 4932292SN/A // If we want to include the squashing instruction in the squash, 4942292SN/A // then use one older sequence number. 4952292SN/A // Hopefully this doesn't mess things up. Basically I want to squash 4962292SN/A // all instructions of this thread. 4972292SN/A InstSeqNum squashed_inst = rob->isEmpty() ? 4982292SN/A 0 : rob->readHeadInst(tid)->seqNum - 1;; 4992292SN/A 5002292SN/A // All younger instructions will be squashed. Set the sequence 5012292SN/A // number as the youngest instruction in the ROB (0 in this case. 5022292SN/A // Hopefully nothing breaks.) 5032292SN/A youngestSeqNum[tid] = 0; 5042292SN/A 5052292SN/A rob->squash(squashed_inst, tid); 5062292SN/A changedROBNumEntries[tid] = true; 5072292SN/A 5082292SN/A // Send back the sequence number of the squashed instruction. 5092316SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 5103795Sgblack@eecs.umich.edu 5114636Sgblack@eecs.umich.edu // Send back the squash signal to tell stages that they should 5122316SN/A // squash. 5132292SN/A toIEW->commitInfo[tid].squash = true; 5142316SN/A 5152316SN/A // Send back the rob squashing signal so other stages know that 5162316SN/A // the ROB is in the process of squashing. 5172316SN/A toIEW->commitInfo[tid].robSquashing = true; 5182316SN/A 5192316SN/A toIEW->commitInfo[tid].branchMispredict = false; 5202316SN/A 5212316SN/A toIEW->commitInfo[tid].nextPC = PC[tid]; 5222316SN/A} 5232316SN/A 5244035Sktlim@umich.edutemplate <class Impl> 5252316SN/Avoid 5262316SN/ADefaultCommit<Impl>::squashFromTrap(unsigned tid) 5272316SN/A{ 5282316SN/A squashAll(tid); 5292316SN/A 5302316SN/A DPRINTF(Commit, "Squashing from trap, restarting at PC %#x\n", PC[tid]); 5312316SN/A 5322316SN/A thread[tid]->trapPending = false; 5332316SN/A thread[tid]->inSyscall = false; 5342680Sktlim@umich.edu 5352316SN/A trapSquash[tid] = false; 5362316SN/A 5372292SN/A commitStatus[tid] = ROBSquashing; 5382680Sktlim@umich.edu cpu->activityThisCycle(); 5392292SN/A 5402292SN/A ++squashCounter; 5412292SN/A} 5422316SN/A 5432292SN/Atemplate <class Impl> 5442292SN/Avoid 5452292SN/ADefaultCommit<Impl>::squashFromXC(unsigned tid) 5462680Sktlim@umich.edu{ 5472292SN/A squashAll(tid); 5482292SN/A 5492292SN/A DPRINTF(Commit, "Squashing from XC, restarting at PC %#x\n", PC[tid]); 5502292SN/A 5512292SN/A thread[tid]->inSyscall = false; 5522292SN/A assert(!thread[tid]->trapPending); 5532292SN/A 5542292SN/A commitStatus[tid] = ROBSquashing; 5552292SN/A cpu->activityThisCycle(); 5562843Sktlim@umich.edu 5572843Sktlim@umich.edu xcSquash[tid] = false; 5582843Sktlim@umich.edu 5592316SN/A ++squashCounter; 5602316SN/A} 5612316SN/A 5623867Sbinkertn@umich.edutemplate <class Impl> 5632875Sksewell@umich.eduvoid 5642875Sksewell@umich.eduDefaultCommit<Impl>::tick() 5653867Sbinkertn@umich.edu{ 5663867Sbinkertn@umich.edu wroteToTimeBuffer = false; 5672292SN/A _nextStatus = Inactive; 5682316SN/A 5692316SN/A if (switchPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 5703867Sbinkertn@umich.edu cpu->signalSwitched(); 5712292SN/A return; 5722292SN/A } 5734035Sktlim@umich.edu 5744035Sktlim@umich.edu list<unsigned>::iterator threads = (*activeThreads).begin(); 5754035Sktlim@umich.edu 5764035Sktlim@umich.edu // Check if any of the threads are done squashing. Change the 5772292SN/A // status if they are done. 5782292SN/A while (threads != (*activeThreads).end()) { 5792292SN/A unsigned tid = *threads++; 5802292SN/A 5812292SN/A if (commitStatus[tid] == ROBSquashing) { 5822292SN/A 5832877Sksewell@umich.edu if (rob->isDoneSquashing(tid)) { 5842702Sktlim@umich.edu commitStatus[tid] = Running; 5852702Sktlim@umich.edu --squashCounter; 5862702Sktlim@umich.edu } else { 5872292SN/A DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 5882292SN/A "insts this cycle.\n", tid); 5892292SN/A } 5902292SN/A } 5912292SN/A } 5922292SN/A 5932292SN/A commit(); 5942292SN/A 5953867Sbinkertn@umich.edu markCompletedInsts(); 5962292SN/A 5973867Sbinkertn@umich.edu threads = (*activeThreads).begin(); 5982292SN/A 5992292SN/A while (threads != (*activeThreads).end()) { 6002292SN/A unsigned tid = *threads++; 6012292SN/A 6022292SN/A if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 6032292SN/A // The ROB has more instructions it can commit. Its next status 6042292SN/A // will be active. 6052292SN/A _nextStatus = Active; 6062292SN/A 6072292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6082292SN/A 6092292SN/A DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %#x is head of" 6102292SN/A " ROB and ready to commit\n", 6112292SN/A tid, inst->seqNum, inst->readPC()); 6122292SN/A 6132292SN/A } else if (!rob->isEmpty(tid)) { 6142292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6152292SN/A 6162292SN/A DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 6172292SN/A "%#x is head of ROB and not ready\n", 6182292SN/A tid, inst->seqNum, inst->readPC()); 6192292SN/A } 6202292SN/A 6212292SN/A DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 6222292SN/A tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 6232292SN/A } 6242292SN/A 6252316SN/A 6262292SN/A if (wroteToTimeBuffer) { 6272292SN/A DPRINTF(Activity, "Activity This Cycle.\n"); 6282292SN/A cpu->activityThisCycle(); 6292292SN/A } 6302292SN/A 6312292SN/A updateStatus(); 6324035Sktlim@umich.edu} 6332292SN/A 6342292SN/Atemplate <class Impl> 6354035Sktlim@umich.eduvoid 6362292SN/ADefaultCommit<Impl>::commit() 6373640Sktlim@umich.edu{ 6382316SN/A 6392316SN/A ////////////////////////////////////// 6402292SN/A // Check for interrupts 6413633Sktlim@umich.edu ////////////////////////////////////// 6423633Sktlim@umich.edu 6433633Sktlim@umich.edu#if FULL_SYSTEM 6443633Sktlim@umich.edu // Process interrupts if interrupts are enabled, not in PAL mode, 6454035Sktlim@umich.edu // and no other traps or external squashes are currently pending. 6464035Sktlim@umich.edu // @todo: Allow other threads to handle interrupts. 6474035Sktlim@umich.edu if (cpu->checkInterrupts && 6482292SN/A cpu->check_interrupts() && 6492292SN/A !cpu->inPalMode(readPC()) && 6502292SN/A !trapSquash[0] && 6513633Sktlim@umich.edu !xcSquash[0]) { 6523640Sktlim@umich.edu // Tell fetch that there is an interrupt pending. This will 6532292SN/A // make fetch wait until it sees a non PAL-mode PC, at which 6543633Sktlim@umich.edu // point it stops fetching instructions. 6553633Sktlim@umich.edu toIEW->commitInfo[0].interruptPending = true; 6562292SN/A 6572292SN/A // Wait until the ROB is empty and all stores have drained in 6582292SN/A // order to enter the interrupt. 6592292SN/A if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 6602292SN/A // Not sure which thread should be the one to interrupt. For now 6613640Sktlim@umich.edu // always do thread 0. 6622292SN/A assert(!thread[0]->inSyscall); 6632292SN/A thread[0]->inSyscall = true; 6642292SN/A 6654035Sktlim@umich.edu // CPU will handle implementation of the interrupt. 6664035Sktlim@umich.edu cpu->processInterrupts(); 6674035Sktlim@umich.edu 6684035Sktlim@umich.edu // Now squash or record that I need to squash this cycle. 6693640Sktlim@umich.edu commitStatus[0] = TrapPending; 6703640Sktlim@umich.edu 6713640Sktlim@umich.edu // Exit state update mode to avoid accidental updating. 6723640Sktlim@umich.edu thread[0]->inSyscall = false; 6733640Sktlim@umich.edu 6743640Sktlim@umich.edu // Generate trap squash event. 6753640Sktlim@umich.edu generateTrapEvent(0); 6763640Sktlim@umich.edu 6773640Sktlim@umich.edu toIEW->commitInfo[0].clearInterrupt = true; 6783640Sktlim@umich.edu 6793640Sktlim@umich.edu DPRINTF(Commit, "Interrupt detected.\n"); 6803640Sktlim@umich.edu } else { 6813640Sktlim@umich.edu DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 6823640Sktlim@umich.edu } 6831060SN/A } 6844035Sktlim@umich.edu#endif // FULL_SYSTEM 6854035Sktlim@umich.edu 6863634Sktlim@umich.edu //////////////////////////////////// 6874035Sktlim@umich.edu // Check for any possible squashes, handle them first 6884035Sktlim@umich.edu //////////////////////////////////// 6894035Sktlim@umich.edu 6904035Sktlim@umich.edu list<unsigned>::iterator threads = (*activeThreads).begin(); 6914035Sktlim@umich.edu 6924035Sktlim@umich.edu while (threads != (*activeThreads).end()) { 6934035Sktlim@umich.edu unsigned tid = *threads++; 6944035Sktlim@umich.edu/* 6954035Sktlim@umich.edu if (fromFetch->fetchFault && commitStatus[0] != TrapPending) { 6964035Sktlim@umich.edu // Record the fault. Wait until it's empty in the ROB. 6974035Sktlim@umich.edu // Then handle the trap. Ignore it if there's already a 6984035Sktlim@umich.edu // trap pending as fetch will be redirected. 6991060SN/A fetchFault = fromFetch->fetchFault; 7001060SN/A fetchFaultTick = curTick + fetchTrapLatency; 7011060SN/A commitStatus[0] = FetchTrapPending; 7022316SN/A DPRINTF(Commit, "Fault from fetch recorded. Will trap if the " 7031060SN/A "ROB empties without squashing the fault.\n"); 7043867Sbinkertn@umich.edu fetchTrapWait = 0; 7053867Sbinkertn@umich.edu } 7061060SN/A 7073867Sbinkertn@umich.edu // Fetch may tell commit to clear the trap if it's been squashed. 7082292SN/A if (fromFetch->clearFetchFault) { 7091060SN/A DPRINTF(Commit, "Received clear fetch fault signal\n"); 7102292SN/A fetchTrapWait = 0; 7112292SN/A if (commitStatus[0] == FetchTrapPending) { 7122292SN/A DPRINTF(Commit, "Clearing fault from fetch\n"); 7132680Sktlim@umich.edu commitStatus[0] = Running; 7142292SN/A } 7152680Sktlim@umich.edu } 7164035Sktlim@umich.edu*/ 7172680Sktlim@umich.edu // Not sure which one takes priority. I think if we have 7182292SN/A // both, that's a bad sign. 7191061SN/A if (trapSquash[tid] == true) { 7202292SN/A assert(!xcSquash[tid]); 7212292SN/A squashFromTrap(tid); 7222292SN/A } else if (xcSquash[tid] == true) { 7232292SN/A squashFromXC(tid); 7242292SN/A } 7252292SN/A 7261061SN/A // Squashed sequence number must be older than youngest valid 7272292SN/A // instruction in the ROB. This prevents squashes from younger 7282292SN/A // instructions overriding squashes from older instructions. 7292292SN/A if (fromIEW->squash[tid] && 7302292SN/A commitStatus[tid] != TrapPending && 7311061SN/A fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 7322292SN/A 7332292SN/A DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n", 7342292SN/A tid, 7351061SN/A fromIEW->mispredPC[tid], 7362292SN/A fromIEW->squashedSeqNum[tid]); 7371061SN/A 7382292SN/A DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 7392292SN/A tid, 7402292SN/A fromIEW->nextPC[tid]); 7411062SN/A 7422935Sksewell@umich.edu commitStatus[tid] = ROBSquashing; 7432292SN/A 7442935Sksewell@umich.edu ++squashCounter; 7454035Sktlim@umich.edu 7462292SN/A // If we want to include the squashing instruction in the squash, 7472292SN/A // then use one older sequence number. 7482292SN/A InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 7492292SN/A 7503093Sksewell@umich.edu if (fromIEW->includeSquashInst[tid] == true) 7512292SN/A squashed_inst--; 7522292SN/A 7532292SN/A // All younger instructions will be squashed. Set the sequence 7542292SN/A // number as the youngest instruction in the ROB. 7552292SN/A youngestSeqNum[tid] = squashed_inst; 7562292SN/A 7572292SN/A rob->squash(squashed_inst, tid); 7582292SN/A changedROBNumEntries[tid] = true; 7592292SN/A 7602292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 7612292SN/A 7622292SN/A toIEW->commitInfo[tid].squash = true; 7632292SN/A 7642292SN/A // Send back the rob squashing signal so other stages know that 7652292SN/A // the ROB is in the process of squashing. 7662292SN/A toIEW->commitInfo[tid].robSquashing = true; 7672292SN/A 7683795Sgblack@eecs.umich.edu toIEW->commitInfo[tid].branchMispredict = 7694636Sgblack@eecs.umich.edu fromIEW->branchMispredict[tid]; 7702292SN/A 7712316SN/A toIEW->commitInfo[tid].branchTaken = 7722292SN/A fromIEW->branchTaken[tid]; 7732292SN/A 7742292SN/A toIEW->commitInfo[tid].nextPC = fromIEW->nextPC[tid]; 7752292SN/A 7761062SN/A toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid]; 7772292SN/A 7781060SN/A if (toIEW->commitInfo[tid].branchMispredict) { 7791060SN/A ++branchMispredicts; 7802292SN/A } 7812292SN/A } 7822292SN/A 7831061SN/A } 7841060SN/A 7851060SN/A setNextStatus(); 7861061SN/A 7871060SN/A if (squashCounter != numThreads) { 7881060SN/A // If we're not currently squashing, then get instructions. 7891060SN/A getInsts(); 7902292SN/A 7913867Sbinkertn@umich.edu // Try to commit any instructions. 7922292SN/A commitInsts(); 7933867Sbinkertn@umich.edu } 7942292SN/A 7952292SN/A //Check for any activity 7962292SN/A threads = (*activeThreads).begin(); 7972292SN/A 7982292SN/A while (threads != (*activeThreads).end()) { 7992292SN/A unsigned tid = *threads++; 8002292SN/A 8012292SN/A if (changedROBNumEntries[tid]) { 8024035Sktlim@umich.edu toIEW->commitInfo[tid].usedROB = true; 8034035Sktlim@umich.edu toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 8042292SN/A 8054035Sktlim@umich.edu if (rob->isEmpty(tid)) { 8064035Sktlim@umich.edu toIEW->commitInfo[tid].emptyROB = true; 8074035Sktlim@umich.edu } 8084035Sktlim@umich.edu 8094035Sktlim@umich.edu wroteToTimeBuffer = true; 8104035Sktlim@umich.edu changedROBNumEntries[tid] = false; 8114035Sktlim@umich.edu } 8124035Sktlim@umich.edu } 8134035Sktlim@umich.edu} 8144035Sktlim@umich.edu 8154035Sktlim@umich.edutemplate <class Impl> 8164035Sktlim@umich.eduvoid 8174035Sktlim@umich.eduDefaultCommit<Impl>::commitInsts() 8184035Sktlim@umich.edu{ 8194035Sktlim@umich.edu //////////////////////////////////// 8204035Sktlim@umich.edu // Handle commit 8214035Sktlim@umich.edu // Note that commit will be handled prior to putting new 8224035Sktlim@umich.edu // instructions in the ROB so that the ROB only tries to commit 8231060SN/A // instructions it has in this current cycle, and not instructions 8241060SN/A // it is writing in during this cycle. Can't commit and squash 8251060SN/A // things at the same time... 8261061SN/A //////////////////////////////////// 8271060SN/A 8282292SN/A DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 8291060SN/A 8301060SN/A unsigned num_committed = 0; 8311060SN/A 8322316SN/A DynInstPtr head_inst; 8332316SN/A 8342316SN/A // Commit as many instructions as possible until the commit bandwidth 8352316SN/A // limit is reached, or it becomes impossible to commit any more. 8362316SN/A while (num_committed < commitWidth) { 8371060SN/A int commit_thread = getCommittingThread(); 8381060SN/A 8392292SN/A if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 8401060SN/A break; 8411060SN/A 8421060SN/A head_inst = rob->readHeadInst(commit_thread); 8432292SN/A 8442316SN/A int tid = head_inst->threadNumber; 8451060SN/A 8461060SN/A assert(tid == commit_thread); 8472292SN/A 8482292SN/A DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 8491060SN/A head_inst->seqNum, tid); 8502292SN/A 8512292SN/A // If the head instruction is squashed, it is ready to retire 8522292SN/A // (be removed from the ROB) at any time. 8532292SN/A if (head_inst->isSquashed()) { 8542292SN/A 8552292SN/A DPRINTF(Commit, "Retiring squashed instruction from " 8562292SN/A "ROB.\n"); 8572292SN/A 8582292SN/A rob->retireHead(commit_thread); 8592292SN/A 8602292SN/A ++commitSquashedInsts; 8612132SN/A 8622316SN/A // Record that the number of ROB entries has changed. 8632316SN/A changedROBNumEntries[tid] = true; 8641060SN/A } else { 8651060SN/A PC[tid] = head_inst->readPC(); 8662292SN/A nextPC[tid] = head_inst->readNextPC(); 8671060SN/A 8681060SN/A // Increment the total number of non-speculative instructions 8692292SN/A // executed. 8701060SN/A // Hack for now: it really shouldn't happen until after the 8711062SN/A // commit is deemed to be successful, but this count is needed 8721062SN/A // for syscalls. 8732292SN/A thread[tid]->funcExeInst++; 8742292SN/A 8751060SN/A // Try to commit the head instruction. 8762292SN/A bool commit_success = commitHead(head_inst, num_committed); 8772292SN/A 8782935Sksewell@umich.edu if (commit_success) { 8794636Sgblack@eecs.umich.edu ++num_committed; 8802292SN/A 8811060SN/A changedROBNumEntries[tid] = true; 8821060SN/A 8831060SN/A // Set the doneSeqNum to the youngest committed instruction. 8841061SN/A toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 8851061SN/A 8862292SN/A ++commitCommittedInsts; 8871060SN/A 8881060SN/A // To match the old model, don't count nops and instruction 8891060SN/A // prefetches towards the total commit count. 8901060SN/A if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 8911062SN/A cpu->instDone(tid); 8921060SN/A } 8931060SN/A 8942292SN/A PC[tid] = nextPC[tid]; 8952292SN/A nextPC[tid] = nextPC[tid] + sizeof(TheISA::MachInst); 8962292SN/A#if FULL_SYSTEM 8972292SN/A int count = 0; 8981060SN/A Addr oldpc; 8991062SN/A do { 9001062SN/A // Debug statement. Checks to make sure we're not 9012292SN/A // currently updating state while handling PC events. 9022292SN/A if (count == 0) 9032292SN/A assert(!thread[tid]->inSyscall && 9042292SN/A !thread[tid]->trapPending); 9051062SN/A oldpc = PC[tid]; 9062292SN/A cpu->system->pcEventQueue.service( 9072292SN/A thread[tid]->getXCProxy()); 9082935Sksewell@umich.edu count++; 9092935Sksewell@umich.edu } while (oldpc != PC[tid]); 9104636Sgblack@eecs.umich.edu if (count > 1) { 9114636Sgblack@eecs.umich.edu DPRINTF(Commit, "PC skip function event, stopping commit\n"); 9122935Sksewell@umich.edu break; 9132292SN/A } 9142292SN/A#endif 9155108Sgblack@eecs.umich.edu } else { 9165108Sgblack@eecs.umich.edu DPRINTF(Commit, "Unable to commit head instruction PC:%#x " 9175108Sgblack@eecs.umich.edu "[tid:%i] [sn:%i].\n", 9182292SN/A head_inst->readPC(), tid ,head_inst->seqNum); 9192292SN/A break; 9205108Sgblack@eecs.umich.edu } 9212292SN/A } 9222292SN/A } 9232292SN/A 9245108Sgblack@eecs.umich.edu DPRINTF(CommitRate, "%i\n", num_committed); 9255108Sgblack@eecs.umich.edu numCommittedDist.sample(num_committed); 9262292SN/A 9272292SN/A if (num_committed == commitWidth) { 9281060SN/A commitEligibleSamples[0]++; 9292292SN/A } 9302292SN/A} 9312292SN/A 9321060SN/Atemplate <class Impl> 9331060SN/Abool 9341060SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 9351060SN/A{ 9361062SN/A assert(head_inst); 9371063SN/A 9382292SN/A int tid = head_inst->threadNumber; 9392307SN/A 9402307SN/A // If the instruction is not executed yet, then it will need extra 9412349SN/A // handling. Signal backwards that it should be executed. 9422307SN/A if (!head_inst->isExecuted()) { 9431060SN/A // Keep this number correct. We have not yet actually executed 9441060SN/A // and committed this instruction. 9451061SN/A thread[tid]->funcExeInst--; 9461060SN/A 9472292SN/A head_inst->reachedCommit = true; 9481060SN/A 9491060SN/A if (head_inst->isNonSpeculative() || 9501060SN/A head_inst->isStoreConditional() || 9512292SN/A head_inst->isMemBarrier() || 9522292SN/A head_inst->isWriteBarrier()) { 9532316SN/A 9542316SN/A DPRINTF(Commit, "Encountered a barrier or non-speculative " 9551061SN/A "instruction [sn:%lli] at the head of the ROB, PC %#x.\n", 9561061SN/A head_inst->seqNum, head_inst->readPC()); 9571061SN/A 9582292SN/A#if !FULL_SYSTEM 9591062SN/A // Hack to make sure syscalls/memory barriers/quiesces 9602292SN/A // aren't executed until all stores write back their data. 9612348SN/A // This direct communication shouldn't be used for 9622292SN/A // anything other than this. 9632292SN/A if (inst_num > 0 || iewStage->hasStoresToWB()) 9642316SN/A#else 9652316SN/A if ((head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 9662316SN/A head_inst->isQuiesce()) && 9672316SN/A iewStage->hasStoresToWB()) 9682316SN/A#endif 9694035Sktlim@umich.edu { 9702292SN/A DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 9712292SN/A return false; 9722292SN/A } 9732292SN/A 9742292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 9751061SN/A 9761061SN/A // Change the instruction so it won't try to commit again until 9771061SN/A // it is executed. 9781061SN/A head_inst->clearCanCommit(); 9791061SN/A 9801062SN/A ++commitNonSpecStalls; 9811062SN/A 9821061SN/A return false; 9832292SN/A } else if (head_inst->isLoad()) { 9844035Sktlim@umich.edu DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %#x.\n", 9854035Sktlim@umich.edu head_inst->seqNum, head_inst->readPC()); 9864035Sktlim@umich.edu 9874035Sktlim@umich.edu // Send back the non-speculative instruction's sequence 9884035Sktlim@umich.edu // number. Tell the lsq to re-execute the load. 9894035Sktlim@umich.edu toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 9902292SN/A toIEW->commitInfo[tid].uncached = true; 9912292SN/A toIEW->commitInfo[tid].uncachedLoad = head_inst; 9922292SN/A 9932292SN/A head_inst->clearCanCommit(); 9942316SN/A 9952292SN/A return false; 9962292SN/A } else { 9972292SN/A panic("Trying to commit un-executed instruction " 9982292SN/A "of unknown type!\n"); 9992292SN/A } 10002292SN/A } 10012292SN/A 10021061SN/A if (head_inst->isThreadSync()) { 10032292SN/A // Not handled for now. 10041061SN/A panic("Thread sync instructions are not handled yet.\n"); 10051061SN/A } 10061060SN/A 10071060SN/A // Stores mark themselves as completed. 10082316SN/A if (!head_inst->isStore()) { 10092292SN/A head_inst->setCompleted(); 10102316SN/A } 10112132SN/A 10122132SN/A // Use checker prior to updating anything due to traps or PC 10134035Sktlim@umich.edu // based events. 10144035Sktlim@umich.edu if (cpu->checker) { 10154035Sktlim@umich.edu cpu->checker->tick(head_inst); 10162316SN/A } 10174035Sktlim@umich.edu 10182310SN/A // Check if the instruction caused a fault. If so, trap. 10192310SN/A Fault inst_fault = head_inst->getFault(); 10202310SN/A 10212733Sktlim@umich.edu if (inst_fault != NoFault) { 10222316SN/A head_inst->setCompleted(); 10232316SN/A#if FULL_SYSTEM 10242316SN/A DPRINTF(Commit, "Inst [sn:%lli] PC %#x has a fault\n", 10252732Sktlim@umich.edu head_inst->seqNum, head_inst->readPC()); 10261060SN/A 10272733Sktlim@umich.edu if (iewStage->hasStoresToWB() || inst_num > 0) { 10281060SN/A DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 10292918Sktlim@umich.edu return false; 10302918Sktlim@umich.edu } 10312918Sktlim@umich.edu 10322918Sktlim@umich.edu if (cpu->checker && head_inst->isStore()) { 10332918Sktlim@umich.edu cpu->checker->tick(head_inst); 10342918Sktlim@umich.edu } 10352112SN/A 10362316SN/A assert(!thread[tid]->inSyscall); 10372316SN/A 10382292SN/A // Mark that we're in state update mode so that the trap's 10392316SN/A // execution doesn't generate extra squashes. 10402316SN/A thread[tid]->inSyscall = true; 10412316SN/A 10422316SN/A // DTB will sometimes need the machine instruction for when 10432310SN/A // faults happen. So we will set it here, prior to the DTB 10444035Sktlim@umich.edu // possibly needing it for its fault. 10454035Sktlim@umich.edu thread[tid]->setInst( 10462733Sktlim@umich.edu static_cast<TheISA::MachInst>(head_inst->staticInst->machInst)); 10472316SN/A 10482732Sktlim@umich.edu // Execute the trap. Although it's slightly unrealistic in 10492316SN/A // terms of timing (as it doesn't wait for the full timing of 10502733Sktlim@umich.edu // the trap event to complete before updating state), it's 10512292SN/A // needed to update the state as soon as possible. This 10522316SN/A // prevents external agents from changing any specific state 10532292SN/A // that the trap need. 10542316SN/A cpu->trap(inst_fault, tid); 10552316SN/A 10562316SN/A // Exit state update mode to avoid accidental updating. 10572292SN/A thread[tid]->inSyscall = false; 10582316SN/A 10592316SN/A commitStatus[tid] = TrapPending; 10602316SN/A 10612316SN/A // Generate trap squash event. 10622316SN/A generateTrapEvent(tid); 10632316SN/A 10642316SN/A return false; 10652292SN/A#else // !FULL_SYSTEM 10662316SN/A panic("fault (%d) detected @ PC %08p", inst_fault, 10672316SN/A head_inst->PC); 10682292SN/A#endif // FULL_SYSTEM 10692316SN/A } 10702292SN/A 10714035Sktlim@umich.edu updateComInstStats(head_inst); 10724035Sktlim@umich.edu 10734035Sktlim@umich.edu if (head_inst->traceData) { 10744288Sktlim@umich.edu head_inst->traceData->setFetchSeq(head_inst->seqNum); 10754288Sktlim@umich.edu head_inst->traceData->setCPSeq(thread[tid]->numInst); 10764035Sktlim@umich.edu head_inst->traceData->finalize(); 10774035Sktlim@umich.edu head_inst->traceData = NULL; 10784035Sktlim@umich.edu } 10792316SN/A 10802316SN/A // Update the commit rename map 10812353SN/A for (int i = 0; i < head_inst->numDestRegs(); i++) { 10822316SN/A renameMap[tid]->setEntry(head_inst->destRegIdx(i), 10831060SN/A head_inst->renamedDestRegIdx(i)); 10841060SN/A } 10852301SN/A 10862132SN/A // Finally clear the head ROB entry. 10872362SN/A rob->retireHead(tid); 10882362SN/A 10893577Sgblack@eecs.umich.edu // Return true to indicate that we have committed an instruction. 10902362SN/A return true; 10912362SN/A} 10923126Sktlim@umich.edu 10932362SN/Atemplate <class Impl> 10942362SN/Avoid 10952362SN/ADefaultCommit<Impl>::getInsts() 10962362SN/A{ 10972362SN/A // Read any renamed instructions and place them into the ROB. 10982362SN/A int insts_to_process = min((int)renameWidth, fromRename->size); 10992362SN/A 11002132SN/A for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) 11012292SN/A { 11022292SN/A DynInstPtr inst = fromRename->insts[inst_num]; 11034046Sbinkertn@umich.edu int tid = inst->threadNumber; 11044046Sbinkertn@umich.edu 11052292SN/A if (!inst->isSquashed() && 11061060SN/A commitStatus[tid] != ROBSquashing) { 11071060SN/A changedROBNumEntries[tid] = true; 11082292SN/A 11092292SN/A DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ROB.\n", 11103771Sgblack@eecs.umich.edu inst->readPC(), inst->seqNum, tid); 11112292SN/A 11121060SN/A rob->insertInst(inst); 11131062SN/A 11142353SN/A assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 11152353SN/A 11162353SN/A youngestSeqNum[tid] = inst->seqNum; 11172292SN/A } else { 11182292SN/A DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was " 11191060SN/A "squashed, skipping.\n", 11204035Sktlim@umich.edu inst->readPC(), inst->seqNum, tid); 11214035Sktlim@umich.edu } 11224035Sktlim@umich.edu } 11234035Sktlim@umich.edu} 11241060SN/A 11251060SN/Atemplate <class Impl> 11261060SN/Avoid 11271060SN/ADefaultCommit<Impl>::markCompletedInsts() 11281061SN/A{ 11291060SN/A // Grab completed insts out of the IEW instruction queue, and mark 11302292SN/A // instructions completed within the ROB. 11311060SN/A for (int inst_num = 0; 11322935Sksewell@umich.edu inst_num < fromIEW->size && fromIEW->insts[inst_num]; 11332935Sksewell@umich.edu ++inst_num) 11343093Sksewell@umich.edu { 11353093Sksewell@umich.edu if (!fromIEW->insts[inst_num]->isSquashed()) { 11362965Sksewell@umich.edu DPRINTF(Commit, "[tid:%i]: Marking PC %#x, [sn:%lli] ready " 11372965Sksewell@umich.edu "within ROB.\n", 11382965Sksewell@umich.edu fromIEW->insts[inst_num]->threadNumber, 11392965Sksewell@umich.edu fromIEW->insts[inst_num]->readPC(), 11403093Sksewell@umich.edu fromIEW->insts[inst_num]->seqNum); 11412292SN/A 11422292SN/A // Mark the instruction as ready to commit. 11432292SN/A fromIEW->insts[inst_num]->setCanCommit(); 11444035Sktlim@umich.edu } 11454035Sktlim@umich.edu } 11462292SN/A} 11472292SN/A 11482292SN/Atemplate <class Impl> 11492292SN/Abool 11502292SN/ADefaultCommit<Impl>::robDoneSquashing() 11512292SN/A{ 11522292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 11532292SN/A 11542292SN/A while (threads != (*activeThreads).end()) { 11552292SN/A unsigned tid = *threads++; 11561061SN/A 11572292SN/A if (!rob->isDoneSquashing(tid)) 11581061SN/A return false; 11592292SN/A } 11601061SN/A 11611060SN/A return true; 11622965Sksewell@umich.edu} 11632965Sksewell@umich.edu 11642965Sksewell@umich.edutemplate <class Impl> 11652965Sksewell@umich.eduvoid 11662965Sksewell@umich.eduDefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 11672965Sksewell@umich.edu{ 11682965Sksewell@umich.edu unsigned thread = inst->threadNumber; 11692965Sksewell@umich.edu 11702965Sksewell@umich.edu // 11712965Sksewell@umich.edu // Pick off the software prefetches 11722965Sksewell@umich.edu // 11732965Sksewell@umich.edu#ifdef TARGET_ALPHA 11742965Sksewell@umich.edu if (inst->isDataPrefetch()) { 11752965Sksewell@umich.edu statComSwp[thread]++; 11763221Sktlim@umich.edu } else { 11773221Sktlim@umich.edu statComInst[thread]++; 11782965Sksewell@umich.edu } 11792965Sksewell@umich.edu#else 11802965Sksewell@umich.edu statComInst[thread]++; 11812965Sksewell@umich.edu#endif 11823221Sktlim@umich.edu 11832965Sksewell@umich.edu // 11842965Sksewell@umich.edu // Control Instructions 11851060SN/A // 11861060SN/A if (inst->isControl()) 11871061SN/A statComBranches[thread]++; 11881060SN/A 11892292SN/A // 11901060SN/A // Memory references 11911060SN/A // 11921060SN/A if (inst->isMemRef()) { 11931060SN/A statComRefs[thread]++; 11941681SN/A 11951060SN/A if (inst->isLoad()) { 11961060SN/A statComLoads[thread]++; 11972292SN/A } 11982316SN/A } 11992316SN/A 12002292SN/A if (inst->isMemBarrier()) { 12012292SN/A statComMembars[thread]++; 12022292SN/A } 12031060SN/A} 12042292SN/A 12052292SN/A//////////////////////////////////////// 12062292SN/A// // 12071060SN/A// SMT COMMIT POLICY MAINTAINED HERE // 12081060SN/A// // 12091060SN/A//////////////////////////////////////// 12101061SN/Atemplate <class Impl> 12112292SN/Aint 12122292SN/ADefaultCommit<Impl>::getCommittingThread() 12131060SN/A{ 12143867Sbinkertn@umich.edu if (numThreads > 1) { 12153867Sbinkertn@umich.edu switch (commitPolicy) { 12162292SN/A 12173867Sbinkertn@umich.edu case Aggressive: 12182292SN/A //If Policy is Aggressive, commit will call 12192292SN/A //this function multiple times per 12202292SN/A //cycle 12212292SN/A return oldestReady(); 12222292SN/A 12232292SN/A case RoundRobin: 12242292SN/A return roundRobin(); 12251060SN/A 12262292SN/A case OldestReady: 12272301SN/A return oldestReady(); 12282301SN/A 12292301SN/A default: 12302301SN/A return -1; 12312301SN/A } 12322301SN/A } else { 12332301SN/A int tid = (*activeThreads).front(); 12342301SN/A 12352301SN/A if (commitStatus[tid] == Running || 12362301SN/A commitStatus[tid] == Idle || 12372301SN/A commitStatus[tid] == FetchTrapPending) { 12382316SN/A return tid; 12392301SN/A } else { 12402316SN/A return -1; 12412301SN/A } 12422301SN/A } 12432316SN/A} 12442301SN/A 12452301SN/Atemplate<class Impl> 12462301SN/Aint 12472301SN/ADefaultCommit<Impl>::roundRobin() 12482301SN/A{ 12492301SN/A list<unsigned>::iterator pri_iter = priority_list.begin(); 12502316SN/A list<unsigned>::iterator end = priority_list.end(); 12512301SN/A 12522301SN/A while (pri_iter != end) { 12532301SN/A unsigned tid = *pri_iter; 12542301SN/A 12552301SN/A if (commitStatus[tid] == Running || 12562316SN/A commitStatus[tid] == Idle) { 12572301SN/A 12582301SN/A if (rob->isHeadReady(tid)) { 12592316SN/A priority_list.erase(pri_iter); 12602301SN/A priority_list.push_back(tid); 12612301SN/A 12622301SN/A return tid; 12632301SN/A } 12642316SN/A } 12652301SN/A 12662301SN/A pri_iter++; 12672301SN/A } 12682292SN/A 12692292SN/A return -1; 12702316SN/A} 12712292SN/A 12722292SN/Atemplate<class Impl> 12732292SN/Aint 12742292SN/ADefaultCommit<Impl>::oldestReady() 12752292SN/A{ 12762292SN/A unsigned oldest = 0; 12772292SN/A bool first = true; 12782292SN/A 12792292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 12802292SN/A 12812292SN/A while (threads != (*activeThreads).end()) { 12822292SN/A unsigned tid = *threads++; 12832292SN/A 12842292SN/A if (!rob->isEmpty(tid) && 12852292SN/A (commitStatus[tid] == Running || 12862292SN/A commitStatus[tid] == Idle || 12872292SN/A commitStatus[tid] == FetchTrapPending)) { 12882292SN/A 12892292SN/A if (rob->isHeadReady(tid)) { 12902292SN/A 12912292SN/A DynInstPtr head_inst = rob->readHeadInst(tid); 12922292SN/A 12932292SN/A if (first) { 12942292SN/A oldest = tid; 12952292SN/A first = false; 12963867Sbinkertn@umich.edu } else if (head_inst->seqNum < oldest) { 12973867Sbinkertn@umich.edu oldest = tid; 12982292SN/A } 12992292SN/A } 13002292SN/A } 13012292SN/A } 13022292SN/A 13032292SN/A if (!first) { 13042292SN/A return oldest; 13052292SN/A } else { 13062292SN/A return -1; 13072292SN/A } 13082292SN/A} 13092292SN/A