commit_impl.hh revision 10023
11689SN/A/* 29948SAli.Saidi@ARM.com * Copyright (c) 2010-2013 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 */ 439944Smatt.horsnell@ARM.com#ifndef __CPU_O3_COMMIT_IMPL_HH__ 449944Smatt.horsnell@ARM.com#define __CPU_O3_COMMIT_IMPL_HH__ 451689SN/A 462292SN/A#include <algorithm> 479516SAli.Saidi@ARM.com#include <set> 482329SN/A#include <string> 492292SN/A 503577Sgblack@eecs.umich.edu#include "arch/utility.hh" 518229Snate@binkert.org#include "base/loader/symtab.hh" 525953Ssaidi@eecs.umich.edu#include "base/cp_annotate.hh" 536658Snate@binkert.org#include "config/the_isa.hh" 548887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 551717SN/A#include "cpu/o3/commit.hh" 562292SN/A#include "cpu/o3/thread_state.hh" 578662SAli.Saidi@ARM.com#include "cpu/base.hh" 588229Snate@binkert.org#include "cpu/exetrace.hh" 598229Snate@binkert.org#include "cpu/timebuf.hh" 608232Snate@binkert.org#include "debug/Activity.hh" 618232Snate@binkert.org#include "debug/Commit.hh" 628232Snate@binkert.org#include "debug/CommitRate.hh" 639444SAndreas.Sandberg@ARM.com#include "debug/Drain.hh" 648232Snate@binkert.org#include "debug/ExecFaulting.hh" 659527SMatt.Horsnell@arm.com#include "debug/O3PipeView.hh" 666221Snate@binkert.org#include "params/DerivO3CPU.hh" 678230Snate@binkert.org#include "sim/faults.hh" 688793Sgblack@eecs.umich.edu#include "sim/full_system.hh" 692292SN/A 706221Snate@binkert.orgusing namespace std; 715529Snate@binkert.org 721061SN/Atemplate <class Impl> 732292SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 746221Snate@binkert.org ThreadID _tid) 758581Ssteve.reinhardt@amd.com : Event(CPU_Tick_Pri, AutoDelete), commit(_commit), tid(_tid) 761060SN/A{ 771060SN/A} 781060SN/A 791061SN/Atemplate <class Impl> 801060SN/Avoid 812292SN/ADefaultCommit<Impl>::TrapEvent::process() 821062SN/A{ 832316SN/A // This will get reset by commit if it was switched out at the 842316SN/A // time of this event processing. 852292SN/A commit->trapSquash[tid] = true; 862292SN/A} 872292SN/A 882292SN/Atemplate <class Impl> 892292SN/Aconst char * 905336Shines@cs.fsu.eduDefaultCommit<Impl>::TrapEvent::description() const 912292SN/A{ 924873Sstever@eecs.umich.edu return "Trap"; 932292SN/A} 942292SN/A 952292SN/Atemplate <class Impl> 965529Snate@binkert.orgDefaultCommit<Impl>::DefaultCommit(O3CPU *_cpu, DerivO3CPUParams *params) 974329Sktlim@umich.edu : cpu(_cpu), 984329Sktlim@umich.edu squashCounter(0), 992292SN/A iewToCommitDelay(params->iewToCommitDelay), 1002292SN/A commitToIEWDelay(params->commitToIEWDelay), 1012292SN/A renameToROBDelay(params->renameToROBDelay), 1022292SN/A fetchToCommitDelay(params->commitToFetchDelay), 1032292SN/A renameWidth(params->renameWidth), 1042292SN/A commitWidth(params->commitWidth), 1055529Snate@binkert.org numThreads(params->numThreads), 1062843Sktlim@umich.edu drainPending(false), 1078823Snilay@cs.wisc.edu trapLatency(params->trapLatency), 1089513SAli.Saidi@ARM.com canHandleInterrupts(true), 1099513SAli.Saidi@ARM.com avoidQuiesceLiveLock(false) 1102292SN/A{ 1112292SN/A _status = Active; 1122292SN/A _nextStatus = Inactive; 1132980Sgblack@eecs.umich.edu std::string policy = params->smtCommitPolicy; 1142292SN/A 1152292SN/A //Convert string to lowercase 1162292SN/A std::transform(policy.begin(), policy.end(), policy.begin(), 1172292SN/A (int(*)(int)) tolower); 1182292SN/A 1192292SN/A //Assign commit policy 1202292SN/A if (policy == "aggressive"){ 1212292SN/A commitPolicy = Aggressive; 1222292SN/A 1238346Sksewell@umich.edu DPRINTF(Commit,"Commit Policy set to Aggressive.\n"); 1242292SN/A } else if (policy == "roundrobin"){ 1252292SN/A commitPolicy = RoundRobin; 1262292SN/A 1272292SN/A //Set-Up Priority List 1286221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 1292292SN/A priority_list.push_back(tid); 1302292SN/A } 1312292SN/A 1328346Sksewell@umich.edu DPRINTF(Commit,"Commit Policy set to Round Robin.\n"); 1332292SN/A } else if (policy == "oldestready"){ 1342292SN/A commitPolicy = OldestReady; 1352292SN/A 1364329Sktlim@umich.edu DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1372292SN/A } else { 1382292SN/A assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1392292SN/A "RoundRobin,OldestReady}"); 1402292SN/A } 1412292SN/A 1426221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 1436221Snate@binkert.org commitStatus[tid] = Idle; 1446221Snate@binkert.org changedROBNumEntries[tid] = false; 1456221Snate@binkert.org checkEmptyROB[tid] = false; 1466221Snate@binkert.org trapInFlight[tid] = false; 1476221Snate@binkert.org committedStores[tid] = false; 1486221Snate@binkert.org trapSquash[tid] = false; 1496221Snate@binkert.org tcSquash[tid] = false; 1507720Sgblack@eecs.umich.edu pc[tid].set(0); 1517855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] = 0; 1529437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = NULL; 1532292SN/A } 1543640Sktlim@umich.edu interrupt = NoFault; 1552292SN/A} 1562292SN/A 1572292SN/Atemplate <class Impl> 1582292SN/Astd::string 1592292SN/ADefaultCommit<Impl>::name() const 1602292SN/A{ 1612292SN/A return cpu->name() + ".commit"; 1622292SN/A} 1632292SN/A 1642292SN/Atemplate <class Impl> 1652292SN/Avoid 16610023Smatt.horsnell@ARM.comDefaultCommit<Impl>::regProbePoints() 16710023Smatt.horsnell@ARM.com{ 16810023Smatt.horsnell@ARM.com ppCommit = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Commit"); 16910023Smatt.horsnell@ARM.com ppCommitStall = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "CommitStall"); 17010023Smatt.horsnell@ARM.com} 17110023Smatt.horsnell@ARM.com 17210023Smatt.horsnell@ARM.comtemplate <class Impl> 17310023Smatt.horsnell@ARM.comvoid 1742292SN/ADefaultCommit<Impl>::regStats() 1752132SN/A{ 1762301SN/A using namespace Stats; 1771062SN/A commitSquashedInsts 1781062SN/A .name(name() + ".commitSquashedInsts") 1791062SN/A .desc("The number of squashed insts skipped by commit") 1801062SN/A .prereq(commitSquashedInsts); 1811062SN/A commitSquashEvents 1821062SN/A .name(name() + ".commitSquashEvents") 1831062SN/A .desc("The number of times commit is told to squash") 1841062SN/A .prereq(commitSquashEvents); 1851062SN/A commitNonSpecStalls 1861062SN/A .name(name() + ".commitNonSpecStalls") 1871062SN/A .desc("The number of times commit has been forced to stall to " 1881062SN/A "communicate backwards") 1891062SN/A .prereq(commitNonSpecStalls); 1901062SN/A branchMispredicts 1911062SN/A .name(name() + ".branchMispredicts") 1921062SN/A .desc("The number of times a branch was mispredicted") 1931062SN/A .prereq(branchMispredicts); 1942292SN/A numCommittedDist 1951062SN/A .init(0,commitWidth,1) 1968240Snate@binkert.org .name(name() + ".committed_per_cycle") 1971062SN/A .desc("Number of insts commited each cycle") 1981062SN/A .flags(Stats::pdf) 1991062SN/A ; 2002301SN/A 2018834Satgutier@umich.edu instsCommitted 2026221Snate@binkert.org .init(cpu->numThreads) 2038834Satgutier@umich.edu .name(name() + ".committedInsts") 2042301SN/A .desc("Number of instructions committed") 2052301SN/A .flags(total) 2062301SN/A ; 2072301SN/A 2088834Satgutier@umich.edu opsCommitted 2098834Satgutier@umich.edu .init(cpu->numThreads) 2108834Satgutier@umich.edu .name(name() + ".committedOps") 2118834Satgutier@umich.edu .desc("Number of ops (including micro ops) committed") 2128834Satgutier@umich.edu .flags(total) 2138834Satgutier@umich.edu ; 2148834Satgutier@umich.edu 2152316SN/A statComSwp 2166221Snate@binkert.org .init(cpu->numThreads) 2178240Snate@binkert.org .name(name() + ".swp_count") 2182301SN/A .desc("Number of s/w prefetches committed") 2192301SN/A .flags(total) 2202301SN/A ; 2212301SN/A 2222316SN/A statComRefs 2236221Snate@binkert.org .init(cpu->numThreads) 2248240Snate@binkert.org .name(name() + ".refs") 2252301SN/A .desc("Number of memory references committed") 2262301SN/A .flags(total) 2272301SN/A ; 2282301SN/A 2292316SN/A statComLoads 2306221Snate@binkert.org .init(cpu->numThreads) 2318240Snate@binkert.org .name(name() + ".loads") 2322301SN/A .desc("Number of loads committed") 2332301SN/A .flags(total) 2342301SN/A ; 2352301SN/A 2362316SN/A statComMembars 2376221Snate@binkert.org .init(cpu->numThreads) 2388240Snate@binkert.org .name(name() + ".membars") 2392301SN/A .desc("Number of memory barriers committed") 2402301SN/A .flags(total) 2412301SN/A ; 2422301SN/A 2432316SN/A statComBranches 2446221Snate@binkert.org .init(cpu->numThreads) 2458240Snate@binkert.org .name(name() + ".branches") 2462301SN/A .desc("Number of branches committed") 2472301SN/A .flags(total) 2482301SN/A ; 2492301SN/A 2507897Shestness@cs.utexas.edu statComFloating 2517897Shestness@cs.utexas.edu .init(cpu->numThreads) 2528240Snate@binkert.org .name(name() + ".fp_insts") 2537897Shestness@cs.utexas.edu .desc("Number of committed floating point instructions.") 2547897Shestness@cs.utexas.edu .flags(total) 2557897Shestness@cs.utexas.edu ; 2567897Shestness@cs.utexas.edu 2577897Shestness@cs.utexas.edu statComInteger 2587897Shestness@cs.utexas.edu .init(cpu->numThreads) 2598240Snate@binkert.org .name(name()+".int_insts") 2607897Shestness@cs.utexas.edu .desc("Number of committed integer instructions.") 2617897Shestness@cs.utexas.edu .flags(total) 2627897Shestness@cs.utexas.edu ; 2637897Shestness@cs.utexas.edu 2647897Shestness@cs.utexas.edu statComFunctionCalls 2657897Shestness@cs.utexas.edu .init(cpu->numThreads) 2668240Snate@binkert.org .name(name()+".function_calls") 2677897Shestness@cs.utexas.edu .desc("Number of function calls committed.") 2687897Shestness@cs.utexas.edu .flags(total) 2697897Shestness@cs.utexas.edu ; 2707897Shestness@cs.utexas.edu 2712316SN/A commitEligible 2726221Snate@binkert.org .init(cpu->numThreads) 2738240Snate@binkert.org .name(name() + ".bw_limited") 2742301SN/A .desc("number of insts not committed due to BW limits") 2752301SN/A .flags(total) 2762301SN/A ; 2772301SN/A 2782316SN/A commitEligibleSamples 2798240Snate@binkert.org .name(name() + ".bw_lim_events") 2802301SN/A .desc("number cycles where commit BW limit reached") 2812301SN/A ; 2821062SN/A} 2831062SN/A 2841062SN/Atemplate <class Impl> 2851062SN/Avoid 2862980Sgblack@eecs.umich.eduDefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 2872292SN/A{ 2882292SN/A thread = threads; 2892292SN/A} 2902292SN/A 2912292SN/Atemplate <class Impl> 2922292SN/Avoid 2932292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 2941060SN/A{ 2951060SN/A timeBuffer = tb_ptr; 2961060SN/A 2971060SN/A // Setup wire to send information back to IEW. 2981060SN/A toIEW = timeBuffer->getWire(0); 2991060SN/A 3001060SN/A // Setup wire to read data from IEW (for the ROB). 3011060SN/A robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 3021060SN/A} 3031060SN/A 3041061SN/Atemplate <class Impl> 3051060SN/Avoid 3062292SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 3072292SN/A{ 3082292SN/A fetchQueue = fq_ptr; 3092292SN/A 3102292SN/A // Setup wire to get instructions from rename (for the ROB). 3112292SN/A fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 3122292SN/A} 3132292SN/A 3142292SN/Atemplate <class Impl> 3152292SN/Avoid 3162292SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3171060SN/A{ 3181060SN/A renameQueue = rq_ptr; 3191060SN/A 3201060SN/A // Setup wire to get instructions from rename (for the ROB). 3211060SN/A fromRename = renameQueue->getWire(-renameToROBDelay); 3221060SN/A} 3231060SN/A 3241061SN/Atemplate <class Impl> 3251060SN/Avoid 3262292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3271060SN/A{ 3281060SN/A iewQueue = iq_ptr; 3291060SN/A 3301060SN/A // Setup wire to get instructions from IEW. 3311060SN/A fromIEW = iewQueue->getWire(-iewToCommitDelay); 3321060SN/A} 3331060SN/A 3341061SN/Atemplate <class Impl> 3351060SN/Avoid 3362292SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 3372292SN/A{ 3382292SN/A iewStage = iew_stage; 3392292SN/A} 3402292SN/A 3412292SN/Atemplate<class Impl> 3422292SN/Avoid 3436221Snate@binkert.orgDefaultCommit<Impl>::setActiveThreads(list<ThreadID> *at_ptr) 3442292SN/A{ 3452292SN/A activeThreads = at_ptr; 3462292SN/A} 3472292SN/A 3482292SN/Atemplate <class Impl> 3492292SN/Avoid 3502292SN/ADefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3512292SN/A{ 3526221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) 3536221Snate@binkert.org renameMap[tid] = &rm_ptr[tid]; 3542292SN/A} 3552292SN/A 3562292SN/Atemplate <class Impl> 3572292SN/Avoid 3582292SN/ADefaultCommit<Impl>::setROB(ROB *rob_ptr) 3591060SN/A{ 3601060SN/A rob = rob_ptr; 3611060SN/A} 3621060SN/A 3631061SN/Atemplate <class Impl> 3641060SN/Avoid 3659427SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::startupStage() 3661060SN/A{ 3672292SN/A rob->setActiveThreads(activeThreads); 3682292SN/A rob->resetEntries(); 3691060SN/A 3702292SN/A // Broadcast the number of free entries. 3716221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 3726221Snate@binkert.org toIEW->commitInfo[tid].usedROB = true; 3736221Snate@binkert.org toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 3746221Snate@binkert.org toIEW->commitInfo[tid].emptyROB = true; 3751060SN/A } 3761060SN/A 3774329Sktlim@umich.edu // Commit must broadcast the number of free entries it has at the 3784329Sktlim@umich.edu // start of the simulation, so it starts as active. 3794329Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 3804329Sktlim@umich.edu 3812292SN/A cpu->activityThisCycle(); 3821060SN/A} 3831060SN/A 3841061SN/Atemplate <class Impl> 3859444SAndreas.Sandberg@ARM.comvoid 3862843Sktlim@umich.eduDefaultCommit<Impl>::drain() 3871060SN/A{ 3882843Sktlim@umich.edu drainPending = true; 3892316SN/A} 3902316SN/A 3912316SN/Atemplate <class Impl> 3922316SN/Avoid 3939444SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::drainResume() 3942843Sktlim@umich.edu{ 3952864Sktlim@umich.edu drainPending = false; 3962843Sktlim@umich.edu} 3972843Sktlim@umich.edu 3982843Sktlim@umich.edutemplate <class Impl> 3992843Sktlim@umich.eduvoid 4009444SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::drainSanityCheck() const 4019444SAndreas.Sandberg@ARM.com{ 4029444SAndreas.Sandberg@ARM.com assert(isDrained()); 4039444SAndreas.Sandberg@ARM.com rob->drainSanityCheck(); 4049444SAndreas.Sandberg@ARM.com} 4059444SAndreas.Sandberg@ARM.com 4069444SAndreas.Sandberg@ARM.comtemplate <class Impl> 4079444SAndreas.Sandberg@ARM.combool 4089444SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::isDrained() const 4099444SAndreas.Sandberg@ARM.com{ 4109444SAndreas.Sandberg@ARM.com /* Make sure no one is executing microcode. There are two reasons 4119444SAndreas.Sandberg@ARM.com * for this: 4129444SAndreas.Sandberg@ARM.com * - Hardware virtualized CPUs can't switch into the middle of a 4139444SAndreas.Sandberg@ARM.com * microcode sequence. 4149444SAndreas.Sandberg@ARM.com * - The current fetch implementation will most likely get very 4159444SAndreas.Sandberg@ARM.com * confused if it tries to start fetching an instruction that 4169444SAndreas.Sandberg@ARM.com * is executing in the middle of a ucode sequence that changes 4179444SAndreas.Sandberg@ARM.com * address mappings. This can happen on for example x86. 4189444SAndreas.Sandberg@ARM.com */ 4199444SAndreas.Sandberg@ARM.com for (ThreadID tid = 0; tid < numThreads; tid++) { 4209444SAndreas.Sandberg@ARM.com if (pc[tid].microPC() != 0) 4219444SAndreas.Sandberg@ARM.com return false; 4229444SAndreas.Sandberg@ARM.com } 4239444SAndreas.Sandberg@ARM.com 4249444SAndreas.Sandberg@ARM.com /* Make sure that all instructions have finished committing before 4259444SAndreas.Sandberg@ARM.com * declaring the system as drained. We want the pipeline to be 4269444SAndreas.Sandberg@ARM.com * completely empty when we declare the CPU to be drained. This 4279444SAndreas.Sandberg@ARM.com * makes debugging easier since CPU handover and restoring from a 4289444SAndreas.Sandberg@ARM.com * checkpoint with a different CPU should have the same timing. 4299444SAndreas.Sandberg@ARM.com */ 4309444SAndreas.Sandberg@ARM.com return rob->isEmpty() && 4319444SAndreas.Sandberg@ARM.com interrupt == NoFault; 4329444SAndreas.Sandberg@ARM.com} 4339444SAndreas.Sandberg@ARM.com 4349444SAndreas.Sandberg@ARM.comtemplate <class Impl> 4359444SAndreas.Sandberg@ARM.comvoid 4362307SN/ADefaultCommit<Impl>::takeOverFrom() 4372307SN/A{ 4382307SN/A _status = Active; 4392307SN/A _nextStatus = Inactive; 4406221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 4416221Snate@binkert.org commitStatus[tid] = Idle; 4426221Snate@binkert.org changedROBNumEntries[tid] = false; 4436221Snate@binkert.org trapSquash[tid] = false; 4446221Snate@binkert.org tcSquash[tid] = false; 4459437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = NULL; 4462307SN/A } 4472307SN/A squashCounter = 0; 4482307SN/A rob->takeOverFrom(); 4492307SN/A} 4502307SN/A 4512307SN/Atemplate <class Impl> 4522307SN/Avoid 4532292SN/ADefaultCommit<Impl>::updateStatus() 4542132SN/A{ 4552316SN/A // reset ROB changed variable 4566221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 4576221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 4583867Sbinkertn@umich.edu 4593867Sbinkertn@umich.edu while (threads != end) { 4606221Snate@binkert.org ThreadID tid = *threads++; 4613867Sbinkertn@umich.edu 4622316SN/A changedROBNumEntries[tid] = false; 4632316SN/A 4642316SN/A // Also check if any of the threads has a trap pending 4652316SN/A if (commitStatus[tid] == TrapPending || 4662316SN/A commitStatus[tid] == FetchTrapPending) { 4672316SN/A _nextStatus = Active; 4682316SN/A } 4692292SN/A } 4702292SN/A 4712292SN/A if (_nextStatus == Inactive && _status == Active) { 4722292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 4732733Sktlim@umich.edu cpu->deactivateStage(O3CPU::CommitIdx); 4742292SN/A } else if (_nextStatus == Active && _status == Inactive) { 4752292SN/A DPRINTF(Activity, "Activating stage.\n"); 4762733Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 4772292SN/A } 4782292SN/A 4792292SN/A _status = _nextStatus; 4802292SN/A} 4812292SN/A 4822292SN/Atemplate <class Impl> 4832292SN/Avoid 4842292SN/ADefaultCommit<Impl>::setNextStatus() 4852292SN/A{ 4862292SN/A int squashes = 0; 4872292SN/A 4886221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 4896221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 4902292SN/A 4913867Sbinkertn@umich.edu while (threads != end) { 4926221Snate@binkert.org ThreadID tid = *threads++; 4932292SN/A 4942292SN/A if (commitStatus[tid] == ROBSquashing) { 4952292SN/A squashes++; 4962292SN/A } 4972292SN/A } 4982292SN/A 4992702Sktlim@umich.edu squashCounter = squashes; 5002292SN/A 5012292SN/A // If commit is currently squashing, then it will have activity for the 5022292SN/A // next cycle. Set its next status as active. 5032292SN/A if (squashCounter) { 5042292SN/A _nextStatus = Active; 5052292SN/A } 5062292SN/A} 5072292SN/A 5082292SN/Atemplate <class Impl> 5092292SN/Abool 5102292SN/ADefaultCommit<Impl>::changedROBEntries() 5112292SN/A{ 5126221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 5136221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 5142292SN/A 5153867Sbinkertn@umich.edu while (threads != end) { 5166221Snate@binkert.org ThreadID tid = *threads++; 5172292SN/A 5182292SN/A if (changedROBNumEntries[tid]) { 5192292SN/A return true; 5202292SN/A } 5212292SN/A } 5222292SN/A 5232292SN/A return false; 5242292SN/A} 5252292SN/A 5262292SN/Atemplate <class Impl> 5276221Snate@binkert.orgsize_t 5286221Snate@binkert.orgDefaultCommit<Impl>::numROBFreeEntries(ThreadID tid) 5292292SN/A{ 5302292SN/A return rob->numFreeEntries(tid); 5312292SN/A} 5322292SN/A 5332292SN/Atemplate <class Impl> 5342292SN/Avoid 5356221Snate@binkert.orgDefaultCommit<Impl>::generateTrapEvent(ThreadID tid) 5362292SN/A{ 5372292SN/A DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 5382292SN/A 5392292SN/A TrapEvent *trap = new TrapEvent(this, tid); 5402292SN/A 5419179Sandreas.hansson@arm.com cpu->schedule(trap, cpu->clockEdge(trapLatency)); 5424035Sktlim@umich.edu trapInFlight[tid] = true; 5438518Sgeoffrey.blake@arm.com thread[tid]->trapPending = true; 5442292SN/A} 5452292SN/A 5462292SN/Atemplate <class Impl> 5472292SN/Avoid 5486221Snate@binkert.orgDefaultCommit<Impl>::generateTCEvent(ThreadID tid) 5492292SN/A{ 5504035Sktlim@umich.edu assert(!trapInFlight[tid]); 5512680Sktlim@umich.edu DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 5522292SN/A 5532680Sktlim@umich.edu tcSquash[tid] = true; 5542292SN/A} 5552292SN/A 5562292SN/Atemplate <class Impl> 5572292SN/Avoid 5586221Snate@binkert.orgDefaultCommit<Impl>::squashAll(ThreadID tid) 5592292SN/A{ 5602292SN/A // If we want to include the squashing instruction in the squash, 5612292SN/A // then use one older sequence number. 5622292SN/A // Hopefully this doesn't mess things up. Basically I want to squash 5632292SN/A // all instructions of this thread. 5642292SN/A InstSeqNum squashed_inst = rob->isEmpty() ? 5657855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] : rob->readHeadInst(tid)->seqNum - 1; 5662292SN/A 5672292SN/A // All younger instructions will be squashed. Set the sequence 5682292SN/A // number as the youngest instruction in the ROB (0 in this case. 5692292SN/A // Hopefully nothing breaks.) 5707855SAli.Saidi@ARM.com youngestSeqNum[tid] = lastCommitedSeqNum[tid]; 5712292SN/A 5722292SN/A rob->squash(squashed_inst, tid); 5732292SN/A changedROBNumEntries[tid] = true; 5742292SN/A 5752292SN/A // Send back the sequence number of the squashed instruction. 5762292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 5772292SN/A 5782292SN/A // Send back the squash signal to tell stages that they should 5792292SN/A // squash. 5802292SN/A toIEW->commitInfo[tid].squash = true; 5812292SN/A 5822292SN/A // Send back the rob squashing signal so other stages know that 5832292SN/A // the ROB is in the process of squashing. 5842292SN/A toIEW->commitInfo[tid].robSquashing = true; 5852292SN/A 5867851SMatt.Horsnell@arm.com toIEW->commitInfo[tid].mispredictInst = NULL; 5878137SAli.Saidi@ARM.com toIEW->commitInfo[tid].squashInst = NULL; 5882292SN/A 5897720Sgblack@eecs.umich.edu toIEW->commitInfo[tid].pc = pc[tid]; 5902316SN/A} 5912292SN/A 5922316SN/Atemplate <class Impl> 5932316SN/Avoid 5946221Snate@binkert.orgDefaultCommit<Impl>::squashFromTrap(ThreadID tid) 5952316SN/A{ 5962316SN/A squashAll(tid); 5972316SN/A 5987720Sgblack@eecs.umich.edu DPRINTF(Commit, "Squashing from trap, restarting at PC %s\n", pc[tid]); 5992316SN/A 6002316SN/A thread[tid]->trapPending = false; 6019382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = false; 6024035Sktlim@umich.edu trapInFlight[tid] = false; 6032316SN/A 6042316SN/A trapSquash[tid] = false; 6052316SN/A 6062316SN/A commitStatus[tid] = ROBSquashing; 6072316SN/A cpu->activityThisCycle(); 6082316SN/A} 6092316SN/A 6102316SN/Atemplate <class Impl> 6112316SN/Avoid 6126221Snate@binkert.orgDefaultCommit<Impl>::squashFromTC(ThreadID tid) 6132316SN/A{ 6142316SN/A squashAll(tid); 6152292SN/A 6167720Sgblack@eecs.umich.edu DPRINTF(Commit, "Squashing from TC, restarting at PC %s\n", pc[tid]); 6172292SN/A 6189382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = false; 6192292SN/A assert(!thread[tid]->trapPending); 6202316SN/A 6212292SN/A commitStatus[tid] = ROBSquashing; 6222292SN/A cpu->activityThisCycle(); 6232292SN/A 6242680Sktlim@umich.edu tcSquash[tid] = false; 6252292SN/A} 6262292SN/A 6272292SN/Atemplate <class Impl> 6282292SN/Avoid 6299437SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::squashFromSquashAfter(ThreadID tid) 6307784SAli.Saidi@ARM.com{ 6319437SAndreas.Sandberg@ARM.com DPRINTF(Commit, "Squashing after squash after request, " 6329437SAndreas.Sandberg@ARM.com "restarting at PC %s\n", pc[tid]); 6337784SAli.Saidi@ARM.com 6349437SAndreas.Sandberg@ARM.com squashAll(tid); 6359437SAndreas.Sandberg@ARM.com // Make sure to inform the fetch stage of which instruction caused 6369437SAndreas.Sandberg@ARM.com // the squash. It'll try to re-fetch an instruction executing in 6379437SAndreas.Sandberg@ARM.com // microcode unless this is set. 6389437SAndreas.Sandberg@ARM.com toIEW->commitInfo[tid].squashInst = squashAfterInst[tid]; 6399437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = NULL; 6407784SAli.Saidi@ARM.com 6419437SAndreas.Sandberg@ARM.com commitStatus[tid] = ROBSquashing; 6429437SAndreas.Sandberg@ARM.com cpu->activityThisCycle(); 6439437SAndreas.Sandberg@ARM.com} 6447784SAli.Saidi@ARM.com 6459437SAndreas.Sandberg@ARM.comtemplate <class Impl> 6469437SAndreas.Sandberg@ARM.comvoid 6479437SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::squashAfter(ThreadID tid, DynInstPtr &head_inst) 6489437SAndreas.Sandberg@ARM.com{ 6499437SAndreas.Sandberg@ARM.com DPRINTF(Commit, "Executing squash after for [tid:%i] inst [sn:%lli]\n", 6509437SAndreas.Sandberg@ARM.com tid, head_inst->seqNum); 6517784SAli.Saidi@ARM.com 6529437SAndreas.Sandberg@ARM.com assert(!squashAfterInst[tid] || squashAfterInst[tid] == head_inst); 6539437SAndreas.Sandberg@ARM.com commitStatus[tid] = SquashAfterPending; 6549437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = head_inst; 6557784SAli.Saidi@ARM.com} 6567784SAli.Saidi@ARM.com 6577784SAli.Saidi@ARM.comtemplate <class Impl> 6587784SAli.Saidi@ARM.comvoid 6592292SN/ADefaultCommit<Impl>::tick() 6602292SN/A{ 6612292SN/A wroteToTimeBuffer = false; 6622292SN/A _nextStatus = Inactive; 6632292SN/A 6643867Sbinkertn@umich.edu if (activeThreads->empty()) 6652875Sksewell@umich.edu return; 6662875Sksewell@umich.edu 6676221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6686221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6692292SN/A 6702316SN/A // Check if any of the threads are done squashing. Change the 6712316SN/A // status if they are done. 6723867Sbinkertn@umich.edu while (threads != end) { 6736221Snate@binkert.org ThreadID tid = *threads++; 6742292SN/A 6754035Sktlim@umich.edu // Clear the bit saying if the thread has committed stores 6764035Sktlim@umich.edu // this cycle. 6774035Sktlim@umich.edu committedStores[tid] = false; 6784035Sktlim@umich.edu 6792292SN/A if (commitStatus[tid] == ROBSquashing) { 6802292SN/A 6812292SN/A if (rob->isDoneSquashing(tid)) { 6822292SN/A commitStatus[tid] = Running; 6832292SN/A } else { 6842292SN/A DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 6852877Sksewell@umich.edu " insts this cycle.\n", tid); 6862702Sktlim@umich.edu rob->doSquash(tid); 6872702Sktlim@umich.edu toIEW->commitInfo[tid].robSquashing = true; 6882702Sktlim@umich.edu wroteToTimeBuffer = true; 6892292SN/A } 6902292SN/A } 6912292SN/A } 6922292SN/A 6932292SN/A commit(); 6942292SN/A 6952292SN/A markCompletedInsts(); 6962292SN/A 6973867Sbinkertn@umich.edu threads = activeThreads->begin(); 6982292SN/A 6993867Sbinkertn@umich.edu while (threads != end) { 7006221Snate@binkert.org ThreadID tid = *threads++; 7012292SN/A 7022292SN/A if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 7032292SN/A // The ROB has more instructions it can commit. Its next status 7042292SN/A // will be active. 7052292SN/A _nextStatus = Active; 7062292SN/A 7072292SN/A DynInstPtr inst = rob->readHeadInst(tid); 7082292SN/A 7097720Sgblack@eecs.umich.edu DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %s is head of" 7102292SN/A " ROB and ready to commit\n", 7117720Sgblack@eecs.umich.edu tid, inst->seqNum, inst->pcState()); 7122292SN/A 7132292SN/A } else if (!rob->isEmpty(tid)) { 7142292SN/A DynInstPtr inst = rob->readHeadInst(tid); 7152292SN/A 71610023Smatt.horsnell@ARM.com ppCommitStall->notify(inst); 71710023Smatt.horsnell@ARM.com 7182292SN/A DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 7197720Sgblack@eecs.umich.edu "%s is head of ROB and not ready\n", 7207720Sgblack@eecs.umich.edu tid, inst->seqNum, inst->pcState()); 7212292SN/A } 7222292SN/A 7232292SN/A DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 7242292SN/A tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 7252292SN/A } 7262292SN/A 7272292SN/A 7282292SN/A if (wroteToTimeBuffer) { 7292316SN/A DPRINTF(Activity, "Activity This Cycle.\n"); 7302292SN/A cpu->activityThisCycle(); 7312292SN/A } 7322292SN/A 7332292SN/A updateStatus(); 7342292SN/A} 7352292SN/A 7362292SN/Atemplate <class Impl> 7372292SN/Avoid 7384035Sktlim@umich.eduDefaultCommit<Impl>::handleInterrupt() 7392292SN/A{ 7407847Sminkyu.jeong@arm.com // Verify that we still have an interrupt to handle 7417847Sminkyu.jeong@arm.com if (!cpu->checkInterrupts(cpu->tcBase(0))) { 7427847Sminkyu.jeong@arm.com DPRINTF(Commit, "Pending interrupt is cleared by master before " 7437847Sminkyu.jeong@arm.com "it got handled. Restart fetching from the orig path.\n"); 7447847Sminkyu.jeong@arm.com toIEW->commitInfo[0].clearInterrupt = true; 7457847Sminkyu.jeong@arm.com interrupt = NoFault; 7469513SAli.Saidi@ARM.com avoidQuiesceLiveLock = true; 7477847Sminkyu.jeong@arm.com return; 7487847Sminkyu.jeong@arm.com } 7493633Sktlim@umich.edu 7508493Sgblack@eecs.umich.edu // Wait until all in flight instructions are finished before enterring 7518493Sgblack@eecs.umich.edu // the interrupt. 7528823Snilay@cs.wisc.edu if (canHandleInterrupts && cpu->instList.empty()) { 7537847Sminkyu.jeong@arm.com // Squash or record that I need to squash this cycle if 7547847Sminkyu.jeong@arm.com // an interrupt needed to be handled. 7557847Sminkyu.jeong@arm.com DPRINTF(Commit, "Interrupt detected.\n"); 7564035Sktlim@umich.edu 7577847Sminkyu.jeong@arm.com // Clear the interrupt now that it's going to be handled 7587847Sminkyu.jeong@arm.com toIEW->commitInfo[0].clearInterrupt = true; 7592292SN/A 7609382SAli.Saidi@ARM.com assert(!thread[0]->noSquashFromTC); 7619382SAli.Saidi@ARM.com thread[0]->noSquashFromTC = true; 7622292SN/A 7638733Sgeoffrey.blake@arm.com if (cpu->checker) { 7648733Sgeoffrey.blake@arm.com cpu->checker->handlePendingInt(); 7658733Sgeoffrey.blake@arm.com } 7668733Sgeoffrey.blake@arm.com 7679624Snilay@cs.wisc.edu // CPU will handle interrupt. Note that we ignore the local copy of 7689624Snilay@cs.wisc.edu // interrupt. This is because the local copy may no longer be the 7699624Snilay@cs.wisc.edu // interrupt that the interrupt controller thinks is being handled. 7709624Snilay@cs.wisc.edu cpu->processInterrupts(cpu->getInterrupts()); 7713633Sktlim@umich.edu 7729382SAli.Saidi@ARM.com thread[0]->noSquashFromTC = false; 7732292SN/A 7747847Sminkyu.jeong@arm.com commitStatus[0] = TrapPending; 7752292SN/A 7767847Sminkyu.jeong@arm.com // Generate trap squash event. 7777847Sminkyu.jeong@arm.com generateTrapEvent(0); 7783640Sktlim@umich.edu 7797847Sminkyu.jeong@arm.com interrupt = NoFault; 7809513SAli.Saidi@ARM.com avoidQuiesceLiveLock = false; 7817847Sminkyu.jeong@arm.com } else { 7828823Snilay@cs.wisc.edu DPRINTF(Commit, "Interrupt pending: instruction is %sin " 7838823Snilay@cs.wisc.edu "flight, ROB is %sempty\n", 7848823Snilay@cs.wisc.edu canHandleInterrupts ? "not " : "", 7858823Snilay@cs.wisc.edu cpu->instList.empty() ? "" : "not " ); 7861060SN/A } 7874035Sktlim@umich.edu} 7887847Sminkyu.jeong@arm.com 7897847Sminkyu.jeong@arm.comtemplate <class Impl> 7907847Sminkyu.jeong@arm.comvoid 7917847Sminkyu.jeong@arm.comDefaultCommit<Impl>::propagateInterrupt() 7927847Sminkyu.jeong@arm.com{ 7937847Sminkyu.jeong@arm.com if (commitStatus[0] == TrapPending || interrupt || trapSquash[0] || 7947847Sminkyu.jeong@arm.com tcSquash[0]) 7957847Sminkyu.jeong@arm.com return; 7967847Sminkyu.jeong@arm.com 7977847Sminkyu.jeong@arm.com // Process interrupts if interrupts are enabled, not in PAL 7987847Sminkyu.jeong@arm.com // mode, and no other traps or external squashes are currently 7997847Sminkyu.jeong@arm.com // pending. 8007847Sminkyu.jeong@arm.com // @todo: Allow other threads to handle interrupts. 8017847Sminkyu.jeong@arm.com 8027847Sminkyu.jeong@arm.com // Get any interrupt that happened 8037847Sminkyu.jeong@arm.com interrupt = cpu->getInterrupts(); 8047847Sminkyu.jeong@arm.com 8057847Sminkyu.jeong@arm.com // Tell fetch that there is an interrupt pending. This 8067847Sminkyu.jeong@arm.com // will make fetch wait until it sees a non PAL-mode PC, 8077847Sminkyu.jeong@arm.com // at which point it stops fetching instructions. 8087847Sminkyu.jeong@arm.com if (interrupt != NoFault) 8097847Sminkyu.jeong@arm.com toIEW->commitInfo[0].interruptPending = true; 8107847Sminkyu.jeong@arm.com} 8117847Sminkyu.jeong@arm.com 8124035Sktlim@umich.edutemplate <class Impl> 8134035Sktlim@umich.eduvoid 8144035Sktlim@umich.eduDefaultCommit<Impl>::commit() 8154035Sktlim@umich.edu{ 8168793Sgblack@eecs.umich.edu if (FullSystem) { 8178793Sgblack@eecs.umich.edu // Check if we have a interrupt and get read to handle it 8188793Sgblack@eecs.umich.edu if (cpu->checkInterrupts(cpu->tcBase(0))) 8198793Sgblack@eecs.umich.edu propagateInterrupt(); 8208793Sgblack@eecs.umich.edu } 8211060SN/A 8221060SN/A //////////////////////////////////// 8232316SN/A // Check for any possible squashes, handle them first 8241060SN/A //////////////////////////////////// 8256221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 8266221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 8271060SN/A 8283867Sbinkertn@umich.edu while (threads != end) { 8296221Snate@binkert.org ThreadID tid = *threads++; 8301060SN/A 8312292SN/A // Not sure which one takes priority. I think if we have 8322292SN/A // both, that's a bad sign. 8332292SN/A if (trapSquash[tid] == true) { 8342680Sktlim@umich.edu assert(!tcSquash[tid]); 8352292SN/A squashFromTrap(tid); 8362680Sktlim@umich.edu } else if (tcSquash[tid] == true) { 8374035Sktlim@umich.edu assert(commitStatus[tid] != TrapPending); 8382680Sktlim@umich.edu squashFromTC(tid); 8399437SAndreas.Sandberg@ARM.com } else if (commitStatus[tid] == SquashAfterPending) { 8409437SAndreas.Sandberg@ARM.com // A squash from the previous cycle of the commit stage (i.e., 8419437SAndreas.Sandberg@ARM.com // commitInsts() called squashAfter) is pending. Squash the 8429437SAndreas.Sandberg@ARM.com // thread now. 8439437SAndreas.Sandberg@ARM.com squashFromSquashAfter(tid); 8442292SN/A } 8451061SN/A 8462292SN/A // Squashed sequence number must be older than youngest valid 8472292SN/A // instruction in the ROB. This prevents squashes from younger 8482292SN/A // instructions overriding squashes from older instructions. 8492292SN/A if (fromIEW->squash[tid] && 8502292SN/A commitStatus[tid] != TrapPending && 8512292SN/A fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 8521061SN/A 8538137SAli.Saidi@ARM.com if (fromIEW->mispredictInst[tid]) { 8548137SAli.Saidi@ARM.com DPRINTF(Commit, 8558137SAli.Saidi@ARM.com "[tid:%i]: Squashing due to branch mispred PC:%#x [sn:%i]\n", 8562292SN/A tid, 8578137SAli.Saidi@ARM.com fromIEW->mispredictInst[tid]->instAddr(), 8582292SN/A fromIEW->squashedSeqNum[tid]); 8598137SAli.Saidi@ARM.com } else { 8608137SAli.Saidi@ARM.com DPRINTF(Commit, 8618137SAli.Saidi@ARM.com "[tid:%i]: Squashing due to order violation [sn:%i]\n", 8628137SAli.Saidi@ARM.com tid, fromIEW->squashedSeqNum[tid]); 8638137SAli.Saidi@ARM.com } 8641061SN/A 8652292SN/A DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 8662292SN/A tid, 8677720Sgblack@eecs.umich.edu fromIEW->pc[tid].nextInstAddr()); 8681061SN/A 8692292SN/A commitStatus[tid] = ROBSquashing; 8701061SN/A 8712292SN/A // If we want to include the squashing instruction in the squash, 8722292SN/A // then use one older sequence number. 8732292SN/A InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 8741062SN/A 8752935Sksewell@umich.edu if (fromIEW->includeSquashInst[tid] == true) { 8762292SN/A squashed_inst--; 8772935Sksewell@umich.edu } 8784035Sktlim@umich.edu 8792292SN/A // All younger instructions will be squashed. Set the sequence 8802292SN/A // number as the youngest instruction in the ROB. 8812292SN/A youngestSeqNum[tid] = squashed_inst; 8822292SN/A 8833093Sksewell@umich.edu rob->squash(squashed_inst, tid); 8842292SN/A changedROBNumEntries[tid] = true; 8852292SN/A 8862292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 8872292SN/A 8882292SN/A toIEW->commitInfo[tid].squash = true; 8892292SN/A 8902292SN/A // Send back the rob squashing signal so other stages know that 8912292SN/A // the ROB is in the process of squashing. 8922292SN/A toIEW->commitInfo[tid].robSquashing = true; 8932292SN/A 8947851SMatt.Horsnell@arm.com toIEW->commitInfo[tid].mispredictInst = 8957851SMatt.Horsnell@arm.com fromIEW->mispredictInst[tid]; 8962292SN/A toIEW->commitInfo[tid].branchTaken = 8972292SN/A fromIEW->branchTaken[tid]; 8988822Snilay@cs.wisc.edu toIEW->commitInfo[tid].squashInst = 8998822Snilay@cs.wisc.edu rob->findInst(tid, squashed_inst); 9008842Smrinmoy.ghosh@arm.com if (toIEW->commitInfo[tid].mispredictInst) { 9018842Smrinmoy.ghosh@arm.com if (toIEW->commitInfo[tid].mispredictInst->isUncondCtrl()) { 9028842Smrinmoy.ghosh@arm.com toIEW->commitInfo[tid].branchTaken = true; 9038842Smrinmoy.ghosh@arm.com } 9048842Smrinmoy.ghosh@arm.com } 9052292SN/A 9067720Sgblack@eecs.umich.edu toIEW->commitInfo[tid].pc = fromIEW->pc[tid]; 9072292SN/A 9088137SAli.Saidi@ARM.com if (toIEW->commitInfo[tid].mispredictInst) { 9092292SN/A ++branchMispredicts; 9102292SN/A } 9111062SN/A } 9122292SN/A 9131060SN/A } 9141060SN/A 9152292SN/A setNextStatus(); 9162292SN/A 9172292SN/A if (squashCounter != numThreads) { 9181061SN/A // If we're not currently squashing, then get instructions. 9191060SN/A getInsts(); 9201060SN/A 9211061SN/A // Try to commit any instructions. 9221060SN/A commitInsts(); 9231060SN/A } 9241060SN/A 9252292SN/A //Check for any activity 9263867Sbinkertn@umich.edu threads = activeThreads->begin(); 9272292SN/A 9283867Sbinkertn@umich.edu while (threads != end) { 9296221Snate@binkert.org ThreadID tid = *threads++; 9302292SN/A 9312292SN/A if (changedROBNumEntries[tid]) { 9322292SN/A toIEW->commitInfo[tid].usedROB = true; 9332292SN/A toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 9342292SN/A 9352292SN/A wroteToTimeBuffer = true; 9362292SN/A changedROBNumEntries[tid] = false; 9374035Sktlim@umich.edu if (rob->isEmpty(tid)) 9384035Sktlim@umich.edu checkEmptyROB[tid] = true; 9392292SN/A } 9404035Sktlim@umich.edu 9414035Sktlim@umich.edu // ROB is only considered "empty" for previous stages if: a) 9424035Sktlim@umich.edu // ROB is empty, b) there are no outstanding stores, c) IEW 9434035Sktlim@umich.edu // stage has received any information regarding stores that 9444035Sktlim@umich.edu // committed. 9454035Sktlim@umich.edu // c) is checked by making sure to not consider the ROB empty 9464035Sktlim@umich.edu // on the same cycle as when stores have been committed. 9474035Sktlim@umich.edu // @todo: Make this handle multi-cycle communication between 9484035Sktlim@umich.edu // commit and IEW. 9494035Sktlim@umich.edu if (checkEmptyROB[tid] && rob->isEmpty(tid) && 9505557Sktlim@umich.edu !iewStage->hasStoresToWB(tid) && !committedStores[tid]) { 9514035Sktlim@umich.edu checkEmptyROB[tid] = false; 9524035Sktlim@umich.edu toIEW->commitInfo[tid].usedROB = true; 9534035Sktlim@umich.edu toIEW->commitInfo[tid].emptyROB = true; 9544035Sktlim@umich.edu toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 9554035Sktlim@umich.edu wroteToTimeBuffer = true; 9564035Sktlim@umich.edu } 9574035Sktlim@umich.edu 9581060SN/A } 9591060SN/A} 9601060SN/A 9611061SN/Atemplate <class Impl> 9621060SN/Avoid 9632292SN/ADefaultCommit<Impl>::commitInsts() 9641060SN/A{ 9651060SN/A //////////////////////////////////// 9661060SN/A // Handle commit 9672316SN/A // Note that commit will be handled prior to putting new 9682316SN/A // instructions in the ROB so that the ROB only tries to commit 9692316SN/A // instructions it has in this current cycle, and not instructions 9702316SN/A // it is writing in during this cycle. Can't commit and squash 9712316SN/A // things at the same time... 9721060SN/A //////////////////////////////////// 9731060SN/A 9742292SN/A DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 9751060SN/A 9761060SN/A unsigned num_committed = 0; 9771060SN/A 9782292SN/A DynInstPtr head_inst; 9792316SN/A 9801060SN/A // Commit as many instructions as possible until the commit bandwidth 9811060SN/A // limit is reached, or it becomes impossible to commit any more. 9822292SN/A while (num_committed < commitWidth) { 9838823Snilay@cs.wisc.edu // Check for any interrupt that we've already squashed for 9848823Snilay@cs.wisc.edu // and start processing it. 9858823Snilay@cs.wisc.edu if (interrupt != NoFault) 9868823Snilay@cs.wisc.edu handleInterrupt(); 9878823Snilay@cs.wisc.edu 9882292SN/A int commit_thread = getCommittingThread(); 9891060SN/A 9902292SN/A if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 9912292SN/A break; 9922292SN/A 9932292SN/A head_inst = rob->readHeadInst(commit_thread); 9942292SN/A 9956221Snate@binkert.org ThreadID tid = head_inst->threadNumber; 9962292SN/A 9972292SN/A assert(tid == commit_thread); 9982292SN/A 9992292SN/A DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 10002292SN/A head_inst->seqNum, tid); 10012132SN/A 10022316SN/A // If the head instruction is squashed, it is ready to retire 10032316SN/A // (be removed from the ROB) at any time. 10041060SN/A if (head_inst->isSquashed()) { 10051060SN/A 10062292SN/A DPRINTF(Commit, "Retiring squashed instruction from " 10071060SN/A "ROB.\n"); 10081060SN/A 10092292SN/A rob->retireHead(commit_thread); 10101060SN/A 10111062SN/A ++commitSquashedInsts; 10121062SN/A 10132292SN/A // Record that the number of ROB entries has changed. 10142292SN/A changedROBNumEntries[tid] = true; 10151060SN/A } else { 10167720Sgblack@eecs.umich.edu pc[tid] = head_inst->pcState(); 10172292SN/A 10181060SN/A // Increment the total number of non-speculative instructions 10191060SN/A // executed. 10201060SN/A // Hack for now: it really shouldn't happen until after the 10211061SN/A // commit is deemed to be successful, but this count is needed 10221061SN/A // for syscalls. 10232292SN/A thread[tid]->funcExeInst++; 10241060SN/A 10251060SN/A // Try to commit the head instruction. 10261060SN/A bool commit_success = commitHead(head_inst, num_committed); 10271060SN/A 10281062SN/A if (commit_success) { 10291060SN/A ++num_committed; 103010023Smatt.horsnell@ARM.com ppCommit->notify(head_inst); 10311060SN/A 10322292SN/A changedROBNumEntries[tid] = true; 10332292SN/A 10342292SN/A // Set the doneSeqNum to the youngest committed instruction. 10352292SN/A toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 10361060SN/A 10378823Snilay@cs.wisc.edu if (tid == 0) { 10388823Snilay@cs.wisc.edu canHandleInterrupts = (!head_inst->isDelayedCommit()) && 10398823Snilay@cs.wisc.edu ((THE_ISA != ALPHA_ISA) || 10408823Snilay@cs.wisc.edu (!(pc[0].instAddr() & 0x3))); 10418823Snilay@cs.wisc.edu } 10428823Snilay@cs.wisc.edu 10437783SGiacomo.Gabrielli@arm.com // Updates misc. registers. 10447783SGiacomo.Gabrielli@arm.com head_inst->updateMiscRegs(); 10457783SGiacomo.Gabrielli@arm.com 10468662SAli.Saidi@ARM.com cpu->traceFunctions(pc[tid].instAddr()); 10478662SAli.Saidi@ARM.com 10487720Sgblack@eecs.umich.edu TheISA::advancePC(pc[tid], head_inst->staticInst); 10492935Sksewell@umich.edu 10507855SAli.Saidi@ARM.com // Keep track of the last sequence number commited 10517855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] = head_inst->seqNum; 10527855SAli.Saidi@ARM.com 10537784SAli.Saidi@ARM.com // If this is an instruction that doesn't play nicely with 10547784SAli.Saidi@ARM.com // others squash everything and restart fetch 10557784SAli.Saidi@ARM.com if (head_inst->isSquashAfter()) 10569437SAndreas.Sandberg@ARM.com squashAfter(tid, head_inst); 10577784SAli.Saidi@ARM.com 10589444SAndreas.Sandberg@ARM.com if (drainPending) { 10599444SAndreas.Sandberg@ARM.com DPRINTF(Drain, "Draining: %i:%s\n", tid, pc[tid]); 10609444SAndreas.Sandberg@ARM.com if (pc[tid].microPC() == 0 && interrupt == NoFault) { 10619444SAndreas.Sandberg@ARM.com squashAfter(tid, head_inst); 10629444SAndreas.Sandberg@ARM.com cpu->commitDrained(tid); 10639444SAndreas.Sandberg@ARM.com } 10649444SAndreas.Sandberg@ARM.com } 10659444SAndreas.Sandberg@ARM.com 10662292SN/A int count = 0; 10672292SN/A Addr oldpc; 10685108Sgblack@eecs.umich.edu // Debug statement. Checks to make sure we're not 10695108Sgblack@eecs.umich.edu // currently updating state while handling PC events. 10709382SAli.Saidi@ARM.com assert(!thread[tid]->noSquashFromTC && !thread[tid]->trapPending); 10712292SN/A do { 10727720Sgblack@eecs.umich.edu oldpc = pc[tid].instAddr(); 10735108Sgblack@eecs.umich.edu cpu->system->pcEventQueue.service(thread[tid]->getTC()); 10742292SN/A count++; 10757720Sgblack@eecs.umich.edu } while (oldpc != pc[tid].instAddr()); 10762292SN/A if (count > 1) { 10775108Sgblack@eecs.umich.edu DPRINTF(Commit, 10785108Sgblack@eecs.umich.edu "PC skip function event, stopping commit\n"); 10792292SN/A break; 10802292SN/A } 10819513SAli.Saidi@ARM.com 10829513SAli.Saidi@ARM.com // Check if an instruction just enabled interrupts and we've 10839513SAli.Saidi@ARM.com // previously had an interrupt pending that was not handled 10849513SAli.Saidi@ARM.com // because interrupts were subsequently disabled before the 10859513SAli.Saidi@ARM.com // pipeline reached a place to handle the interrupt. In that 10869513SAli.Saidi@ARM.com // case squash now to make sure the interrupt is handled. 10879513SAli.Saidi@ARM.com // 10889513SAli.Saidi@ARM.com // If we don't do this, we might end up in a live lock situation 10899513SAli.Saidi@ARM.com if (!interrupt && avoidQuiesceLiveLock && 10909513SAli.Saidi@ARM.com (!head_inst->isMicroop() || head_inst->isLastMicroop()) && 10919513SAli.Saidi@ARM.com cpu->checkInterrupts(cpu->tcBase(0))) 10929513SAli.Saidi@ARM.com squashAfter(tid, head_inst); 10931060SN/A } else { 10947720Sgblack@eecs.umich.edu DPRINTF(Commit, "Unable to commit head instruction PC:%s " 10952292SN/A "[tid:%i] [sn:%i].\n", 10967720Sgblack@eecs.umich.edu head_inst->pcState(), tid ,head_inst->seqNum); 10971060SN/A break; 10981060SN/A } 10991060SN/A } 11001060SN/A } 11011062SN/A 11021063SN/A DPRINTF(CommitRate, "%i\n", num_committed); 11032292SN/A numCommittedDist.sample(num_committed); 11042307SN/A 11052307SN/A if (num_committed == commitWidth) { 11062349SN/A commitEligibleSamples++; 11072307SN/A } 11081060SN/A} 11091060SN/A 11101061SN/Atemplate <class Impl> 11111060SN/Abool 11122292SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 11131060SN/A{ 11141060SN/A assert(head_inst); 11151060SN/A 11166221Snate@binkert.org ThreadID tid = head_inst->threadNumber; 11172292SN/A 11182316SN/A // If the instruction is not executed yet, then it will need extra 11192316SN/A // handling. Signal backwards that it should be executed. 11201061SN/A if (!head_inst->isExecuted()) { 11211061SN/A // Keep this number correct. We have not yet actually executed 11221061SN/A // and committed this instruction. 11232292SN/A thread[tid]->funcExeInst--; 11241062SN/A 11259948SAli.Saidi@ARM.com // Make sure we are only trying to commit un-executed instructions we 11269948SAli.Saidi@ARM.com // think are possible. 11279948SAli.Saidi@ARM.com assert(head_inst->isNonSpeculative() || head_inst->isStoreConditional() 11289948SAli.Saidi@ARM.com || head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 11299948SAli.Saidi@ARM.com (head_inst->isLoad() && head_inst->uncacheable())); 11302316SN/A 11319948SAli.Saidi@ARM.com DPRINTF(Commit, "Encountered a barrier or non-speculative " 11329948SAli.Saidi@ARM.com "instruction [sn:%lli] at the head of the ROB, PC %s.\n", 11339948SAli.Saidi@ARM.com head_inst->seqNum, head_inst->pcState()); 11342316SN/A 11359948SAli.Saidi@ARM.com if (inst_num > 0 || iewStage->hasStoresToWB(tid)) { 11369948SAli.Saidi@ARM.com DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 11379948SAli.Saidi@ARM.com return false; 11389948SAli.Saidi@ARM.com } 11392292SN/A 11409948SAli.Saidi@ARM.com toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 11411061SN/A 11429948SAli.Saidi@ARM.com // Change the instruction so it won't try to commit again until 11439948SAli.Saidi@ARM.com // it is executed. 11449948SAli.Saidi@ARM.com head_inst->clearCanCommit(); 11451061SN/A 11469948SAli.Saidi@ARM.com if (head_inst->isLoad() && head_inst->uncacheable()) { 11477720Sgblack@eecs.umich.edu DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %s.\n", 11487720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 11492292SN/A toIEW->commitInfo[tid].uncached = true; 11502292SN/A toIEW->commitInfo[tid].uncachedLoad = head_inst; 11519948SAli.Saidi@ARM.com } else { 11529948SAli.Saidi@ARM.com ++commitNonSpecStalls; 11539948SAli.Saidi@ARM.com } 11542292SN/A 11559948SAli.Saidi@ARM.com return false; 11561060SN/A } 11571060SN/A 11582316SN/A if (head_inst->isThreadSync()) { 11592292SN/A // Not handled for now. 11602316SN/A panic("Thread sync instructions are not handled yet.\n"); 11612132SN/A } 11622132SN/A 11634035Sktlim@umich.edu // Check if the instruction caused a fault. If so, trap. 11644035Sktlim@umich.edu Fault inst_fault = head_inst->getFault(); 11654035Sktlim@umich.edu 11662316SN/A // Stores mark themselves as completed. 11674035Sktlim@umich.edu if (!head_inst->isStore() && inst_fault == NoFault) { 11682310SN/A head_inst->setCompleted(); 11692310SN/A } 11702310SN/A 11712316SN/A // Use checker prior to updating anything due to traps or PC 11722316SN/A // based events. 11732316SN/A if (cpu->checker) { 11742732Sktlim@umich.edu cpu->checker->verify(head_inst); 11751060SN/A } 11761060SN/A 11772112SN/A if (inst_fault != NoFault) { 11787720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inst [sn:%lli] PC %s has a fault\n", 11797720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 11802292SN/A 11815557Sktlim@umich.edu if (iewStage->hasStoresToWB(tid) || inst_num > 0) { 11822316SN/A DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 11832316SN/A return false; 11842316SN/A } 11852310SN/A 11864035Sktlim@umich.edu head_inst->setCompleted(); 11874035Sktlim@umich.edu 11888733Sgeoffrey.blake@arm.com if (cpu->checker) { 11898733Sgeoffrey.blake@arm.com // Need to check the instruction before its fault is processed 11902732Sktlim@umich.edu cpu->checker->verify(head_inst); 11912316SN/A } 11922292SN/A 11939382SAli.Saidi@ARM.com assert(!thread[tid]->noSquashFromTC); 11942292SN/A 11952316SN/A // Mark that we're in state update mode so that the trap's 11962316SN/A // execution doesn't generate extra squashes. 11979382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = true; 11982292SN/A 11992316SN/A // Execute the trap. Although it's slightly unrealistic in 12002316SN/A // terms of timing (as it doesn't wait for the full timing of 12012316SN/A // the trap event to complete before updating state), it's 12022316SN/A // needed to update the state as soon as possible. This 12032316SN/A // prevents external agents from changing any specific state 12042316SN/A // that the trap need. 12057684Sgblack@eecs.umich.edu cpu->trap(inst_fault, tid, head_inst->staticInst); 12062292SN/A 12072316SN/A // Exit state update mode to avoid accidental updating. 12089382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = false; 12092292SN/A 12102316SN/A commitStatus[tid] = TrapPending; 12112292SN/A 12128067SAli.Saidi@ARM.com DPRINTF(Commit, "Committing instruction with fault [sn:%lli]\n", 12138067SAli.Saidi@ARM.com head_inst->seqNum); 12144035Sktlim@umich.edu if (head_inst->traceData) { 12156667Ssteve.reinhardt@amd.com if (DTRACE(ExecFaulting)) { 12166667Ssteve.reinhardt@amd.com head_inst->traceData->setFetchSeq(head_inst->seqNum); 12178834Satgutier@umich.edu head_inst->traceData->setCPSeq(thread[tid]->numOp); 12186667Ssteve.reinhardt@amd.com head_inst->traceData->dump(); 12196667Ssteve.reinhardt@amd.com } 12204288Sktlim@umich.edu delete head_inst->traceData; 12214035Sktlim@umich.edu head_inst->traceData = NULL; 12224035Sktlim@umich.edu } 12234035Sktlim@umich.edu 12242316SN/A // Generate trap squash event. 12252316SN/A generateTrapEvent(tid); 12262316SN/A return false; 12271060SN/A } 12281060SN/A 12292301SN/A updateComInstStats(head_inst); 12302132SN/A 12318793Sgblack@eecs.umich.edu if (FullSystem) { 12328793Sgblack@eecs.umich.edu if (thread[tid]->profile) { 12338793Sgblack@eecs.umich.edu thread[tid]->profilePC = head_inst->instAddr(); 12348793Sgblack@eecs.umich.edu ProfileNode *node = thread[tid]->profile->consume( 12358793Sgblack@eecs.umich.edu thread[tid]->getTC(), head_inst->staticInst); 12362362SN/A 12378793Sgblack@eecs.umich.edu if (node) 12388793Sgblack@eecs.umich.edu thread[tid]->profileNode = node; 12398793Sgblack@eecs.umich.edu } 12408793Sgblack@eecs.umich.edu if (CPA::available()) { 12418793Sgblack@eecs.umich.edu if (head_inst->isControl()) { 12428793Sgblack@eecs.umich.edu ThreadContext *tc = thread[tid]->getTC(); 12438793Sgblack@eecs.umich.edu CPA::cpa()->swAutoBegin(tc, head_inst->nextInstAddr()); 12448793Sgblack@eecs.umich.edu } 12455953Ssaidi@eecs.umich.edu } 12465953Ssaidi@eecs.umich.edu } 12478516SMrinmoy.Ghosh@arm.com DPRINTF(Commit, "Committing instruction with [sn:%lli] PC %s\n", 12488516SMrinmoy.Ghosh@arm.com head_inst->seqNum, head_inst->pcState()); 12492132SN/A if (head_inst->traceData) { 12502292SN/A head_inst->traceData->setFetchSeq(head_inst->seqNum); 12518834Satgutier@umich.edu head_inst->traceData->setCPSeq(thread[tid]->numOp); 12524046Sbinkertn@umich.edu head_inst->traceData->dump(); 12534046Sbinkertn@umich.edu delete head_inst->traceData; 12542292SN/A head_inst->traceData = NULL; 12551060SN/A } 12568843Smrinmoy.ghosh@arm.com if (head_inst->isReturn()) { 12578843Smrinmoy.ghosh@arm.com DPRINTF(Commit,"Return Instruction Committed [sn:%lli] PC %s \n", 12588843Smrinmoy.ghosh@arm.com head_inst->seqNum, head_inst->pcState()); 12598843Smrinmoy.ghosh@arm.com } 12601060SN/A 12612292SN/A // Update the commit rename map 12622292SN/A for (int i = 0; i < head_inst->numDestRegs(); i++) { 12633771Sgblack@eecs.umich.edu renameMap[tid]->setEntry(head_inst->flattenedDestRegIdx(i), 12642292SN/A head_inst->renamedDestRegIdx(i)); 12651060SN/A } 12661062SN/A 12672292SN/A // Finally clear the head ROB entry. 12682292SN/A rob->retireHead(tid); 12691060SN/A 12708471SGiacomo.Gabrielli@arm.com#if TRACING_ON 12719527SMatt.Horsnell@arm.com if (DTRACE(O3PipeView)) { 12729527SMatt.Horsnell@arm.com head_inst->commitTick = curTick() - head_inst->fetchTick; 12739527SMatt.Horsnell@arm.com } 12748471SGiacomo.Gabrielli@arm.com#endif 12758471SGiacomo.Gabrielli@arm.com 12764035Sktlim@umich.edu // If this was a store, record it for this cycle. 12774035Sktlim@umich.edu if (head_inst->isStore()) 12784035Sktlim@umich.edu committedStores[tid] = true; 12794035Sktlim@umich.edu 12801060SN/A // Return true to indicate that we have committed an instruction. 12811060SN/A return true; 12821060SN/A} 12831060SN/A 12841061SN/Atemplate <class Impl> 12851060SN/Avoid 12862292SN/ADefaultCommit<Impl>::getInsts() 12871060SN/A{ 12882935Sksewell@umich.edu DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 12892935Sksewell@umich.edu 12903093Sksewell@umich.edu // Read any renamed instructions and place them into the ROB. 12913093Sksewell@umich.edu int insts_to_process = std::min((int)renameWidth, fromRename->size); 12922965Sksewell@umich.edu 12932965Sksewell@umich.edu for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 12942965Sksewell@umich.edu DynInstPtr inst; 12952965Sksewell@umich.edu 12963093Sksewell@umich.edu inst = fromRename->insts[inst_num]; 12976221Snate@binkert.org ThreadID tid = inst->threadNumber; 12982292SN/A 12992292SN/A if (!inst->isSquashed() && 13004035Sktlim@umich.edu commitStatus[tid] != ROBSquashing && 13014035Sktlim@umich.edu commitStatus[tid] != TrapPending) { 13022292SN/A changedROBNumEntries[tid] = true; 13032292SN/A 13047720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ROB.\n", 13057720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, tid); 13062292SN/A 13072292SN/A rob->insertInst(inst); 13082292SN/A 13092292SN/A assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 13102292SN/A 13112292SN/A youngestSeqNum[tid] = inst->seqNum; 13121061SN/A } else { 13137720Sgblack@eecs.umich.edu DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 13141061SN/A "squashed, skipping.\n", 13157720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, tid); 13161061SN/A } 13171060SN/A } 13182965Sksewell@umich.edu} 13192965Sksewell@umich.edu 13202965Sksewell@umich.edutemplate <class Impl> 13212965Sksewell@umich.eduvoid 13222965Sksewell@umich.eduDefaultCommit<Impl>::skidInsert() 13232965Sksewell@umich.edu{ 13242965Sksewell@umich.edu DPRINTF(Commit, "Attempting to any instructions from rename into " 13252965Sksewell@umich.edu "skidBuffer.\n"); 13262965Sksewell@umich.edu 13272965Sksewell@umich.edu for (int inst_num = 0; inst_num < fromRename->size; ++inst_num) { 13282965Sksewell@umich.edu DynInstPtr inst = fromRename->insts[inst_num]; 13292965Sksewell@umich.edu 13302965Sksewell@umich.edu if (!inst->isSquashed()) { 13317720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ", 13327720Sgblack@eecs.umich.edu "skidBuffer.\n", inst->pcState(), inst->seqNum, 13333221Sktlim@umich.edu inst->threadNumber); 13342965Sksewell@umich.edu skidBuffer.push(inst); 13352965Sksewell@umich.edu } else { 13367720Sgblack@eecs.umich.edu DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 13372965Sksewell@umich.edu "squashed, skipping.\n", 13387720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, inst->threadNumber); 13392965Sksewell@umich.edu } 13402965Sksewell@umich.edu } 13411060SN/A} 13421060SN/A 13431061SN/Atemplate <class Impl> 13441060SN/Avoid 13452292SN/ADefaultCommit<Impl>::markCompletedInsts() 13461060SN/A{ 13471060SN/A // Grab completed insts out of the IEW instruction queue, and mark 13481060SN/A // instructions completed within the ROB. 13491060SN/A for (int inst_num = 0; 13501681SN/A inst_num < fromIEW->size && fromIEW->insts[inst_num]; 13511060SN/A ++inst_num) 13521060SN/A { 13532292SN/A if (!fromIEW->insts[inst_num]->isSquashed()) { 13547720Sgblack@eecs.umich.edu DPRINTF(Commit, "[tid:%i]: Marking PC %s, [sn:%lli] ready " 13552316SN/A "within ROB.\n", 13562292SN/A fromIEW->insts[inst_num]->threadNumber, 13577720Sgblack@eecs.umich.edu fromIEW->insts[inst_num]->pcState(), 13582292SN/A fromIEW->insts[inst_num]->seqNum); 13591060SN/A 13602292SN/A // Mark the instruction as ready to commit. 13612292SN/A fromIEW->insts[inst_num]->setCanCommit(); 13622292SN/A } 13631060SN/A } 13641060SN/A} 13651060SN/A 13661061SN/Atemplate <class Impl> 13672292SN/Abool 13682292SN/ADefaultCommit<Impl>::robDoneSquashing() 13691060SN/A{ 13706221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 13716221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 13722292SN/A 13733867Sbinkertn@umich.edu while (threads != end) { 13746221Snate@binkert.org ThreadID tid = *threads++; 13752292SN/A 13762292SN/A if (!rob->isDoneSquashing(tid)) 13772292SN/A return false; 13782292SN/A } 13792292SN/A 13802292SN/A return true; 13811060SN/A} 13822292SN/A 13832301SN/Atemplate <class Impl> 13842301SN/Avoid 13852301SN/ADefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 13862301SN/A{ 13876221Snate@binkert.org ThreadID tid = inst->threadNumber; 13882301SN/A 13898834Satgutier@umich.edu if (!inst->isMicroop() || inst->isLastMicroop()) 13908834Satgutier@umich.edu instsCommitted[tid]++; 13918834Satgutier@umich.edu opsCommitted[tid]++; 13922301SN/A 13939218Satgutier@umich.edu // To match the old model, don't count nops and instruction 13949218Satgutier@umich.edu // prefetches towards the total commit count. 13959218Satgutier@umich.edu if (!inst->isNop() && !inst->isInstPrefetch()) { 13969218Satgutier@umich.edu cpu->instDone(tid, inst); 13979218Satgutier@umich.edu } 13989218Satgutier@umich.edu 13992301SN/A // 14002301SN/A // Control Instructions 14012301SN/A // 14022301SN/A if (inst->isControl()) 14036221Snate@binkert.org statComBranches[tid]++; 14042301SN/A 14052301SN/A // 14062301SN/A // Memory references 14072301SN/A // 14082301SN/A if (inst->isMemRef()) { 14096221Snate@binkert.org statComRefs[tid]++; 14102301SN/A 14112301SN/A if (inst->isLoad()) { 14126221Snate@binkert.org statComLoads[tid]++; 14132301SN/A } 14142301SN/A } 14152301SN/A 14162301SN/A if (inst->isMemBarrier()) { 14176221Snate@binkert.org statComMembars[tid]++; 14182301SN/A } 14197897Shestness@cs.utexas.edu 14207897Shestness@cs.utexas.edu // Integer Instruction 14217897Shestness@cs.utexas.edu if (inst->isInteger()) 14227897Shestness@cs.utexas.edu statComInteger[tid]++; 14237897Shestness@cs.utexas.edu 14247897Shestness@cs.utexas.edu // Floating Point Instruction 14257897Shestness@cs.utexas.edu if (inst->isFloating()) 14267897Shestness@cs.utexas.edu statComFloating[tid]++; 14277897Shestness@cs.utexas.edu 14287897Shestness@cs.utexas.edu // Function Calls 14297897Shestness@cs.utexas.edu if (inst->isCall()) 14307897Shestness@cs.utexas.edu statComFunctionCalls[tid]++; 14317897Shestness@cs.utexas.edu 14322301SN/A} 14332301SN/A 14342292SN/A//////////////////////////////////////// 14352292SN/A// // 14362316SN/A// SMT COMMIT POLICY MAINTAINED HERE // 14372292SN/A// // 14382292SN/A//////////////////////////////////////// 14392292SN/Atemplate <class Impl> 14406221Snate@binkert.orgThreadID 14412292SN/ADefaultCommit<Impl>::getCommittingThread() 14422292SN/A{ 14432292SN/A if (numThreads > 1) { 14442292SN/A switch (commitPolicy) { 14452292SN/A 14462292SN/A case Aggressive: 14472292SN/A //If Policy is Aggressive, commit will call 14482292SN/A //this function multiple times per 14492292SN/A //cycle 14502292SN/A return oldestReady(); 14512292SN/A 14522292SN/A case RoundRobin: 14532292SN/A return roundRobin(); 14542292SN/A 14552292SN/A case OldestReady: 14562292SN/A return oldestReady(); 14572292SN/A 14582292SN/A default: 14596221Snate@binkert.org return InvalidThreadID; 14602292SN/A } 14612292SN/A } else { 14623867Sbinkertn@umich.edu assert(!activeThreads->empty()); 14636221Snate@binkert.org ThreadID tid = activeThreads->front(); 14642292SN/A 14652292SN/A if (commitStatus[tid] == Running || 14662292SN/A commitStatus[tid] == Idle || 14672292SN/A commitStatus[tid] == FetchTrapPending) { 14682292SN/A return tid; 14692292SN/A } else { 14706221Snate@binkert.org return InvalidThreadID; 14712292SN/A } 14722292SN/A } 14732292SN/A} 14742292SN/A 14752292SN/Atemplate<class Impl> 14766221Snate@binkert.orgThreadID 14772292SN/ADefaultCommit<Impl>::roundRobin() 14782292SN/A{ 14796221Snate@binkert.org list<ThreadID>::iterator pri_iter = priority_list.begin(); 14806221Snate@binkert.org list<ThreadID>::iterator end = priority_list.end(); 14812292SN/A 14822292SN/A while (pri_iter != end) { 14836221Snate@binkert.org ThreadID tid = *pri_iter; 14842292SN/A 14852292SN/A if (commitStatus[tid] == Running || 14862831Sksewell@umich.edu commitStatus[tid] == Idle || 14872831Sksewell@umich.edu commitStatus[tid] == FetchTrapPending) { 14882292SN/A 14892292SN/A if (rob->isHeadReady(tid)) { 14902292SN/A priority_list.erase(pri_iter); 14912292SN/A priority_list.push_back(tid); 14922292SN/A 14932292SN/A return tid; 14942292SN/A } 14952292SN/A } 14962292SN/A 14972292SN/A pri_iter++; 14982292SN/A } 14992292SN/A 15006221Snate@binkert.org return InvalidThreadID; 15012292SN/A} 15022292SN/A 15032292SN/Atemplate<class Impl> 15046221Snate@binkert.orgThreadID 15052292SN/ADefaultCommit<Impl>::oldestReady() 15062292SN/A{ 15072292SN/A unsigned oldest = 0; 15082292SN/A bool first = true; 15092292SN/A 15106221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 15116221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 15122292SN/A 15133867Sbinkertn@umich.edu while (threads != end) { 15146221Snate@binkert.org ThreadID tid = *threads++; 15152292SN/A 15162292SN/A if (!rob->isEmpty(tid) && 15172292SN/A (commitStatus[tid] == Running || 15182292SN/A commitStatus[tid] == Idle || 15192292SN/A commitStatus[tid] == FetchTrapPending)) { 15202292SN/A 15212292SN/A if (rob->isHeadReady(tid)) { 15222292SN/A 15232292SN/A DynInstPtr head_inst = rob->readHeadInst(tid); 15242292SN/A 15252292SN/A if (first) { 15262292SN/A oldest = tid; 15272292SN/A first = false; 15282292SN/A } else if (head_inst->seqNum < oldest) { 15292292SN/A oldest = tid; 15302292SN/A } 15312292SN/A } 15322292SN/A } 15332292SN/A } 15342292SN/A 15352292SN/A if (!first) { 15362292SN/A return oldest; 15372292SN/A } else { 15386221Snate@binkert.org return InvalidThreadID; 15392292SN/A } 15402292SN/A} 15419944Smatt.horsnell@ARM.com 15429944Smatt.horsnell@ARM.com#endif//__CPU_O3_COMMIT_IMPL_HH__ 1543