iew_impl.hh revision 13453
11689SN/A/* 29783Sandreas.hansson@arm.com * Copyright (c) 2010-2013 ARM Limited 310239Sbinhpham@cs.rutgers.edu * Copyright (c) 2013 Advanced Micro Devices, Inc. 47598Sminkyu.jeong@arm.com * All rights reserved. 57598Sminkyu.jeong@arm.com * 67598Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall 77598Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual 87598Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating 97598Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software 107598Sminkyu.jeong@arm.com * licensed hereunder. You may use the software subject to the license 117598Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated 127598Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software, 137598Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form. 147598Sminkyu.jeong@arm.com * 152326SN/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 421689SN/A */ 431689SN/A 449944Smatt.horsnell@ARM.com#ifndef __CPU_O3_IEW_IMPL_IMPL_HH__ 459944Smatt.horsnell@ARM.com#define __CPU_O3_IEW_IMPL_IMPL_HH__ 469944Smatt.horsnell@ARM.com 471060SN/A// @todo: Fix the instantaneous communication among all the stages within 481060SN/A// iew. There's a clear delay between issue and execute, yet backwards 491689SN/A// communication happens simultaneously. 501060SN/A 511060SN/A#include <queue> 521060SN/A 538230Snate@binkert.org#include "arch/utility.hh" 546658Snate@binkert.org#include "config/the_isa.hh" 558887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 562292SN/A#include "cpu/o3/fu_pool.hh" 571717SN/A#include "cpu/o3/iew.hh" 588229Snate@binkert.org#include "cpu/timebuf.hh" 598232Snate@binkert.org#include "debug/Activity.hh" 609444SAndreas.Sandberg@ARM.com#include "debug/Drain.hh" 618232Snate@binkert.org#include "debug/IEW.hh" 629527SMatt.Horsnell@arm.com#include "debug/O3PipeView.hh" 635529Snate@binkert.org#include "params/DerivO3CPU.hh" 641060SN/A 656221Snate@binkert.orgusing namespace std; 666221Snate@binkert.org 671681SN/Atemplate<class Impl> 685529Snate@binkert.orgDefaultIEW<Impl>::DefaultIEW(O3CPU *_cpu, DerivO3CPUParams *params) 692873Sktlim@umich.edu : issueToExecQueue(params->backComSize, params->forwardComSize), 704329Sktlim@umich.edu cpu(_cpu), 714329Sktlim@umich.edu instQueue(_cpu, this, params), 724329Sktlim@umich.edu ldstQueue(_cpu, this, params), 732292SN/A fuPool(params->fuPool), 742292SN/A commitToIEWDelay(params->commitToIEWDelay), 752292SN/A renameToIEWDelay(params->renameToIEWDelay), 762292SN/A issueToExecuteDelay(params->issueToExecuteDelay), 772820Sktlim@umich.edu dispatchWidth(params->dispatchWidth), 782292SN/A issueWidth(params->issueWidth), 7913453Srekai.gonzalezalberquilla@arm.com wbNumInst(0), 8013453Srekai.gonzalezalberquilla@arm.com wbCycle(0), 812820Sktlim@umich.edu wbWidth(params->wbWidth), 829444SAndreas.Sandberg@ARM.com numThreads(params->numThreads) 831060SN/A{ 8410172Sdam.sunwoo@arm.com if (dispatchWidth > Impl::MaxWidth) 8510172Sdam.sunwoo@arm.com fatal("dispatchWidth (%d) is larger than compiled limit (%d),\n" 8610172Sdam.sunwoo@arm.com "\tincrease MaxWidth in src/cpu/o3/impl.hh\n", 8710172Sdam.sunwoo@arm.com dispatchWidth, static_cast<int>(Impl::MaxWidth)); 8810172Sdam.sunwoo@arm.com if (issueWidth > Impl::MaxWidth) 8910172Sdam.sunwoo@arm.com fatal("issueWidth (%d) is larger than compiled limit (%d),\n" 9010172Sdam.sunwoo@arm.com "\tincrease MaxWidth in src/cpu/o3/impl.hh\n", 9110172Sdam.sunwoo@arm.com issueWidth, static_cast<int>(Impl::MaxWidth)); 9210172Sdam.sunwoo@arm.com if (wbWidth > Impl::MaxWidth) 9310172Sdam.sunwoo@arm.com fatal("wbWidth (%d) is larger than compiled limit (%d),\n" 9410172Sdam.sunwoo@arm.com "\tincrease MaxWidth in src/cpu/o3/impl.hh\n", 9510172Sdam.sunwoo@arm.com wbWidth, static_cast<int>(Impl::MaxWidth)); 9610172Sdam.sunwoo@arm.com 972292SN/A _status = Active; 982292SN/A exeStatus = Running; 992292SN/A wbStatus = Idle; 1001060SN/A 1011060SN/A // Setup wire to read instructions coming from issue. 1021060SN/A fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay); 1031060SN/A 1041060SN/A // Instruction queue needs the queue between issue and execute. 1051060SN/A instQueue.setIssueToExecuteQueue(&issueToExecQueue); 1061681SN/A 10713453Srekai.gonzalezalberquilla@arm.com for (ThreadID tid = 0; tid < Impl::MaxThreads; tid++) { 1086221Snate@binkert.org dispatchStatus[tid] = Running; 1096221Snate@binkert.org fetchRedirect[tid] = false; 1102292SN/A } 1112292SN/A 1122292SN/A updateLSQNextCycle = false; 1132292SN/A 11410328Smitch.hayenga@arm.com skidBufferMax = (renameToIEWDelay + 1) * params->renameWidth; 1152292SN/A} 1162292SN/A 1172292SN/Atemplate <class Impl> 1182292SN/Astd::string 1192292SN/ADefaultIEW<Impl>::name() const 1202292SN/A{ 1212292SN/A return cpu->name() + ".iew"; 1221060SN/A} 1231060SN/A 1241681SN/Atemplate <class Impl> 1251062SN/Avoid 12610023Smatt.horsnell@ARM.comDefaultIEW<Impl>::regProbePoints() 12710023Smatt.horsnell@ARM.com{ 12810023Smatt.horsnell@ARM.com ppDispatch = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Dispatch"); 12910023Smatt.horsnell@ARM.com ppMispredict = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Mispredict"); 13011246Sradhika.jagtap@ARM.com /** 13111246Sradhika.jagtap@ARM.com * Probe point with dynamic instruction as the argument used to probe when 13211246Sradhika.jagtap@ARM.com * an instruction starts to execute. 13311246Sradhika.jagtap@ARM.com */ 13411246Sradhika.jagtap@ARM.com ppExecute = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), 13511246Sradhika.jagtap@ARM.com "Execute"); 13611246Sradhika.jagtap@ARM.com /** 13711246Sradhika.jagtap@ARM.com * Probe point with dynamic instruction as the argument used to probe when 13811246Sradhika.jagtap@ARM.com * an instruction execution completes and it is marked ready to commit. 13911246Sradhika.jagtap@ARM.com */ 14011246Sradhika.jagtap@ARM.com ppToCommit = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), 14111246Sradhika.jagtap@ARM.com "ToCommit"); 14210023Smatt.horsnell@ARM.com} 14310023Smatt.horsnell@ARM.com 14410023Smatt.horsnell@ARM.comtemplate <class Impl> 14510023Smatt.horsnell@ARM.comvoid 1462292SN/ADefaultIEW<Impl>::regStats() 1471062SN/A{ 1482301SN/A using namespace Stats; 1492301SN/A 1501062SN/A instQueue.regStats(); 1512727Sktlim@umich.edu ldstQueue.regStats(); 1521062SN/A 1531062SN/A iewIdleCycles 1541062SN/A .name(name() + ".iewIdleCycles") 1551062SN/A .desc("Number of cycles IEW is idle"); 1561062SN/A 1571062SN/A iewSquashCycles 1581062SN/A .name(name() + ".iewSquashCycles") 1591062SN/A .desc("Number of cycles IEW is squashing"); 1601062SN/A 1611062SN/A iewBlockCycles 1621062SN/A .name(name() + ".iewBlockCycles") 1631062SN/A .desc("Number of cycles IEW is blocking"); 1641062SN/A 1651062SN/A iewUnblockCycles 1661062SN/A .name(name() + ".iewUnblockCycles") 1671062SN/A .desc("Number of cycles IEW is unblocking"); 1681062SN/A 1691062SN/A iewDispatchedInsts 1701062SN/A .name(name() + ".iewDispatchedInsts") 1711062SN/A .desc("Number of instructions dispatched to IQ"); 1721062SN/A 1731062SN/A iewDispSquashedInsts 1741062SN/A .name(name() + ".iewDispSquashedInsts") 1751062SN/A .desc("Number of squashed instructions skipped by dispatch"); 1761062SN/A 1771062SN/A iewDispLoadInsts 1781062SN/A .name(name() + ".iewDispLoadInsts") 1791062SN/A .desc("Number of dispatched load instructions"); 1801062SN/A 1811062SN/A iewDispStoreInsts 1821062SN/A .name(name() + ".iewDispStoreInsts") 1831062SN/A .desc("Number of dispatched store instructions"); 1841062SN/A 1851062SN/A iewDispNonSpecInsts 1861062SN/A .name(name() + ".iewDispNonSpecInsts") 1871062SN/A .desc("Number of dispatched non-speculative instructions"); 1881062SN/A 1891062SN/A iewIQFullEvents 1901062SN/A .name(name() + ".iewIQFullEvents") 1911062SN/A .desc("Number of times the IQ has become full, causing a stall"); 1921062SN/A 1932292SN/A iewLSQFullEvents 1942292SN/A .name(name() + ".iewLSQFullEvents") 1952292SN/A .desc("Number of times the LSQ has become full, causing a stall"); 1962292SN/A 1971062SN/A memOrderViolationEvents 1981062SN/A .name(name() + ".memOrderViolationEvents") 1991062SN/A .desc("Number of memory order violations"); 2001062SN/A 2011062SN/A predictedTakenIncorrect 2021062SN/A .name(name() + ".predictedTakenIncorrect") 2031062SN/A .desc("Number of branches that were predicted taken incorrectly"); 2042292SN/A 2052292SN/A predictedNotTakenIncorrect 2062292SN/A .name(name() + ".predictedNotTakenIncorrect") 2072292SN/A .desc("Number of branches that were predicted not taken incorrectly"); 2082292SN/A 2092292SN/A branchMispredicts 2102292SN/A .name(name() + ".branchMispredicts") 2112292SN/A .desc("Number of branch mispredicts detected at execute"); 2122292SN/A 2132292SN/A branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect; 2142301SN/A 2152727Sktlim@umich.edu iewExecutedInsts 2162353SN/A .name(name() + ".iewExecutedInsts") 2172727Sktlim@umich.edu .desc("Number of executed instructions"); 2182727Sktlim@umich.edu 2192727Sktlim@umich.edu iewExecLoadInsts 2206221Snate@binkert.org .init(cpu->numThreads) 2212353SN/A .name(name() + ".iewExecLoadInsts") 2222727Sktlim@umich.edu .desc("Number of load instructions executed") 2232727Sktlim@umich.edu .flags(total); 2242727Sktlim@umich.edu 2252727Sktlim@umich.edu iewExecSquashedInsts 2262353SN/A .name(name() + ".iewExecSquashedInsts") 2272727Sktlim@umich.edu .desc("Number of squashed instructions skipped in execute"); 2282727Sktlim@umich.edu 2292727Sktlim@umich.edu iewExecutedSwp 2306221Snate@binkert.org .init(cpu->numThreads) 2318240Snate@binkert.org .name(name() + ".exec_swp") 2322301SN/A .desc("number of swp insts executed") 2332727Sktlim@umich.edu .flags(total); 2342301SN/A 2352727Sktlim@umich.edu iewExecutedNop 2366221Snate@binkert.org .init(cpu->numThreads) 2378240Snate@binkert.org .name(name() + ".exec_nop") 2382301SN/A .desc("number of nop insts executed") 2392727Sktlim@umich.edu .flags(total); 2402301SN/A 2412727Sktlim@umich.edu iewExecutedRefs 2426221Snate@binkert.org .init(cpu->numThreads) 2438240Snate@binkert.org .name(name() + ".exec_refs") 2442301SN/A .desc("number of memory reference insts executed") 2452727Sktlim@umich.edu .flags(total); 2462301SN/A 2472727Sktlim@umich.edu iewExecutedBranches 2486221Snate@binkert.org .init(cpu->numThreads) 2498240Snate@binkert.org .name(name() + ".exec_branches") 2502301SN/A .desc("Number of branches executed") 2512727Sktlim@umich.edu .flags(total); 2522301SN/A 2532301SN/A iewExecStoreInsts 2548240Snate@binkert.org .name(name() + ".exec_stores") 2552301SN/A .desc("Number of stores executed") 2562727Sktlim@umich.edu .flags(total); 2572727Sktlim@umich.edu iewExecStoreInsts = iewExecutedRefs - iewExecLoadInsts; 2582727Sktlim@umich.edu 2592727Sktlim@umich.edu iewExecRate 2608240Snate@binkert.org .name(name() + ".exec_rate") 2612727Sktlim@umich.edu .desc("Inst execution rate") 2622727Sktlim@umich.edu .flags(total); 2632727Sktlim@umich.edu 2642727Sktlim@umich.edu iewExecRate = iewExecutedInsts / cpu->numCycles; 2652301SN/A 2662301SN/A iewInstsToCommit 2676221Snate@binkert.org .init(cpu->numThreads) 2688240Snate@binkert.org .name(name() + ".wb_sent") 2692301SN/A .desc("cumulative count of insts sent to commit") 2702727Sktlim@umich.edu .flags(total); 2712301SN/A 2722326SN/A writebackCount 2736221Snate@binkert.org .init(cpu->numThreads) 2748240Snate@binkert.org .name(name() + ".wb_count") 2752301SN/A .desc("cumulative count of insts written-back") 2762727Sktlim@umich.edu .flags(total); 2772301SN/A 2782326SN/A producerInst 2796221Snate@binkert.org .init(cpu->numThreads) 2808240Snate@binkert.org .name(name() + ".wb_producers") 2812301SN/A .desc("num instructions producing a value") 2822727Sktlim@umich.edu .flags(total); 2832301SN/A 2842326SN/A consumerInst 2856221Snate@binkert.org .init(cpu->numThreads) 2868240Snate@binkert.org .name(name() + ".wb_consumers") 2872301SN/A .desc("num instructions consuming a value") 2882727Sktlim@umich.edu .flags(total); 2892301SN/A 2902326SN/A wbFanout 2918240Snate@binkert.org .name(name() + ".wb_fanout") 2922301SN/A .desc("average fanout of values written-back") 2932727Sktlim@umich.edu .flags(total); 2942301SN/A 2952326SN/A wbFanout = producerInst / consumerInst; 2962301SN/A 2972326SN/A wbRate 2988240Snate@binkert.org .name(name() + ".wb_rate") 2992301SN/A .desc("insts written-back per cycle") 3002727Sktlim@umich.edu .flags(total); 3012326SN/A wbRate = writebackCount / cpu->numCycles; 3021062SN/A} 3031062SN/A 3041681SN/Atemplate<class Impl> 3051060SN/Avoid 3069427SAndreas.Sandberg@ARM.comDefaultIEW<Impl>::startupStage() 3071060SN/A{ 3086221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 3092292SN/A toRename->iewInfo[tid].usedIQ = true; 3102292SN/A toRename->iewInfo[tid].freeIQEntries = 3112292SN/A instQueue.numFreeEntries(tid); 3122292SN/A 3132292SN/A toRename->iewInfo[tid].usedLSQ = true; 31410239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].freeLQEntries = ldstQueue.numFreeLoadEntries(tid); 31510239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].freeSQEntries = ldstQueue.numFreeStoreEntries(tid); 3162292SN/A } 3172292SN/A 3188887Sgeoffrey.blake@arm.com // Initialize the checker's dcache port here 3198733Sgeoffrey.blake@arm.com if (cpu->checker) { 3208850Sandreas.hansson@arm.com cpu->checker->setDcachePort(&cpu->getDataPort()); 3218887Sgeoffrey.blake@arm.com } 3228733Sgeoffrey.blake@arm.com 3232733Sktlim@umich.edu cpu->activateStage(O3CPU::IEWIdx); 3241060SN/A} 3251060SN/A 3261681SN/Atemplate<class Impl> 3271060SN/Avoid 3282292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 3291060SN/A{ 3301060SN/A timeBuffer = tb_ptr; 3311060SN/A 3321060SN/A // Setup wire to read information from time buffer, from commit. 3331060SN/A fromCommit = timeBuffer->getWire(-commitToIEWDelay); 3341060SN/A 3351060SN/A // Setup wire to write information back to previous stages. 3361060SN/A toRename = timeBuffer->getWire(0); 3371060SN/A 3382292SN/A toFetch = timeBuffer->getWire(0); 3392292SN/A 3401060SN/A // Instruction queue also needs main time buffer. 3411060SN/A instQueue.setTimeBuffer(tb_ptr); 3421060SN/A} 3431060SN/A 3441681SN/Atemplate<class Impl> 3451060SN/Avoid 3462292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3471060SN/A{ 3481060SN/A renameQueue = rq_ptr; 3491060SN/A 3501060SN/A // Setup wire to read information from rename queue. 3511060SN/A fromRename = renameQueue->getWire(-renameToIEWDelay); 3521060SN/A} 3531060SN/A 3541681SN/Atemplate<class Impl> 3551060SN/Avoid 3562292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3571060SN/A{ 3581060SN/A iewQueue = iq_ptr; 3591060SN/A 3601060SN/A // Setup wire to write instructions to commit. 3611060SN/A toCommit = iewQueue->getWire(0); 3621060SN/A} 3631060SN/A 3641681SN/Atemplate<class Impl> 3651060SN/Avoid 3666221Snate@binkert.orgDefaultIEW<Impl>::setActiveThreads(list<ThreadID> *at_ptr) 3671060SN/A{ 3682292SN/A activeThreads = at_ptr; 3692292SN/A 3702292SN/A ldstQueue.setActiveThreads(at_ptr); 3712292SN/A instQueue.setActiveThreads(at_ptr); 3721060SN/A} 3731060SN/A 3741681SN/Atemplate<class Impl> 3751060SN/Avoid 3762292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr) 3771060SN/A{ 3782292SN/A scoreboard = sb_ptr; 3791060SN/A} 3801060SN/A 3812307SN/Atemplate <class Impl> 3822863Sktlim@umich.edubool 3839444SAndreas.Sandberg@ARM.comDefaultIEW<Impl>::isDrained() const 3842307SN/A{ 38510510Smitch.hayenga@arm.com bool drained = ldstQueue.isDrained() && instQueue.isDrained(); 3869444SAndreas.Sandberg@ARM.com 3879444SAndreas.Sandberg@ARM.com for (ThreadID tid = 0; tid < numThreads; tid++) { 3889444SAndreas.Sandberg@ARM.com if (!insts[tid].empty()) { 3899444SAndreas.Sandberg@ARM.com DPRINTF(Drain, "%i: Insts not empty.\n", tid); 3909444SAndreas.Sandberg@ARM.com drained = false; 3919444SAndreas.Sandberg@ARM.com } 3929444SAndreas.Sandberg@ARM.com if (!skidBuffer[tid].empty()) { 3939444SAndreas.Sandberg@ARM.com DPRINTF(Drain, "%i: Skid buffer not empty.\n", tid); 3949444SAndreas.Sandberg@ARM.com drained = false; 3959444SAndreas.Sandberg@ARM.com } 39611650Srekai.gonzalezalberquilla@arm.com drained = drained && dispatchStatus[tid] == Running; 3979444SAndreas.Sandberg@ARM.com } 3989444SAndreas.Sandberg@ARM.com 3999783Sandreas.hansson@arm.com // Also check the FU pool as instructions are "stored" in FU 4009783Sandreas.hansson@arm.com // completion events until they are done and not accounted for 4019783Sandreas.hansson@arm.com // above 4029783Sandreas.hansson@arm.com if (drained && !fuPool->isDrained()) { 4039783Sandreas.hansson@arm.com DPRINTF(Drain, "FU pool still busy.\n"); 4049783Sandreas.hansson@arm.com drained = false; 4059783Sandreas.hansson@arm.com } 4069783Sandreas.hansson@arm.com 4079444SAndreas.Sandberg@ARM.com return drained; 4081681SN/A} 4091681SN/A 4102316SN/Atemplate <class Impl> 4111681SN/Avoid 4129444SAndreas.Sandberg@ARM.comDefaultIEW<Impl>::drainSanityCheck() const 4132843Sktlim@umich.edu{ 4149444SAndreas.Sandberg@ARM.com assert(isDrained()); 4152843Sktlim@umich.edu 4169444SAndreas.Sandberg@ARM.com instQueue.drainSanityCheck(); 4179444SAndreas.Sandberg@ARM.com ldstQueue.drainSanityCheck(); 4181681SN/A} 4191681SN/A 4202307SN/Atemplate <class Impl> 4211681SN/Avoid 4222307SN/ADefaultIEW<Impl>::takeOverFrom() 4231060SN/A{ 4242348SN/A // Reset all state. 4252307SN/A _status = Active; 4262307SN/A exeStatus = Running; 4272307SN/A wbStatus = Idle; 4281060SN/A 4292307SN/A instQueue.takeOverFrom(); 4302307SN/A ldstQueue.takeOverFrom(); 4319444SAndreas.Sandberg@ARM.com fuPool->takeOverFrom(); 4321060SN/A 4339427SAndreas.Sandberg@ARM.com startupStage(); 4342307SN/A cpu->activityThisCycle(); 4351060SN/A 4366221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 4376221Snate@binkert.org dispatchStatus[tid] = Running; 4386221Snate@binkert.org fetchRedirect[tid] = false; 4392307SN/A } 4401060SN/A 4412307SN/A updateLSQNextCycle = false; 4422307SN/A 4432873Sktlim@umich.edu for (int i = 0; i < issueToExecQueue.getSize(); ++i) { 4442307SN/A issueToExecQueue.advance(); 4451060SN/A } 4461060SN/A} 4471060SN/A 4481681SN/Atemplate<class Impl> 4491060SN/Avoid 4506221Snate@binkert.orgDefaultIEW<Impl>::squash(ThreadID tid) 4512107SN/A{ 4526221Snate@binkert.org DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", tid); 4532107SN/A 4542292SN/A // Tell the IQ to start squashing. 4552292SN/A instQueue.squash(tid); 4562107SN/A 4572292SN/A // Tell the LDSTQ to start squashing. 4582326SN/A ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid); 4592292SN/A updatedQueues = true; 4602107SN/A 4612292SN/A // Clear the skid buffer in case it has any data in it. 4622935Sksewell@umich.edu DPRINTF(IEW, "[tid:%i]: Removing skidbuffer instructions until [sn:%i].\n", 4634632Sgblack@eecs.umich.edu tid, fromCommit->commitInfo[tid].doneSeqNum); 4642935Sksewell@umich.edu 4652292SN/A while (!skidBuffer[tid].empty()) { 46610239Sbinhpham@cs.rutgers.edu if (skidBuffer[tid].front()->isLoad()) { 46710239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToLQ++; 46810239Sbinhpham@cs.rutgers.edu } 46910239Sbinhpham@cs.rutgers.edu if (skidBuffer[tid].front()->isStore()) { 47010239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToSQ++; 4712292SN/A } 4722107SN/A 4732292SN/A toRename->iewInfo[tid].dispatched++; 4742107SN/A 4752292SN/A skidBuffer[tid].pop(); 4762292SN/A } 4772107SN/A 4782702Sktlim@umich.edu emptyRenameInsts(tid); 4792107SN/A} 4802107SN/A 4812107SN/Atemplate<class Impl> 4822107SN/Avoid 48313429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::squashDueToBranch(const DynInstPtr& inst, ThreadID tid) 4842292SN/A{ 4857720Sgblack@eecs.umich.edu DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %s " 4867720Sgblack@eecs.umich.edu "[sn:%i].\n", tid, inst->pcState(), inst->seqNum); 4872292SN/A 48810231Ssteve.reinhardt@amd.com if (!toCommit->squash[tid] || 4897852SMatt.Horsnell@arm.com inst->seqNum < toCommit->squashedSeqNum[tid]) { 4907852SMatt.Horsnell@arm.com toCommit->squash[tid] = true; 4917852SMatt.Horsnell@arm.com toCommit->squashedSeqNum[tid] = inst->seqNum; 4927852SMatt.Horsnell@arm.com toCommit->branchTaken[tid] = inst->pcState().branching(); 4932935Sksewell@umich.edu 4947852SMatt.Horsnell@arm.com TheISA::PCState pc = inst->pcState(); 4957852SMatt.Horsnell@arm.com TheISA::advancePC(pc, inst->staticInst); 4962292SN/A 4977852SMatt.Horsnell@arm.com toCommit->pc[tid] = pc; 4987852SMatt.Horsnell@arm.com toCommit->mispredictInst[tid] = inst; 4997852SMatt.Horsnell@arm.com toCommit->includeSquashInst[tid] = false; 5002292SN/A 5017852SMatt.Horsnell@arm.com wroteToTimeBuffer = true; 5027852SMatt.Horsnell@arm.com } 5037852SMatt.Horsnell@arm.com 5042292SN/A} 5052292SN/A 5062292SN/Atemplate<class Impl> 5072292SN/Avoid 50813429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::squashDueToMemOrder(const DynInstPtr& inst, ThreadID tid) 5092292SN/A{ 5108513SGiacomo.Gabrielli@arm.com DPRINTF(IEW, "[tid:%i]: Memory violation, squashing violator and younger " 5118513SGiacomo.Gabrielli@arm.com "insts, PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum); 5128513SGiacomo.Gabrielli@arm.com // Need to include inst->seqNum in the following comparison to cover the 5138513SGiacomo.Gabrielli@arm.com // corner case when a branch misprediction and a memory violation for the 5148513SGiacomo.Gabrielli@arm.com // same instruction (e.g. load PC) are detected in the same cycle. In this 5158513SGiacomo.Gabrielli@arm.com // case the memory violator should take precedence over the branch 5168513SGiacomo.Gabrielli@arm.com // misprediction because it requires the violator itself to be included in 5178513SGiacomo.Gabrielli@arm.com // the squash. 51810231Ssteve.reinhardt@amd.com if (!toCommit->squash[tid] || 5198513SGiacomo.Gabrielli@arm.com inst->seqNum <= toCommit->squashedSeqNum[tid]) { 5208513SGiacomo.Gabrielli@arm.com toCommit->squash[tid] = true; 5212292SN/A 5227852SMatt.Horsnell@arm.com toCommit->squashedSeqNum[tid] = inst->seqNum; 5238513SGiacomo.Gabrielli@arm.com toCommit->pc[tid] = inst->pcState(); 5248137SAli.Saidi@ARM.com toCommit->mispredictInst[tid] = NULL; 5252292SN/A 5268513SGiacomo.Gabrielli@arm.com // Must include the memory violator in the squash. 5278513SGiacomo.Gabrielli@arm.com toCommit->includeSquashInst[tid] = true; 5282292SN/A 5297852SMatt.Horsnell@arm.com wroteToTimeBuffer = true; 5307852SMatt.Horsnell@arm.com } 5312292SN/A} 5322292SN/A 5332292SN/Atemplate<class Impl> 5342292SN/Avoid 5356221Snate@binkert.orgDefaultIEW<Impl>::block(ThreadID tid) 5362292SN/A{ 5372292SN/A DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid); 5382292SN/A 5392292SN/A if (dispatchStatus[tid] != Blocked && 5402292SN/A dispatchStatus[tid] != Unblocking) { 5412292SN/A toRename->iewBlock[tid] = true; 5422292SN/A wroteToTimeBuffer = true; 5432292SN/A } 5442292SN/A 5452292SN/A // Add the current inputs to the skid buffer so they can be 5462292SN/A // reprocessed when this stage unblocks. 5472292SN/A skidInsert(tid); 5482292SN/A 5492292SN/A dispatchStatus[tid] = Blocked; 5502292SN/A} 5512292SN/A 5522292SN/Atemplate<class Impl> 5532292SN/Avoid 5546221Snate@binkert.orgDefaultIEW<Impl>::unblock(ThreadID tid) 5552292SN/A{ 5562292SN/A DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid " 5572292SN/A "buffer %u.\n",tid, tid); 5582292SN/A 5592292SN/A // If the skid bufffer is empty, signal back to previous stages to unblock. 5602292SN/A // Also switch status to running. 5612292SN/A if (skidBuffer[tid].empty()) { 5622292SN/A toRename->iewUnblock[tid] = true; 5632292SN/A wroteToTimeBuffer = true; 5642292SN/A DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid); 5652292SN/A dispatchStatus[tid] = Running; 5662292SN/A } 5672292SN/A} 5682292SN/A 5692292SN/Atemplate<class Impl> 5702292SN/Avoid 57113429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::wakeDependents(const DynInstPtr& inst) 5721060SN/A{ 5731681SN/A instQueue.wakeDependents(inst); 5741060SN/A} 5751060SN/A 5762292SN/Atemplate<class Impl> 5772292SN/Avoid 57813429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::rescheduleMemInst(const DynInstPtr& inst) 5792292SN/A{ 5802292SN/A instQueue.rescheduleMemInst(inst); 5812292SN/A} 5821681SN/A 5831681SN/Atemplate<class Impl> 5841060SN/Avoid 58513429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::replayMemInst(const DynInstPtr& inst) 5861060SN/A{ 5872292SN/A instQueue.replayMemInst(inst); 5882292SN/A} 5891060SN/A 5902292SN/Atemplate<class Impl> 5912292SN/Avoid 59213429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::blockMemInst(const DynInstPtr& inst) 59310333Smitch.hayenga@arm.com{ 59410333Smitch.hayenga@arm.com instQueue.blockMemInst(inst); 59510333Smitch.hayenga@arm.com} 59610333Smitch.hayenga@arm.com 59710333Smitch.hayenga@arm.comtemplate<class Impl> 59810333Smitch.hayenga@arm.comvoid 59910333Smitch.hayenga@arm.comDefaultIEW<Impl>::cacheUnblocked() 60010333Smitch.hayenga@arm.com{ 60110333Smitch.hayenga@arm.com instQueue.cacheUnblocked(); 60210333Smitch.hayenga@arm.com} 60310333Smitch.hayenga@arm.com 60410333Smitch.hayenga@arm.comtemplate<class Impl> 60510333Smitch.hayenga@arm.comvoid 60613429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::instToCommit(const DynInstPtr& inst) 6072292SN/A{ 6083221Sktlim@umich.edu // This function should not be called after writebackInsts in a 6093221Sktlim@umich.edu // single cycle. That will cause problems with an instruction 6103221Sktlim@umich.edu // being added to the queue to commit without being processed by 6113221Sktlim@umich.edu // writebackInsts prior to being sent to commit. 6123221Sktlim@umich.edu 6132292SN/A // First check the time slot that this instruction will write 6142292SN/A // to. If there are free write ports at the time, then go ahead 6152292SN/A // and write the instruction to that time. If there are not, 6162292SN/A // keep looking back to see where's the first time there's a 6172326SN/A // free slot. 6182292SN/A while ((*iewQueue)[wbCycle].insts[wbNumInst]) { 6192292SN/A ++wbNumInst; 6202820Sktlim@umich.edu if (wbNumInst == wbWidth) { 6212292SN/A ++wbCycle; 6222292SN/A wbNumInst = 0; 6232292SN/A } 6242292SN/A } 6252292SN/A 6262353SN/A DPRINTF(IEW, "Current wb cycle: %i, width: %i, numInst: %i\nwbActual:%i\n", 6272353SN/A wbCycle, wbWidth, wbNumInst, wbCycle * wbWidth + wbNumInst); 6282292SN/A // Add finished instruction to queue to commit. 6292292SN/A (*iewQueue)[wbCycle].insts[wbNumInst] = inst; 6302292SN/A (*iewQueue)[wbCycle].size++; 6312292SN/A} 6322292SN/A 6332292SN/Atemplate <class Impl> 6342292SN/Aunsigned 6352292SN/ADefaultIEW<Impl>::validInstsFromRename() 6362292SN/A{ 6372292SN/A unsigned inst_count = 0; 6382292SN/A 6392292SN/A for (int i=0; i<fromRename->size; i++) { 6402731Sktlim@umich.edu if (!fromRename->insts[i]->isSquashed()) 6412292SN/A inst_count++; 6422292SN/A } 6432292SN/A 6442292SN/A return inst_count; 6452292SN/A} 6462292SN/A 6472292SN/Atemplate<class Impl> 6482292SN/Avoid 6496221Snate@binkert.orgDefaultIEW<Impl>::skidInsert(ThreadID tid) 6502292SN/A{ 6512292SN/A DynInstPtr inst = NULL; 6522292SN/A 6532292SN/A while (!insts[tid].empty()) { 6542292SN/A inst = insts[tid].front(); 6552292SN/A 6562292SN/A insts[tid].pop(); 6572292SN/A 6589937SFaissal.Sleiman@arm.com DPRINTF(IEW,"[tid:%i]: Inserting [sn:%lli] PC:%s into " 6592292SN/A "dispatch skidBuffer %i\n",tid, inst->seqNum, 6607720Sgblack@eecs.umich.edu inst->pcState(),tid); 6612292SN/A 6622292SN/A skidBuffer[tid].push(inst); 6632292SN/A } 6642292SN/A 6652292SN/A assert(skidBuffer[tid].size() <= skidBufferMax && 6662292SN/A "Skidbuffer Exceeded Max Size"); 6672292SN/A} 6682292SN/A 6692292SN/Atemplate<class Impl> 6702292SN/Aint 6712292SN/ADefaultIEW<Impl>::skidCount() 6722292SN/A{ 6732292SN/A int max=0; 6742292SN/A 6756221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6766221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6772292SN/A 6783867Sbinkertn@umich.edu while (threads != end) { 6796221Snate@binkert.org ThreadID tid = *threads++; 6803867Sbinkertn@umich.edu unsigned thread_count = skidBuffer[tid].size(); 6812292SN/A if (max < thread_count) 6822292SN/A max = thread_count; 6832292SN/A } 6842292SN/A 6852292SN/A return max; 6862292SN/A} 6872292SN/A 6882292SN/Atemplate<class Impl> 6892292SN/Abool 6902292SN/ADefaultIEW<Impl>::skidsEmpty() 6912292SN/A{ 6926221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6936221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6942292SN/A 6953867Sbinkertn@umich.edu while (threads != end) { 6966221Snate@binkert.org ThreadID tid = *threads++; 6973867Sbinkertn@umich.edu 6983867Sbinkertn@umich.edu if (!skidBuffer[tid].empty()) 6992292SN/A return false; 7002292SN/A } 7012292SN/A 7022292SN/A return true; 7031062SN/A} 7041062SN/A 7051681SN/Atemplate <class Impl> 7061062SN/Avoid 7072292SN/ADefaultIEW<Impl>::updateStatus() 7081062SN/A{ 7092292SN/A bool any_unblocking = false; 7101062SN/A 7116221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 7126221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 7131062SN/A 7143867Sbinkertn@umich.edu while (threads != end) { 7156221Snate@binkert.org ThreadID tid = *threads++; 7161062SN/A 7172292SN/A if (dispatchStatus[tid] == Unblocking) { 7182292SN/A any_unblocking = true; 7192292SN/A break; 7202292SN/A } 7212292SN/A } 7221062SN/A 7232292SN/A // If there are no ready instructions waiting to be scheduled by the IQ, 7242292SN/A // and there's no stores waiting to write back, and dispatch is not 7252292SN/A // unblocking, then there is no internal activity for the IEW stage. 7267897Shestness@cs.utexas.edu instQueue.intInstQueueReads++; 7272292SN/A if (_status == Active && !instQueue.hasReadyInsts() && 7282292SN/A !ldstQueue.willWB() && !any_unblocking) { 7292292SN/A DPRINTF(IEW, "IEW switching to idle\n"); 7301062SN/A 7312292SN/A deactivateStage(); 7321062SN/A 7332292SN/A _status = Inactive; 7342292SN/A } else if (_status == Inactive && (instQueue.hasReadyInsts() || 7352292SN/A ldstQueue.willWB() || 7362292SN/A any_unblocking)) { 7372292SN/A // Otherwise there is internal activity. Set to active. 7382292SN/A DPRINTF(IEW, "IEW switching to active\n"); 7391062SN/A 7402292SN/A activateStage(); 7411062SN/A 7422292SN/A _status = Active; 7431062SN/A } 7441062SN/A} 7451062SN/A 7461681SN/Atemplate <class Impl> 7471062SN/Avoid 7482292SN/ADefaultIEW<Impl>::resetEntries() 7491062SN/A{ 7502292SN/A instQueue.resetEntries(); 7512292SN/A ldstQueue.resetEntries(); 7522292SN/A} 7531062SN/A 7542292SN/Atemplate <class Impl> 7552292SN/Abool 7566221Snate@binkert.orgDefaultIEW<Impl>::checkStall(ThreadID tid) 7572292SN/A{ 7582292SN/A bool ret_val(false); 7592292SN/A 76010328Smitch.hayenga@arm.com if (fromCommit->commitInfo[tid].robSquashing) { 7612292SN/A DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid); 7622292SN/A ret_val = true; 7632292SN/A } else if (instQueue.isFull(tid)) { 7642292SN/A DPRINTF(IEW,"[tid:%i]: Stall: IQ is full.\n",tid); 7652292SN/A ret_val = true; 7662292SN/A } 7672292SN/A 7682292SN/A return ret_val; 7692292SN/A} 7702292SN/A 7712292SN/Atemplate <class Impl> 7722292SN/Avoid 7736221Snate@binkert.orgDefaultIEW<Impl>::checkSignalsAndUpdate(ThreadID tid) 7742292SN/A{ 7752292SN/A // Check if there's a squash signal, squash if there is 7762292SN/A // Check stall signals, block if there is. 7772292SN/A // If status was Blocked 7782292SN/A // if so then go to unblocking 7792292SN/A // If status was Squashing 7802292SN/A // check if squashing is not high. Switch to running this cycle. 7812292SN/A 7822292SN/A if (fromCommit->commitInfo[tid].squash) { 7832292SN/A squash(tid); 7842292SN/A 7852292SN/A if (dispatchStatus[tid] == Blocked || 7862292SN/A dispatchStatus[tid] == Unblocking) { 7872292SN/A toRename->iewUnblock[tid] = true; 7882292SN/A wroteToTimeBuffer = true; 7892292SN/A } 7902292SN/A 7912292SN/A dispatchStatus[tid] = Squashing; 7922292SN/A fetchRedirect[tid] = false; 7932292SN/A return; 7942292SN/A } 7952292SN/A 7962292SN/A if (fromCommit->commitInfo[tid].robSquashing) { 7972702Sktlim@umich.edu DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n", tid); 7982292SN/A 7992292SN/A dispatchStatus[tid] = Squashing; 8002702Sktlim@umich.edu emptyRenameInsts(tid); 8012702Sktlim@umich.edu wroteToTimeBuffer = true; 8022292SN/A } 8032292SN/A 8042292SN/A if (checkStall(tid)) { 8052292SN/A block(tid); 8062292SN/A dispatchStatus[tid] = Blocked; 8072292SN/A return; 8082292SN/A } 8092292SN/A 8102292SN/A if (dispatchStatus[tid] == Blocked) { 8112292SN/A // Status from previous cycle was blocked, but there are no more stall 8122292SN/A // conditions. Switch over to unblocking. 8132292SN/A DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n", 8142292SN/A tid); 8152292SN/A 8162292SN/A dispatchStatus[tid] = Unblocking; 8172292SN/A 8182292SN/A unblock(tid); 8192292SN/A 8202292SN/A return; 8212292SN/A } 8222292SN/A 8232292SN/A if (dispatchStatus[tid] == Squashing) { 8242292SN/A // Switch status to running if rename isn't being told to block or 8252292SN/A // squash this cycle. 8262292SN/A DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n", 8272292SN/A tid); 8282292SN/A 8292292SN/A dispatchStatus[tid] = Running; 8302292SN/A 8312292SN/A return; 8322292SN/A } 8332292SN/A} 8342292SN/A 8352292SN/Atemplate <class Impl> 8362292SN/Avoid 8372292SN/ADefaultIEW<Impl>::sortInsts() 8382292SN/A{ 8392292SN/A int insts_from_rename = fromRename->size; 8402326SN/A#ifdef DEBUG 8416221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) 8426221Snate@binkert.org assert(insts[tid].empty()); 8432326SN/A#endif 8442292SN/A for (int i = 0; i < insts_from_rename; ++i) { 8452292SN/A insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]); 8462292SN/A } 8472292SN/A} 8482292SN/A 8492292SN/Atemplate <class Impl> 8502292SN/Avoid 8516221Snate@binkert.orgDefaultIEW<Impl>::emptyRenameInsts(ThreadID tid) 8522702Sktlim@umich.edu{ 8534632Sgblack@eecs.umich.edu DPRINTF(IEW, "[tid:%i]: Removing incoming rename instructions\n", tid); 8542935Sksewell@umich.edu 8552702Sktlim@umich.edu while (!insts[tid].empty()) { 8562935Sksewell@umich.edu 85710239Sbinhpham@cs.rutgers.edu if (insts[tid].front()->isLoad()) { 85810239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToLQ++; 85910239Sbinhpham@cs.rutgers.edu } 86010239Sbinhpham@cs.rutgers.edu if (insts[tid].front()->isStore()) { 86110239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToSQ++; 8622702Sktlim@umich.edu } 8632702Sktlim@umich.edu 8642702Sktlim@umich.edu toRename->iewInfo[tid].dispatched++; 8652702Sktlim@umich.edu 8662702Sktlim@umich.edu insts[tid].pop(); 8672702Sktlim@umich.edu } 8682702Sktlim@umich.edu} 8692702Sktlim@umich.edu 8702702Sktlim@umich.edutemplate <class Impl> 8712702Sktlim@umich.eduvoid 8722292SN/ADefaultIEW<Impl>::wakeCPU() 8732292SN/A{ 8742292SN/A cpu->wakeCPU(); 8752292SN/A} 8762292SN/A 8772292SN/Atemplate <class Impl> 8782292SN/Avoid 8792292SN/ADefaultIEW<Impl>::activityThisCycle() 8802292SN/A{ 8812292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 8822292SN/A cpu->activityThisCycle(); 8832292SN/A} 8842292SN/A 8852292SN/Atemplate <class Impl> 8862292SN/Ainline void 8872292SN/ADefaultIEW<Impl>::activateStage() 8882292SN/A{ 8892292SN/A DPRINTF(Activity, "Activating stage.\n"); 8902733Sktlim@umich.edu cpu->activateStage(O3CPU::IEWIdx); 8912292SN/A} 8922292SN/A 8932292SN/Atemplate <class Impl> 8942292SN/Ainline void 8952292SN/ADefaultIEW<Impl>::deactivateStage() 8962292SN/A{ 8972292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 8982733Sktlim@umich.edu cpu->deactivateStage(O3CPU::IEWIdx); 8992292SN/A} 9002292SN/A 9012292SN/Atemplate<class Impl> 9022292SN/Avoid 9036221Snate@binkert.orgDefaultIEW<Impl>::dispatch(ThreadID tid) 9042292SN/A{ 9052292SN/A // If status is Running or idle, 9062292SN/A // call dispatchInsts() 9072292SN/A // If status is Unblocking, 9082292SN/A // buffer any instructions coming from rename 9092292SN/A // continue trying to empty skid buffer 9102292SN/A // check if stall conditions have passed 9112292SN/A 9122292SN/A if (dispatchStatus[tid] == Blocked) { 9132292SN/A ++iewBlockCycles; 9142292SN/A 9152292SN/A } else if (dispatchStatus[tid] == Squashing) { 9162292SN/A ++iewSquashCycles; 9172292SN/A } 9182292SN/A 9192292SN/A // Dispatch should try to dispatch as many instructions as its bandwidth 9202292SN/A // will allow, as long as it is not currently blocked. 9212292SN/A if (dispatchStatus[tid] == Running || 9222292SN/A dispatchStatus[tid] == Idle) { 9232292SN/A DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run " 9242292SN/A "dispatch.\n", tid); 9252292SN/A 9262292SN/A dispatchInsts(tid); 9272292SN/A } else if (dispatchStatus[tid] == Unblocking) { 9282292SN/A // Make sure that the skid buffer has something in it if the 9292292SN/A // status is unblocking. 9302292SN/A assert(!skidsEmpty()); 9312292SN/A 9322292SN/A // If the status was unblocking, then instructions from the skid 9332292SN/A // buffer were used. Remove those instructions and handle 9342292SN/A // the rest of unblocking. 9352292SN/A dispatchInsts(tid); 9362292SN/A 9372292SN/A ++iewUnblockCycles; 9382292SN/A 9395215Sgblack@eecs.umich.edu if (validInstsFromRename()) { 9402292SN/A // Add the current inputs to the skid buffer so they can be 9412292SN/A // reprocessed when this stage unblocks. 9422292SN/A skidInsert(tid); 9432292SN/A } 9442292SN/A 9452292SN/A unblock(tid); 9462292SN/A } 9472292SN/A} 9482292SN/A 9492292SN/Atemplate <class Impl> 9502292SN/Avoid 9516221Snate@binkert.orgDefaultIEW<Impl>::dispatchInsts(ThreadID tid) 9522292SN/A{ 9532292SN/A // Obtain instructions from skid buffer if unblocking, or queue from rename 9542292SN/A // otherwise. 9552292SN/A std::queue<DynInstPtr> &insts_to_dispatch = 9562292SN/A dispatchStatus[tid] == Unblocking ? 9572292SN/A skidBuffer[tid] : insts[tid]; 9582292SN/A 9592292SN/A int insts_to_add = insts_to_dispatch.size(); 9602292SN/A 9612292SN/A DynInstPtr inst; 9622292SN/A bool add_to_iq = false; 9632292SN/A int dis_num_inst = 0; 9642292SN/A 9652292SN/A // Loop through the instructions, putting them in the instruction 9662292SN/A // queue. 9672292SN/A for ( ; dis_num_inst < insts_to_add && 9682820Sktlim@umich.edu dis_num_inst < dispatchWidth; 9692292SN/A ++dis_num_inst) 9702292SN/A { 9712292SN/A inst = insts_to_dispatch.front(); 9722292SN/A 9732292SN/A if (dispatchStatus[tid] == Unblocking) { 9742292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid " 9752292SN/A "buffer\n", tid); 9762292SN/A } 9772292SN/A 9782292SN/A // Make sure there's a valid instruction there. 9792292SN/A assert(inst); 9802292SN/A 9817720Sgblack@eecs.umich.edu DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %s [sn:%lli] [tid:%i] to " 9822292SN/A "IQ.\n", 9837720Sgblack@eecs.umich.edu tid, inst->pcState(), inst->seqNum, inst->threadNumber); 9842292SN/A 9852292SN/A // Be sure to mark these instructions as ready so that the 9862292SN/A // commit stage can go ahead and execute them, and mark 9872292SN/A // them as issued so the IQ doesn't reprocess them. 9882292SN/A 9892292SN/A // Check for squashed instructions. 9902292SN/A if (inst->isSquashed()) { 9912292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, " 9922292SN/A "not adding to IQ.\n", tid); 9932292SN/A 9942292SN/A ++iewDispSquashedInsts; 9952292SN/A 9962292SN/A insts_to_dispatch.pop(); 9972292SN/A 9982292SN/A //Tell Rename That An Instruction has been processed 99910239Sbinhpham@cs.rutgers.edu if (inst->isLoad()) { 100010239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToLQ++; 10012292SN/A } 100210239Sbinhpham@cs.rutgers.edu if (inst->isStore()) { 100310239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToSQ++; 100410239Sbinhpham@cs.rutgers.edu } 100510239Sbinhpham@cs.rutgers.edu 10062292SN/A toRename->iewInfo[tid].dispatched++; 10072292SN/A 10082292SN/A continue; 10092292SN/A } 10102292SN/A 10112292SN/A // Check for full conditions. 10122292SN/A if (instQueue.isFull(tid)) { 10132292SN/A DPRINTF(IEW, "[tid:%i]: Issue: IQ has become full.\n", tid); 10142292SN/A 10152292SN/A // Call function to start blocking. 10162292SN/A block(tid); 10172292SN/A 10182292SN/A // Set unblock to false. Special case where we are using 10192292SN/A // skidbuffer (unblocking) instructions but then we still 10202292SN/A // get full in the IQ. 10212292SN/A toRename->iewUnblock[tid] = false; 10222292SN/A 10232292SN/A ++iewIQFullEvents; 10242292SN/A break; 102510240Sbinhpham@cs.rutgers.edu } 102610240Sbinhpham@cs.rutgers.edu 102710240Sbinhpham@cs.rutgers.edu // Check LSQ if inst is LD/ST 102810240Sbinhpham@cs.rutgers.edu if ((inst->isLoad() && ldstQueue.lqFull(tid)) || 102910240Sbinhpham@cs.rutgers.edu (inst->isStore() && ldstQueue.sqFull(tid))) { 103010240Sbinhpham@cs.rutgers.edu DPRINTF(IEW, "[tid:%i]: Issue: %s has become full.\n",tid, 103110240Sbinhpham@cs.rutgers.edu inst->isLoad() ? "LQ" : "SQ"); 10322292SN/A 10332292SN/A // Call function to start blocking. 10342292SN/A block(tid); 10352292SN/A 10362292SN/A // Set unblock to false. Special case where we are using 10372292SN/A // skidbuffer (unblocking) instructions but then we still 10382292SN/A // get full in the IQ. 10392292SN/A toRename->iewUnblock[tid] = false; 10402292SN/A 10412292SN/A ++iewLSQFullEvents; 10422292SN/A break; 10432292SN/A } 10442292SN/A 10452292SN/A // Otherwise issue the instruction just fine. 10462292SN/A if (inst->isLoad()) { 10472292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10482292SN/A "encountered, adding to LSQ.\n", tid); 10492292SN/A 10502292SN/A // Reserve a spot in the load store queue for this 10512292SN/A // memory access. 10522292SN/A ldstQueue.insertLoad(inst); 10532292SN/A 10542292SN/A ++iewDispLoadInsts; 10552292SN/A 10562292SN/A add_to_iq = true; 10572292SN/A 105810239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToLQ++; 10592292SN/A } else if (inst->isStore()) { 10602292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10612292SN/A "encountered, adding to LSQ.\n", tid); 10622292SN/A 10632292SN/A ldstQueue.insertStore(inst); 10642292SN/A 10652292SN/A ++iewDispStoreInsts; 10662292SN/A 10672336SN/A if (inst->isStoreConditional()) { 10682336SN/A // Store conditionals need to be set as "canCommit()" 10692336SN/A // so that commit can process them when they reach the 10702336SN/A // head of commit. 10712348SN/A // @todo: This is somewhat specific to Alpha. 10722292SN/A inst->setCanCommit(); 10732292SN/A instQueue.insertNonSpec(inst); 10742292SN/A add_to_iq = false; 10752292SN/A 10762292SN/A ++iewDispNonSpecInsts; 10772292SN/A } else { 10782292SN/A add_to_iq = true; 10792292SN/A } 10802292SN/A 108110239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].dispatchedToSQ++; 10822292SN/A } else if (inst->isMemBarrier() || inst->isWriteBarrier()) { 10832326SN/A // Same as non-speculative stores. 10842292SN/A inst->setCanCommit(); 10852292SN/A instQueue.insertBarrier(inst); 10862292SN/A add_to_iq = false; 10872292SN/A } else if (inst->isNop()) { 10882292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, " 10892292SN/A "skipping.\n", tid); 10902292SN/A 10912292SN/A inst->setIssued(); 10922292SN/A inst->setExecuted(); 10932292SN/A inst->setCanCommit(); 10942292SN/A 10952326SN/A instQueue.recordProducer(inst); 10962292SN/A 10972727Sktlim@umich.edu iewExecutedNop[tid]++; 10982301SN/A 10992292SN/A add_to_iq = false; 11002292SN/A } else { 110110733Snilay@cs.wisc.edu assert(!inst->isExecuted()); 11022292SN/A add_to_iq = true; 11032292SN/A } 110410733Snilay@cs.wisc.edu 110512537Sandreas.sandberg@arm.com if (add_to_iq && inst->isNonSpeculative()) { 11064033Sktlim@umich.edu DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction " 11074033Sktlim@umich.edu "encountered, skipping.\n", tid); 11084033Sktlim@umich.edu 11094033Sktlim@umich.edu // Same as non-speculative stores. 11104033Sktlim@umich.edu inst->setCanCommit(); 11114033Sktlim@umich.edu 11124033Sktlim@umich.edu // Specifically insert it as nonspeculative. 11134033Sktlim@umich.edu instQueue.insertNonSpec(inst); 11144033Sktlim@umich.edu 11154033Sktlim@umich.edu ++iewDispNonSpecInsts; 11164033Sktlim@umich.edu 11174033Sktlim@umich.edu add_to_iq = false; 11184033Sktlim@umich.edu } 11192292SN/A 11202292SN/A // If the instruction queue is not full, then add the 11212292SN/A // instruction. 11222292SN/A if (add_to_iq) { 11232292SN/A instQueue.insert(inst); 11242292SN/A } 11252292SN/A 11262292SN/A insts_to_dispatch.pop(); 11272292SN/A 11282292SN/A toRename->iewInfo[tid].dispatched++; 11292292SN/A 11302292SN/A ++iewDispatchedInsts; 11318471SGiacomo.Gabrielli@arm.com 11328471SGiacomo.Gabrielli@arm.com#if TRACING_ON 11339046SAli.Saidi@ARM.com inst->dispatchTick = curTick() - inst->fetchTick; 11348471SGiacomo.Gabrielli@arm.com#endif 113510023Smatt.horsnell@ARM.com ppDispatch->notify(inst); 11362292SN/A } 11372292SN/A 11382292SN/A if (!insts_to_dispatch.empty()) { 11392935Sksewell@umich.edu DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n", tid); 11402292SN/A block(tid); 11412292SN/A toRename->iewUnblock[tid] = false; 11422292SN/A } 11432292SN/A 11442292SN/A if (dispatchStatus[tid] == Idle && dis_num_inst) { 11452292SN/A dispatchStatus[tid] = Running; 11462292SN/A 11472292SN/A updatedQueues = true; 11482292SN/A } 11492292SN/A 11502292SN/A dis_num_inst = 0; 11512292SN/A} 11522292SN/A 11532292SN/Atemplate <class Impl> 11542292SN/Avoid 11552292SN/ADefaultIEW<Impl>::printAvailableInsts() 11562292SN/A{ 11572292SN/A int inst = 0; 11582292SN/A 11592980Sgblack@eecs.umich.edu std::cout << "Available Instructions: "; 11602292SN/A 11612292SN/A while (fromIssue->insts[inst]) { 11622292SN/A 11632980Sgblack@eecs.umich.edu if (inst%3==0) std::cout << "\n\t"; 11642292SN/A 11657720Sgblack@eecs.umich.edu std::cout << "PC: " << fromIssue->insts[inst]->pcState() 11662292SN/A << " TN: " << fromIssue->insts[inst]->threadNumber 11672292SN/A << " SN: " << fromIssue->insts[inst]->seqNum << " | "; 11682292SN/A 11692292SN/A inst++; 11702292SN/A 11712292SN/A } 11722292SN/A 11732980Sgblack@eecs.umich.edu std::cout << "\n"; 11742292SN/A} 11752292SN/A 11762292SN/Atemplate <class Impl> 11772292SN/Avoid 11782292SN/ADefaultIEW<Impl>::executeInsts() 11792292SN/A{ 11802292SN/A wbNumInst = 0; 11812292SN/A wbCycle = 0; 11822292SN/A 11836221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 11846221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 11852292SN/A 11863867Sbinkertn@umich.edu while (threads != end) { 11876221Snate@binkert.org ThreadID tid = *threads++; 11882292SN/A fetchRedirect[tid] = false; 11892292SN/A } 11902292SN/A 11912698Sktlim@umich.edu // Uncomment this if you want to see all available instructions. 11927599Sminkyu.jeong@arm.com // @todo This doesn't actually work anymore, we should fix it. 11932698Sktlim@umich.edu// printAvailableInsts(); 11941062SN/A 11951062SN/A // Execute/writeback any instructions that are available. 11962333SN/A int insts_to_execute = fromIssue->size; 11972292SN/A int inst_num = 0; 11982333SN/A for (; inst_num < insts_to_execute; 11992326SN/A ++inst_num) { 12001062SN/A 12012292SN/A DPRINTF(IEW, "Execute: Executing instructions from IQ.\n"); 12021062SN/A 12032333SN/A DynInstPtr inst = instQueue.getInstToExecute(); 12041062SN/A 12057720Sgblack@eecs.umich.edu DPRINTF(IEW, "Execute: Processing PC %s, [tid:%i] [sn:%i].\n", 12067720Sgblack@eecs.umich.edu inst->pcState(), inst->threadNumber,inst->seqNum); 12071062SN/A 120811246Sradhika.jagtap@ARM.com // Notify potential listeners that this instruction has started 120911246Sradhika.jagtap@ARM.com // executing 121011246Sradhika.jagtap@ARM.com ppExecute->notify(inst); 121111246Sradhika.jagtap@ARM.com 12121062SN/A // Check if the instruction is squashed; if so then skip it 12131062SN/A if (inst->isSquashed()) { 12148315Sgeoffrey.blake@arm.com DPRINTF(IEW, "Execute: Instruction was squashed. PC: %s, [tid:%i]" 12158315Sgeoffrey.blake@arm.com " [sn:%i]\n", inst->pcState(), inst->threadNumber, 12168315Sgeoffrey.blake@arm.com inst->seqNum); 12171062SN/A 12181062SN/A // Consider this instruction executed so that commit can go 12191062SN/A // ahead and retire the instruction. 12201062SN/A inst->setExecuted(); 12211062SN/A 12222292SN/A // Not sure if I should set this here or just let commit try to 12232292SN/A // commit any squashed instructions. I like the latter a bit more. 12242292SN/A inst->setCanCommit(); 12251062SN/A 12261062SN/A ++iewExecSquashedInsts; 12271062SN/A 12281062SN/A continue; 12291062SN/A } 12301062SN/A 12312292SN/A Fault fault = NoFault; 12321062SN/A 12331062SN/A // Execute instruction. 12341062SN/A // Note that if the instruction faults, it will be handled 12351062SN/A // at the commit stage. 12367850SMatt.Horsnell@arm.com if (inst->isMemRef()) { 12372292SN/A DPRINTF(IEW, "Execute: Calculating address for memory " 12381062SN/A "reference.\n"); 12391062SN/A 12401062SN/A // Tell the LDSTQ to execute this instruction (if it is a load). 12411062SN/A if (inst->isLoad()) { 12422292SN/A // Loads will mark themselves as executed, and their writeback 12432292SN/A // event adds the instruction to the queue to commit 12442292SN/A fault = ldstQueue.executeLoad(inst); 12457944SGiacomo.Gabrielli@arm.com 12467944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 12477944SGiacomo.Gabrielli@arm.com fault == NoFault) { 12487944SGiacomo.Gabrielli@arm.com // A hw page table walk is currently going on; the 12497944SGiacomo.Gabrielli@arm.com // instruction must be deferred. 12507944SGiacomo.Gabrielli@arm.com DPRINTF(IEW, "Execute: Delayed translation, deferring " 12517944SGiacomo.Gabrielli@arm.com "load.\n"); 12527944SGiacomo.Gabrielli@arm.com instQueue.deferMemInst(inst); 12537944SGiacomo.Gabrielli@arm.com continue; 12547944SGiacomo.Gabrielli@arm.com } 12557944SGiacomo.Gabrielli@arm.com 12567850SMatt.Horsnell@arm.com if (inst->isDataPrefetch() || inst->isInstPrefetch()) { 12578073SAli.Saidi@ARM.com inst->fault = NoFault; 12587850SMatt.Horsnell@arm.com } 12591062SN/A } else if (inst->isStore()) { 12602367SN/A fault = ldstQueue.executeStore(inst); 12611062SN/A 12627944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 12637944SGiacomo.Gabrielli@arm.com fault == NoFault) { 12647944SGiacomo.Gabrielli@arm.com // A hw page table walk is currently going on; the 12657944SGiacomo.Gabrielli@arm.com // instruction must be deferred. 12667944SGiacomo.Gabrielli@arm.com DPRINTF(IEW, "Execute: Delayed translation, deferring " 12677944SGiacomo.Gabrielli@arm.com "store.\n"); 12687944SGiacomo.Gabrielli@arm.com instQueue.deferMemInst(inst); 12697944SGiacomo.Gabrielli@arm.com continue; 12707944SGiacomo.Gabrielli@arm.com } 12717944SGiacomo.Gabrielli@arm.com 12722292SN/A // If the store had a fault then it may not have a mem req 127310231Ssteve.reinhardt@amd.com if (fault != NoFault || !inst->readPredicate() || 12747782Sminkyu.jeong@arm.com !inst->isStoreConditional()) { 12757782Sminkyu.jeong@arm.com // If the instruction faulted, then we need to send it along 12767782Sminkyu.jeong@arm.com // to commit without the instruction completing. 12772367SN/A // Send this instruction to commit, also make sure iew stage 12782367SN/A // realizes there is activity. 12792367SN/A inst->setExecuted(); 12802367SN/A instToCommit(inst); 12812367SN/A activityThisCycle(); 12822292SN/A } 12832326SN/A 12842326SN/A // Store conditionals will mark themselves as 12852326SN/A // executed, and their writeback event will add the 12862326SN/A // instruction to the queue to commit. 12871062SN/A } else { 12882292SN/A panic("Unexpected memory type!\n"); 12891062SN/A } 12901062SN/A 12911062SN/A } else { 12927847Sminkyu.jeong@arm.com // If the instruction has already faulted, then skip executing it. 12937847Sminkyu.jeong@arm.com // Such case can happen when it faulted during ITLB translation. 12947847Sminkyu.jeong@arm.com // If we execute the instruction (even if it's a nop) the fault 12957847Sminkyu.jeong@arm.com // will be replaced and we will lose it. 12967847Sminkyu.jeong@arm.com if (inst->getFault() == NoFault) { 12977847Sminkyu.jeong@arm.com inst->execute(); 129810231Ssteve.reinhardt@amd.com if (!inst->readPredicate()) 12997848SAli.Saidi@ARM.com inst->forwardOldRegs(); 13007847Sminkyu.jeong@arm.com } 13011062SN/A 13022292SN/A inst->setExecuted(); 13032292SN/A 13042292SN/A instToCommit(inst); 13051062SN/A } 13061062SN/A 13072301SN/A updateExeInstStats(inst); 13081681SN/A 13092326SN/A // Check if branch prediction was correct, if not then we need 13102326SN/A // to tell commit to squash in flight instructions. Only 13112326SN/A // handle this if there hasn't already been something that 13122107SN/A // redirects fetch in this group of instructions. 13131681SN/A 13142292SN/A // This probably needs to prioritize the redirects if a different 13152292SN/A // scheduler is used. Currently the scheduler schedules the oldest 13162292SN/A // instruction first, so the branch resolution order will be correct. 13176221Snate@binkert.org ThreadID tid = inst->threadNumber; 13181062SN/A 13193732Sktlim@umich.edu if (!fetchRedirect[tid] || 13207852SMatt.Horsnell@arm.com !toCommit->squash[tid] || 13213732Sktlim@umich.edu toCommit->squashedSeqNum[tid] > inst->seqNum) { 13221062SN/A 13237856SMatt.Horsnell@arm.com // Prevent testing for misprediction on load instructions, 13247856SMatt.Horsnell@arm.com // that have not been executed. 13257856SMatt.Horsnell@arm.com bool loadNotExecuted = !inst->isExecuted() && inst->isLoad(); 13267856SMatt.Horsnell@arm.com 13277856SMatt.Horsnell@arm.com if (inst->mispredicted() && !loadNotExecuted) { 13282292SN/A fetchRedirect[tid] = true; 13291062SN/A 13302292SN/A DPRINTF(IEW, "Execute: Branch mispredict detected.\n"); 13318674Snilay@cs.wisc.edu DPRINTF(IEW, "Predicted target was PC: %s.\n", 13328674Snilay@cs.wisc.edu inst->readPredTarg()); 13337720Sgblack@eecs.umich.edu DPRINTF(IEW, "Execute: Redirecting fetch to PC: %s.\n", 13348674Snilay@cs.wisc.edu inst->pcState()); 13351062SN/A // If incorrect, then signal the ROB that it must be squashed. 13362292SN/A squashDueToBranch(inst, tid); 13371062SN/A 133810023Smatt.horsnell@ARM.com ppMispredict->notify(inst); 133910023Smatt.horsnell@ARM.com 13403795Sgblack@eecs.umich.edu if (inst->readPredTaken()) { 13411062SN/A predictedTakenIncorrect++; 13422292SN/A } else { 13432292SN/A predictedNotTakenIncorrect++; 13441062SN/A } 13452292SN/A } else if (ldstQueue.violation(tid)) { 13464033Sktlim@umich.edu assert(inst->isMemRef()); 13472326SN/A // If there was an ordering violation, then get the 13482326SN/A // DynInst that caused the violation. Note that this 13492292SN/A // clears the violation signal. 13502292SN/A DynInstPtr violator; 13512292SN/A violator = ldstQueue.getMemDepViolator(tid); 13521062SN/A 13537720Sgblack@eecs.umich.edu DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: %s " 13547720Sgblack@eecs.umich.edu "[sn:%lli], inst PC: %s [sn:%lli]. Addr is: %#x.\n", 13557720Sgblack@eecs.umich.edu violator->pcState(), violator->seqNum, 135611097Songal@cs.wisc.edu inst->pcState(), inst->seqNum, inst->physEffAddrLow); 13577720Sgblack@eecs.umich.edu 13583732Sktlim@umich.edu fetchRedirect[tid] = true; 13593732Sktlim@umich.edu 13601062SN/A // Tell the instruction queue that a violation has occured. 13611062SN/A instQueue.violation(inst, violator); 13621062SN/A 13631062SN/A // Squash. 13648513SGiacomo.Gabrielli@arm.com squashDueToMemOrder(violator, tid); 13651062SN/A 13661062SN/A ++memOrderViolationEvents; 13671062SN/A } 13684033Sktlim@umich.edu } else { 13694033Sktlim@umich.edu // Reset any state associated with redirects that will not 13704033Sktlim@umich.edu // be used. 13714033Sktlim@umich.edu if (ldstQueue.violation(tid)) { 13724033Sktlim@umich.edu assert(inst->isMemRef()); 13734033Sktlim@umich.edu 13744033Sktlim@umich.edu DynInstPtr violator = ldstQueue.getMemDepViolator(tid); 13754033Sktlim@umich.edu 13764033Sktlim@umich.edu DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: " 13777720Sgblack@eecs.umich.edu "%s, inst PC: %s. Addr is: %#x.\n", 13787720Sgblack@eecs.umich.edu violator->pcState(), inst->pcState(), 137911097Songal@cs.wisc.edu inst->physEffAddrLow); 13804033Sktlim@umich.edu DPRINTF(IEW, "Violation will not be handled because " 13814033Sktlim@umich.edu "already squashing\n"); 13824033Sktlim@umich.edu 13834033Sktlim@umich.edu ++memOrderViolationEvents; 13844033Sktlim@umich.edu } 13851062SN/A } 13861062SN/A } 13872292SN/A 13882348SN/A // Update and record activity if we processed any instructions. 13892292SN/A if (inst_num) { 13902292SN/A if (exeStatus == Idle) { 13912292SN/A exeStatus = Running; 13922292SN/A } 13932292SN/A 13942292SN/A updatedQueues = true; 13952292SN/A 13962292SN/A cpu->activityThisCycle(); 13972292SN/A } 13982292SN/A 13992292SN/A // Need to reset this in case a writeback event needs to write into the 14002292SN/A // iew queue. That way the writeback event will write into the correct 14012292SN/A // spot in the queue. 14022292SN/A wbNumInst = 0; 14037852SMatt.Horsnell@arm.com 14042107SN/A} 14052107SN/A 14062292SN/Atemplate <class Impl> 14072107SN/Avoid 14082292SN/ADefaultIEW<Impl>::writebackInsts() 14092107SN/A{ 14102326SN/A // Loop through the head of the time buffer and wake any 14112326SN/A // dependents. These instructions are about to write back. Also 14122326SN/A // mark scoreboard that this instruction is finally complete. 14132326SN/A // Either have IEW have direct access to scoreboard, or have this 14142326SN/A // as part of backwards communication. 14153958Sgblack@eecs.umich.edu for (int inst_num = 0; inst_num < wbWidth && 14162292SN/A toCommit->insts[inst_num]; inst_num++) { 14172107SN/A DynInstPtr inst = toCommit->insts[inst_num]; 14186221Snate@binkert.org ThreadID tid = inst->threadNumber; 14192107SN/A 14207720Sgblack@eecs.umich.edu DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %s.\n", 14217720Sgblack@eecs.umich.edu inst->seqNum, inst->pcState()); 14222107SN/A 14232301SN/A iewInstsToCommit[tid]++; 142411246Sradhika.jagtap@ARM.com // Notify potential listeners that execution is complete for this 142511246Sradhika.jagtap@ARM.com // instruction. 142611246Sradhika.jagtap@ARM.com ppToCommit->notify(inst); 14272301SN/A 14282292SN/A // Some instructions will be sent to commit without having 14292292SN/A // executed because they need commit to handle them. 143010824SAndreas.Sandberg@ARM.com // E.g. Strictly ordered loads have not actually executed when they 14312292SN/A // are first sent to commit. Instead commit must tell the LSQ 143210824SAndreas.Sandberg@ARM.com // when it's ready to execute the strictly ordered load. 14332367SN/A if (!inst->isSquashed() && inst->isExecuted() && inst->getFault() == NoFault) { 14342301SN/A int dependents = instQueue.wakeDependents(inst); 14352107SN/A 14362292SN/A for (int i = 0; i < inst->numDestRegs(); i++) { 14372292SN/A //mark as Ready 143812105Snathanael.premillieu@arm.com DPRINTF(IEW,"Setting Destination Register %i (%s)\n", 143912106SRekai.GonzalezAlberquilla@arm.com inst->renamedDestRegIdx(i)->index(), 144012106SRekai.GonzalezAlberquilla@arm.com inst->renamedDestRegIdx(i)->className()); 14412292SN/A scoreboard->setReg(inst->renamedDestRegIdx(i)); 14422107SN/A } 14432301SN/A 14442348SN/A if (dependents) { 14452348SN/A producerInst[tid]++; 14462348SN/A consumerInst[tid]+= dependents; 14472348SN/A } 14482326SN/A writebackCount[tid]++; 14492107SN/A } 14502107SN/A } 14511060SN/A} 14521060SN/A 14531681SN/Atemplate<class Impl> 14541060SN/Avoid 14552292SN/ADefaultIEW<Impl>::tick() 14561060SN/A{ 14572292SN/A wbNumInst = 0; 14582292SN/A wbCycle = 0; 14591060SN/A 14602292SN/A wroteToTimeBuffer = false; 14612292SN/A updatedQueues = false; 14621060SN/A 14632292SN/A sortInsts(); 14641060SN/A 14652326SN/A // Free function units marked as being freed this cycle. 14662326SN/A fuPool->processFreeUnits(); 14671062SN/A 14686221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 14696221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 14701060SN/A 14712326SN/A // Check stall and squash signals, dispatch any instructions. 14723867Sbinkertn@umich.edu while (threads != end) { 14736221Snate@binkert.org ThreadID tid = *threads++; 14741060SN/A 14752292SN/A DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid); 14761060SN/A 14772292SN/A checkSignalsAndUpdate(tid); 14782292SN/A dispatch(tid); 14791060SN/A } 14801060SN/A 14812292SN/A if (exeStatus != Squashing) { 14822292SN/A executeInsts(); 14831060SN/A 14842292SN/A writebackInsts(); 14852292SN/A 14862292SN/A // Have the instruction queue try to schedule any ready instructions. 14872292SN/A // (In actuality, this scheduling is for instructions that will 14882292SN/A // be executed next cycle.) 14892292SN/A instQueue.scheduleReadyInsts(); 14902292SN/A 14912292SN/A // Also should advance its own time buffers if the stage ran. 14922292SN/A // Not the best place for it, but this works (hopefully). 14932292SN/A issueToExecQueue.advance(); 14942292SN/A } 14952292SN/A 14962292SN/A bool broadcast_free_entries = false; 14972292SN/A 14982292SN/A if (updatedQueues || exeStatus == Running || updateLSQNextCycle) { 14992292SN/A exeStatus = Idle; 15002292SN/A updateLSQNextCycle = false; 15012292SN/A 15022292SN/A broadcast_free_entries = true; 15032292SN/A } 15042292SN/A 15052292SN/A // Writeback any stores using any leftover bandwidth. 15061681SN/A ldstQueue.writebackStores(); 15071681SN/A 15081061SN/A // Check the committed load/store signals to see if there's a load 15091061SN/A // or store to commit. Also check if it's being told to execute a 15101061SN/A // nonspeculative instruction. 15111681SN/A // This is pretty inefficient... 15122292SN/A 15133867Sbinkertn@umich.edu threads = activeThreads->begin(); 15143867Sbinkertn@umich.edu while (threads != end) { 15156221Snate@binkert.org ThreadID tid = (*threads++); 15162292SN/A 15172292SN/A DPRINTF(IEW,"Processing [tid:%i]\n",tid); 15182292SN/A 15192348SN/A // Update structures based on instructions committed. 15202292SN/A if (fromCommit->commitInfo[tid].doneSeqNum != 0 && 15212292SN/A !fromCommit->commitInfo[tid].squash && 15222292SN/A !fromCommit->commitInfo[tid].robSquashing) { 15232292SN/A 15242292SN/A ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid); 15252292SN/A 15262292SN/A ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid); 15272292SN/A 15282292SN/A updateLSQNextCycle = true; 15292292SN/A instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid); 15302292SN/A } 15312292SN/A 15322292SN/A if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) { 15332292SN/A 15342292SN/A //DPRINTF(IEW,"NonspecInst from thread %i",tid); 153510824SAndreas.Sandberg@ARM.com if (fromCommit->commitInfo[tid].strictlyOrdered) { 153610824SAndreas.Sandberg@ARM.com instQueue.replayMemInst( 153710824SAndreas.Sandberg@ARM.com fromCommit->commitInfo[tid].strictlyOrderedLoad); 153810824SAndreas.Sandberg@ARM.com fromCommit->commitInfo[tid].strictlyOrderedLoad->setAtCommit(); 15392292SN/A } else { 15402292SN/A instQueue.scheduleNonSpec( 15412292SN/A fromCommit->commitInfo[tid].nonSpecSeqNum); 15422292SN/A } 15432292SN/A } 15442292SN/A 15452292SN/A if (broadcast_free_entries) { 15462292SN/A toFetch->iewInfo[tid].iqCount = 15472292SN/A instQueue.getCount(tid); 15482292SN/A toFetch->iewInfo[tid].ldstqCount = 15492292SN/A ldstQueue.getCount(tid); 15502292SN/A 15512292SN/A toRename->iewInfo[tid].usedIQ = true; 15522292SN/A toRename->iewInfo[tid].freeIQEntries = 155310164Ssleimanf@umich.edu instQueue.numFreeEntries(tid); 15542292SN/A toRename->iewInfo[tid].usedLSQ = true; 155510239Sbinhpham@cs.rutgers.edu 155610239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].freeLQEntries = 155710239Sbinhpham@cs.rutgers.edu ldstQueue.numFreeLoadEntries(tid); 155810239Sbinhpham@cs.rutgers.edu toRename->iewInfo[tid].freeSQEntries = 155910239Sbinhpham@cs.rutgers.edu ldstQueue.numFreeStoreEntries(tid); 15602292SN/A 15612292SN/A wroteToTimeBuffer = true; 15622292SN/A } 15632292SN/A 15642292SN/A DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n", 15652292SN/A tid, toRename->iewInfo[tid].dispatched); 15661061SN/A } 15671061SN/A 15682292SN/A DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i). " 156910239Sbinhpham@cs.rutgers.edu "LQ has %i free entries. SQ has %i free entries.\n", 15702292SN/A instQueue.numFreeEntries(), instQueue.hasReadyInsts(), 157110239Sbinhpham@cs.rutgers.edu ldstQueue.numFreeLoadEntries(), ldstQueue.numFreeStoreEntries()); 15722292SN/A 15732292SN/A updateStatus(); 15742292SN/A 15752292SN/A if (wroteToTimeBuffer) { 15762292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 15772292SN/A cpu->activityThisCycle(); 15781061SN/A } 15791060SN/A} 15801060SN/A 15812301SN/Atemplate <class Impl> 15821060SN/Avoid 158313429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::updateExeInstStats(const DynInstPtr& inst) 15841060SN/A{ 15856221Snate@binkert.org ThreadID tid = inst->threadNumber; 15861060SN/A 15872669Sktlim@umich.edu iewExecutedInsts++; 15881060SN/A 15898471SGiacomo.Gabrielli@arm.com#if TRACING_ON 15909527SMatt.Horsnell@arm.com if (DTRACE(O3PipeView)) { 15919527SMatt.Horsnell@arm.com inst->completeTick = curTick() - inst->fetchTick; 15929527SMatt.Horsnell@arm.com } 15938471SGiacomo.Gabrielli@arm.com#endif 15948471SGiacomo.Gabrielli@arm.com 15952301SN/A // 15962301SN/A // Control operations 15972301SN/A // 15982301SN/A if (inst->isControl()) 15996221Snate@binkert.org iewExecutedBranches[tid]++; 16001060SN/A 16012301SN/A // 16022301SN/A // Memory operations 16032301SN/A // 16042301SN/A if (inst->isMemRef()) { 16056221Snate@binkert.org iewExecutedRefs[tid]++; 16061060SN/A 16072301SN/A if (inst->isLoad()) { 16086221Snate@binkert.org iewExecLoadInsts[tid]++; 16091060SN/A } 16101060SN/A } 16111060SN/A} 16127598Sminkyu.jeong@arm.com 16137598Sminkyu.jeong@arm.comtemplate <class Impl> 16147598Sminkyu.jeong@arm.comvoid 161513429Srekai.gonzalezalberquilla@arm.comDefaultIEW<Impl>::checkMisprediction(const DynInstPtr& inst) 16167598Sminkyu.jeong@arm.com{ 16177598Sminkyu.jeong@arm.com ThreadID tid = inst->threadNumber; 16187598Sminkyu.jeong@arm.com 16197598Sminkyu.jeong@arm.com if (!fetchRedirect[tid] || 16207852SMatt.Horsnell@arm.com !toCommit->squash[tid] || 16217598Sminkyu.jeong@arm.com toCommit->squashedSeqNum[tid] > inst->seqNum) { 16227598Sminkyu.jeong@arm.com 16237598Sminkyu.jeong@arm.com if (inst->mispredicted()) { 16247598Sminkyu.jeong@arm.com fetchRedirect[tid] = true; 16257598Sminkyu.jeong@arm.com 16267598Sminkyu.jeong@arm.com DPRINTF(IEW, "Execute: Branch mispredict detected.\n"); 16277598Sminkyu.jeong@arm.com DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n", 16287720Sgblack@eecs.umich.edu inst->predInstAddr(), inst->predNextInstAddr()); 16297598Sminkyu.jeong@arm.com DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x," 16307720Sgblack@eecs.umich.edu " NPC: %#x.\n", inst->nextInstAddr(), 16317720Sgblack@eecs.umich.edu inst->nextInstAddr()); 16327598Sminkyu.jeong@arm.com // If incorrect, then signal the ROB that it must be squashed. 16337598Sminkyu.jeong@arm.com squashDueToBranch(inst, tid); 16347598Sminkyu.jeong@arm.com 16357598Sminkyu.jeong@arm.com if (inst->readPredTaken()) { 16367598Sminkyu.jeong@arm.com predictedTakenIncorrect++; 16377598Sminkyu.jeong@arm.com } else { 16387598Sminkyu.jeong@arm.com predictedNotTakenIncorrect++; 16397598Sminkyu.jeong@arm.com } 16407598Sminkyu.jeong@arm.com } 16417598Sminkyu.jeong@arm.com } 16427598Sminkyu.jeong@arm.com} 16439944Smatt.horsnell@ARM.com 16449944Smatt.horsnell@ARM.com#endif//__CPU_O3_IEW_IMPL_IMPL_HH__ 1645