commit_impl.hh revision 10729
11689SN/A/* 210596Sgabeblack@google.com * Copyright 2014 Google, Inc. 310331Smitch.hayenga@arm.com * Copyright (c) 2010-2014 ARM Limited 47783SGiacomo.Gabrielli@arm.com * All rights reserved 57783SGiacomo.Gabrielli@arm.com * 67783SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 77783SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 87783SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 97783SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 107783SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 117783SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 127783SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 137783SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 147783SGiacomo.Gabrielli@arm.com * 152316SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 161689SN/A * All rights reserved. 171689SN/A * 181689SN/A * Redistribution and use in source and binary forms, with or without 191689SN/A * modification, are permitted provided that the following conditions are 201689SN/A * met: redistributions of source code must retain the above copyright 211689SN/A * notice, this list of conditions and the following disclaimer; 221689SN/A * redistributions in binary form must reproduce the above copyright 231689SN/A * notice, this list of conditions and the following disclaimer in the 241689SN/A * documentation and/or other materials provided with the distribution; 251689SN/A * neither the name of the copyright holders nor the names of its 261689SN/A * contributors may be used to endorse or promote products derived from 271689SN/A * this software without specific prior written permission. 281689SN/A * 291689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 301689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 311689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 321689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 331689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 341689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 351689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 361689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 371689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 381689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 391689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 422965Sksewell@umich.edu * Korey Sewell 431689SN/A */ 449944Smatt.horsnell@ARM.com#ifndef __CPU_O3_COMMIT_IMPL_HH__ 459944Smatt.horsnell@ARM.com#define __CPU_O3_COMMIT_IMPL_HH__ 461689SN/A 472292SN/A#include <algorithm> 489516SAli.Saidi@ARM.com#include <set> 492329SN/A#include <string> 502292SN/A 513577Sgblack@eecs.umich.edu#include "arch/utility.hh" 528229Snate@binkert.org#include "base/loader/symtab.hh" 535953Ssaidi@eecs.umich.edu#include "base/cp_annotate.hh" 546658Snate@binkert.org#include "config/the_isa.hh" 558887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 561717SN/A#include "cpu/o3/commit.hh" 572292SN/A#include "cpu/o3/thread_state.hh" 588662SAli.Saidi@ARM.com#include "cpu/base.hh" 598229Snate@binkert.org#include "cpu/exetrace.hh" 608229Snate@binkert.org#include "cpu/timebuf.hh" 618232Snate@binkert.org#include "debug/Activity.hh" 628232Snate@binkert.org#include "debug/Commit.hh" 638232Snate@binkert.org#include "debug/CommitRate.hh" 649444SAndreas.Sandberg@ARM.com#include "debug/Drain.hh" 658232Snate@binkert.org#include "debug/ExecFaulting.hh" 669527SMatt.Horsnell@arm.com#include "debug/O3PipeView.hh" 676221Snate@binkert.org#include "params/DerivO3CPU.hh" 688230Snate@binkert.org#include "sim/faults.hh" 698793Sgblack@eecs.umich.edu#include "sim/full_system.hh" 702292SN/A 716221Snate@binkert.orgusing namespace std; 725529Snate@binkert.org 731061SN/Atemplate <class Impl> 742292SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit, 756221Snate@binkert.org ThreadID _tid) 768581Ssteve.reinhardt@amd.com : Event(CPU_Tick_Pri, AutoDelete), commit(_commit), tid(_tid) 771060SN/A{ 781060SN/A} 791060SN/A 801061SN/Atemplate <class Impl> 811060SN/Avoid 822292SN/ADefaultCommit<Impl>::TrapEvent::process() 831062SN/A{ 842316SN/A // This will get reset by commit if it was switched out at the 852316SN/A // time of this event processing. 862292SN/A commit->trapSquash[tid] = true; 872292SN/A} 882292SN/A 892292SN/Atemplate <class Impl> 902292SN/Aconst char * 915336Shines@cs.fsu.eduDefaultCommit<Impl>::TrapEvent::description() const 922292SN/A{ 934873Sstever@eecs.umich.edu return "Trap"; 942292SN/A} 952292SN/A 962292SN/Atemplate <class Impl> 975529Snate@binkert.orgDefaultCommit<Impl>::DefaultCommit(O3CPU *_cpu, DerivO3CPUParams *params) 984329Sktlim@umich.edu : cpu(_cpu), 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), 10710340Smitch.hayenga@arm.com drainImminent(false), 1088823Snilay@cs.wisc.edu trapLatency(params->trapLatency), 1099513SAli.Saidi@ARM.com canHandleInterrupts(true), 1109513SAli.Saidi@ARM.com avoidQuiesceLiveLock(false) 1112292SN/A{ 11210172Sdam.sunwoo@arm.com if (commitWidth > Impl::MaxWidth) 11310172Sdam.sunwoo@arm.com fatal("commitWidth (%d) is larger than compiled limit (%d),\n" 11410172Sdam.sunwoo@arm.com "\tincrease MaxWidth in src/cpu/o3/impl.hh\n", 11510172Sdam.sunwoo@arm.com commitWidth, static_cast<int>(Impl::MaxWidth)); 11610172Sdam.sunwoo@arm.com 1172292SN/A _status = Active; 1182292SN/A _nextStatus = Inactive; 1192980Sgblack@eecs.umich.edu std::string policy = params->smtCommitPolicy; 1202292SN/A 1212292SN/A //Convert string to lowercase 1222292SN/A std::transform(policy.begin(), policy.end(), policy.begin(), 1232292SN/A (int(*)(int)) tolower); 1242292SN/A 1252292SN/A //Assign commit policy 1262292SN/A if (policy == "aggressive"){ 1272292SN/A commitPolicy = Aggressive; 1282292SN/A 1298346Sksewell@umich.edu DPRINTF(Commit,"Commit Policy set to Aggressive.\n"); 1302292SN/A } else if (policy == "roundrobin"){ 1312292SN/A commitPolicy = RoundRobin; 1322292SN/A 1332292SN/A //Set-Up Priority List 1346221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 1352292SN/A priority_list.push_back(tid); 1362292SN/A } 1372292SN/A 1388346Sksewell@umich.edu DPRINTF(Commit,"Commit Policy set to Round Robin.\n"); 1392292SN/A } else if (policy == "oldestready"){ 1402292SN/A commitPolicy = OldestReady; 1412292SN/A 1424329Sktlim@umich.edu DPRINTF(Commit,"Commit Policy set to Oldest Ready."); 1432292SN/A } else { 1442292SN/A assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive," 1452292SN/A "RoundRobin,OldestReady}"); 1462292SN/A } 1472292SN/A 1486221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 1496221Snate@binkert.org commitStatus[tid] = Idle; 1506221Snate@binkert.org changedROBNumEntries[tid] = false; 1516221Snate@binkert.org checkEmptyROB[tid] = false; 1526221Snate@binkert.org trapInFlight[tid] = false; 1536221Snate@binkert.org committedStores[tid] = false; 1546221Snate@binkert.org trapSquash[tid] = false; 1556221Snate@binkert.org tcSquash[tid] = false; 1567720Sgblack@eecs.umich.edu pc[tid].set(0); 1577855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] = 0; 1589437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = NULL; 1592292SN/A } 1603640Sktlim@umich.edu interrupt = NoFault; 1612292SN/A} 1622292SN/A 1632292SN/Atemplate <class Impl> 1642292SN/Astd::string 1652292SN/ADefaultCommit<Impl>::name() const 1662292SN/A{ 1672292SN/A return cpu->name() + ".commit"; 1682292SN/A} 1692292SN/A 1702292SN/Atemplate <class Impl> 1712292SN/Avoid 17210023Smatt.horsnell@ARM.comDefaultCommit<Impl>::regProbePoints() 17310023Smatt.horsnell@ARM.com{ 17410023Smatt.horsnell@ARM.com ppCommit = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Commit"); 17510023Smatt.horsnell@ARM.com ppCommitStall = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "CommitStall"); 17610023Smatt.horsnell@ARM.com} 17710023Smatt.horsnell@ARM.com 17810023Smatt.horsnell@ARM.comtemplate <class Impl> 17910023Smatt.horsnell@ARM.comvoid 1802292SN/ADefaultCommit<Impl>::regStats() 1812132SN/A{ 1822301SN/A using namespace Stats; 1831062SN/A commitSquashedInsts 1841062SN/A .name(name() + ".commitSquashedInsts") 1851062SN/A .desc("The number of squashed insts skipped by commit") 1861062SN/A .prereq(commitSquashedInsts); 1871062SN/A commitSquashEvents 1881062SN/A .name(name() + ".commitSquashEvents") 1891062SN/A .desc("The number of times commit is told to squash") 1901062SN/A .prereq(commitSquashEvents); 1911062SN/A commitNonSpecStalls 1921062SN/A .name(name() + ".commitNonSpecStalls") 1931062SN/A .desc("The number of times commit has been forced to stall to " 1941062SN/A "communicate backwards") 1951062SN/A .prereq(commitNonSpecStalls); 1961062SN/A branchMispredicts 1971062SN/A .name(name() + ".branchMispredicts") 1981062SN/A .desc("The number of times a branch was mispredicted") 1991062SN/A .prereq(branchMispredicts); 2002292SN/A numCommittedDist 2011062SN/A .init(0,commitWidth,1) 2028240Snate@binkert.org .name(name() + ".committed_per_cycle") 2031062SN/A .desc("Number of insts commited each cycle") 2041062SN/A .flags(Stats::pdf) 2051062SN/A ; 2062301SN/A 2078834Satgutier@umich.edu instsCommitted 2086221Snate@binkert.org .init(cpu->numThreads) 2098834Satgutier@umich.edu .name(name() + ".committedInsts") 2102301SN/A .desc("Number of instructions committed") 2112301SN/A .flags(total) 2122301SN/A ; 2132301SN/A 2148834Satgutier@umich.edu opsCommitted 2158834Satgutier@umich.edu .init(cpu->numThreads) 2168834Satgutier@umich.edu .name(name() + ".committedOps") 2178834Satgutier@umich.edu .desc("Number of ops (including micro ops) committed") 2188834Satgutier@umich.edu .flags(total) 2198834Satgutier@umich.edu ; 2208834Satgutier@umich.edu 2212316SN/A statComSwp 2226221Snate@binkert.org .init(cpu->numThreads) 2238240Snate@binkert.org .name(name() + ".swp_count") 2242301SN/A .desc("Number of s/w prefetches committed") 2252301SN/A .flags(total) 2262301SN/A ; 2272301SN/A 2282316SN/A statComRefs 2296221Snate@binkert.org .init(cpu->numThreads) 2308240Snate@binkert.org .name(name() + ".refs") 2312301SN/A .desc("Number of memory references committed") 2322301SN/A .flags(total) 2332301SN/A ; 2342301SN/A 2352316SN/A statComLoads 2366221Snate@binkert.org .init(cpu->numThreads) 2378240Snate@binkert.org .name(name() + ".loads") 2382301SN/A .desc("Number of loads committed") 2392301SN/A .flags(total) 2402301SN/A ; 2412301SN/A 2422316SN/A statComMembars 2436221Snate@binkert.org .init(cpu->numThreads) 2448240Snate@binkert.org .name(name() + ".membars") 2452301SN/A .desc("Number of memory barriers committed") 2462301SN/A .flags(total) 2472301SN/A ; 2482301SN/A 2492316SN/A statComBranches 2506221Snate@binkert.org .init(cpu->numThreads) 2518240Snate@binkert.org .name(name() + ".branches") 2522301SN/A .desc("Number of branches committed") 2532301SN/A .flags(total) 2542301SN/A ; 2552301SN/A 2567897Shestness@cs.utexas.edu statComFloating 2577897Shestness@cs.utexas.edu .init(cpu->numThreads) 2588240Snate@binkert.org .name(name() + ".fp_insts") 2597897Shestness@cs.utexas.edu .desc("Number of committed floating point instructions.") 2607897Shestness@cs.utexas.edu .flags(total) 2617897Shestness@cs.utexas.edu ; 2627897Shestness@cs.utexas.edu 2637897Shestness@cs.utexas.edu statComInteger 2647897Shestness@cs.utexas.edu .init(cpu->numThreads) 2658240Snate@binkert.org .name(name()+".int_insts") 2667897Shestness@cs.utexas.edu .desc("Number of committed integer instructions.") 2677897Shestness@cs.utexas.edu .flags(total) 2687897Shestness@cs.utexas.edu ; 2697897Shestness@cs.utexas.edu 2707897Shestness@cs.utexas.edu statComFunctionCalls 2717897Shestness@cs.utexas.edu .init(cpu->numThreads) 2728240Snate@binkert.org .name(name()+".function_calls") 2737897Shestness@cs.utexas.edu .desc("Number of function calls committed.") 2747897Shestness@cs.utexas.edu .flags(total) 2757897Shestness@cs.utexas.edu ; 2767897Shestness@cs.utexas.edu 27710193SCurtis.Dunham@arm.com statCommittedInstType 27810193SCurtis.Dunham@arm.com .init(numThreads,Enums::Num_OpClass) 27910193SCurtis.Dunham@arm.com .name(name() + ".op_class") 28010193SCurtis.Dunham@arm.com .desc("Class of committed instruction") 28110193SCurtis.Dunham@arm.com .flags(total | pdf | dist) 28210193SCurtis.Dunham@arm.com ; 28310193SCurtis.Dunham@arm.com statCommittedInstType.ysubnames(Enums::OpClassStrings); 28410193SCurtis.Dunham@arm.com 2852316SN/A commitEligible 2866221Snate@binkert.org .init(cpu->numThreads) 2878240Snate@binkert.org .name(name() + ".bw_limited") 2882301SN/A .desc("number of insts not committed due to BW limits") 2892301SN/A .flags(total) 2902301SN/A ; 2912301SN/A 2922316SN/A commitEligibleSamples 2938240Snate@binkert.org .name(name() + ".bw_lim_events") 2942301SN/A .desc("number cycles where commit BW limit reached") 2952301SN/A ; 2961062SN/A} 2971062SN/A 2981062SN/Atemplate <class Impl> 2991062SN/Avoid 3002980Sgblack@eecs.umich.eduDefaultCommit<Impl>::setThreads(std::vector<Thread *> &threads) 3012292SN/A{ 3022292SN/A thread = threads; 3032292SN/A} 3042292SN/A 3052292SN/Atemplate <class Impl> 3062292SN/Avoid 3072292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 3081060SN/A{ 3091060SN/A timeBuffer = tb_ptr; 3101060SN/A 3111060SN/A // Setup wire to send information back to IEW. 3121060SN/A toIEW = timeBuffer->getWire(0); 3131060SN/A 3141060SN/A // Setup wire to read data from IEW (for the ROB). 3151060SN/A robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay); 3161060SN/A} 3171060SN/A 3181061SN/Atemplate <class Impl> 3191060SN/Avoid 3202292SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 3212292SN/A{ 3222292SN/A fetchQueue = fq_ptr; 3232292SN/A 3242292SN/A // Setup wire to get instructions from rename (for the ROB). 3252292SN/A fromFetch = fetchQueue->getWire(-fetchToCommitDelay); 3262292SN/A} 3272292SN/A 3282292SN/Atemplate <class Impl> 3292292SN/Avoid 3302292SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3311060SN/A{ 3321060SN/A renameQueue = rq_ptr; 3331060SN/A 3341060SN/A // Setup wire to get instructions from rename (for the ROB). 3351060SN/A fromRename = renameQueue->getWire(-renameToROBDelay); 3361060SN/A} 3371060SN/A 3381061SN/Atemplate <class Impl> 3391060SN/Avoid 3402292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3411060SN/A{ 3421060SN/A iewQueue = iq_ptr; 3431060SN/A 3441060SN/A // Setup wire to get instructions from IEW. 3451060SN/A fromIEW = iewQueue->getWire(-iewToCommitDelay); 3461060SN/A} 3471060SN/A 3481061SN/Atemplate <class Impl> 3491060SN/Avoid 3502292SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage) 3512292SN/A{ 3522292SN/A iewStage = iew_stage; 3532292SN/A} 3542292SN/A 3552292SN/Atemplate<class Impl> 3562292SN/Avoid 3576221Snate@binkert.orgDefaultCommit<Impl>::setActiveThreads(list<ThreadID> *at_ptr) 3582292SN/A{ 3592292SN/A activeThreads = at_ptr; 3602292SN/A} 3612292SN/A 3622292SN/Atemplate <class Impl> 3632292SN/Avoid 3642292SN/ADefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[]) 3652292SN/A{ 3666221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) 3676221Snate@binkert.org renameMap[tid] = &rm_ptr[tid]; 3682292SN/A} 3692292SN/A 3702292SN/Atemplate <class Impl> 3712292SN/Avoid 3722292SN/ADefaultCommit<Impl>::setROB(ROB *rob_ptr) 3731060SN/A{ 3741060SN/A rob = rob_ptr; 3751060SN/A} 3761060SN/A 3771061SN/Atemplate <class Impl> 3781060SN/Avoid 3799427SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::startupStage() 3801060SN/A{ 3812292SN/A rob->setActiveThreads(activeThreads); 3822292SN/A rob->resetEntries(); 3831060SN/A 3842292SN/A // Broadcast the number of free entries. 3856221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 3866221Snate@binkert.org toIEW->commitInfo[tid].usedROB = true; 3876221Snate@binkert.org toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 3886221Snate@binkert.org toIEW->commitInfo[tid].emptyROB = true; 3891060SN/A } 3901060SN/A 3914329Sktlim@umich.edu // Commit must broadcast the number of free entries it has at the 3924329Sktlim@umich.edu // start of the simulation, so it starts as active. 3934329Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 3944329Sktlim@umich.edu 3952292SN/A cpu->activityThisCycle(); 3961060SN/A} 3971060SN/A 3981061SN/Atemplate <class Impl> 3999444SAndreas.Sandberg@ARM.comvoid 4002843Sktlim@umich.eduDefaultCommit<Impl>::drain() 4011060SN/A{ 4022843Sktlim@umich.edu drainPending = true; 4032316SN/A} 4042316SN/A 4052316SN/Atemplate <class Impl> 4062316SN/Avoid 4079444SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::drainResume() 4082843Sktlim@umich.edu{ 4092864Sktlim@umich.edu drainPending = false; 41010340Smitch.hayenga@arm.com drainImminent = false; 4112843Sktlim@umich.edu} 4122843Sktlim@umich.edu 4132843Sktlim@umich.edutemplate <class Impl> 4142843Sktlim@umich.eduvoid 4159444SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::drainSanityCheck() const 4169444SAndreas.Sandberg@ARM.com{ 4179444SAndreas.Sandberg@ARM.com assert(isDrained()); 4189444SAndreas.Sandberg@ARM.com rob->drainSanityCheck(); 4199444SAndreas.Sandberg@ARM.com} 4209444SAndreas.Sandberg@ARM.com 4219444SAndreas.Sandberg@ARM.comtemplate <class Impl> 4229444SAndreas.Sandberg@ARM.combool 4239444SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::isDrained() const 4249444SAndreas.Sandberg@ARM.com{ 4259444SAndreas.Sandberg@ARM.com /* Make sure no one is executing microcode. There are two reasons 4269444SAndreas.Sandberg@ARM.com * for this: 4279444SAndreas.Sandberg@ARM.com * - Hardware virtualized CPUs can't switch into the middle of a 4289444SAndreas.Sandberg@ARM.com * microcode sequence. 4299444SAndreas.Sandberg@ARM.com * - The current fetch implementation will most likely get very 4309444SAndreas.Sandberg@ARM.com * confused if it tries to start fetching an instruction that 4319444SAndreas.Sandberg@ARM.com * is executing in the middle of a ucode sequence that changes 4329444SAndreas.Sandberg@ARM.com * address mappings. This can happen on for example x86. 4339444SAndreas.Sandberg@ARM.com */ 4349444SAndreas.Sandberg@ARM.com for (ThreadID tid = 0; tid < numThreads; tid++) { 4359444SAndreas.Sandberg@ARM.com if (pc[tid].microPC() != 0) 4369444SAndreas.Sandberg@ARM.com return false; 4379444SAndreas.Sandberg@ARM.com } 4389444SAndreas.Sandberg@ARM.com 4399444SAndreas.Sandberg@ARM.com /* Make sure that all instructions have finished committing before 4409444SAndreas.Sandberg@ARM.com * declaring the system as drained. We want the pipeline to be 4419444SAndreas.Sandberg@ARM.com * completely empty when we declare the CPU to be drained. This 4429444SAndreas.Sandberg@ARM.com * makes debugging easier since CPU handover and restoring from a 4439444SAndreas.Sandberg@ARM.com * checkpoint with a different CPU should have the same timing. 4449444SAndreas.Sandberg@ARM.com */ 4459444SAndreas.Sandberg@ARM.com return rob->isEmpty() && 4469444SAndreas.Sandberg@ARM.com interrupt == NoFault; 4479444SAndreas.Sandberg@ARM.com} 4489444SAndreas.Sandberg@ARM.com 4499444SAndreas.Sandberg@ARM.comtemplate <class Impl> 4509444SAndreas.Sandberg@ARM.comvoid 4512307SN/ADefaultCommit<Impl>::takeOverFrom() 4522307SN/A{ 4532307SN/A _status = Active; 4542307SN/A _nextStatus = Inactive; 4556221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 4566221Snate@binkert.org commitStatus[tid] = Idle; 4576221Snate@binkert.org changedROBNumEntries[tid] = false; 4586221Snate@binkert.org trapSquash[tid] = false; 4596221Snate@binkert.org tcSquash[tid] = false; 4609437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = NULL; 4612307SN/A } 4622307SN/A rob->takeOverFrom(); 4632307SN/A} 4642307SN/A 4652307SN/Atemplate <class Impl> 4662307SN/Avoid 46710331Smitch.hayenga@arm.comDefaultCommit<Impl>::deactivateThread(ThreadID tid) 46810331Smitch.hayenga@arm.com{ 46910331Smitch.hayenga@arm.com list<ThreadID>::iterator thread_it = std::find(priority_list.begin(), 47010331Smitch.hayenga@arm.com priority_list.end(), tid); 47110331Smitch.hayenga@arm.com 47210331Smitch.hayenga@arm.com if (thread_it != priority_list.end()) { 47310331Smitch.hayenga@arm.com priority_list.erase(thread_it); 47410331Smitch.hayenga@arm.com } 47510331Smitch.hayenga@arm.com} 47610331Smitch.hayenga@arm.com 47710331Smitch.hayenga@arm.com 47810331Smitch.hayenga@arm.comtemplate <class Impl> 47910331Smitch.hayenga@arm.comvoid 4802292SN/ADefaultCommit<Impl>::updateStatus() 4812132SN/A{ 4822316SN/A // reset ROB changed variable 4836221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 4846221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 4853867Sbinkertn@umich.edu 4863867Sbinkertn@umich.edu while (threads != end) { 4876221Snate@binkert.org ThreadID tid = *threads++; 4883867Sbinkertn@umich.edu 4892316SN/A changedROBNumEntries[tid] = false; 4902316SN/A 4912316SN/A // Also check if any of the threads has a trap pending 4922316SN/A if (commitStatus[tid] == TrapPending || 4932316SN/A commitStatus[tid] == FetchTrapPending) { 4942316SN/A _nextStatus = Active; 4952316SN/A } 4962292SN/A } 4972292SN/A 4982292SN/A if (_nextStatus == Inactive && _status == Active) { 4992292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 5002733Sktlim@umich.edu cpu->deactivateStage(O3CPU::CommitIdx); 5012292SN/A } else if (_nextStatus == Active && _status == Inactive) { 5022292SN/A DPRINTF(Activity, "Activating stage.\n"); 5032733Sktlim@umich.edu cpu->activateStage(O3CPU::CommitIdx); 5042292SN/A } 5052292SN/A 5062292SN/A _status = _nextStatus; 5072292SN/A} 5082292SN/A 5092292SN/Atemplate <class Impl> 5102292SN/Abool 5112292SN/ADefaultCommit<Impl>::changedROBEntries() 5122292SN/A{ 5136221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 5146221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 5152292SN/A 5163867Sbinkertn@umich.edu while (threads != end) { 5176221Snate@binkert.org ThreadID tid = *threads++; 5182292SN/A 5192292SN/A if (changedROBNumEntries[tid]) { 5202292SN/A return true; 5212292SN/A } 5222292SN/A } 5232292SN/A 5242292SN/A return false; 5252292SN/A} 5262292SN/A 5272292SN/Atemplate <class Impl> 5286221Snate@binkert.orgsize_t 5296221Snate@binkert.orgDefaultCommit<Impl>::numROBFreeEntries(ThreadID tid) 5302292SN/A{ 5312292SN/A return rob->numFreeEntries(tid); 5322292SN/A} 5332292SN/A 5342292SN/Atemplate <class Impl> 5352292SN/Avoid 5366221Snate@binkert.orgDefaultCommit<Impl>::generateTrapEvent(ThreadID tid) 5372292SN/A{ 5382292SN/A DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid); 5392292SN/A 5402292SN/A TrapEvent *trap = new TrapEvent(this, tid); 5412292SN/A 5429179Sandreas.hansson@arm.com cpu->schedule(trap, cpu->clockEdge(trapLatency)); 5434035Sktlim@umich.edu trapInFlight[tid] = true; 5448518Sgeoffrey.blake@arm.com thread[tid]->trapPending = true; 5452292SN/A} 5462292SN/A 5472292SN/Atemplate <class Impl> 5482292SN/Avoid 5496221Snate@binkert.orgDefaultCommit<Impl>::generateTCEvent(ThreadID tid) 5502292SN/A{ 5514035Sktlim@umich.edu assert(!trapInFlight[tid]); 5522680Sktlim@umich.edu DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid); 5532292SN/A 5542680Sktlim@umich.edu tcSquash[tid] = true; 5552292SN/A} 5562292SN/A 5572292SN/Atemplate <class Impl> 5582292SN/Avoid 5596221Snate@binkert.orgDefaultCommit<Impl>::squashAll(ThreadID tid) 5602292SN/A{ 5612292SN/A // If we want to include the squashing instruction in the squash, 5622292SN/A // then use one older sequence number. 5632292SN/A // Hopefully this doesn't mess things up. Basically I want to squash 5642292SN/A // all instructions of this thread. 56510164Ssleimanf@umich.edu InstSeqNum squashed_inst = rob->isEmpty(tid) ? 5667855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] : rob->readHeadInst(tid)->seqNum - 1; 5672292SN/A 5682292SN/A // All younger instructions will be squashed. Set the sequence 5692292SN/A // number as the youngest instruction in the ROB (0 in this case. 5702292SN/A // Hopefully nothing breaks.) 5717855SAli.Saidi@ARM.com youngestSeqNum[tid] = lastCommitedSeqNum[tid]; 5722292SN/A 5732292SN/A rob->squash(squashed_inst, tid); 5742292SN/A changedROBNumEntries[tid] = true; 5752292SN/A 5762292SN/A // Send back the sequence number of the squashed instruction. 5772292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 5782292SN/A 5792292SN/A // Send back the squash signal to tell stages that they should 5802292SN/A // squash. 5812292SN/A toIEW->commitInfo[tid].squash = true; 5822292SN/A 5832292SN/A // Send back the rob squashing signal so other stages know that 5842292SN/A // the ROB is in the process of squashing. 5852292SN/A toIEW->commitInfo[tid].robSquashing = true; 5862292SN/A 5877851SMatt.Horsnell@arm.com toIEW->commitInfo[tid].mispredictInst = NULL; 5888137SAli.Saidi@ARM.com toIEW->commitInfo[tid].squashInst = NULL; 5892292SN/A 5907720Sgblack@eecs.umich.edu toIEW->commitInfo[tid].pc = pc[tid]; 5912316SN/A} 5922292SN/A 5932316SN/Atemplate <class Impl> 5942316SN/Avoid 5956221Snate@binkert.orgDefaultCommit<Impl>::squashFromTrap(ThreadID tid) 5962316SN/A{ 5972316SN/A squashAll(tid); 5982316SN/A 5997720Sgblack@eecs.umich.edu DPRINTF(Commit, "Squashing from trap, restarting at PC %s\n", pc[tid]); 6002316SN/A 6012316SN/A thread[tid]->trapPending = false; 6029382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = false; 6034035Sktlim@umich.edu trapInFlight[tid] = false; 6042316SN/A 6052316SN/A trapSquash[tid] = false; 6062316SN/A 6072316SN/A commitStatus[tid] = ROBSquashing; 6082316SN/A cpu->activityThisCycle(); 6092316SN/A} 6102316SN/A 6112316SN/Atemplate <class Impl> 6122316SN/Avoid 6136221Snate@binkert.orgDefaultCommit<Impl>::squashFromTC(ThreadID tid) 6142316SN/A{ 6152316SN/A squashAll(tid); 6162292SN/A 6177720Sgblack@eecs.umich.edu DPRINTF(Commit, "Squashing from TC, restarting at PC %s\n", pc[tid]); 6182292SN/A 6199382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = false; 6202292SN/A assert(!thread[tid]->trapPending); 6212316SN/A 6222292SN/A commitStatus[tid] = ROBSquashing; 6232292SN/A cpu->activityThisCycle(); 6242292SN/A 6252680Sktlim@umich.edu tcSquash[tid] = false; 6262292SN/A} 6272292SN/A 6282292SN/Atemplate <class Impl> 6292292SN/Avoid 6309437SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::squashFromSquashAfter(ThreadID tid) 6317784SAli.Saidi@ARM.com{ 6329437SAndreas.Sandberg@ARM.com DPRINTF(Commit, "Squashing after squash after request, " 6339437SAndreas.Sandberg@ARM.com "restarting at PC %s\n", pc[tid]); 6347784SAli.Saidi@ARM.com 6359437SAndreas.Sandberg@ARM.com squashAll(tid); 6369437SAndreas.Sandberg@ARM.com // Make sure to inform the fetch stage of which instruction caused 6379437SAndreas.Sandberg@ARM.com // the squash. It'll try to re-fetch an instruction executing in 6389437SAndreas.Sandberg@ARM.com // microcode unless this is set. 6399437SAndreas.Sandberg@ARM.com toIEW->commitInfo[tid].squashInst = squashAfterInst[tid]; 6409437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = NULL; 6417784SAli.Saidi@ARM.com 6429437SAndreas.Sandberg@ARM.com commitStatus[tid] = ROBSquashing; 6439437SAndreas.Sandberg@ARM.com cpu->activityThisCycle(); 6449437SAndreas.Sandberg@ARM.com} 6457784SAli.Saidi@ARM.com 6469437SAndreas.Sandberg@ARM.comtemplate <class Impl> 6479437SAndreas.Sandberg@ARM.comvoid 6489437SAndreas.Sandberg@ARM.comDefaultCommit<Impl>::squashAfter(ThreadID tid, DynInstPtr &head_inst) 6499437SAndreas.Sandberg@ARM.com{ 6509437SAndreas.Sandberg@ARM.com DPRINTF(Commit, "Executing squash after for [tid:%i] inst [sn:%lli]\n", 6519437SAndreas.Sandberg@ARM.com tid, head_inst->seqNum); 6527784SAli.Saidi@ARM.com 6539437SAndreas.Sandberg@ARM.com assert(!squashAfterInst[tid] || squashAfterInst[tid] == head_inst); 6549437SAndreas.Sandberg@ARM.com commitStatus[tid] = SquashAfterPending; 6559437SAndreas.Sandberg@ARM.com squashAfterInst[tid] = head_inst; 6567784SAli.Saidi@ARM.com} 6577784SAli.Saidi@ARM.com 6587784SAli.Saidi@ARM.comtemplate <class Impl> 6597784SAli.Saidi@ARM.comvoid 6602292SN/ADefaultCommit<Impl>::tick() 6612292SN/A{ 6622292SN/A wroteToTimeBuffer = false; 6632292SN/A _nextStatus = Inactive; 6642292SN/A 6653867Sbinkertn@umich.edu if (activeThreads->empty()) 6662875Sksewell@umich.edu return; 6672875Sksewell@umich.edu 6686221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6696221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6702292SN/A 6712316SN/A // Check if any of the threads are done squashing. Change the 6722316SN/A // status if they are done. 6733867Sbinkertn@umich.edu while (threads != end) { 6746221Snate@binkert.org ThreadID tid = *threads++; 6752292SN/A 6764035Sktlim@umich.edu // Clear the bit saying if the thread has committed stores 6774035Sktlim@umich.edu // this cycle. 6784035Sktlim@umich.edu committedStores[tid] = false; 6794035Sktlim@umich.edu 6802292SN/A if (commitStatus[tid] == ROBSquashing) { 6812292SN/A 6822292SN/A if (rob->isDoneSquashing(tid)) { 6832292SN/A commitStatus[tid] = Running; 6842292SN/A } else { 6852292SN/A DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any" 6862877Sksewell@umich.edu " insts this cycle.\n", tid); 6872702Sktlim@umich.edu rob->doSquash(tid); 6882702Sktlim@umich.edu toIEW->commitInfo[tid].robSquashing = true; 6892702Sktlim@umich.edu wroteToTimeBuffer = true; 6902292SN/A } 6912292SN/A } 6922292SN/A } 6932292SN/A 6942292SN/A commit(); 6952292SN/A 6962292SN/A markCompletedInsts(); 6972292SN/A 6983867Sbinkertn@umich.edu threads = activeThreads->begin(); 6992292SN/A 7003867Sbinkertn@umich.edu while (threads != end) { 7016221Snate@binkert.org ThreadID tid = *threads++; 7022292SN/A 7032292SN/A if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) { 7042292SN/A // The ROB has more instructions it can commit. Its next status 7052292SN/A // will be active. 7062292SN/A _nextStatus = Active; 7072292SN/A 7082292SN/A DynInstPtr inst = rob->readHeadInst(tid); 7092292SN/A 7107720Sgblack@eecs.umich.edu DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %s is head of" 7112292SN/A " ROB and ready to commit\n", 7127720Sgblack@eecs.umich.edu tid, inst->seqNum, inst->pcState()); 7132292SN/A 7142292SN/A } else if (!rob->isEmpty(tid)) { 7152292SN/A DynInstPtr inst = rob->readHeadInst(tid); 7162292SN/A 71710023Smatt.horsnell@ARM.com ppCommitStall->notify(inst); 71810023Smatt.horsnell@ARM.com 7192292SN/A DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC " 7207720Sgblack@eecs.umich.edu "%s is head of ROB and not ready\n", 7217720Sgblack@eecs.umich.edu tid, inst->seqNum, inst->pcState()); 7222292SN/A } 7232292SN/A 7242292SN/A DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n", 7252292SN/A tid, rob->countInsts(tid), rob->numFreeEntries(tid)); 7262292SN/A } 7272292SN/A 7282292SN/A 7292292SN/A if (wroteToTimeBuffer) { 7302316SN/A DPRINTF(Activity, "Activity This Cycle.\n"); 7312292SN/A cpu->activityThisCycle(); 7322292SN/A } 7332292SN/A 7342292SN/A updateStatus(); 7352292SN/A} 7362292SN/A 7372292SN/Atemplate <class Impl> 7382292SN/Avoid 7394035Sktlim@umich.eduDefaultCommit<Impl>::handleInterrupt() 7402292SN/A{ 7417847Sminkyu.jeong@arm.com // Verify that we still have an interrupt to handle 7427847Sminkyu.jeong@arm.com if (!cpu->checkInterrupts(cpu->tcBase(0))) { 7437847Sminkyu.jeong@arm.com DPRINTF(Commit, "Pending interrupt is cleared by master before " 7447847Sminkyu.jeong@arm.com "it got handled. Restart fetching from the orig path.\n"); 7457847Sminkyu.jeong@arm.com toIEW->commitInfo[0].clearInterrupt = true; 7467847Sminkyu.jeong@arm.com interrupt = NoFault; 7479513SAli.Saidi@ARM.com avoidQuiesceLiveLock = true; 7487847Sminkyu.jeong@arm.com return; 7497847Sminkyu.jeong@arm.com } 7503633Sktlim@umich.edu 7518493Sgblack@eecs.umich.edu // Wait until all in flight instructions are finished before enterring 7528493Sgblack@eecs.umich.edu // the interrupt. 7538823Snilay@cs.wisc.edu if (canHandleInterrupts && cpu->instList.empty()) { 7547847Sminkyu.jeong@arm.com // Squash or record that I need to squash this cycle if 7557847Sminkyu.jeong@arm.com // an interrupt needed to be handled. 7567847Sminkyu.jeong@arm.com DPRINTF(Commit, "Interrupt detected.\n"); 7574035Sktlim@umich.edu 7587847Sminkyu.jeong@arm.com // Clear the interrupt now that it's going to be handled 7597847Sminkyu.jeong@arm.com toIEW->commitInfo[0].clearInterrupt = true; 7602292SN/A 7619382SAli.Saidi@ARM.com assert(!thread[0]->noSquashFromTC); 7629382SAli.Saidi@ARM.com thread[0]->noSquashFromTC = true; 7632292SN/A 7648733Sgeoffrey.blake@arm.com if (cpu->checker) { 7658733Sgeoffrey.blake@arm.com cpu->checker->handlePendingInt(); 7668733Sgeoffrey.blake@arm.com } 7678733Sgeoffrey.blake@arm.com 7689624Snilay@cs.wisc.edu // CPU will handle interrupt. Note that we ignore the local copy of 7699624Snilay@cs.wisc.edu // interrupt. This is because the local copy may no longer be the 7709624Snilay@cs.wisc.edu // interrupt that the interrupt controller thinks is being handled. 7719624Snilay@cs.wisc.edu cpu->processInterrupts(cpu->getInterrupts()); 7723633Sktlim@umich.edu 7739382SAli.Saidi@ARM.com thread[0]->noSquashFromTC = false; 7742292SN/A 7757847Sminkyu.jeong@arm.com commitStatus[0] = TrapPending; 7762292SN/A 7777847Sminkyu.jeong@arm.com // Generate trap squash event. 7787847Sminkyu.jeong@arm.com generateTrapEvent(0); 7793640Sktlim@umich.edu 7807847Sminkyu.jeong@arm.com interrupt = NoFault; 7819513SAli.Saidi@ARM.com avoidQuiesceLiveLock = false; 7827847Sminkyu.jeong@arm.com } else { 7838823Snilay@cs.wisc.edu DPRINTF(Commit, "Interrupt pending: instruction is %sin " 7848823Snilay@cs.wisc.edu "flight, ROB is %sempty\n", 7858823Snilay@cs.wisc.edu canHandleInterrupts ? "not " : "", 7868823Snilay@cs.wisc.edu cpu->instList.empty() ? "" : "not " ); 7871060SN/A } 7884035Sktlim@umich.edu} 7897847Sminkyu.jeong@arm.com 7907847Sminkyu.jeong@arm.comtemplate <class Impl> 7917847Sminkyu.jeong@arm.comvoid 7927847Sminkyu.jeong@arm.comDefaultCommit<Impl>::propagateInterrupt() 7937847Sminkyu.jeong@arm.com{ 79410340Smitch.hayenga@arm.com // Don't propagate intterupts if we are currently handling a trap or 79510340Smitch.hayenga@arm.com // in draining and the last observable instruction has been committed. 7967847Sminkyu.jeong@arm.com if (commitStatus[0] == TrapPending || interrupt || trapSquash[0] || 79710340Smitch.hayenga@arm.com tcSquash[0] || drainImminent) 7987847Sminkyu.jeong@arm.com return; 7997847Sminkyu.jeong@arm.com 8007847Sminkyu.jeong@arm.com // Process interrupts if interrupts are enabled, not in PAL 8017847Sminkyu.jeong@arm.com // mode, and no other traps or external squashes are currently 8027847Sminkyu.jeong@arm.com // pending. 8037847Sminkyu.jeong@arm.com // @todo: Allow other threads to handle interrupts. 8047847Sminkyu.jeong@arm.com 8057847Sminkyu.jeong@arm.com // Get any interrupt that happened 8067847Sminkyu.jeong@arm.com interrupt = cpu->getInterrupts(); 8077847Sminkyu.jeong@arm.com 8087847Sminkyu.jeong@arm.com // Tell fetch that there is an interrupt pending. This 8097847Sminkyu.jeong@arm.com // will make fetch wait until it sees a non PAL-mode PC, 8107847Sminkyu.jeong@arm.com // at which point it stops fetching instructions. 8117847Sminkyu.jeong@arm.com if (interrupt != NoFault) 8127847Sminkyu.jeong@arm.com toIEW->commitInfo[0].interruptPending = true; 8137847Sminkyu.jeong@arm.com} 8147847Sminkyu.jeong@arm.com 8154035Sktlim@umich.edutemplate <class Impl> 8164035Sktlim@umich.eduvoid 8174035Sktlim@umich.eduDefaultCommit<Impl>::commit() 8184035Sktlim@umich.edu{ 8198793Sgblack@eecs.umich.edu if (FullSystem) { 8208793Sgblack@eecs.umich.edu // Check if we have a interrupt and get read to handle it 8218793Sgblack@eecs.umich.edu if (cpu->checkInterrupts(cpu->tcBase(0))) 8228793Sgblack@eecs.umich.edu propagateInterrupt(); 8238793Sgblack@eecs.umich.edu } 8241060SN/A 8251060SN/A //////////////////////////////////// 8262316SN/A // Check for any possible squashes, handle them first 8271060SN/A //////////////////////////////////// 8286221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 8296221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 8301060SN/A 83110729Snilay@cs.wisc.edu int num_squashing_threads = 0; 83210729Snilay@cs.wisc.edu 8333867Sbinkertn@umich.edu while (threads != end) { 8346221Snate@binkert.org ThreadID tid = *threads++; 8351060SN/A 8362292SN/A // Not sure which one takes priority. I think if we have 8372292SN/A // both, that's a bad sign. 83810231Ssteve.reinhardt@amd.com if (trapSquash[tid]) { 8392680Sktlim@umich.edu assert(!tcSquash[tid]); 8402292SN/A squashFromTrap(tid); 84110231Ssteve.reinhardt@amd.com } else if (tcSquash[tid]) { 8424035Sktlim@umich.edu assert(commitStatus[tid] != TrapPending); 8432680Sktlim@umich.edu squashFromTC(tid); 8449437SAndreas.Sandberg@ARM.com } else if (commitStatus[tid] == SquashAfterPending) { 8459437SAndreas.Sandberg@ARM.com // A squash from the previous cycle of the commit stage (i.e., 8469437SAndreas.Sandberg@ARM.com // commitInsts() called squashAfter) is pending. Squash the 8479437SAndreas.Sandberg@ARM.com // thread now. 8489437SAndreas.Sandberg@ARM.com squashFromSquashAfter(tid); 8492292SN/A } 8501061SN/A 8512292SN/A // Squashed sequence number must be older than youngest valid 8522292SN/A // instruction in the ROB. This prevents squashes from younger 8532292SN/A // instructions overriding squashes from older instructions. 8542292SN/A if (fromIEW->squash[tid] && 8552292SN/A commitStatus[tid] != TrapPending && 8562292SN/A fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) { 8571061SN/A 8588137SAli.Saidi@ARM.com if (fromIEW->mispredictInst[tid]) { 8598137SAli.Saidi@ARM.com DPRINTF(Commit, 8608137SAli.Saidi@ARM.com "[tid:%i]: Squashing due to branch mispred PC:%#x [sn:%i]\n", 8612292SN/A tid, 8628137SAli.Saidi@ARM.com fromIEW->mispredictInst[tid]->instAddr(), 8632292SN/A fromIEW->squashedSeqNum[tid]); 8648137SAli.Saidi@ARM.com } else { 8658137SAli.Saidi@ARM.com DPRINTF(Commit, 8668137SAli.Saidi@ARM.com "[tid:%i]: Squashing due to order violation [sn:%i]\n", 8678137SAli.Saidi@ARM.com tid, fromIEW->squashedSeqNum[tid]); 8688137SAli.Saidi@ARM.com } 8691061SN/A 8702292SN/A DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n", 8712292SN/A tid, 8727720Sgblack@eecs.umich.edu fromIEW->pc[tid].nextInstAddr()); 8731061SN/A 8742292SN/A commitStatus[tid] = ROBSquashing; 8751061SN/A 8762292SN/A // If we want to include the squashing instruction in the squash, 8772292SN/A // then use one older sequence number. 8782292SN/A InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid]; 8791062SN/A 88010231Ssteve.reinhardt@amd.com if (fromIEW->includeSquashInst[tid]) { 8812292SN/A squashed_inst--; 8822935Sksewell@umich.edu } 8834035Sktlim@umich.edu 8842292SN/A // All younger instructions will be squashed. Set the sequence 8852292SN/A // number as the youngest instruction in the ROB. 8862292SN/A youngestSeqNum[tid] = squashed_inst; 8872292SN/A 8883093Sksewell@umich.edu rob->squash(squashed_inst, tid); 8892292SN/A changedROBNumEntries[tid] = true; 8902292SN/A 8912292SN/A toIEW->commitInfo[tid].doneSeqNum = squashed_inst; 8922292SN/A 8932292SN/A toIEW->commitInfo[tid].squash = true; 8942292SN/A 8952292SN/A // Send back the rob squashing signal so other stages know that 8962292SN/A // the ROB is in the process of squashing. 8972292SN/A toIEW->commitInfo[tid].robSquashing = true; 8982292SN/A 8997851SMatt.Horsnell@arm.com toIEW->commitInfo[tid].mispredictInst = 9007851SMatt.Horsnell@arm.com fromIEW->mispredictInst[tid]; 9012292SN/A toIEW->commitInfo[tid].branchTaken = 9022292SN/A fromIEW->branchTaken[tid]; 9038822Snilay@cs.wisc.edu toIEW->commitInfo[tid].squashInst = 9048822Snilay@cs.wisc.edu rob->findInst(tid, squashed_inst); 9058842Smrinmoy.ghosh@arm.com if (toIEW->commitInfo[tid].mispredictInst) { 9068842Smrinmoy.ghosh@arm.com if (toIEW->commitInfo[tid].mispredictInst->isUncondCtrl()) { 9078842Smrinmoy.ghosh@arm.com toIEW->commitInfo[tid].branchTaken = true; 9088842Smrinmoy.ghosh@arm.com } 9098842Smrinmoy.ghosh@arm.com } 9102292SN/A 9117720Sgblack@eecs.umich.edu toIEW->commitInfo[tid].pc = fromIEW->pc[tid]; 9122292SN/A 9138137SAli.Saidi@ARM.com if (toIEW->commitInfo[tid].mispredictInst) { 9142292SN/A ++branchMispredicts; 9152292SN/A } 9161062SN/A } 9172292SN/A 91810729Snilay@cs.wisc.edu if (commitStatus[tid] == ROBSquashing) { 91910729Snilay@cs.wisc.edu num_squashing_threads++; 92010729Snilay@cs.wisc.edu } 9211060SN/A } 9221060SN/A 92310729Snilay@cs.wisc.edu // If commit is currently squashing, then it will have activity for the 92410729Snilay@cs.wisc.edu // next cycle. Set its next status as active. 92510729Snilay@cs.wisc.edu if (num_squashing_threads) { 92610729Snilay@cs.wisc.edu _nextStatus = Active; 92710729Snilay@cs.wisc.edu } 9282292SN/A 92910729Snilay@cs.wisc.edu if (num_squashing_threads != numThreads) { 9301061SN/A // If we're not currently squashing, then get instructions. 9311060SN/A getInsts(); 9321060SN/A 9331061SN/A // Try to commit any instructions. 9341060SN/A commitInsts(); 9351060SN/A } 9361060SN/A 9372292SN/A //Check for any activity 9383867Sbinkertn@umich.edu threads = activeThreads->begin(); 9392292SN/A 9403867Sbinkertn@umich.edu while (threads != end) { 9416221Snate@binkert.org ThreadID tid = *threads++; 9422292SN/A 9432292SN/A if (changedROBNumEntries[tid]) { 9442292SN/A toIEW->commitInfo[tid].usedROB = true; 9452292SN/A toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 9462292SN/A 9472292SN/A wroteToTimeBuffer = true; 9482292SN/A changedROBNumEntries[tid] = false; 9494035Sktlim@umich.edu if (rob->isEmpty(tid)) 9504035Sktlim@umich.edu checkEmptyROB[tid] = true; 9512292SN/A } 9524035Sktlim@umich.edu 9534035Sktlim@umich.edu // ROB is only considered "empty" for previous stages if: a) 9544035Sktlim@umich.edu // ROB is empty, b) there are no outstanding stores, c) IEW 9554035Sktlim@umich.edu // stage has received any information regarding stores that 9564035Sktlim@umich.edu // committed. 9574035Sktlim@umich.edu // c) is checked by making sure to not consider the ROB empty 9584035Sktlim@umich.edu // on the same cycle as when stores have been committed. 9594035Sktlim@umich.edu // @todo: Make this handle multi-cycle communication between 9604035Sktlim@umich.edu // commit and IEW. 9614035Sktlim@umich.edu if (checkEmptyROB[tid] && rob->isEmpty(tid) && 9625557Sktlim@umich.edu !iewStage->hasStoresToWB(tid) && !committedStores[tid]) { 9634035Sktlim@umich.edu checkEmptyROB[tid] = false; 9644035Sktlim@umich.edu toIEW->commitInfo[tid].usedROB = true; 9654035Sktlim@umich.edu toIEW->commitInfo[tid].emptyROB = true; 9664035Sktlim@umich.edu toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid); 9674035Sktlim@umich.edu wroteToTimeBuffer = true; 9684035Sktlim@umich.edu } 9694035Sktlim@umich.edu 9701060SN/A } 9711060SN/A} 9721060SN/A 9731061SN/Atemplate <class Impl> 9741060SN/Avoid 9752292SN/ADefaultCommit<Impl>::commitInsts() 9761060SN/A{ 9771060SN/A //////////////////////////////////// 9781060SN/A // Handle commit 9792316SN/A // Note that commit will be handled prior to putting new 9802316SN/A // instructions in the ROB so that the ROB only tries to commit 9812316SN/A // instructions it has in this current cycle, and not instructions 9822316SN/A // it is writing in during this cycle. Can't commit and squash 9832316SN/A // things at the same time... 9841060SN/A //////////////////////////////////// 9851060SN/A 9862292SN/A DPRINTF(Commit, "Trying to commit instructions in the ROB.\n"); 9871060SN/A 9881060SN/A unsigned num_committed = 0; 9891060SN/A 9902292SN/A DynInstPtr head_inst; 9912316SN/A 9921060SN/A // Commit as many instructions as possible until the commit bandwidth 9931060SN/A // limit is reached, or it becomes impossible to commit any more. 9942292SN/A while (num_committed < commitWidth) { 9958823Snilay@cs.wisc.edu // Check for any interrupt that we've already squashed for 9968823Snilay@cs.wisc.edu // and start processing it. 9978823Snilay@cs.wisc.edu if (interrupt != NoFault) 9988823Snilay@cs.wisc.edu handleInterrupt(); 9998823Snilay@cs.wisc.edu 10002292SN/A int commit_thread = getCommittingThread(); 10011060SN/A 10022292SN/A if (commit_thread == -1 || !rob->isHeadReady(commit_thread)) 10032292SN/A break; 10042292SN/A 10052292SN/A head_inst = rob->readHeadInst(commit_thread); 10062292SN/A 10076221Snate@binkert.org ThreadID tid = head_inst->threadNumber; 10082292SN/A 10092292SN/A assert(tid == commit_thread); 10102292SN/A 10112292SN/A DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n", 10122292SN/A head_inst->seqNum, tid); 10132132SN/A 10142316SN/A // If the head instruction is squashed, it is ready to retire 10152316SN/A // (be removed from the ROB) at any time. 10161060SN/A if (head_inst->isSquashed()) { 10171060SN/A 10182292SN/A DPRINTF(Commit, "Retiring squashed instruction from " 10191060SN/A "ROB.\n"); 10201060SN/A 10212292SN/A rob->retireHead(commit_thread); 10221060SN/A 10231062SN/A ++commitSquashedInsts; 10241062SN/A 10252292SN/A // Record that the number of ROB entries has changed. 10262292SN/A changedROBNumEntries[tid] = true; 10271060SN/A } else { 10287720Sgblack@eecs.umich.edu pc[tid] = head_inst->pcState(); 10292292SN/A 10301060SN/A // Increment the total number of non-speculative instructions 10311060SN/A // executed. 10321060SN/A // Hack for now: it really shouldn't happen until after the 10331061SN/A // commit is deemed to be successful, but this count is needed 10341061SN/A // for syscalls. 10352292SN/A thread[tid]->funcExeInst++; 10361060SN/A 10371060SN/A // Try to commit the head instruction. 10381060SN/A bool commit_success = commitHead(head_inst, num_committed); 10391060SN/A 10401062SN/A if (commit_success) { 10411060SN/A ++num_committed; 104210193SCurtis.Dunham@arm.com statCommittedInstType[tid][head_inst->opClass()]++; 104310023Smatt.horsnell@ARM.com ppCommit->notify(head_inst); 10441060SN/A 10452292SN/A changedROBNumEntries[tid] = true; 10462292SN/A 10472292SN/A // Set the doneSeqNum to the youngest committed instruction. 10482292SN/A toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum; 10491060SN/A 10508823Snilay@cs.wisc.edu if (tid == 0) { 10518823Snilay@cs.wisc.edu canHandleInterrupts = (!head_inst->isDelayedCommit()) && 10528823Snilay@cs.wisc.edu ((THE_ISA != ALPHA_ISA) || 10538823Snilay@cs.wisc.edu (!(pc[0].instAddr() & 0x3))); 10548823Snilay@cs.wisc.edu } 10558823Snilay@cs.wisc.edu 10567783SGiacomo.Gabrielli@arm.com // Updates misc. registers. 10577783SGiacomo.Gabrielli@arm.com head_inst->updateMiscRegs(); 10587783SGiacomo.Gabrielli@arm.com 105910034SGeoffrey.Blake@arm.com // Check instruction execution if it successfully commits and 106010034SGeoffrey.Blake@arm.com // is not carrying a fault. 106110034SGeoffrey.Blake@arm.com if (cpu->checker) { 106210034SGeoffrey.Blake@arm.com cpu->checker->verify(head_inst); 106310034SGeoffrey.Blake@arm.com } 106410034SGeoffrey.Blake@arm.com 10658662SAli.Saidi@ARM.com cpu->traceFunctions(pc[tid].instAddr()); 10668662SAli.Saidi@ARM.com 10677720Sgblack@eecs.umich.edu TheISA::advancePC(pc[tid], head_inst->staticInst); 10682935Sksewell@umich.edu 10697855SAli.Saidi@ARM.com // Keep track of the last sequence number commited 10707855SAli.Saidi@ARM.com lastCommitedSeqNum[tid] = head_inst->seqNum; 10717855SAli.Saidi@ARM.com 10727784SAli.Saidi@ARM.com // If this is an instruction that doesn't play nicely with 10737784SAli.Saidi@ARM.com // others squash everything and restart fetch 10747784SAli.Saidi@ARM.com if (head_inst->isSquashAfter()) 10759437SAndreas.Sandberg@ARM.com squashAfter(tid, head_inst); 10767784SAli.Saidi@ARM.com 10779444SAndreas.Sandberg@ARM.com if (drainPending) { 107810340Smitch.hayenga@arm.com if (pc[tid].microPC() == 0 && interrupt == NoFault && 107910340Smitch.hayenga@arm.com !thread[tid]->trapPending) { 108010340Smitch.hayenga@arm.com // Last architectually committed instruction. 108110340Smitch.hayenga@arm.com // Squash the pipeline, stall fetch, and use 108210340Smitch.hayenga@arm.com // drainImminent to disable interrupts 108310340Smitch.hayenga@arm.com DPRINTF(Drain, "Draining: %i:%s\n", tid, pc[tid]); 10849444SAndreas.Sandberg@ARM.com squashAfter(tid, head_inst); 10859444SAndreas.Sandberg@ARM.com cpu->commitDrained(tid); 108610340Smitch.hayenga@arm.com drainImminent = true; 10879444SAndreas.Sandberg@ARM.com } 10889444SAndreas.Sandberg@ARM.com } 10899444SAndreas.Sandberg@ARM.com 109010596Sgabeblack@google.com bool onInstBoundary = !head_inst->isMicroop() || 109110596Sgabeblack@google.com head_inst->isLastMicroop() || 109210596Sgabeblack@google.com !head_inst->isDelayedCommit(); 109310596Sgabeblack@google.com 109410596Sgabeblack@google.com if (onInstBoundary) { 109510596Sgabeblack@google.com int count = 0; 109610596Sgabeblack@google.com Addr oldpc; 109710596Sgabeblack@google.com // Make sure we're not currently updating state while 109810596Sgabeblack@google.com // handling PC events. 109910596Sgabeblack@google.com assert(!thread[tid]->noSquashFromTC && 110010596Sgabeblack@google.com !thread[tid]->trapPending); 110110596Sgabeblack@google.com do { 110210596Sgabeblack@google.com oldpc = pc[tid].instAddr(); 110310596Sgabeblack@google.com cpu->system->pcEventQueue.service(thread[tid]->getTC()); 110410596Sgabeblack@google.com count++; 110510596Sgabeblack@google.com } while (oldpc != pc[tid].instAddr()); 110610596Sgabeblack@google.com if (count > 1) { 110710596Sgabeblack@google.com DPRINTF(Commit, 110810596Sgabeblack@google.com "PC skip function event, stopping commit\n"); 110910596Sgabeblack@google.com break; 111010596Sgabeblack@google.com } 11112292SN/A } 11129513SAli.Saidi@ARM.com 11139513SAli.Saidi@ARM.com // Check if an instruction just enabled interrupts and we've 11149513SAli.Saidi@ARM.com // previously had an interrupt pending that was not handled 11159513SAli.Saidi@ARM.com // because interrupts were subsequently disabled before the 11169513SAli.Saidi@ARM.com // pipeline reached a place to handle the interrupt. In that 11179513SAli.Saidi@ARM.com // case squash now to make sure the interrupt is handled. 11189513SAli.Saidi@ARM.com // 11199513SAli.Saidi@ARM.com // If we don't do this, we might end up in a live lock situation 112010596Sgabeblack@google.com if (!interrupt && avoidQuiesceLiveLock && 112110596Sgabeblack@google.com onInstBoundary && cpu->checkInterrupts(cpu->tcBase(0))) 11229513SAli.Saidi@ARM.com squashAfter(tid, head_inst); 11231060SN/A } else { 11247720Sgblack@eecs.umich.edu DPRINTF(Commit, "Unable to commit head instruction PC:%s " 11252292SN/A "[tid:%i] [sn:%i].\n", 11267720Sgblack@eecs.umich.edu head_inst->pcState(), tid ,head_inst->seqNum); 11271060SN/A break; 11281060SN/A } 11291060SN/A } 11301060SN/A } 11311062SN/A 11321063SN/A DPRINTF(CommitRate, "%i\n", num_committed); 11332292SN/A numCommittedDist.sample(num_committed); 11342307SN/A 11352307SN/A if (num_committed == commitWidth) { 11362349SN/A commitEligibleSamples++; 11372307SN/A } 11381060SN/A} 11391060SN/A 11401061SN/Atemplate <class Impl> 11411060SN/Abool 11422292SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num) 11431060SN/A{ 11441060SN/A assert(head_inst); 11451060SN/A 11466221Snate@binkert.org ThreadID tid = head_inst->threadNumber; 11472292SN/A 11482316SN/A // If the instruction is not executed yet, then it will need extra 11492316SN/A // handling. Signal backwards that it should be executed. 11501061SN/A if (!head_inst->isExecuted()) { 11511061SN/A // Keep this number correct. We have not yet actually executed 11521061SN/A // and committed this instruction. 11532292SN/A thread[tid]->funcExeInst--; 11541062SN/A 11559948SAli.Saidi@ARM.com // Make sure we are only trying to commit un-executed instructions we 11569948SAli.Saidi@ARM.com // think are possible. 11579948SAli.Saidi@ARM.com assert(head_inst->isNonSpeculative() || head_inst->isStoreConditional() 11589948SAli.Saidi@ARM.com || head_inst->isMemBarrier() || head_inst->isWriteBarrier() || 11599948SAli.Saidi@ARM.com (head_inst->isLoad() && head_inst->uncacheable())); 11602316SN/A 11619948SAli.Saidi@ARM.com DPRINTF(Commit, "Encountered a barrier or non-speculative " 11629948SAli.Saidi@ARM.com "instruction [sn:%lli] at the head of the ROB, PC %s.\n", 11639948SAli.Saidi@ARM.com head_inst->seqNum, head_inst->pcState()); 11642316SN/A 11659948SAli.Saidi@ARM.com if (inst_num > 0 || iewStage->hasStoresToWB(tid)) { 11669948SAli.Saidi@ARM.com DPRINTF(Commit, "Waiting for all stores to writeback.\n"); 11679948SAli.Saidi@ARM.com return false; 11689948SAli.Saidi@ARM.com } 11692292SN/A 11709948SAli.Saidi@ARM.com toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum; 11711061SN/A 11729948SAli.Saidi@ARM.com // Change the instruction so it won't try to commit again until 11739948SAli.Saidi@ARM.com // it is executed. 11749948SAli.Saidi@ARM.com head_inst->clearCanCommit(); 11751061SN/A 11769948SAli.Saidi@ARM.com if (head_inst->isLoad() && head_inst->uncacheable()) { 11777720Sgblack@eecs.umich.edu DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %s.\n", 11787720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 11792292SN/A toIEW->commitInfo[tid].uncached = true; 11802292SN/A toIEW->commitInfo[tid].uncachedLoad = head_inst; 11819948SAli.Saidi@ARM.com } else { 11829948SAli.Saidi@ARM.com ++commitNonSpecStalls; 11839948SAli.Saidi@ARM.com } 11842292SN/A 11859948SAli.Saidi@ARM.com return false; 11861060SN/A } 11871060SN/A 11882316SN/A if (head_inst->isThreadSync()) { 11892292SN/A // Not handled for now. 11902316SN/A panic("Thread sync instructions are not handled yet.\n"); 11912132SN/A } 11922132SN/A 11934035Sktlim@umich.edu // Check if the instruction caused a fault. If so, trap. 11944035Sktlim@umich.edu Fault inst_fault = head_inst->getFault(); 11954035Sktlim@umich.edu 11962316SN/A // Stores mark themselves as completed. 11974035Sktlim@umich.edu if (!head_inst->isStore() && inst_fault == NoFault) { 11982310SN/A head_inst->setCompleted(); 11992310SN/A } 12002310SN/A 12012112SN/A if (inst_fault != NoFault) { 12027720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inst [sn:%lli] PC %s has a fault\n", 12037720Sgblack@eecs.umich.edu head_inst->seqNum, head_inst->pcState()); 12042292SN/A 12055557Sktlim@umich.edu if (iewStage->hasStoresToWB(tid) || inst_num > 0) { 12062316SN/A DPRINTF(Commit, "Stores outstanding, fault must wait.\n"); 12072316SN/A return false; 12082316SN/A } 12092310SN/A 12104035Sktlim@umich.edu head_inst->setCompleted(); 12114035Sktlim@umich.edu 121210034SGeoffrey.Blake@arm.com // If instruction has faulted, let the checker execute it and 121310034SGeoffrey.Blake@arm.com // check if it sees the same fault and control flow. 12148733Sgeoffrey.blake@arm.com if (cpu->checker) { 12158733Sgeoffrey.blake@arm.com // Need to check the instruction before its fault is processed 12162732Sktlim@umich.edu cpu->checker->verify(head_inst); 12172316SN/A } 12182292SN/A 12199382SAli.Saidi@ARM.com assert(!thread[tid]->noSquashFromTC); 12202292SN/A 12212316SN/A // Mark that we're in state update mode so that the trap's 12222316SN/A // execution doesn't generate extra squashes. 12239382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = true; 12242292SN/A 12252316SN/A // Execute the trap. Although it's slightly unrealistic in 12262316SN/A // terms of timing (as it doesn't wait for the full timing of 12272316SN/A // the trap event to complete before updating state), it's 12282316SN/A // needed to update the state as soon as possible. This 12292316SN/A // prevents external agents from changing any specific state 12302316SN/A // that the trap need. 12317684Sgblack@eecs.umich.edu cpu->trap(inst_fault, tid, head_inst->staticInst); 12322292SN/A 12332316SN/A // Exit state update mode to avoid accidental updating. 12349382SAli.Saidi@ARM.com thread[tid]->noSquashFromTC = false; 12352292SN/A 12362316SN/A commitStatus[tid] = TrapPending; 12372292SN/A 12388067SAli.Saidi@ARM.com DPRINTF(Commit, "Committing instruction with fault [sn:%lli]\n", 12398067SAli.Saidi@ARM.com head_inst->seqNum); 12404035Sktlim@umich.edu if (head_inst->traceData) { 12416667Ssteve.reinhardt@amd.com if (DTRACE(ExecFaulting)) { 12426667Ssteve.reinhardt@amd.com head_inst->traceData->setFetchSeq(head_inst->seqNum); 12438834Satgutier@umich.edu head_inst->traceData->setCPSeq(thread[tid]->numOp); 12446667Ssteve.reinhardt@amd.com head_inst->traceData->dump(); 12456667Ssteve.reinhardt@amd.com } 12464288Sktlim@umich.edu delete head_inst->traceData; 12474035Sktlim@umich.edu head_inst->traceData = NULL; 12484035Sktlim@umich.edu } 12494035Sktlim@umich.edu 12502316SN/A // Generate trap squash event. 12512316SN/A generateTrapEvent(tid); 12522316SN/A return false; 12531060SN/A } 12541060SN/A 12552301SN/A updateComInstStats(head_inst); 12562132SN/A 12578793Sgblack@eecs.umich.edu if (FullSystem) { 12588793Sgblack@eecs.umich.edu if (thread[tid]->profile) { 12598793Sgblack@eecs.umich.edu thread[tid]->profilePC = head_inst->instAddr(); 12608793Sgblack@eecs.umich.edu ProfileNode *node = thread[tid]->profile->consume( 12618793Sgblack@eecs.umich.edu thread[tid]->getTC(), head_inst->staticInst); 12622362SN/A 12638793Sgblack@eecs.umich.edu if (node) 12648793Sgblack@eecs.umich.edu thread[tid]->profileNode = node; 12658793Sgblack@eecs.umich.edu } 12668793Sgblack@eecs.umich.edu if (CPA::available()) { 12678793Sgblack@eecs.umich.edu if (head_inst->isControl()) { 12688793Sgblack@eecs.umich.edu ThreadContext *tc = thread[tid]->getTC(); 12698793Sgblack@eecs.umich.edu CPA::cpa()->swAutoBegin(tc, head_inst->nextInstAddr()); 12708793Sgblack@eecs.umich.edu } 12715953Ssaidi@eecs.umich.edu } 12725953Ssaidi@eecs.umich.edu } 12738516SMrinmoy.Ghosh@arm.com DPRINTF(Commit, "Committing instruction with [sn:%lli] PC %s\n", 12748516SMrinmoy.Ghosh@arm.com head_inst->seqNum, head_inst->pcState()); 12752132SN/A if (head_inst->traceData) { 12762292SN/A head_inst->traceData->setFetchSeq(head_inst->seqNum); 12778834Satgutier@umich.edu head_inst->traceData->setCPSeq(thread[tid]->numOp); 12784046Sbinkertn@umich.edu head_inst->traceData->dump(); 12794046Sbinkertn@umich.edu delete head_inst->traceData; 12802292SN/A head_inst->traceData = NULL; 12811060SN/A } 12828843Smrinmoy.ghosh@arm.com if (head_inst->isReturn()) { 12838843Smrinmoy.ghosh@arm.com DPRINTF(Commit,"Return Instruction Committed [sn:%lli] PC %s \n", 12848843Smrinmoy.ghosh@arm.com head_inst->seqNum, head_inst->pcState()); 12858843Smrinmoy.ghosh@arm.com } 12861060SN/A 12872292SN/A // Update the commit rename map 12882292SN/A for (int i = 0; i < head_inst->numDestRegs(); i++) { 12893771Sgblack@eecs.umich.edu renameMap[tid]->setEntry(head_inst->flattenedDestRegIdx(i), 12902292SN/A head_inst->renamedDestRegIdx(i)); 12911060SN/A } 12921062SN/A 12932292SN/A // Finally clear the head ROB entry. 12942292SN/A rob->retireHead(tid); 12951060SN/A 12968471SGiacomo.Gabrielli@arm.com#if TRACING_ON 12979527SMatt.Horsnell@arm.com if (DTRACE(O3PipeView)) { 12989527SMatt.Horsnell@arm.com head_inst->commitTick = curTick() - head_inst->fetchTick; 12999527SMatt.Horsnell@arm.com } 13008471SGiacomo.Gabrielli@arm.com#endif 13018471SGiacomo.Gabrielli@arm.com 13024035Sktlim@umich.edu // If this was a store, record it for this cycle. 13034035Sktlim@umich.edu if (head_inst->isStore()) 13044035Sktlim@umich.edu committedStores[tid] = true; 13054035Sktlim@umich.edu 13061060SN/A // Return true to indicate that we have committed an instruction. 13071060SN/A return true; 13081060SN/A} 13091060SN/A 13101061SN/Atemplate <class Impl> 13111060SN/Avoid 13122292SN/ADefaultCommit<Impl>::getInsts() 13131060SN/A{ 13142935Sksewell@umich.edu DPRINTF(Commit, "Getting instructions from Rename stage.\n"); 13152935Sksewell@umich.edu 13163093Sksewell@umich.edu // Read any renamed instructions and place them into the ROB. 13173093Sksewell@umich.edu int insts_to_process = std::min((int)renameWidth, fromRename->size); 13182965Sksewell@umich.edu 13192965Sksewell@umich.edu for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) { 13202965Sksewell@umich.edu DynInstPtr inst; 13212965Sksewell@umich.edu 13223093Sksewell@umich.edu inst = fromRename->insts[inst_num]; 13236221Snate@binkert.org ThreadID tid = inst->threadNumber; 13242292SN/A 13252292SN/A if (!inst->isSquashed() && 13264035Sktlim@umich.edu commitStatus[tid] != ROBSquashing && 13274035Sktlim@umich.edu commitStatus[tid] != TrapPending) { 13282292SN/A changedROBNumEntries[tid] = true; 13292292SN/A 13307720Sgblack@eecs.umich.edu DPRINTF(Commit, "Inserting PC %s [sn:%i] [tid:%i] into ROB.\n", 13317720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, tid); 13322292SN/A 13332292SN/A rob->insertInst(inst); 13342292SN/A 13352292SN/A assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid)); 13362292SN/A 13372292SN/A youngestSeqNum[tid] = inst->seqNum; 13381061SN/A } else { 13397720Sgblack@eecs.umich.edu DPRINTF(Commit, "Instruction PC %s [sn:%i] [tid:%i] was " 13401061SN/A "squashed, skipping.\n", 13417720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, tid); 13421061SN/A } 13431060SN/A } 13442965Sksewell@umich.edu} 13452965Sksewell@umich.edu 13462965Sksewell@umich.edutemplate <class Impl> 13472965Sksewell@umich.eduvoid 13482292SN/ADefaultCommit<Impl>::markCompletedInsts() 13491060SN/A{ 13501060SN/A // Grab completed insts out of the IEW instruction queue, and mark 13511060SN/A // instructions completed within the ROB. 13521060SN/A for (int inst_num = 0; 13531681SN/A inst_num < fromIEW->size && fromIEW->insts[inst_num]; 13541060SN/A ++inst_num) 13551060SN/A { 13562292SN/A if (!fromIEW->insts[inst_num]->isSquashed()) { 13577720Sgblack@eecs.umich.edu DPRINTF(Commit, "[tid:%i]: Marking PC %s, [sn:%lli] ready " 13582316SN/A "within ROB.\n", 13592292SN/A fromIEW->insts[inst_num]->threadNumber, 13607720Sgblack@eecs.umich.edu fromIEW->insts[inst_num]->pcState(), 13612292SN/A fromIEW->insts[inst_num]->seqNum); 13621060SN/A 13632292SN/A // Mark the instruction as ready to commit. 13642292SN/A fromIEW->insts[inst_num]->setCanCommit(); 13652292SN/A } 13661060SN/A } 13671060SN/A} 13681060SN/A 13691061SN/Atemplate <class Impl> 13702301SN/Avoid 13712301SN/ADefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst) 13722301SN/A{ 13736221Snate@binkert.org ThreadID tid = inst->threadNumber; 13742301SN/A 13758834Satgutier@umich.edu if (!inst->isMicroop() || inst->isLastMicroop()) 13768834Satgutier@umich.edu instsCommitted[tid]++; 13778834Satgutier@umich.edu opsCommitted[tid]++; 13782301SN/A 13799218Satgutier@umich.edu // To match the old model, don't count nops and instruction 13809218Satgutier@umich.edu // prefetches towards the total commit count. 13819218Satgutier@umich.edu if (!inst->isNop() && !inst->isInstPrefetch()) { 13829218Satgutier@umich.edu cpu->instDone(tid, inst); 13839218Satgutier@umich.edu } 13849218Satgutier@umich.edu 13852301SN/A // 13862301SN/A // Control Instructions 13872301SN/A // 13882301SN/A if (inst->isControl()) 13896221Snate@binkert.org statComBranches[tid]++; 13902301SN/A 13912301SN/A // 13922301SN/A // Memory references 13932301SN/A // 13942301SN/A if (inst->isMemRef()) { 13956221Snate@binkert.org statComRefs[tid]++; 13962301SN/A 13972301SN/A if (inst->isLoad()) { 13986221Snate@binkert.org statComLoads[tid]++; 13992301SN/A } 14002301SN/A } 14012301SN/A 14022301SN/A if (inst->isMemBarrier()) { 14036221Snate@binkert.org statComMembars[tid]++; 14042301SN/A } 14057897Shestness@cs.utexas.edu 14067897Shestness@cs.utexas.edu // Integer Instruction 14077897Shestness@cs.utexas.edu if (inst->isInteger()) 14087897Shestness@cs.utexas.edu statComInteger[tid]++; 14097897Shestness@cs.utexas.edu 14107897Shestness@cs.utexas.edu // Floating Point Instruction 14117897Shestness@cs.utexas.edu if (inst->isFloating()) 14127897Shestness@cs.utexas.edu statComFloating[tid]++; 14137897Shestness@cs.utexas.edu 14147897Shestness@cs.utexas.edu // Function Calls 14157897Shestness@cs.utexas.edu if (inst->isCall()) 14167897Shestness@cs.utexas.edu statComFunctionCalls[tid]++; 14177897Shestness@cs.utexas.edu 14182301SN/A} 14192301SN/A 14202292SN/A//////////////////////////////////////// 14212292SN/A// // 14222316SN/A// SMT COMMIT POLICY MAINTAINED HERE // 14232292SN/A// // 14242292SN/A//////////////////////////////////////// 14252292SN/Atemplate <class Impl> 14266221Snate@binkert.orgThreadID 14272292SN/ADefaultCommit<Impl>::getCommittingThread() 14282292SN/A{ 14292292SN/A if (numThreads > 1) { 14302292SN/A switch (commitPolicy) { 14312292SN/A 14322292SN/A case Aggressive: 14332292SN/A //If Policy is Aggressive, commit will call 14342292SN/A //this function multiple times per 14352292SN/A //cycle 14362292SN/A return oldestReady(); 14372292SN/A 14382292SN/A case RoundRobin: 14392292SN/A return roundRobin(); 14402292SN/A 14412292SN/A case OldestReady: 14422292SN/A return oldestReady(); 14432292SN/A 14442292SN/A default: 14456221Snate@binkert.org return InvalidThreadID; 14462292SN/A } 14472292SN/A } else { 14483867Sbinkertn@umich.edu assert(!activeThreads->empty()); 14496221Snate@binkert.org ThreadID tid = activeThreads->front(); 14502292SN/A 14512292SN/A if (commitStatus[tid] == Running || 14522292SN/A commitStatus[tid] == Idle || 14532292SN/A commitStatus[tid] == FetchTrapPending) { 14542292SN/A return tid; 14552292SN/A } else { 14566221Snate@binkert.org return InvalidThreadID; 14572292SN/A } 14582292SN/A } 14592292SN/A} 14602292SN/A 14612292SN/Atemplate<class Impl> 14626221Snate@binkert.orgThreadID 14632292SN/ADefaultCommit<Impl>::roundRobin() 14642292SN/A{ 14656221Snate@binkert.org list<ThreadID>::iterator pri_iter = priority_list.begin(); 14666221Snate@binkert.org list<ThreadID>::iterator end = priority_list.end(); 14672292SN/A 14682292SN/A while (pri_iter != end) { 14696221Snate@binkert.org ThreadID tid = *pri_iter; 14702292SN/A 14712292SN/A if (commitStatus[tid] == Running || 14722831Sksewell@umich.edu commitStatus[tid] == Idle || 14732831Sksewell@umich.edu commitStatus[tid] == FetchTrapPending) { 14742292SN/A 14752292SN/A if (rob->isHeadReady(tid)) { 14762292SN/A priority_list.erase(pri_iter); 14772292SN/A priority_list.push_back(tid); 14782292SN/A 14792292SN/A return tid; 14802292SN/A } 14812292SN/A } 14822292SN/A 14832292SN/A pri_iter++; 14842292SN/A } 14852292SN/A 14866221Snate@binkert.org return InvalidThreadID; 14872292SN/A} 14882292SN/A 14892292SN/Atemplate<class Impl> 14906221Snate@binkert.orgThreadID 14912292SN/ADefaultCommit<Impl>::oldestReady() 14922292SN/A{ 14932292SN/A unsigned oldest = 0; 14942292SN/A bool first = true; 14952292SN/A 14966221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 14976221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 14982292SN/A 14993867Sbinkertn@umich.edu while (threads != end) { 15006221Snate@binkert.org ThreadID tid = *threads++; 15012292SN/A 15022292SN/A if (!rob->isEmpty(tid) && 15032292SN/A (commitStatus[tid] == Running || 15042292SN/A commitStatus[tid] == Idle || 15052292SN/A commitStatus[tid] == FetchTrapPending)) { 15062292SN/A 15072292SN/A if (rob->isHeadReady(tid)) { 15082292SN/A 15092292SN/A DynInstPtr head_inst = rob->readHeadInst(tid); 15102292SN/A 15112292SN/A if (first) { 15122292SN/A oldest = tid; 15132292SN/A first = false; 15142292SN/A } else if (head_inst->seqNum < oldest) { 15152292SN/A oldest = tid; 15162292SN/A } 15172292SN/A } 15182292SN/A } 15192292SN/A } 15202292SN/A 15212292SN/A if (!first) { 15222292SN/A return oldest; 15232292SN/A } else { 15246221Snate@binkert.org return InvalidThreadID; 15252292SN/A } 15262292SN/A} 15279944Smatt.horsnell@ARM.com 15289944Smatt.horsnell@ARM.com#endif//__CPU_O3_COMMIT_IMPL_HH__ 1529