commit_impl.hh revision 8346
11689SN/A/* 27783SGiacomo.Gabrielli@arm.com * Copyright (c) 2010 ARM Limited 37783SGiacomo.Gabrielli@arm.com * All rights reserved 47783SGiacomo.Gabrielli@arm.com * 57783SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 67783SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 77783SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 87783SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 97783SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 107783SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 117783SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 127783SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 137783SGiacomo.Gabrielli@arm.com * 142316SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 271689SN/A * 281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 412965Sksewell@umich.edu * Korey Sewell 421689SN/A */ 431689SN/A 442292SN/A#include <algorithm> 452329SN/A#include <string> 462292SN/A 473577Sgblack@eecs.umich.edu#include "arch/utility.hh" 488229Snate@binkert.org#include "base/loader/symtab.hh" 495953Ssaidi@eecs.umich.edu#include "base/cp_annotate.hh" 506221Snate@binkert.org#include "config/full_system.hh" 516658Snate@binkert.org#include "config/the_isa.hh" 526221Snate@binkert.org#include "config/use_checker.hh" 531717SN/A#include "cpu/o3/commit.hh" 542292SN/A#include "cpu/o3/thread_state.hh" 558229Snate@binkert.org#include "cpu/exetrace.hh" 568229Snate@binkert.org#include "cpu/timebuf.hh" 578232Snate@binkert.org#include "debug/Activity.hh" 588232Snate@binkert.org#include "debug/Commit.hh" 598232Snate@binkert.org#include "debug/CommitRate.hh" 608232Snate@binkert.org#include "debug/ExecFaulting.hh" 616221Snate@binkert.org#include "params/DerivO3CPU.hh" 628230Snate@binkert.org#include "sim/faults.hh" 632292SN/A 642790Sktlim@umich.edu#if USE_CHECKER 652790Sktlim@umich.edu#include "cpu/checker/cpu.hh" 662790Sktlim@umich.edu#endif 672790Sktlim@umich.edu 686221Snate@binkert.orgusing namespace std; 695529Snate@binkert.org 701061SN/Atemplate <class Impl> 712292SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 726221Snate@binkert.org ThreadID _tid) 735606Snate@binkert.org : Event(CPU_Tick_Pri), commit(_commit), tid(_tid) 741060SN/A{ 755769Snate@binkert.org this->setFlags(AutoDelete); 761060SN/A} 771060SN/A 781061SN/Atemplate <class Impl> 791060SN/Avoid 802292SN/ADefaultCommit<Impl>::TrapEvent::process() 811062SN/A{ 822316SN/A // This will get reset by commit if it was switched out at the 832316SN/A // time of this event processing. 842292SN/A commit->trapSquash[tid] = true; 852292SN/A} 862292SN/A 872292SN/Atemplate <class Impl> 882292SN/Aconst char * 895336Shines@cs.fsu.eduDefaultCommit<Impl>::TrapEvent::description() const 902292SN/A{ 914873Sstever@eecs.umich.edu return "Trap"; 922292SN/A} 932292SN/A 942292SN/Atemplate <class Impl> 955529Snate@binkert.orgDefaultCommit<Impl>::DefaultCommit(O3CPU *_cpu, DerivO3CPUParams *params) 964329Sktlim@umich.edu : cpu(_cpu), 974329Sktlim@umich.edu squashCounter(0), 982292SN/A iewToCommitDelay(params->iewToCommitDelay), 992292SN/A commitToIEWDelay(params->commitToIEWDelay), 1002292SN/A renameToROBDelay(params->renameToROBDelay), 1012292SN/A fetchToCommitDelay(params->commitToFetchDelay), 1022292SN/A renameWidth(params->renameWidth), 1032292SN/A commitWidth(params->commitWidth), 1045529Snate@binkert.org numThreads(params->numThreads), 1052843Sktlim@umich.edu drainPending(false), 1062316SN/A switchedOut(false), 1072874Sktlim@umich.edu trapLatency(params->trapLatency) 1082292SN/A{ 1092292SN/A _status = Active; 1102292SN/A _nextStatus = Inactive; 1112980Sgblack@eecs.umich.edu std::string policy = params->smtCommitPolicy; 1122292SN/A 1132292SN/A //Convert string to lowercase 1142292SN/A std::transform(policy.begin(), policy.end(), policy.begin(), 1152292SN/A (int(*)(int)) tolower); 1162292SN/A 1172292SN/A //Assign commit policy 1182292SN/A if (policy == "aggressive"){ 1192292SN/A commitPolicy = Aggressive; 1202292SN/A 1218346Sksewell@umich.edu DPRINTF(Commit,"Commit Policy set to Aggressive.\n"); 1222292SN/A } else if (policy == "roundrobin"){ 1232292SN/A commitPolicy = RoundRobin; 1242292SN/A 1252292SN/A //Set-Up Priority List 1266221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 1272292SN/A priority_list.push_back(tid); 1282292SN/A } 1292292SN/A 1308346Sksewell@umich.edu DPRINTF(Commit,"Commit Policy set to Round Robin.\n"); 1312292SN/A } else if (policy == "oldestready"){ 1322292SN/A commitPolicy = OldestReady; 1332292SN/A 1344329Sktlim@umich.edu DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1352292SN/A } else { 1362292SN/A assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1372292SN/A "RoundRobin,OldestReady}"); 1382292SN/A } 1392292SN/A 1406221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 1416221Snate@binkert.org commitStatus[tid] = Idle; 1426221Snate@binkert.org changedROBNumEntries[tid] = false; 1436221Snate@binkert.org checkEmptyROB[tid] = false; 1446221Snate@binkert.org trapInFlight[tid] = false; 1456221Snate@binkert.org committedStores[tid] = false; 1466221Snate@binkert.org trapSquash[tid] = false; 1476221Snate@binkert.org tcSquash[tid] = false; 1487720Sgblack@eecs.umich.edu pc[tid].set(0); 1497855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] = 0; 1502292SN/A } 1513640Sktlim@umich.edu#if FULL_SYSTEM 1523640Sktlim@umich.edu interrupt = NoFault; 1533640Sktlim@umich.edu#endif 1542292SN/A} 1552292SN/A 1562292SN/Atemplate <class Impl> 1572292SN/Astd::string 1582292SN/ADefaultCommit<Impl>::name() const 1592292SN/A{ 1602292SN/A return cpu->name() + ".commit"; 1612292SN/A} 1622292SN/A 1632292SN/Atemplate <class Impl> 1642292SN/Avoid 1652292SN/ADefaultCommit<Impl>::regStats() 1662132SN/A{ 1672301SN/A using namespace Stats; 1681062SN/A commitCommittedInsts 1691062SN/A .name(name() + ".commitCommittedInsts") 1701062SN/A .desc("The number of committed instructions") 1711062SN/A .prereq(commitCommittedInsts); 1721062SN/A commitSquashedInsts 1731062SN/A .name(name() + ".commitSquashedInsts") 1741062SN/A .desc("The number of squashed insts skipped by commit") 1751062SN/A .prereq(commitSquashedInsts); 1761062SN/A commitSquashEvents 1771062SN/A .name(name() + ".commitSquashEvents") 1781062SN/A .desc("The number of times commit is told to squash") 1791062SN/A .prereq(commitSquashEvents); 1801062SN/A commitNonSpecStalls 1811062SN/A .name(name() + ".commitNonSpecStalls") 1821062SN/A .desc("The number of times commit has been forced to stall to " 1831062SN/A "communicate backwards") 1841062SN/A .prereq(commitNonSpecStalls); 1851062SN/A branchMispredicts 1861062SN/A .name(name() + ".branchMispredicts") 1871062SN/A .desc("The number of times a branch was mispredicted") 1881062SN/A .prereq(branchMispredicts); 1892292SN/A numCommittedDist 1901062SN/A .init(0,commitWidth,1) 1918240Snate@binkert.org .name(name() + ".committed_per_cycle") 1921062SN/A .desc("Number of insts commited each cycle") 1931062SN/A .flags(Stats::pdf) 1941062SN/A ; 1952301SN/A 1962316SN/A statComInst 1976221Snate@binkert.org .init(cpu->numThreads) 1988240Snate@binkert.org .name(name() + ".count") 1992301SN/A .desc("Number of instructions committed") 2002301SN/A .flags(total) 2012301SN/A ; 2022301SN/A 2032316SN/A statComSwp 2046221Snate@binkert.org .init(cpu->numThreads) 2058240Snate@binkert.org .name(name() + ".swp_count") 2062301SN/A .desc("Number of s/w prefetches committed") 2072301SN/A .flags(total) 2082301SN/A ; 2092301SN/A 2102316SN/A statComRefs 2116221Snate@binkert.org .init(cpu->numThreads) 2128240Snate@binkert.org .name(name() + ".refs") 2132301SN/A .desc("Number of memory references committed") 2142301SN/A .flags(total) 2152301SN/A ; 2162301SN/A 2172316SN/A statComLoads 2186221Snate@binkert.org .init(cpu->numThreads) 2198240Snate@binkert.org .name(name() + ".loads") 2202301SN/A .desc("Number of loads committed") 2212301SN/A .flags(total) 2222301SN/A ; 2232301SN/A 2242316SN/A statComMembars 2256221Snate@binkert.org .init(cpu->numThreads) 2268240Snate@binkert.org .name(name() + ".membars") 2272301SN/A .desc("Number of memory barriers committed") 2282301SN/A .flags(total) 2292301SN/A ; 2302301SN/A 2312316SN/A statComBranches 2326221Snate@binkert.org .init(cpu->numThreads) 2338240Snate@binkert.org .name(name() + ".branches") 2342301SN/A .desc("Number of branches committed") 2352301SN/A .flags(total) 2362301SN/A ; 2372301SN/A 2387897Shestness@cs.utexas.edu statComFloating 2397897Shestness@cs.utexas.edu .init(cpu->numThreads) 2408240Snate@binkert.org .name(name() + ".fp_insts") 2417897Shestness@cs.utexas.edu .desc("Number of committed floating point instructions.") 2427897Shestness@cs.utexas.edu .flags(total) 2437897Shestness@cs.utexas.edu ; 2447897Shestness@cs.utexas.edu 2457897Shestness@cs.utexas.edu statComInteger 2467897Shestness@cs.utexas.edu .init(cpu->numThreads) 2478240Snate@binkert.org .name(name()+".int_insts") 2487897Shestness@cs.utexas.edu .desc("Number of committed integer instructions.") 2497897Shestness@cs.utexas.edu .flags(total) 2507897Shestness@cs.utexas.edu ; 2517897Shestness@cs.utexas.edu 2527897Shestness@cs.utexas.edu statComFunctionCalls 2537897Shestness@cs.utexas.edu .init(cpu->numThreads) 2548240Snate@binkert.org .name(name()+".function_calls") 2557897Shestness@cs.utexas.edu .desc("Number of function calls committed.") 2567897Shestness@cs.utexas.edu .flags(total) 2577897Shestness@cs.utexas.edu ; 2587897Shestness@cs.utexas.edu 2592316SN/A commitEligible 2606221Snate@binkert.org .init(cpu->numThreads) 2618240Snate@binkert.org .name(name() + ".bw_limited") 2622301SN/A .desc("number of insts not committed due to BW limits") 2632301SN/A .flags(total) 2642301SN/A ; 2652301SN/A 2662316SN/A commitEligibleSamples 2678240Snate@binkert.org .name(name() + ".bw_lim_events") 2682301SN/A .desc("number cycles where commit BW limit reached") 2692301SN/A ; 2701062SN/A} 2711062SN/A 2721062SN/Atemplate <class Impl> 2731062SN/Avoid 2742980Sgblack@eecs.umich.eduDefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 2752292SN/A{ 2762292SN/A thread = threads; 2772292SN/A} 2782292SN/A 2792292SN/Atemplate <class Impl> 2802292SN/Avoid 2812292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 2821060SN/A{ 2831060SN/A timeBuffer = tb_ptr; 2841060SN/A 2851060SN/A // Setup wire to send information back to IEW. 2861060SN/A toIEW = timeBuffer->getWire(0); 2871060SN/A 2881060SN/A // Setup wire to read data from IEW (for the ROB). 2891060SN/A robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 2901060SN/A} 2911060SN/A 2921061SN/Atemplate <class Impl> 2931060SN/Avoid 2942292SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 2952292SN/A{ 2962292SN/A fetchQueue = fq_ptr; 2972292SN/A 2982292SN/A // Setup wire to get instructions from rename (for the ROB). 2992292SN/A fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 3002292SN/A} 3012292SN/A 3022292SN/Atemplate <class Impl> 3032292SN/Avoid 3042292SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3051060SN/A{ 3061060SN/A renameQueue = rq_ptr; 3071060SN/A 3081060SN/A // Setup wire to get instructions from rename (for the ROB). 3091060SN/A fromRename = renameQueue->getWire(-renameToROBDelay); 3101060SN/A} 3111060SN/A 3121061SN/Atemplate <class Impl> 3131060SN/Avoid 3142292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3151060SN/A{ 3161060SN/A iewQueue = iq_ptr; 3171060SN/A 3181060SN/A // Setup wire to get instructions from IEW. 3191060SN/A fromIEW = iewQueue->getWire(-iewToCommitDelay); 3201060SN/A} 3211060SN/A 3221061SN/Atemplate <class Impl> 3231060SN/Avoid 3242292SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 3252292SN/A{ 3262292SN/A iewStage = iew_stage; 3272292SN/A} 3282292SN/A 3292292SN/Atemplate<class Impl> 3302292SN/Avoid 3316221Snate@binkert.orgDefaultCommit<Impl>::setActiveThreads(list<ThreadID> *at_ptr) 3322292SN/A{ 3332292SN/A activeThreads = at_ptr; 3342292SN/A} 3352292SN/A 3362292SN/Atemplate <class Impl> 3372292SN/Avoid 3382292SN/ADefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3392292SN/A{ 3406221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) 3416221Snate@binkert.org renameMap[tid] = &rm_ptr[tid]; 3422292SN/A} 3432292SN/A 3442292SN/Atemplate <class Impl> 3452292SN/Avoid 3462292SN/ADefaultCommit<Impl>::setROB(ROB *rob_ptr) 3471060SN/A{ 3481060SN/A rob = rob_ptr; 3491060SN/A} 3501060SN/A 3511061SN/Atemplate <class Impl> 3521060SN/Avoid 3532292SN/ADefaultCommit<Impl>::initStage() 3541060SN/A{ 3552292SN/A rob->setActiveThreads(activeThreads); 3562292SN/A rob->resetEntries(); 3571060SN/A 3582292SN/A // Broadcast the number of free entries. 3596221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 3606221Snate@binkert.org toIEW->commitInfo[tid].usedROB = true; 3616221Snate@binkert.org toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 3626221Snate@binkert.org toIEW->commitInfo[tid].emptyROB = true; 3631060SN/A } 3641060SN/A 3654329Sktlim@umich.edu // Commit must broadcast the number of free entries it has at the 3664329Sktlim@umich.edu // start of the simulation, so it starts as active. 3674329Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 3684329Sktlim@umich.edu 3692292SN/A cpu->activityThisCycle(); 3705100Ssaidi@eecs.umich.edu trapLatency = cpu->ticks(trapLatency); 3711060SN/A} 3721060SN/A 3731061SN/Atemplate <class Impl> 3742863Sktlim@umich.edubool 3752843Sktlim@umich.eduDefaultCommit<Impl>::drain() 3761060SN/A{ 3772843Sktlim@umich.edu drainPending = true; 3782863Sktlim@umich.edu 3792863Sktlim@umich.edu return false; 3802316SN/A} 3812316SN/A 3822316SN/Atemplate <class Impl> 3832316SN/Avoid 3842843Sktlim@umich.eduDefaultCommit<Impl>::switchOut() 3852316SN/A{ 3862316SN/A switchedOut = true; 3872843Sktlim@umich.edu drainPending = false; 3882307SN/A rob->switchOut(); 3892307SN/A} 3902307SN/A 3912307SN/Atemplate <class Impl> 3922307SN/Avoid 3932843Sktlim@umich.eduDefaultCommit<Impl>::resume() 3942843Sktlim@umich.edu{ 3952864Sktlim@umich.edu drainPending = false; 3962843Sktlim@umich.edu} 3972843Sktlim@umich.edu 3982843Sktlim@umich.edutemplate <class Impl> 3992843Sktlim@umich.eduvoid 4002307SN/ADefaultCommit<Impl>::takeOverFrom() 4012307SN/A{ 4022316SN/A switchedOut = false; 4032307SN/A _status = Active; 4042307SN/A _nextStatus = Inactive; 4056221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 4066221Snate@binkert.org commitStatus[tid] = Idle; 4076221Snate@binkert.org changedROBNumEntries[tid] = false; 4086221Snate@binkert.org trapSquash[tid] = false; 4096221Snate@binkert.org tcSquash[tid] = false; 4102307SN/A } 4112307SN/A squashCounter = 0; 4122307SN/A rob->takeOverFrom(); 4132307SN/A} 4142307SN/A 4152307SN/Atemplate <class Impl> 4162307SN/Avoid 4172292SN/ADefaultCommit<Impl>::updateStatus() 4182132SN/A{ 4192316SN/A // reset ROB changed variable 4206221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 4216221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 4223867Sbinkertn@umich.edu 4233867Sbinkertn@umich.edu while (threads != end) { 4246221Snate@binkert.org ThreadID tid = *threads++; 4253867Sbinkertn@umich.edu 4262316SN/A changedROBNumEntries[tid] = false; 4272316SN/A 4282316SN/A // Also check if any of the threads has a trap pending 4292316SN/A if (commitStatus[tid] == TrapPending || 4302316SN/A commitStatus[tid] == FetchTrapPending) { 4312316SN/A _nextStatus = Active; 4322316SN/A } 4332292SN/A } 4342292SN/A 4352292SN/A if (_nextStatus == Inactive && _status == Active) { 4362292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 4372733Sktlim@umich.edu cpu->deactivateStage(O3CPU::CommitIdx); 4382292SN/A } else if (_nextStatus == Active && _status == Inactive) { 4392292SN/A DPRINTF(Activity, "Activating stage.\n"); 4402733Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 4412292SN/A } 4422292SN/A 4432292SN/A _status = _nextStatus; 4442292SN/A} 4452292SN/A 4462292SN/Atemplate <class Impl> 4472292SN/Avoid 4482292SN/ADefaultCommit<Impl>::setNextStatus() 4492292SN/A{ 4502292SN/A int squashes = 0; 4512292SN/A 4526221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 4536221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 4542292SN/A 4553867Sbinkertn@umich.edu while (threads != end) { 4566221Snate@binkert.org ThreadID tid = *threads++; 4572292SN/A 4582292SN/A if (commitStatus[tid] == ROBSquashing) { 4592292SN/A squashes++; 4602292SN/A } 4612292SN/A } 4622292SN/A 4632702Sktlim@umich.edu squashCounter = squashes; 4642292SN/A 4652292SN/A // If commit is currently squashing, then it will have activity for the 4662292SN/A // next cycle. Set its next status as active. 4672292SN/A if (squashCounter) { 4682292SN/A _nextStatus = Active; 4692292SN/A } 4702292SN/A} 4712292SN/A 4722292SN/Atemplate <class Impl> 4732292SN/Abool 4742292SN/ADefaultCommit<Impl>::changedROBEntries() 4752292SN/A{ 4766221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 4776221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 4782292SN/A 4793867Sbinkertn@umich.edu while (threads != end) { 4806221Snate@binkert.org ThreadID tid = *threads++; 4812292SN/A 4822292SN/A if (changedROBNumEntries[tid]) { 4832292SN/A return true; 4842292SN/A } 4852292SN/A } 4862292SN/A 4872292SN/A return false; 4882292SN/A} 4892292SN/A 4902292SN/Atemplate <class Impl> 4916221Snate@binkert.orgsize_t 4926221Snate@binkert.orgDefaultCommit<Impl>::numROBFreeEntries(ThreadID tid) 4932292SN/A{ 4942292SN/A return rob->numFreeEntries(tid); 4952292SN/A} 4962292SN/A 4972292SN/Atemplate <class Impl> 4982292SN/Avoid 4996221Snate@binkert.orgDefaultCommit<Impl>::generateTrapEvent(ThreadID tid) 5002292SN/A{ 5012292SN/A DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 5022292SN/A 5032292SN/A TrapEvent *trap = new TrapEvent(this, tid); 5042292SN/A 5057823Ssteve.reinhardt@amd.com cpu->schedule(trap, curTick() + trapLatency); 5064035Sktlim@umich.edu trapInFlight[tid] = true; 5072292SN/A} 5082292SN/A 5092292SN/Atemplate <class Impl> 5102292SN/Avoid 5116221Snate@binkert.orgDefaultCommit<Impl>::generateTCEvent(ThreadID tid) 5122292SN/A{ 5134035Sktlim@umich.edu assert(!trapInFlight[tid]); 5142680Sktlim@umich.edu DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 5152292SN/A 5162680Sktlim@umich.edu tcSquash[tid] = true; 5172292SN/A} 5182292SN/A 5192292SN/Atemplate <class Impl> 5202292SN/Avoid 5216221Snate@binkert.orgDefaultCommit<Impl>::squashAll(ThreadID tid) 5222292SN/A{ 5232292SN/A // If we want to include the squashing instruction in the squash, 5242292SN/A // then use one older sequence number. 5252292SN/A // Hopefully this doesn't mess things up. Basically I want to squash 5262292SN/A // all instructions of this thread. 5272292SN/A InstSeqNum squashed_inst = rob->isEmpty() ? 5287855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] : rob->readHeadInst(tid)->seqNum - 1; 5292292SN/A 5302292SN/A // All younger instructions will be squashed. Set the sequence 5312292SN/A // number as the youngest instruction in the ROB (0 in this case. 5322292SN/A // Hopefully nothing breaks.) 5337855SAli.Saidi@ARM.com youngestSeqNum[tid] = lastCommitedSeqNum[tid]; 5342292SN/A 5352292SN/A rob->squash(squashed_inst, tid); 5362292SN/A changedROBNumEntries[tid] = true; 5372292SN/A 5382292SN/A // Send back the sequence number of the squashed instruction. 5392292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 5402292SN/A 5412292SN/A // Send back the squash signal to tell stages that they should 5422292SN/A // squash. 5432292SN/A toIEW->commitInfo[tid].squash = true; 5442292SN/A 5452292SN/A // Send back the rob squashing signal so other stages know that 5462292SN/A // the ROB is in the process of squashing. 5472292SN/A toIEW->commitInfo[tid].robSquashing = true; 5482292SN/A 5497851SMatt.Horsnell@arm.com toIEW->commitInfo[tid].mispredictInst = NULL; 5508137SAli.Saidi@ARM.com toIEW->commitInfo[tid].squashInst = NULL; 5512292SN/A 5527720Sgblack@eecs.umich.edu toIEW->commitInfo[tid].pc = pc[tid]; 5532316SN/A} 5542292SN/A 5552316SN/Atemplate <class Impl> 5562316SN/Avoid 5576221Snate@binkert.orgDefaultCommit<Impl>::squashFromTrap(ThreadID tid) 5582316SN/A{ 5592316SN/A squashAll(tid); 5602316SN/A 5617720Sgblack@eecs.umich.edu DPRINTF(Commit, "Squashing from trap, restarting at PC %s\n", pc[tid]); 5622316SN/A 5632316SN/A thread[tid]->trapPending = false; 5642316SN/A thread[tid]->inSyscall = false; 5654035Sktlim@umich.edu trapInFlight[tid] = false; 5662316SN/A 5672316SN/A trapSquash[tid] = false; 5682316SN/A 5692316SN/A commitStatus[tid] = ROBSquashing; 5702316SN/A cpu->activityThisCycle(); 5712316SN/A} 5722316SN/A 5732316SN/Atemplate <class Impl> 5742316SN/Avoid 5756221Snate@binkert.orgDefaultCommit<Impl>::squashFromTC(ThreadID tid) 5762316SN/A{ 5772316SN/A squashAll(tid); 5782292SN/A 5797720Sgblack@eecs.umich.edu DPRINTF(Commit, "Squashing from TC, restarting at PC %s\n", pc[tid]); 5802292SN/A 5812292SN/A thread[tid]->inSyscall = false; 5822292SN/A assert(!thread[tid]->trapPending); 5832316SN/A 5842292SN/A commitStatus[tid] = ROBSquashing; 5852292SN/A cpu->activityThisCycle(); 5862292SN/A 5872680Sktlim@umich.edu tcSquash[tid] = false; 5882292SN/A} 5892292SN/A 5902292SN/Atemplate <class Impl> 5912292SN/Avoid 5928137SAli.Saidi@ARM.comDefaultCommit<Impl>::squashAfter(ThreadID tid, DynInstPtr &head_inst, 5938137SAli.Saidi@ARM.com uint64_t squash_after_seq_num) 5947784SAli.Saidi@ARM.com{ 5957784SAli.Saidi@ARM.com youngestSeqNum[tid] = squash_after_seq_num; 5967784SAli.Saidi@ARM.com 5977784SAli.Saidi@ARM.com rob->squash(squash_after_seq_num, tid); 5987784SAli.Saidi@ARM.com changedROBNumEntries[tid] = true; 5997784SAli.Saidi@ARM.com 6007784SAli.Saidi@ARM.com // Send back the sequence number of the squashed instruction. 6017784SAli.Saidi@ARM.com toIEW->commitInfo[tid].doneSeqNum = squash_after_seq_num; 6027784SAli.Saidi@ARM.com 6038137SAli.Saidi@ARM.com toIEW->commitInfo[tid].squashInst = head_inst; 6047784SAli.Saidi@ARM.com // Send back the squash signal to tell stages that they should squash. 6057784SAli.Saidi@ARM.com toIEW->commitInfo[tid].squash = true; 6067784SAli.Saidi@ARM.com 6077784SAli.Saidi@ARM.com // Send back the rob squashing signal so other stages know that 6087784SAli.Saidi@ARM.com // the ROB is in the process of squashing. 6097784SAli.Saidi@ARM.com toIEW->commitInfo[tid].robSquashing = true; 6107784SAli.Saidi@ARM.com 6118137SAli.Saidi@ARM.com toIEW->commitInfo[tid].mispredictInst = NULL; 6127784SAli.Saidi@ARM.com 6137784SAli.Saidi@ARM.com toIEW->commitInfo[tid].pc = pc[tid]; 6147784SAli.Saidi@ARM.com DPRINTF(Commit, "Executing squash after for [tid:%i] inst [sn:%lli]\n", 6157784SAli.Saidi@ARM.com tid, squash_after_seq_num); 6167784SAli.Saidi@ARM.com commitStatus[tid] = ROBSquashing; 6177784SAli.Saidi@ARM.com} 6187784SAli.Saidi@ARM.com 6197784SAli.Saidi@ARM.comtemplate <class Impl> 6207784SAli.Saidi@ARM.comvoid 6212292SN/ADefaultCommit<Impl>::tick() 6222292SN/A{ 6232292SN/A wroteToTimeBuffer = false; 6242292SN/A _nextStatus = Inactive; 6252292SN/A 6262843Sktlim@umich.edu if (drainPending && rob->isEmpty() && !iewStage->hasStoresToWB()) { 6272843Sktlim@umich.edu cpu->signalDrained(); 6282843Sktlim@umich.edu drainPending = false; 6292316SN/A return; 6302316SN/A } 6312316SN/A 6323867Sbinkertn@umich.edu if (activeThreads->empty()) 6332875Sksewell@umich.edu return; 6342875Sksewell@umich.edu 6356221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6366221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6372292SN/A 6382316SN/A // Check if any of the threads are done squashing. Change the 6392316SN/A // status if they are done. 6403867Sbinkertn@umich.edu while (threads != end) { 6416221Snate@binkert.org ThreadID tid = *threads++; 6422292SN/A 6434035Sktlim@umich.edu // Clear the bit saying if the thread has committed stores 6444035Sktlim@umich.edu // this cycle. 6454035Sktlim@umich.edu committedStores[tid] = false; 6464035Sktlim@umich.edu 6472292SN/A if (commitStatus[tid] == ROBSquashing) { 6482292SN/A 6492292SN/A if (rob->isDoneSquashing(tid)) { 6502292SN/A commitStatus[tid] = Running; 6512292SN/A } else { 6522292SN/A DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 6532877Sksewell@umich.edu " insts this cycle.\n", tid); 6542702Sktlim@umich.edu rob->doSquash(tid); 6552702Sktlim@umich.edu toIEW->commitInfo[tid].robSquashing = true; 6562702Sktlim@umich.edu wroteToTimeBuffer = true; 6572292SN/A } 6582292SN/A } 6592292SN/A } 6602292SN/A 6612292SN/A commit(); 6622292SN/A 6632292SN/A markCompletedInsts(); 6642292SN/A 6653867Sbinkertn@umich.edu threads = activeThreads->begin(); 6662292SN/A 6673867Sbinkertn@umich.edu while (threads != end) { 6686221Snate@binkert.org ThreadID tid = *threads++; 6692292SN/A 6702292SN/A if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 6712292SN/A // The ROB has more instructions it can commit. Its next status 6722292SN/A // will be active. 6732292SN/A _nextStatus = Active; 6742292SN/A 6752292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6762292SN/A 6777720Sgblack@eecs.umich.edu DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %s is head of" 6782292SN/A " ROB and ready to commit\n", 6797720Sgblack@eecs.umich.edu tid, inst->seqNum, inst->pcState()); 6802292SN/A 6812292SN/A } else if (!rob->isEmpty(tid)) { 6822292SN/A DynInstPtr inst = rob->readHeadInst(tid); 6832292SN/A 6842292SN/A DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 6857720Sgblack@eecs.umich.edu "%s is head of ROB and not ready\n", 6867720Sgblack@eecs.umich.edu tid, inst->seqNum, inst->pcState()); 6872292SN/A } 6882292SN/A 6892292SN/A DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 6902292SN/A tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 6912292SN/A } 6922292SN/A 6932292SN/A 6942292SN/A if (wroteToTimeBuffer) { 6952316SN/A DPRINTF(Activity, "Activity This Cycle.\n"); 6962292SN/A cpu->activityThisCycle(); 6972292SN/A } 6982292SN/A 6992292SN/A updateStatus(); 7002292SN/A} 7012292SN/A 7024035Sktlim@umich.edu#if FULL_SYSTEM 7032292SN/Atemplate <class Impl> 7042292SN/Avoid 7054035Sktlim@umich.eduDefaultCommit<Impl>::handleInterrupt() 7062292SN/A{ 7077847Sminkyu.jeong@arm.com // Verify that we still have an interrupt to handle 7087847Sminkyu.jeong@arm.com if (!cpu->checkInterrupts(cpu->tcBase(0))) { 7097847Sminkyu.jeong@arm.com DPRINTF(Commit, "Pending interrupt is cleared by master before " 7107847Sminkyu.jeong@arm.com "it got handled. Restart fetching from the orig path.\n"); 7117847Sminkyu.jeong@arm.com toIEW->commitInfo[0].clearInterrupt = true; 7127847Sminkyu.jeong@arm.com interrupt = NoFault; 7137847Sminkyu.jeong@arm.com return; 7147847Sminkyu.jeong@arm.com } 7153633Sktlim@umich.edu 7167847Sminkyu.jeong@arm.com // Wait until the ROB is empty and all stores have drained in 7177847Sminkyu.jeong@arm.com // order to enter the interrupt. 7187847Sminkyu.jeong@arm.com if (rob->isEmpty() && !iewStage->hasStoresToWB()) { 7197847Sminkyu.jeong@arm.com // Squash or record that I need to squash this cycle if 7207847Sminkyu.jeong@arm.com // an interrupt needed to be handled. 7217847Sminkyu.jeong@arm.com DPRINTF(Commit, "Interrupt detected.\n"); 7224035Sktlim@umich.edu 7237847Sminkyu.jeong@arm.com // Clear the interrupt now that it's going to be handled 7247847Sminkyu.jeong@arm.com toIEW->commitInfo[0].clearInterrupt = true; 7252292SN/A 7267847Sminkyu.jeong@arm.com assert(!thread[0]->inSyscall); 7277847Sminkyu.jeong@arm.com thread[0]->inSyscall = true; 7282292SN/A 7297847Sminkyu.jeong@arm.com // CPU will handle interrupt. 7307847Sminkyu.jeong@arm.com cpu->processInterrupts(interrupt); 7313633Sktlim@umich.edu 7327847Sminkyu.jeong@arm.com thread[0]->inSyscall = false; 7332292SN/A 7347847Sminkyu.jeong@arm.com commitStatus[0] = TrapPending; 7352292SN/A 7367847Sminkyu.jeong@arm.com // Generate trap squash event. 7377847Sminkyu.jeong@arm.com generateTrapEvent(0); 7383640Sktlim@umich.edu 7397847Sminkyu.jeong@arm.com interrupt = NoFault; 7407847Sminkyu.jeong@arm.com } else { 7417847Sminkyu.jeong@arm.com DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n"); 7421060SN/A } 7434035Sktlim@umich.edu} 7447847Sminkyu.jeong@arm.com 7457847Sminkyu.jeong@arm.comtemplate <class Impl> 7467847Sminkyu.jeong@arm.comvoid 7477847Sminkyu.jeong@arm.comDefaultCommit<Impl>::propagateInterrupt() 7487847Sminkyu.jeong@arm.com{ 7497847Sminkyu.jeong@arm.com if (commitStatus[0] == TrapPending || interrupt || trapSquash[0] || 7507847Sminkyu.jeong@arm.com tcSquash[0]) 7517847Sminkyu.jeong@arm.com return; 7527847Sminkyu.jeong@arm.com 7537847Sminkyu.jeong@arm.com // Process interrupts if interrupts are enabled, not in PAL 7547847Sminkyu.jeong@arm.com // mode, and no other traps or external squashes are currently 7557847Sminkyu.jeong@arm.com // pending. 7567847Sminkyu.jeong@arm.com // @todo: Allow other threads to handle interrupts. 7577847Sminkyu.jeong@arm.com 7587847Sminkyu.jeong@arm.com // Get any interrupt that happened 7597847Sminkyu.jeong@arm.com interrupt = cpu->getInterrupts(); 7607847Sminkyu.jeong@arm.com 7617847Sminkyu.jeong@arm.com // Tell fetch that there is an interrupt pending. This 7627847Sminkyu.jeong@arm.com // will make fetch wait until it sees a non PAL-mode PC, 7637847Sminkyu.jeong@arm.com // at which point it stops fetching instructions. 7647847Sminkyu.jeong@arm.com if (interrupt != NoFault) 7657847Sminkyu.jeong@arm.com toIEW->commitInfo[0].interruptPending = true; 7667847Sminkyu.jeong@arm.com} 7677847Sminkyu.jeong@arm.com 7684035Sktlim@umich.edu#endif // FULL_SYSTEM 7693634Sktlim@umich.edu 7704035Sktlim@umich.edutemplate <class Impl> 7714035Sktlim@umich.eduvoid 7724035Sktlim@umich.eduDefaultCommit<Impl>::commit() 7734035Sktlim@umich.edu{ 7744035Sktlim@umich.edu 7754035Sktlim@umich.edu#if FULL_SYSTEM 7767847Sminkyu.jeong@arm.com // Check for any interrupt that we've already squashed for and start processing it. 7777847Sminkyu.jeong@arm.com if (interrupt != NoFault) 7784035Sktlim@umich.edu handleInterrupt(); 7797847Sminkyu.jeong@arm.com 7807847Sminkyu.jeong@arm.com // Check if we have a interrupt and get read to handle it 7817847Sminkyu.jeong@arm.com if (cpu->checkInterrupts(cpu->tcBase(0))) 7827847Sminkyu.jeong@arm.com propagateInterrupt(); 7831060SN/A#endif // FULL_SYSTEM 7841060SN/A 7851060SN/A //////////////////////////////////// 7862316SN/A // Check for any possible squashes, handle them first 7871060SN/A //////////////////////////////////// 7886221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 7896221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 7901060SN/A 7913867Sbinkertn@umich.edu while (threads != end) { 7926221Snate@binkert.org ThreadID tid = *threads++; 7931060SN/A 7942292SN/A // Not sure which one takes priority. I think if we have 7952292SN/A // both, that's a bad sign. 7962292SN/A if (trapSquash[tid] == true) { 7972680Sktlim@umich.edu assert(!tcSquash[tid]); 7982292SN/A squashFromTrap(tid); 7992680Sktlim@umich.edu } else if (tcSquash[tid] == true) { 8004035Sktlim@umich.edu assert(commitStatus[tid] != TrapPending); 8012680Sktlim@umich.edu squashFromTC(tid); 8022292SN/A } 8031061SN/A 8042292SN/A // Squashed sequence number must be older than youngest valid 8052292SN/A // instruction in the ROB. This prevents squashes from younger 8062292SN/A // instructions overriding squashes from older instructions. 8072292SN/A if (fromIEW->squash[tid] && 8082292SN/A commitStatus[tid] != TrapPending && 8092292SN/A fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 8101061SN/A 8118137SAli.Saidi@ARM.com if (fromIEW->mispredictInst[tid]) { 8128137SAli.Saidi@ARM.com DPRINTF(Commit, 8138137SAli.Saidi@ARM.com "[tid:%i]: Squashing due to branch mispred PC:%#x [sn:%i]\n", 8142292SN/A tid, 8158137SAli.Saidi@ARM.com fromIEW->mispredictInst[tid]->instAddr(), 8162292SN/A fromIEW->squashedSeqNum[tid]); 8178137SAli.Saidi@ARM.com } else { 8188137SAli.Saidi@ARM.com DPRINTF(Commit, 8198137SAli.Saidi@ARM.com "[tid:%i]: Squashing due to order violation [sn:%i]\n", 8208137SAli.Saidi@ARM.com tid, fromIEW->squashedSeqNum[tid]); 8218137SAli.Saidi@ARM.com } 8221061SN/A 8232292SN/A DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 8242292SN/A tid, 8257720Sgblack@eecs.umich.edu fromIEW->pc[tid].nextInstAddr()); 8261061SN/A 8272292SN/A commitStatus[tid] = ROBSquashing; 8281061SN/A 8292292SN/A // If we want to include the squashing instruction in the squash, 8302292SN/A // then use one older sequence number. 8312292SN/A InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 8321062SN/A 8332935Sksewell@umich.edu if (fromIEW->includeSquashInst[tid] == true) { 8342292SN/A squashed_inst--; 8352935Sksewell@umich.edu } 8364035Sktlim@umich.edu 8372292SN/A // All younger instructions will be squashed. Set the sequence 8382292SN/A // number as the youngest instruction in the ROB. 8392292SN/A youngestSeqNum[tid] = squashed_inst; 8402292SN/A 8413093Sksewell@umich.edu rob->squash(squashed_inst, tid); 8422292SN/A changedROBNumEntries[tid] = true; 8432292SN/A 8442292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 8452292SN/A 8462292SN/A toIEW->commitInfo[tid].squash = true; 8472292SN/A 8482292SN/A // Send back the rob squashing signal so other stages know that 8492292SN/A // the ROB is in the process of squashing. 8502292SN/A toIEW->commitInfo[tid].robSquashing = true; 8512292SN/A 8527851SMatt.Horsnell@arm.com toIEW->commitInfo[tid].mispredictInst = 8537851SMatt.Horsnell@arm.com fromIEW->mispredictInst[tid]; 8542292SN/A toIEW->commitInfo[tid].branchTaken = 8552292SN/A fromIEW->branchTaken[tid]; 8568137SAli.Saidi@ARM.com toIEW->commitInfo[tid].squashInst = NULL; 8572292SN/A 8587720Sgblack@eecs.umich.edu toIEW->commitInfo[tid].pc = fromIEW->pc[tid]; 8592292SN/A 8608137SAli.Saidi@ARM.com if (toIEW->commitInfo[tid].mispredictInst) { 8612292SN/A ++branchMispredicts; 8622292SN/A } 8631062SN/A } 8642292SN/A 8651060SN/A } 8661060SN/A 8672292SN/A setNextStatus(); 8682292SN/A 8692292SN/A if (squashCounter != numThreads) { 8701061SN/A // If we're not currently squashing, then get instructions. 8711060SN/A getInsts(); 8721060SN/A 8731061SN/A // Try to commit any instructions. 8741060SN/A commitInsts(); 8751060SN/A } 8761060SN/A 8772292SN/A //Check for any activity 8783867Sbinkertn@umich.edu threads = activeThreads->begin(); 8792292SN/A 8803867Sbinkertn@umich.edu while (threads != end) { 8816221Snate@binkert.org ThreadID tid = *threads++; 8822292SN/A 8832292SN/A if (changedROBNumEntries[tid]) { 8842292SN/A toIEW->commitInfo[tid].usedROB = true; 8852292SN/A toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 8862292SN/A 8872292SN/A wroteToTimeBuffer = true; 8882292SN/A changedROBNumEntries[tid] = false; 8894035Sktlim@umich.edu if (rob->isEmpty(tid)) 8904035Sktlim@umich.edu checkEmptyROB[tid] = true; 8912292SN/A } 8924035Sktlim@umich.edu 8934035Sktlim@umich.edu // ROB is only considered "empty" for previous stages if: a) 8944035Sktlim@umich.edu // ROB is empty, b) there are no outstanding stores, c) IEW 8954035Sktlim@umich.edu // stage has received any information regarding stores that 8964035Sktlim@umich.edu // committed. 8974035Sktlim@umich.edu // c) is checked by making sure to not consider the ROB empty 8984035Sktlim@umich.edu // on the same cycle as when stores have been committed. 8994035Sktlim@umich.edu // @todo: Make this handle multi-cycle communication between 9004035Sktlim@umich.edu // commit and IEW. 9014035Sktlim@umich.edu if (checkEmptyROB[tid] && rob->isEmpty(tid) && 9025557Sktlim@umich.edu !iewStage->hasStoresToWB(tid) && !committedStores[tid]) { 9034035Sktlim@umich.edu checkEmptyROB[tid] = false; 9044035Sktlim@umich.edu toIEW->commitInfo[tid].usedROB = true; 9054035Sktlim@umich.edu toIEW->commitInfo[tid].emptyROB = true; 9064035Sktlim@umich.edu toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 9074035Sktlim@umich.edu wroteToTimeBuffer = true; 9084035Sktlim@umich.edu } 9094035Sktlim@umich.edu 9101060SN/A } 9111060SN/A} 9121060SN/A 9131061SN/Atemplate <class Impl> 9141060SN/Avoid 9152292SN/ADefaultCommit<Impl>::commitInsts() 9161060SN/A{ 9171060SN/A //////////////////////////////////// 9181060SN/A // Handle commit 9192316SN/A // Note that commit will be handled prior to putting new 9202316SN/A // instructions in the ROB so that the ROB only tries to commit 9212316SN/A // instructions it has in this current cycle, and not instructions 9222316SN/A // it is writing in during this cycle. Can't commit and squash 9232316SN/A // things at the same time... 9241060SN/A //////////////////////////////////// 9251060SN/A 9262292SN/A DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 9271060SN/A 9281060SN/A unsigned num_committed = 0; 9291060SN/A 9302292SN/A DynInstPtr head_inst; 9312316SN/A 9321060SN/A // Commit as many instructions as possible until the commit bandwidth 9331060SN/A // limit is reached, or it becomes impossible to commit any more. 9342292SN/A while (num_committed < commitWidth) { 9352292SN/A int commit_thread = getCommittingThread(); 9361060SN/A 9372292SN/A if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 9382292SN/A break; 9392292SN/A 9402292SN/A head_inst = rob->readHeadInst(commit_thread); 9412292SN/A 9426221Snate@binkert.org ThreadID tid = head_inst->threadNumber; 9432292SN/A 9442292SN/A assert(tid == commit_thread); 9452292SN/A 9462292SN/A DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 9472292SN/A head_inst->seqNum, tid); 9482132SN/A 9492316SN/A // If the head instruction is squashed, it is ready to retire 9502316SN/A // (be removed from the ROB) at any time. 9511060SN/A if (head_inst->isSquashed()) { 9521060SN/A 9532292SN/A DPRINTF(Commit, "Retiring squashed instruction from " 9541060SN/A "ROB.\n"); 9551060SN/A 9562292SN/A rob->retireHead(commit_thread); 9571060SN/A 9581062SN/A ++commitSquashedInsts; 9591062SN/A 9602292SN/A // Record that the number of ROB entries has changed. 9612292SN/A changedROBNumEntries[tid] = true; 9621060SN/A } else { 9637720Sgblack@eecs.umich.edu pc[tid] = head_inst->pcState(); 9642292SN/A 9651060SN/A // Increment the total number of non-speculative instructions 9661060SN/A // executed. 9671060SN/A // Hack for now: it really shouldn't happen until after the 9681061SN/A // commit is deemed to be successful, but this count is needed 9691061SN/A // for syscalls. 9702292SN/A thread[tid]->funcExeInst++; 9711060SN/A 9721060SN/A // Try to commit the head instruction. 9731060SN/A bool commit_success = commitHead(head_inst, num_committed); 9741060SN/A 9751062SN/A if (commit_success) { 9761060SN/A ++num_committed; 9771060SN/A 9782292SN/A changedROBNumEntries[tid] = true; 9792292SN/A 9802292SN/A // Set the doneSeqNum to the youngest committed instruction. 9812292SN/A toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 9821060SN/A 9831062SN/A ++commitCommittedInsts; 9841062SN/A 9852292SN/A // To match the old model, don't count nops and instruction 9862292SN/A // prefetches towards the total commit count. 9872292SN/A if (!head_inst->isNop() && !head_inst->isInstPrefetch()) { 9882292SN/A cpu->instDone(tid); 9891062SN/A } 9902292SN/A 9917783SGiacomo.Gabrielli@arm.com // Updates misc. registers. 9927783SGiacomo.Gabrielli@arm.com head_inst->updateMiscRegs(); 9937783SGiacomo.Gabrielli@arm.com 9947720Sgblack@eecs.umich.edu TheISA::advancePC(pc[tid], head_inst->staticInst); 9952935Sksewell@umich.edu 9967855SAli.Saidi@ARM.com // Keep track of the last sequence number commited 9977855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] = head_inst->seqNum; 9987855SAli.Saidi@ARM.com 9997784SAli.Saidi@ARM.com // If this is an instruction that doesn't play nicely with 10007784SAli.Saidi@ARM.com // others squash everything and restart fetch 10017784SAli.Saidi@ARM.com if (head_inst->isSquashAfter()) 10028137SAli.Saidi@ARM.com squashAfter(tid, head_inst, head_inst->seqNum); 10037784SAli.Saidi@ARM.com 10042292SN/A int count = 0; 10052292SN/A Addr oldpc; 10065108Sgblack@eecs.umich.edu // Debug statement. Checks to make sure we're not 10075108Sgblack@eecs.umich.edu // currently updating state while handling PC events. 10085108Sgblack@eecs.umich.edu assert(!thread[tid]->inSyscall && !thread[tid]->trapPending); 10092292SN/A do { 10107720Sgblack@eecs.umich.edu oldpc = pc[tid].instAddr(); 10115108Sgblack@eecs.umich.edu cpu->system->pcEventQueue.service(thread[tid]->getTC()); 10122292SN/A count++; 10137720Sgblack@eecs.umich.edu } while (oldpc != pc[tid].instAddr()); 10142292SN/A if (count > 1) { 10155108Sgblack@eecs.umich.edu DPRINTF(Commit, 10165108Sgblack@eecs.umich.edu "PC skip function event, stopping commit\n"); 10172292SN/A break; 10182292SN/A } 10191060SN/A } else { 10207720Sgblack@eecs.umich.edu DPRINTF(Commit, "Unable to commit head instruction PC:%s " 10212292SN/A "[tid:%i] [sn:%i].\n", 10227720Sgblack@eecs.umich.edu head_inst->pcState(), tid ,head_inst->seqNum); 10231060SN/A break; 10241060SN/A } 10251060SN/A } 10261060SN/A } 10271062SN/A 10281063SN/A DPRINTF(CommitRate, "%i\n", num_committed); 10292292SN/A numCommittedDist.sample(num_committed); 10302307SN/A 10312307SN/A if (num_committed == commitWidth) { 10322349SN/A commitEligibleSamples++; 10332307SN/A } 10341060SN/A} 10351060SN/A 10361061SN/Atemplate <class Impl> 10371060SN/Abool 10382292SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 10391060SN/A{ 10401060SN/A assert(head_inst); 10411060SN/A 10426221Snate@binkert.org ThreadID tid = head_inst->threadNumber; 10432292SN/A 10442316SN/A // If the instruction is not executed yet, then it will need extra 10452316SN/A // handling. Signal backwards that it should be executed. 10461061SN/A if (!head_inst->isExecuted()) { 10471061SN/A // Keep this number correct. We have not yet actually executed 10481061SN/A // and committed this instruction. 10492292SN/A thread[tid]->funcExeInst--; 10501062SN/A 10512292SN/A if (head_inst->isNonSpeculative() || 10522348SN/A head_inst->isStoreConditional() || 10532292SN/A head_inst->isMemBarrier() || 10542292SN/A head_inst->isWriteBarrier()) { 10552316SN/A 10562316SN/A DPRINTF(Commit, "Encountered a barrier or non-speculative " 10577720Sgblack@eecs.umich.edu "instruction [sn:%lli] at the head of the ROB, PC %s.\n", 10587720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 10592316SN/A 10605557Sktlim@umich.edu if (inst_num > 0 || iewStage->hasStoresToWB(tid)) { 10612292SN/A DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 10622292SN/A return false; 10632292SN/A } 10642292SN/A 10652292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 10661061SN/A 10671061SN/A // Change the instruction so it won't try to commit again until 10681061SN/A // it is executed. 10691061SN/A head_inst->clearCanCommit(); 10701061SN/A 10711062SN/A ++commitNonSpecStalls; 10721062SN/A 10731061SN/A return false; 10742292SN/A } else if (head_inst->isLoad()) { 10755557Sktlim@umich.edu if (inst_num > 0 || iewStage->hasStoresToWB(tid)) { 10764035Sktlim@umich.edu DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 10774035Sktlim@umich.edu return false; 10784035Sktlim@umich.edu } 10794035Sktlim@umich.edu 10804035Sktlim@umich.edu assert(head_inst->uncacheable()); 10817720Sgblack@eecs.umich.edu DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %s.\n", 10827720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 10832292SN/A 10842292SN/A // Send back the non-speculative instruction's sequence 10852316SN/A // number. Tell the lsq to re-execute the load. 10862292SN/A toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 10872292SN/A toIEW->commitInfo[tid].uncached = true; 10882292SN/A toIEW->commitInfo[tid].uncachedLoad = head_inst; 10892292SN/A 10902292SN/A head_inst->clearCanCommit(); 10912292SN/A 10922292SN/A return false; 10931061SN/A } else { 10942292SN/A panic("Trying to commit un-executed instruction " 10951061SN/A "of unknown type!\n"); 10961061SN/A } 10971060SN/A } 10981060SN/A 10992316SN/A if (head_inst->isThreadSync()) { 11002292SN/A // Not handled for now. 11012316SN/A panic("Thread sync instructions are not handled yet.\n"); 11022132SN/A } 11032132SN/A 11044035Sktlim@umich.edu // Check if the instruction caused a fault. If so, trap. 11054035Sktlim@umich.edu Fault inst_fault = head_inst->getFault(); 11064035Sktlim@umich.edu 11072316SN/A // Stores mark themselves as completed. 11084035Sktlim@umich.edu if (!head_inst->isStore() && inst_fault == NoFault) { 11092310SN/A head_inst->setCompleted(); 11102310SN/A } 11112310SN/A 11122733Sktlim@umich.edu#if USE_CHECKER 11132316SN/A // Use checker prior to updating anything due to traps or PC 11142316SN/A // based events. 11152316SN/A if (cpu->checker) { 11162732Sktlim@umich.edu cpu->checker->verify(head_inst); 11171060SN/A } 11182733Sktlim@umich.edu#endif 11191060SN/A 11202112SN/A if (inst_fault != NoFault) { 11217720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inst [sn:%lli] PC %s has a fault\n", 11227720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 11232292SN/A 11245557Sktlim@umich.edu if (iewStage->hasStoresToWB(tid) || inst_num > 0) { 11252316SN/A DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 11262316SN/A return false; 11272316SN/A } 11282310SN/A 11294035Sktlim@umich.edu head_inst->setCompleted(); 11304035Sktlim@umich.edu 11312733Sktlim@umich.edu#if USE_CHECKER 11322316SN/A if (cpu->checker && head_inst->isStore()) { 11332732Sktlim@umich.edu cpu->checker->verify(head_inst); 11342316SN/A } 11352733Sktlim@umich.edu#endif 11362292SN/A 11372316SN/A assert(!thread[tid]->inSyscall); 11382292SN/A 11392316SN/A // Mark that we're in state update mode so that the trap's 11402316SN/A // execution doesn't generate extra squashes. 11412316SN/A thread[tid]->inSyscall = true; 11422292SN/A 11432316SN/A // Execute the trap. Although it's slightly unrealistic in 11442316SN/A // terms of timing (as it doesn't wait for the full timing of 11452316SN/A // the trap event to complete before updating state), it's 11462316SN/A // needed to update the state as soon as possible. This 11472316SN/A // prevents external agents from changing any specific state 11482316SN/A // that the trap need. 11497684Sgblack@eecs.umich.edu cpu->trap(inst_fault, tid, head_inst->staticInst); 11502292SN/A 11512316SN/A // Exit state update mode to avoid accidental updating. 11522316SN/A thread[tid]->inSyscall = false; 11532292SN/A 11542316SN/A commitStatus[tid] = TrapPending; 11552292SN/A 11568067SAli.Saidi@ARM.com DPRINTF(Commit, "Committing instruction with fault [sn:%lli]\n", 11578067SAli.Saidi@ARM.com head_inst->seqNum); 11584035Sktlim@umich.edu if (head_inst->traceData) { 11596667Ssteve.reinhardt@amd.com if (DTRACE(ExecFaulting)) { 11606667Ssteve.reinhardt@amd.com head_inst->traceData->setFetchSeq(head_inst->seqNum); 11616667Ssteve.reinhardt@amd.com head_inst->traceData->setCPSeq(thread[tid]->numInst); 11626667Ssteve.reinhardt@amd.com head_inst->traceData->dump(); 11636667Ssteve.reinhardt@amd.com } 11644288Sktlim@umich.edu delete head_inst->traceData; 11654035Sktlim@umich.edu head_inst->traceData = NULL; 11664035Sktlim@umich.edu } 11674035Sktlim@umich.edu 11682316SN/A // Generate trap squash event. 11692316SN/A generateTrapEvent(tid); 11702316SN/A return false; 11711060SN/A } 11721060SN/A 11732301SN/A updateComInstStats(head_inst); 11742132SN/A 11752362SN/A#if FULL_SYSTEM 11762362SN/A if (thread[tid]->profile) { 11777720Sgblack@eecs.umich.edu thread[tid]->profilePC = head_inst->instAddr(); 11783126Sktlim@umich.edu ProfileNode *node = thread[tid]->profile->consume(thread[tid]->getTC(), 11792362SN/A head_inst->staticInst); 11802362SN/A 11812362SN/A if (node) 11822362SN/A thread[tid]->profileNode = node; 11832362SN/A } 11845953Ssaidi@eecs.umich.edu if (CPA::available()) { 11855953Ssaidi@eecs.umich.edu if (head_inst->isControl()) { 11865953Ssaidi@eecs.umich.edu ThreadContext *tc = thread[tid]->getTC(); 11877720Sgblack@eecs.umich.edu CPA::cpa()->swAutoBegin(tc, head_inst->nextInstAddr()); 11885953Ssaidi@eecs.umich.edu } 11895953Ssaidi@eecs.umich.edu } 11902362SN/A#endif 11918068SAli.Saidi@ARM.com DPRINTF(Commit, "Committing instruction with [sn:%lli]\n", 11928068SAli.Saidi@ARM.com head_inst->seqNum); 11932132SN/A if (head_inst->traceData) { 11942292SN/A head_inst->traceData->setFetchSeq(head_inst->seqNum); 11952292SN/A head_inst->traceData->setCPSeq(thread[tid]->numInst); 11964046Sbinkertn@umich.edu head_inst->traceData->dump(); 11974046Sbinkertn@umich.edu delete head_inst->traceData; 11982292SN/A head_inst->traceData = NULL; 11991060SN/A } 12001060SN/A 12012292SN/A // Update the commit rename map 12022292SN/A for (int i = 0; i < head_inst->numDestRegs(); i++) { 12033771Sgblack@eecs.umich.edu renameMap[tid]->setEntry(head_inst->flattenedDestRegIdx(i), 12042292SN/A head_inst->renamedDestRegIdx(i)); 12051060SN/A } 12061062SN/A 12072292SN/A // Finally clear the head ROB entry. 12082292SN/A rob->retireHead(tid); 12091060SN/A 12104035Sktlim@umich.edu // If this was a store, record it for this cycle. 12114035Sktlim@umich.edu if (head_inst->isStore()) 12124035Sktlim@umich.edu committedStores[tid] = true; 12134035Sktlim@umich.edu 12141060SN/A // Return true to indicate that we have committed an instruction. 12151060SN/A return true; 12161060SN/A} 12171060SN/A 12181061SN/Atemplate <class Impl> 12191060SN/Avoid 12202292SN/ADefaultCommit<Impl>::getInsts() 12211060SN/A{ 12222935Sksewell@umich.edu DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 12232935Sksewell@umich.edu 12243093Sksewell@umich.edu // Read any renamed instructions and place them into the ROB. 12253093Sksewell@umich.edu int insts_to_process = std::min((int)renameWidth, fromRename->size); 12262965Sksewell@umich.edu 12272965Sksewell@umich.edu for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 12282965Sksewell@umich.edu DynInstPtr inst; 12292965Sksewell@umich.edu 12303093Sksewell@umich.edu inst = fromRename->insts[inst_num]; 12316221Snate@binkert.org ThreadID tid = inst->threadNumber; 12322292SN/A 12332292SN/A if (!inst->isSquashed() && 12344035Sktlim@umich.edu commitStatus[tid] != ROBSquashing && 12354035Sktlim@umich.edu commitStatus[tid] != TrapPending) { 12362292SN/A changedROBNumEntries[tid] = true; 12372292SN/A 12387720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ROB.\n", 12397720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, tid); 12402292SN/A 12412292SN/A rob->insertInst(inst); 12422292SN/A 12432292SN/A assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 12442292SN/A 12452292SN/A youngestSeqNum[tid] = inst->seqNum; 12461061SN/A } else { 12477720Sgblack@eecs.umich.edu DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 12481061SN/A "squashed, skipping.\n", 12497720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, tid); 12501061SN/A } 12511060SN/A } 12522965Sksewell@umich.edu} 12532965Sksewell@umich.edu 12542965Sksewell@umich.edutemplate <class Impl> 12552965Sksewell@umich.eduvoid 12562965Sksewell@umich.eduDefaultCommit<Impl>::skidInsert() 12572965Sksewell@umich.edu{ 12582965Sksewell@umich.edu DPRINTF(Commit, "Attempting to any instructions from rename into " 12592965Sksewell@umich.edu "skidBuffer.\n"); 12602965Sksewell@umich.edu 12612965Sksewell@umich.edu for (int inst_num = 0; inst_num < fromRename->size; ++inst_num) { 12622965Sksewell@umich.edu DynInstPtr inst = fromRename->insts[inst_num]; 12632965Sksewell@umich.edu 12642965Sksewell@umich.edu if (!inst->isSquashed()) { 12657720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ", 12667720Sgblack@eecs.umich.edu "skidBuffer.\n", inst->pcState(), inst->seqNum, 12673221Sktlim@umich.edu inst->threadNumber); 12682965Sksewell@umich.edu skidBuffer.push(inst); 12692965Sksewell@umich.edu } else { 12707720Sgblack@eecs.umich.edu DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 12712965Sksewell@umich.edu "squashed, skipping.\n", 12727720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, inst->threadNumber); 12732965Sksewell@umich.edu } 12742965Sksewell@umich.edu } 12751060SN/A} 12761060SN/A 12771061SN/Atemplate <class Impl> 12781060SN/Avoid 12792292SN/ADefaultCommit<Impl>::markCompletedInsts() 12801060SN/A{ 12811060SN/A // Grab completed insts out of the IEW instruction queue, and mark 12821060SN/A // instructions completed within the ROB. 12831060SN/A for (int inst_num = 0; 12841681SN/A inst_num < fromIEW->size && fromIEW->insts[inst_num]; 12851060SN/A ++inst_num) 12861060SN/A { 12872292SN/A if (!fromIEW->insts[inst_num]->isSquashed()) { 12887720Sgblack@eecs.umich.edu DPRINTF(Commit, "[tid:%i]: Marking PC %s, [sn:%lli] ready " 12892316SN/A "within ROB.\n", 12902292SN/A fromIEW->insts[inst_num]->threadNumber, 12917720Sgblack@eecs.umich.edu fromIEW->insts[inst_num]->pcState(), 12922292SN/A fromIEW->insts[inst_num]->seqNum); 12931060SN/A 12942292SN/A // Mark the instruction as ready to commit. 12952292SN/A fromIEW->insts[inst_num]->setCanCommit(); 12962292SN/A } 12971060SN/A } 12981060SN/A} 12991060SN/A 13001061SN/Atemplate <class Impl> 13012292SN/Abool 13022292SN/ADefaultCommit<Impl>::robDoneSquashing() 13031060SN/A{ 13046221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 13056221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 13062292SN/A 13073867Sbinkertn@umich.edu while (threads != end) { 13086221Snate@binkert.org ThreadID tid = *threads++; 13092292SN/A 13102292SN/A if (!rob->isDoneSquashing(tid)) 13112292SN/A return false; 13122292SN/A } 13132292SN/A 13142292SN/A return true; 13151060SN/A} 13162292SN/A 13172301SN/Atemplate <class Impl> 13182301SN/Avoid 13192301SN/ADefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 13202301SN/A{ 13216221Snate@binkert.org ThreadID tid = inst->threadNumber; 13222301SN/A 13232301SN/A // 13242301SN/A // Pick off the software prefetches 13252301SN/A // 13262301SN/A#ifdef TARGET_ALPHA 13272301SN/A if (inst->isDataPrefetch()) { 13286221Snate@binkert.org statComSwp[tid]++; 13292301SN/A } else { 13306221Snate@binkert.org statComInst[tid]++; 13312301SN/A } 13322301SN/A#else 13336221Snate@binkert.org statComInst[tid]++; 13342301SN/A#endif 13352301SN/A 13362301SN/A // 13372301SN/A // Control Instructions 13382301SN/A // 13392301SN/A if (inst->isControl()) 13406221Snate@binkert.org statComBranches[tid]++; 13412301SN/A 13422301SN/A // 13432301SN/A // Memory references 13442301SN/A // 13452301SN/A if (inst->isMemRef()) { 13466221Snate@binkert.org statComRefs[tid]++; 13472301SN/A 13482301SN/A if (inst->isLoad()) { 13496221Snate@binkert.org statComLoads[tid]++; 13502301SN/A } 13512301SN/A } 13522301SN/A 13532301SN/A if (inst->isMemBarrier()) { 13546221Snate@binkert.org statComMembars[tid]++; 13552301SN/A } 13567897Shestness@cs.utexas.edu 13577897Shestness@cs.utexas.edu // Integer Instruction 13587897Shestness@cs.utexas.edu if (inst->isInteger()) 13597897Shestness@cs.utexas.edu statComInteger[tid]++; 13607897Shestness@cs.utexas.edu 13617897Shestness@cs.utexas.edu // Floating Point Instruction 13627897Shestness@cs.utexas.edu if (inst->isFloating()) 13637897Shestness@cs.utexas.edu statComFloating[tid]++; 13647897Shestness@cs.utexas.edu 13657897Shestness@cs.utexas.edu // Function Calls 13667897Shestness@cs.utexas.edu if (inst->isCall()) 13677897Shestness@cs.utexas.edu statComFunctionCalls[tid]++; 13687897Shestness@cs.utexas.edu 13692301SN/A} 13702301SN/A 13712292SN/A//////////////////////////////////////// 13722292SN/A// // 13732316SN/A// SMT COMMIT POLICY MAINTAINED HERE // 13742292SN/A// // 13752292SN/A//////////////////////////////////////// 13762292SN/Atemplate <class Impl> 13776221Snate@binkert.orgThreadID 13782292SN/ADefaultCommit<Impl>::getCommittingThread() 13792292SN/A{ 13802292SN/A if (numThreads > 1) { 13812292SN/A switch (commitPolicy) { 13822292SN/A 13832292SN/A case Aggressive: 13842292SN/A //If Policy is Aggressive, commit will call 13852292SN/A //this function multiple times per 13862292SN/A //cycle 13872292SN/A return oldestReady(); 13882292SN/A 13892292SN/A case RoundRobin: 13902292SN/A return roundRobin(); 13912292SN/A 13922292SN/A case OldestReady: 13932292SN/A return oldestReady(); 13942292SN/A 13952292SN/A default: 13966221Snate@binkert.org return InvalidThreadID; 13972292SN/A } 13982292SN/A } else { 13993867Sbinkertn@umich.edu assert(!activeThreads->empty()); 14006221Snate@binkert.org ThreadID tid = activeThreads->front(); 14012292SN/A 14022292SN/A if (commitStatus[tid] == Running || 14032292SN/A commitStatus[tid] == Idle || 14042292SN/A commitStatus[tid] == FetchTrapPending) { 14052292SN/A return tid; 14062292SN/A } else { 14076221Snate@binkert.org return InvalidThreadID; 14082292SN/A } 14092292SN/A } 14102292SN/A} 14112292SN/A 14122292SN/Atemplate<class Impl> 14136221Snate@binkert.orgThreadID 14142292SN/ADefaultCommit<Impl>::roundRobin() 14152292SN/A{ 14166221Snate@binkert.org list<ThreadID>::iterator pri_iter = priority_list.begin(); 14176221Snate@binkert.org list<ThreadID>::iterator end = priority_list.end(); 14182292SN/A 14192292SN/A while (pri_iter != end) { 14206221Snate@binkert.org ThreadID tid = *pri_iter; 14212292SN/A 14222292SN/A if (commitStatus[tid] == Running || 14232831Sksewell@umich.edu commitStatus[tid] == Idle || 14242831Sksewell@umich.edu commitStatus[tid] == FetchTrapPending) { 14252292SN/A 14262292SN/A if (rob->isHeadReady(tid)) { 14272292SN/A priority_list.erase(pri_iter); 14282292SN/A priority_list.push_back(tid); 14292292SN/A 14302292SN/A return tid; 14312292SN/A } 14322292SN/A } 14332292SN/A 14342292SN/A pri_iter++; 14352292SN/A } 14362292SN/A 14376221Snate@binkert.org return InvalidThreadID; 14382292SN/A} 14392292SN/A 14402292SN/Atemplate<class Impl> 14416221Snate@binkert.orgThreadID 14422292SN/ADefaultCommit<Impl>::oldestReady() 14432292SN/A{ 14442292SN/A unsigned oldest = 0; 14452292SN/A bool first = true; 14462292SN/A 14476221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 14486221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 14492292SN/A 14503867Sbinkertn@umich.edu while (threads != end) { 14516221Snate@binkert.org ThreadID tid = *threads++; 14522292SN/A 14532292SN/A if (!rob->isEmpty(tid) && 14542292SN/A (commitStatus[tid] == Running || 14552292SN/A commitStatus[tid] == Idle || 14562292SN/A commitStatus[tid] == FetchTrapPending)) { 14572292SN/A 14582292SN/A if (rob->isHeadReady(tid)) { 14592292SN/A 14602292SN/A DynInstPtr head_inst = rob->readHeadInst(tid); 14612292SN/A 14622292SN/A if (first) { 14632292SN/A oldest = tid; 14642292SN/A first = false; 14652292SN/A } else if (head_inst->seqNum < oldest) { 14662292SN/A oldest = tid; 14672292SN/A } 14682292SN/A } 14692292SN/A } 14702292SN/A } 14712292SN/A 14722292SN/A if (!first) { 14732292SN/A return oldest; 14742292SN/A } else { 14756221Snate@binkert.org return InvalidThreadID; 14762292SN/A } 14772292SN/A} 1478