iew_impl.hh revision 2820
11689SN/A/* 22326SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 291689SN/A */ 301689SN/A 311060SN/A// @todo: Fix the instantaneous communication among all the stages within 321060SN/A// iew. There's a clear delay between issue and execute, yet backwards 331689SN/A// communication happens simultaneously. 341060SN/A 351060SN/A#include <queue> 361060SN/A 371060SN/A#include "base/timebuf.hh" 382292SN/A#include "cpu/o3/fu_pool.hh" 391717SN/A#include "cpu/o3/iew.hh" 401060SN/A 412292SN/Ausing namespace std; 421681SN/A 431681SN/Atemplate<class Impl> 442292SN/ADefaultIEW<Impl>::DefaultIEW(Params *params) 452326SN/A : // @todo: Make this into a parameter. 461061SN/A issueToExecQueue(5, 5), 471060SN/A instQueue(params), 481061SN/A ldstQueue(params), 492292SN/A fuPool(params->fuPool), 502292SN/A commitToIEWDelay(params->commitToIEWDelay), 512292SN/A renameToIEWDelay(params->renameToIEWDelay), 522292SN/A issueToExecuteDelay(params->issueToExecuteDelay), 532820Sktlim@umich.edu dispatchWidth(params->dispatchWidth), 542292SN/A issueWidth(params->issueWidth), 552820Sktlim@umich.edu wbOutstanding(0), 562820Sktlim@umich.edu wbWidth(params->wbWidth), 572307SN/A numThreads(params->numberOfThreads), 582307SN/A switchedOut(false) 591060SN/A{ 602292SN/A _status = Active; 612292SN/A exeStatus = Running; 622292SN/A wbStatus = Idle; 631060SN/A 641060SN/A // Setup wire to read instructions coming from issue. 651060SN/A fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay); 661060SN/A 671060SN/A // Instruction queue needs the queue between issue and execute. 681060SN/A instQueue.setIssueToExecuteQueue(&issueToExecQueue); 691681SN/A 702292SN/A instQueue.setIEW(this); 711681SN/A ldstQueue.setIEW(this); 722292SN/A 732292SN/A for (int i=0; i < numThreads; i++) { 742292SN/A dispatchStatus[i] = Running; 752292SN/A stalls[i].commit = false; 762292SN/A fetchRedirect[i] = false; 772292SN/A } 782292SN/A 792820Sktlim@umich.edu wbMax = wbWidth * params->wbDepth; 802820Sktlim@umich.edu 812292SN/A updateLSQNextCycle = false; 822292SN/A 832820Sktlim@umich.edu ableToIssue = true; 842820Sktlim@umich.edu 852292SN/A skidBufferMax = (3 * (renameToIEWDelay * params->renameWidth)) + issueWidth; 862292SN/A} 872292SN/A 882292SN/Atemplate <class Impl> 892292SN/Astd::string 902292SN/ADefaultIEW<Impl>::name() const 912292SN/A{ 922292SN/A return cpu->name() + ".iew"; 931060SN/A} 941060SN/A 951681SN/Atemplate <class Impl> 961062SN/Avoid 972292SN/ADefaultIEW<Impl>::regStats() 981062SN/A{ 992301SN/A using namespace Stats; 1002301SN/A 1011062SN/A instQueue.regStats(); 1022727Sktlim@umich.edu ldstQueue.regStats(); 1031062SN/A 1041062SN/A iewIdleCycles 1051062SN/A .name(name() + ".iewIdleCycles") 1061062SN/A .desc("Number of cycles IEW is idle"); 1071062SN/A 1081062SN/A iewSquashCycles 1091062SN/A .name(name() + ".iewSquashCycles") 1101062SN/A .desc("Number of cycles IEW is squashing"); 1111062SN/A 1121062SN/A iewBlockCycles 1131062SN/A .name(name() + ".iewBlockCycles") 1141062SN/A .desc("Number of cycles IEW is blocking"); 1151062SN/A 1161062SN/A iewUnblockCycles 1171062SN/A .name(name() + ".iewUnblockCycles") 1181062SN/A .desc("Number of cycles IEW is unblocking"); 1191062SN/A 1201062SN/A iewDispatchedInsts 1211062SN/A .name(name() + ".iewDispatchedInsts") 1221062SN/A .desc("Number of instructions dispatched to IQ"); 1231062SN/A 1241062SN/A iewDispSquashedInsts 1251062SN/A .name(name() + ".iewDispSquashedInsts") 1261062SN/A .desc("Number of squashed instructions skipped by dispatch"); 1271062SN/A 1281062SN/A iewDispLoadInsts 1291062SN/A .name(name() + ".iewDispLoadInsts") 1301062SN/A .desc("Number of dispatched load instructions"); 1311062SN/A 1321062SN/A iewDispStoreInsts 1331062SN/A .name(name() + ".iewDispStoreInsts") 1341062SN/A .desc("Number of dispatched store instructions"); 1351062SN/A 1361062SN/A iewDispNonSpecInsts 1371062SN/A .name(name() + ".iewDispNonSpecInsts") 1381062SN/A .desc("Number of dispatched non-speculative instructions"); 1391062SN/A 1401062SN/A iewIQFullEvents 1411062SN/A .name(name() + ".iewIQFullEvents") 1421062SN/A .desc("Number of times the IQ has become full, causing a stall"); 1431062SN/A 1442292SN/A iewLSQFullEvents 1452292SN/A .name(name() + ".iewLSQFullEvents") 1462292SN/A .desc("Number of times the LSQ has become full, causing a stall"); 1472292SN/A 1481062SN/A memOrderViolationEvents 1491062SN/A .name(name() + ".memOrderViolationEvents") 1501062SN/A .desc("Number of memory order violations"); 1511062SN/A 1521062SN/A predictedTakenIncorrect 1531062SN/A .name(name() + ".predictedTakenIncorrect") 1541062SN/A .desc("Number of branches that were predicted taken incorrectly"); 1552292SN/A 1562292SN/A predictedNotTakenIncorrect 1572292SN/A .name(name() + ".predictedNotTakenIncorrect") 1582292SN/A .desc("Number of branches that were predicted not taken incorrectly"); 1592292SN/A 1602292SN/A branchMispredicts 1612292SN/A .name(name() + ".branchMispredicts") 1622292SN/A .desc("Number of branch mispredicts detected at execute"); 1632292SN/A 1642292SN/A branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect; 1652301SN/A 1662727Sktlim@umich.edu iewExecutedInsts 1672727Sktlim@umich.edu .name(name() + ".EXEC:insts") 1682727Sktlim@umich.edu .desc("Number of executed instructions"); 1692727Sktlim@umich.edu 1702727Sktlim@umich.edu iewExecLoadInsts 1712727Sktlim@umich.edu .init(cpu->number_of_threads) 1722727Sktlim@umich.edu .name(name() + ".EXEC:loads") 1732727Sktlim@umich.edu .desc("Number of load instructions executed") 1742727Sktlim@umich.edu .flags(total); 1752727Sktlim@umich.edu 1762727Sktlim@umich.edu iewExecSquashedInsts 1772727Sktlim@umich.edu .name(name() + ".EXEC:squashedInsts") 1782727Sktlim@umich.edu .desc("Number of squashed instructions skipped in execute"); 1792727Sktlim@umich.edu 1802727Sktlim@umich.edu iewExecutedSwp 1812301SN/A .init(cpu->number_of_threads) 1822301SN/A .name(name() + ".EXEC:swp") 1832301SN/A .desc("number of swp insts executed") 1842727Sktlim@umich.edu .flags(total); 1852301SN/A 1862727Sktlim@umich.edu iewExecutedNop 1872301SN/A .init(cpu->number_of_threads) 1882301SN/A .name(name() + ".EXEC:nop") 1892301SN/A .desc("number of nop insts executed") 1902727Sktlim@umich.edu .flags(total); 1912301SN/A 1922727Sktlim@umich.edu iewExecutedRefs 1932301SN/A .init(cpu->number_of_threads) 1942301SN/A .name(name() + ".EXEC:refs") 1952301SN/A .desc("number of memory reference insts executed") 1962727Sktlim@umich.edu .flags(total); 1972301SN/A 1982727Sktlim@umich.edu iewExecutedBranches 1992301SN/A .init(cpu->number_of_threads) 2002301SN/A .name(name() + ".EXEC:branches") 2012301SN/A .desc("Number of branches executed") 2022727Sktlim@umich.edu .flags(total); 2032301SN/A 2042301SN/A iewExecStoreInsts 2052301SN/A .name(name() + ".EXEC:stores") 2062301SN/A .desc("Number of stores executed") 2072727Sktlim@umich.edu .flags(total); 2082727Sktlim@umich.edu iewExecStoreInsts = iewExecutedRefs - iewExecLoadInsts; 2092727Sktlim@umich.edu 2102727Sktlim@umich.edu iewExecRate 2112727Sktlim@umich.edu .name(name() + ".EXEC:rate") 2122727Sktlim@umich.edu .desc("Inst execution rate") 2132727Sktlim@umich.edu .flags(total); 2142727Sktlim@umich.edu 2152727Sktlim@umich.edu iewExecRate = iewExecutedInsts / cpu->numCycles; 2162301SN/A 2172301SN/A iewInstsToCommit 2182301SN/A .init(cpu->number_of_threads) 2192301SN/A .name(name() + ".WB:sent") 2202301SN/A .desc("cumulative count of insts sent to commit") 2212727Sktlim@umich.edu .flags(total); 2222301SN/A 2232326SN/A writebackCount 2242301SN/A .init(cpu->number_of_threads) 2252301SN/A .name(name() + ".WB:count") 2262301SN/A .desc("cumulative count of insts written-back") 2272727Sktlim@umich.edu .flags(total); 2282301SN/A 2292326SN/A producerInst 2302301SN/A .init(cpu->number_of_threads) 2312301SN/A .name(name() + ".WB:producers") 2322301SN/A .desc("num instructions producing a value") 2332727Sktlim@umich.edu .flags(total); 2342301SN/A 2352326SN/A consumerInst 2362301SN/A .init(cpu->number_of_threads) 2372301SN/A .name(name() + ".WB:consumers") 2382301SN/A .desc("num instructions consuming a value") 2392727Sktlim@umich.edu .flags(total); 2402301SN/A 2412326SN/A wbPenalized 2422301SN/A .init(cpu->number_of_threads) 2432301SN/A .name(name() + ".WB:penalized") 2442301SN/A .desc("number of instrctions required to write to 'other' IQ") 2452727Sktlim@umich.edu .flags(total); 2462301SN/A 2472326SN/A wbPenalizedRate 2482301SN/A .name(name() + ".WB:penalized_rate") 2492301SN/A .desc ("fraction of instructions written-back that wrote to 'other' IQ") 2502727Sktlim@umich.edu .flags(total); 2512301SN/A 2522326SN/A wbPenalizedRate = wbPenalized / writebackCount; 2532301SN/A 2542326SN/A wbFanout 2552301SN/A .name(name() + ".WB:fanout") 2562301SN/A .desc("average fanout of values written-back") 2572727Sktlim@umich.edu .flags(total); 2582301SN/A 2592326SN/A wbFanout = producerInst / consumerInst; 2602301SN/A 2612326SN/A wbRate 2622301SN/A .name(name() + ".WB:rate") 2632301SN/A .desc("insts written-back per cycle") 2642727Sktlim@umich.edu .flags(total); 2652326SN/A wbRate = writebackCount / cpu->numCycles; 2661062SN/A} 2671062SN/A 2681681SN/Atemplate<class Impl> 2691060SN/Avoid 2702292SN/ADefaultIEW<Impl>::initStage() 2711060SN/A{ 2722292SN/A for (int tid=0; tid < numThreads; tid++) { 2732292SN/A toRename->iewInfo[tid].usedIQ = true; 2742292SN/A toRename->iewInfo[tid].freeIQEntries = 2752292SN/A instQueue.numFreeEntries(tid); 2762292SN/A 2772292SN/A toRename->iewInfo[tid].usedLSQ = true; 2782292SN/A toRename->iewInfo[tid].freeLSQEntries = 2792292SN/A ldstQueue.numFreeEntries(tid); 2802292SN/A } 2812292SN/A} 2822292SN/A 2832292SN/Atemplate<class Impl> 2842292SN/Avoid 2852733Sktlim@umich.eduDefaultIEW<Impl>::setCPU(O3CPU *cpu_ptr) 2862292SN/A{ 2872292SN/A DPRINTF(IEW, "Setting CPU pointer.\n"); 2881060SN/A cpu = cpu_ptr; 2891060SN/A 2901060SN/A instQueue.setCPU(cpu_ptr); 2911061SN/A ldstQueue.setCPU(cpu_ptr); 2922292SN/A 2932733Sktlim@umich.edu cpu->activateStage(O3CPU::IEWIdx); 2941060SN/A} 2951060SN/A 2961681SN/Atemplate<class Impl> 2971060SN/Avoid 2982292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 2991060SN/A{ 3002292SN/A DPRINTF(IEW, "Setting time buffer pointer.\n"); 3011060SN/A timeBuffer = tb_ptr; 3021060SN/A 3031060SN/A // Setup wire to read information from time buffer, from commit. 3041060SN/A fromCommit = timeBuffer->getWire(-commitToIEWDelay); 3051060SN/A 3061060SN/A // Setup wire to write information back to previous stages. 3071060SN/A toRename = timeBuffer->getWire(0); 3081060SN/A 3092292SN/A toFetch = timeBuffer->getWire(0); 3102292SN/A 3111060SN/A // Instruction queue also needs main time buffer. 3121060SN/A instQueue.setTimeBuffer(tb_ptr); 3131060SN/A} 3141060SN/A 3151681SN/Atemplate<class Impl> 3161060SN/Avoid 3172292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3181060SN/A{ 3192292SN/A DPRINTF(IEW, "Setting rename queue pointer.\n"); 3201060SN/A renameQueue = rq_ptr; 3211060SN/A 3221060SN/A // Setup wire to read information from rename queue. 3231060SN/A fromRename = renameQueue->getWire(-renameToIEWDelay); 3241060SN/A} 3251060SN/A 3261681SN/Atemplate<class Impl> 3271060SN/Avoid 3282292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3291060SN/A{ 3302292SN/A DPRINTF(IEW, "Setting IEW queue pointer.\n"); 3311060SN/A iewQueue = iq_ptr; 3321060SN/A 3331060SN/A // Setup wire to write instructions to commit. 3341060SN/A toCommit = iewQueue->getWire(0); 3351060SN/A} 3361060SN/A 3371681SN/Atemplate<class Impl> 3381060SN/Avoid 3392292SN/ADefaultIEW<Impl>::setActiveThreads(list<unsigned> *at_ptr) 3401060SN/A{ 3412292SN/A DPRINTF(IEW, "Setting active threads list pointer.\n"); 3422292SN/A activeThreads = at_ptr; 3432292SN/A 3442292SN/A ldstQueue.setActiveThreads(at_ptr); 3452292SN/A instQueue.setActiveThreads(at_ptr); 3461060SN/A} 3471060SN/A 3481681SN/Atemplate<class Impl> 3491060SN/Avoid 3502292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr) 3511060SN/A{ 3522292SN/A DPRINTF(IEW, "Setting scoreboard pointer.\n"); 3532292SN/A scoreboard = sb_ptr; 3541060SN/A} 3551060SN/A 3562307SN/Atemplate <class Impl> 3572307SN/Avoid 3582307SN/ADefaultIEW<Impl>::switchOut() 3592307SN/A{ 3602348SN/A // IEW is ready to switch out at any time. 3612316SN/A cpu->signalSwitched(); 3621681SN/A} 3631681SN/A 3642316SN/Atemplate <class Impl> 3651681SN/Avoid 3662316SN/ADefaultIEW<Impl>::doSwitchOut() 3671681SN/A{ 3682348SN/A // Clear any state. 3692307SN/A switchedOut = true; 3701681SN/A 3712307SN/A instQueue.switchOut(); 3722307SN/A ldstQueue.switchOut(); 3732307SN/A fuPool->switchOut(); 3742307SN/A 3752307SN/A for (int i = 0; i < numThreads; i++) { 3762307SN/A while (!insts[i].empty()) 3772307SN/A insts[i].pop(); 3782307SN/A while (!skidBuffer[i].empty()) 3792307SN/A skidBuffer[i].pop(); 3802307SN/A } 3811681SN/A} 3821681SN/A 3832307SN/Atemplate <class Impl> 3841681SN/Avoid 3852307SN/ADefaultIEW<Impl>::takeOverFrom() 3861060SN/A{ 3872348SN/A // Reset all state. 3882307SN/A _status = Active; 3892307SN/A exeStatus = Running; 3902307SN/A wbStatus = Idle; 3912307SN/A switchedOut = false; 3921060SN/A 3932307SN/A instQueue.takeOverFrom(); 3942307SN/A ldstQueue.takeOverFrom(); 3952307SN/A fuPool->takeOverFrom(); 3961060SN/A 3972307SN/A initStage(); 3982307SN/A cpu->activityThisCycle(); 3991060SN/A 4002307SN/A for (int i=0; i < numThreads; i++) { 4012307SN/A dispatchStatus[i] = Running; 4022307SN/A stalls[i].commit = false; 4032307SN/A fetchRedirect[i] = false; 4042307SN/A } 4051060SN/A 4062307SN/A updateLSQNextCycle = false; 4072307SN/A 4082307SN/A // @todo: Fix hardcoded number 4092307SN/A for (int i = 0; i < 6; ++i) { 4102307SN/A issueToExecQueue.advance(); 4111060SN/A } 4121060SN/A} 4131060SN/A 4141681SN/Atemplate<class Impl> 4151060SN/Avoid 4162292SN/ADefaultIEW<Impl>::squash(unsigned tid) 4172107SN/A{ 4182292SN/A DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", 4192292SN/A tid); 4202107SN/A 4212292SN/A // Tell the IQ to start squashing. 4222292SN/A instQueue.squash(tid); 4232107SN/A 4242292SN/A // Tell the LDSTQ to start squashing. 4252326SN/A ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid); 4262107SN/A 4272292SN/A updatedQueues = true; 4282107SN/A 4292292SN/A // Clear the skid buffer in case it has any data in it. 4302292SN/A while (!skidBuffer[tid].empty()) { 4312107SN/A 4322292SN/A if (skidBuffer[tid].front()->isLoad() || 4332292SN/A skidBuffer[tid].front()->isStore() ) { 4342292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 4352292SN/A } 4362107SN/A 4372292SN/A toRename->iewInfo[tid].dispatched++; 4382107SN/A 4392292SN/A skidBuffer[tid].pop(); 4402292SN/A } 4412107SN/A 4422702Sktlim@umich.edu emptyRenameInsts(tid); 4432107SN/A} 4442107SN/A 4452107SN/Atemplate<class Impl> 4462107SN/Avoid 4472292SN/ADefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, unsigned tid) 4482292SN/A{ 4492292SN/A DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %#x " 4502292SN/A "[sn:%i].\n", tid, inst->readPC(), inst->seqNum); 4512292SN/A 4522292SN/A toCommit->squash[tid] = true; 4532292SN/A toCommit->squashedSeqNum[tid] = inst->seqNum; 4542292SN/A toCommit->mispredPC[tid] = inst->readPC(); 4552292SN/A toCommit->nextPC[tid] = inst->readNextPC(); 4562292SN/A toCommit->branchMispredict[tid] = true; 4572292SN/A toCommit->branchTaken[tid] = inst->readNextPC() != 4582292SN/A (inst->readPC() + sizeof(TheISA::MachInst)); 4592292SN/A 4602292SN/A toCommit->includeSquashInst[tid] = false; 4612292SN/A 4622292SN/A wroteToTimeBuffer = true; 4632292SN/A} 4642292SN/A 4652292SN/Atemplate<class Impl> 4662292SN/Avoid 4672292SN/ADefaultIEW<Impl>::squashDueToMemOrder(DynInstPtr &inst, unsigned tid) 4682292SN/A{ 4692292SN/A DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, " 4702292SN/A "PC: %#x [sn:%i].\n", tid, inst->readPC(), inst->seqNum); 4712292SN/A 4722292SN/A toCommit->squash[tid] = true; 4732292SN/A toCommit->squashedSeqNum[tid] = inst->seqNum; 4742292SN/A toCommit->nextPC[tid] = inst->readNextPC(); 4752292SN/A 4762292SN/A toCommit->includeSquashInst[tid] = false; 4772292SN/A 4782292SN/A wroteToTimeBuffer = true; 4792292SN/A} 4802292SN/A 4812292SN/Atemplate<class Impl> 4822292SN/Avoid 4832292SN/ADefaultIEW<Impl>::squashDueToMemBlocked(DynInstPtr &inst, unsigned tid) 4842292SN/A{ 4852292SN/A DPRINTF(IEW, "[tid:%i]: Memory blocked, squashing load and younger insts, " 4862292SN/A "PC: %#x [sn:%i].\n", tid, inst->readPC(), inst->seqNum); 4872292SN/A 4882292SN/A toCommit->squash[tid] = true; 4892292SN/A toCommit->squashedSeqNum[tid] = inst->seqNum; 4902292SN/A toCommit->nextPC[tid] = inst->readPC(); 4912292SN/A 4922348SN/A // Must include the broadcasted SN in the squash. 4932292SN/A toCommit->includeSquashInst[tid] = true; 4942292SN/A 4952292SN/A ldstQueue.setLoadBlockedHandled(tid); 4962292SN/A 4972292SN/A wroteToTimeBuffer = true; 4982292SN/A} 4992292SN/A 5002292SN/Atemplate<class Impl> 5012292SN/Avoid 5022292SN/ADefaultIEW<Impl>::block(unsigned tid) 5032292SN/A{ 5042292SN/A DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid); 5052292SN/A 5062292SN/A if (dispatchStatus[tid] != Blocked && 5072292SN/A dispatchStatus[tid] != Unblocking) { 5082292SN/A toRename->iewBlock[tid] = true; 5092292SN/A wroteToTimeBuffer = true; 5102292SN/A } 5112292SN/A 5122292SN/A // Add the current inputs to the skid buffer so they can be 5132292SN/A // reprocessed when this stage unblocks. 5142292SN/A skidInsert(tid); 5152292SN/A 5162292SN/A dispatchStatus[tid] = Blocked; 5172292SN/A} 5182292SN/A 5192292SN/Atemplate<class Impl> 5202292SN/Avoid 5212292SN/ADefaultIEW<Impl>::unblock(unsigned tid) 5222292SN/A{ 5232292SN/A DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid " 5242292SN/A "buffer %u.\n",tid, tid); 5252292SN/A 5262292SN/A // If the skid bufffer is empty, signal back to previous stages to unblock. 5272292SN/A // Also switch status to running. 5282292SN/A if (skidBuffer[tid].empty()) { 5292292SN/A toRename->iewUnblock[tid] = true; 5302292SN/A wroteToTimeBuffer = true; 5312292SN/A DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid); 5322292SN/A dispatchStatus[tid] = Running; 5332292SN/A } 5342292SN/A} 5352292SN/A 5362292SN/Atemplate<class Impl> 5372292SN/Avoid 5382292SN/ADefaultIEW<Impl>::wakeDependents(DynInstPtr &inst) 5391060SN/A{ 5401681SN/A instQueue.wakeDependents(inst); 5411060SN/A} 5421060SN/A 5432292SN/Atemplate<class Impl> 5442292SN/Avoid 5452292SN/ADefaultIEW<Impl>::rescheduleMemInst(DynInstPtr &inst) 5462292SN/A{ 5472292SN/A instQueue.rescheduleMemInst(inst); 5482292SN/A} 5491681SN/A 5501681SN/Atemplate<class Impl> 5511060SN/Avoid 5522292SN/ADefaultIEW<Impl>::replayMemInst(DynInstPtr &inst) 5531060SN/A{ 5542292SN/A instQueue.replayMemInst(inst); 5552292SN/A} 5561060SN/A 5572292SN/Atemplate<class Impl> 5582292SN/Avoid 5592292SN/ADefaultIEW<Impl>::instToCommit(DynInstPtr &inst) 5602292SN/A{ 5612292SN/A // First check the time slot that this instruction will write 5622292SN/A // to. If there are free write ports at the time, then go ahead 5632292SN/A // and write the instruction to that time. If there are not, 5642292SN/A // keep looking back to see where's the first time there's a 5652326SN/A // free slot. 5662292SN/A while ((*iewQueue)[wbCycle].insts[wbNumInst]) { 5672292SN/A ++wbNumInst; 5682820Sktlim@umich.edu if (wbNumInst == wbWidth) { 5692292SN/A ++wbCycle; 5702292SN/A wbNumInst = 0; 5712292SN/A } 5722292SN/A 5732820Sktlim@umich.edu assert((wbCycle * wbWidth + wbNumInst) < wbMax); 5742292SN/A } 5752292SN/A 5762292SN/A // Add finished instruction to queue to commit. 5772292SN/A (*iewQueue)[wbCycle].insts[wbNumInst] = inst; 5782292SN/A (*iewQueue)[wbCycle].size++; 5792292SN/A} 5802292SN/A 5812292SN/Atemplate <class Impl> 5822292SN/Aunsigned 5832292SN/ADefaultIEW<Impl>::validInstsFromRename() 5842292SN/A{ 5852292SN/A unsigned inst_count = 0; 5862292SN/A 5872292SN/A for (int i=0; i<fromRename->size; i++) { 5882731Sktlim@umich.edu if (!fromRename->insts[i]->isSquashed()) 5892292SN/A inst_count++; 5902292SN/A } 5912292SN/A 5922292SN/A return inst_count; 5932292SN/A} 5942292SN/A 5952292SN/Atemplate<class Impl> 5962292SN/Avoid 5972292SN/ADefaultIEW<Impl>::skidInsert(unsigned tid) 5982292SN/A{ 5992292SN/A DynInstPtr inst = NULL; 6002292SN/A 6012292SN/A while (!insts[tid].empty()) { 6022292SN/A inst = insts[tid].front(); 6032292SN/A 6042292SN/A insts[tid].pop(); 6052292SN/A 6062292SN/A DPRINTF(Decode,"[tid:%i]: Inserting [sn:%lli] PC:%#x into " 6072292SN/A "dispatch skidBuffer %i\n",tid, inst->seqNum, 6082292SN/A inst->readPC(),tid); 6092292SN/A 6102292SN/A skidBuffer[tid].push(inst); 6112292SN/A } 6122292SN/A 6132292SN/A assert(skidBuffer[tid].size() <= skidBufferMax && 6142292SN/A "Skidbuffer Exceeded Max Size"); 6152292SN/A} 6162292SN/A 6172292SN/Atemplate<class Impl> 6182292SN/Aint 6192292SN/ADefaultIEW<Impl>::skidCount() 6202292SN/A{ 6212292SN/A int max=0; 6222292SN/A 6232292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6242292SN/A 6252292SN/A while (threads != (*activeThreads).end()) { 6262292SN/A unsigned thread_count = skidBuffer[*threads++].size(); 6272292SN/A if (max < thread_count) 6282292SN/A max = thread_count; 6292292SN/A } 6302292SN/A 6312292SN/A return max; 6322292SN/A} 6332292SN/A 6342292SN/Atemplate<class Impl> 6352292SN/Abool 6362292SN/ADefaultIEW<Impl>::skidsEmpty() 6372292SN/A{ 6382292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6392292SN/A 6402292SN/A while (threads != (*activeThreads).end()) { 6412292SN/A if (!skidBuffer[*threads++].empty()) 6422292SN/A return false; 6432292SN/A } 6442292SN/A 6452292SN/A return true; 6461062SN/A} 6471062SN/A 6481681SN/Atemplate <class Impl> 6491062SN/Avoid 6502292SN/ADefaultIEW<Impl>::updateStatus() 6511062SN/A{ 6522292SN/A bool any_unblocking = false; 6531062SN/A 6542292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6551062SN/A 6562292SN/A threads = (*activeThreads).begin(); 6571062SN/A 6582292SN/A while (threads != (*activeThreads).end()) { 6592292SN/A unsigned tid = *threads++; 6601062SN/A 6612292SN/A if (dispatchStatus[tid] == Unblocking) { 6622292SN/A any_unblocking = true; 6632292SN/A break; 6642292SN/A } 6652292SN/A } 6661062SN/A 6672292SN/A // If there are no ready instructions waiting to be scheduled by the IQ, 6682292SN/A // and there's no stores waiting to write back, and dispatch is not 6692292SN/A // unblocking, then there is no internal activity for the IEW stage. 6702292SN/A if (_status == Active && !instQueue.hasReadyInsts() && 6712292SN/A !ldstQueue.willWB() && !any_unblocking) { 6722292SN/A DPRINTF(IEW, "IEW switching to idle\n"); 6731062SN/A 6742292SN/A deactivateStage(); 6751062SN/A 6762292SN/A _status = Inactive; 6772292SN/A } else if (_status == Inactive && (instQueue.hasReadyInsts() || 6782292SN/A ldstQueue.willWB() || 6792292SN/A any_unblocking)) { 6802292SN/A // Otherwise there is internal activity. Set to active. 6812292SN/A DPRINTF(IEW, "IEW switching to active\n"); 6821062SN/A 6832292SN/A activateStage(); 6841062SN/A 6852292SN/A _status = Active; 6861062SN/A } 6871062SN/A} 6881062SN/A 6891681SN/Atemplate <class Impl> 6901062SN/Avoid 6912292SN/ADefaultIEW<Impl>::resetEntries() 6921062SN/A{ 6932292SN/A instQueue.resetEntries(); 6942292SN/A ldstQueue.resetEntries(); 6952292SN/A} 6961062SN/A 6972292SN/Atemplate <class Impl> 6982292SN/Avoid 6992292SN/ADefaultIEW<Impl>::readStallSignals(unsigned tid) 7002292SN/A{ 7012292SN/A if (fromCommit->commitBlock[tid]) { 7022292SN/A stalls[tid].commit = true; 7032292SN/A } 7041062SN/A 7052292SN/A if (fromCommit->commitUnblock[tid]) { 7062292SN/A assert(stalls[tid].commit); 7072292SN/A stalls[tid].commit = false; 7082292SN/A } 7092292SN/A} 7102292SN/A 7112292SN/Atemplate <class Impl> 7122292SN/Abool 7132292SN/ADefaultIEW<Impl>::checkStall(unsigned tid) 7142292SN/A{ 7152292SN/A bool ret_val(false); 7162292SN/A 7172292SN/A if (stalls[tid].commit) { 7182292SN/A DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid); 7192292SN/A ret_val = true; 7202292SN/A } else if (instQueue.isFull(tid)) { 7212292SN/A DPRINTF(IEW,"[tid:%i]: Stall: IQ is full.\n",tid); 7222292SN/A ret_val = true; 7232292SN/A } else if (ldstQueue.isFull(tid)) { 7242292SN/A DPRINTF(IEW,"[tid:%i]: Stall: LSQ is full\n",tid); 7252292SN/A 7262292SN/A if (ldstQueue.numLoads(tid) > 0 ) { 7272292SN/A 7282292SN/A DPRINTF(IEW,"[tid:%i]: LSQ oldest load: [sn:%i] \n", 7292292SN/A tid,ldstQueue.getLoadHeadSeqNum(tid)); 7302292SN/A } 7312292SN/A 7322292SN/A if (ldstQueue.numStores(tid) > 0) { 7332292SN/A 7342292SN/A DPRINTF(IEW,"[tid:%i]: LSQ oldest store: [sn:%i] \n", 7352292SN/A tid,ldstQueue.getStoreHeadSeqNum(tid)); 7362292SN/A } 7372292SN/A 7382292SN/A ret_val = true; 7392292SN/A } else if (ldstQueue.isStalled(tid)) { 7402292SN/A DPRINTF(IEW,"[tid:%i]: Stall: LSQ stall detected.\n",tid); 7412292SN/A ret_val = true; 7422292SN/A } 7432292SN/A 7442292SN/A return ret_val; 7452292SN/A} 7462292SN/A 7472292SN/Atemplate <class Impl> 7482292SN/Avoid 7492292SN/ADefaultIEW<Impl>::checkSignalsAndUpdate(unsigned tid) 7502292SN/A{ 7512292SN/A // Check if there's a squash signal, squash if there is 7522292SN/A // Check stall signals, block if there is. 7532292SN/A // If status was Blocked 7542292SN/A // if so then go to unblocking 7552292SN/A // If status was Squashing 7562292SN/A // check if squashing is not high. Switch to running this cycle. 7572292SN/A 7582292SN/A readStallSignals(tid); 7592292SN/A 7602292SN/A if (fromCommit->commitInfo[tid].squash) { 7612292SN/A squash(tid); 7622292SN/A 7632292SN/A if (dispatchStatus[tid] == Blocked || 7642292SN/A dispatchStatus[tid] == Unblocking) { 7652292SN/A toRename->iewUnblock[tid] = true; 7662292SN/A wroteToTimeBuffer = true; 7672292SN/A } 7682292SN/A 7692292SN/A dispatchStatus[tid] = Squashing; 7702292SN/A 7712292SN/A fetchRedirect[tid] = false; 7722292SN/A return; 7732292SN/A } 7742292SN/A 7752292SN/A if (fromCommit->commitInfo[tid].robSquashing) { 7762702Sktlim@umich.edu DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n", tid); 7772292SN/A 7782292SN/A dispatchStatus[tid] = Squashing; 7792292SN/A 7802702Sktlim@umich.edu emptyRenameInsts(tid); 7812702Sktlim@umich.edu wroteToTimeBuffer = true; 7822292SN/A return; 7832292SN/A } 7842292SN/A 7852292SN/A if (checkStall(tid)) { 7862292SN/A block(tid); 7872292SN/A dispatchStatus[tid] = Blocked; 7882292SN/A return; 7892292SN/A } 7902292SN/A 7912292SN/A if (dispatchStatus[tid] == Blocked) { 7922292SN/A // Status from previous cycle was blocked, but there are no more stall 7932292SN/A // conditions. Switch over to unblocking. 7942292SN/A DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n", 7952292SN/A tid); 7962292SN/A 7972292SN/A dispatchStatus[tid] = Unblocking; 7982292SN/A 7992292SN/A unblock(tid); 8002292SN/A 8012292SN/A return; 8022292SN/A } 8032292SN/A 8042292SN/A if (dispatchStatus[tid] == Squashing) { 8052292SN/A // Switch status to running if rename isn't being told to block or 8062292SN/A // squash this cycle. 8072292SN/A DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n", 8082292SN/A tid); 8092292SN/A 8102292SN/A dispatchStatus[tid] = Running; 8112292SN/A 8122292SN/A return; 8132292SN/A } 8142292SN/A} 8152292SN/A 8162292SN/Atemplate <class Impl> 8172292SN/Avoid 8182292SN/ADefaultIEW<Impl>::sortInsts() 8192292SN/A{ 8202292SN/A int insts_from_rename = fromRename->size; 8212326SN/A#ifdef DEBUG 8222292SN/A for (int i = 0; i < numThreads; i++) 8232292SN/A assert(insts[i].empty()); 8242326SN/A#endif 8252292SN/A for (int i = 0; i < insts_from_rename; ++i) { 8262292SN/A insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]); 8272292SN/A } 8282292SN/A} 8292292SN/A 8302292SN/Atemplate <class Impl> 8312292SN/Avoid 8322702Sktlim@umich.eduDefaultIEW<Impl>::emptyRenameInsts(unsigned tid) 8332702Sktlim@umich.edu{ 8342702Sktlim@umich.edu while (!insts[tid].empty()) { 8352702Sktlim@umich.edu if (insts[tid].front()->isLoad() || 8362702Sktlim@umich.edu insts[tid].front()->isStore() ) { 8372702Sktlim@umich.edu toRename->iewInfo[tid].dispatchedToLSQ++; 8382702Sktlim@umich.edu } 8392702Sktlim@umich.edu 8402702Sktlim@umich.edu toRename->iewInfo[tid].dispatched++; 8412702Sktlim@umich.edu 8422702Sktlim@umich.edu insts[tid].pop(); 8432702Sktlim@umich.edu } 8442702Sktlim@umich.edu} 8452702Sktlim@umich.edu 8462702Sktlim@umich.edutemplate <class Impl> 8472702Sktlim@umich.eduvoid 8482292SN/ADefaultIEW<Impl>::wakeCPU() 8492292SN/A{ 8502292SN/A cpu->wakeCPU(); 8512292SN/A} 8522292SN/A 8532292SN/Atemplate <class Impl> 8542292SN/Avoid 8552292SN/ADefaultIEW<Impl>::activityThisCycle() 8562292SN/A{ 8572292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 8582292SN/A cpu->activityThisCycle(); 8592292SN/A} 8602292SN/A 8612292SN/Atemplate <class Impl> 8622292SN/Ainline void 8632292SN/ADefaultIEW<Impl>::activateStage() 8642292SN/A{ 8652292SN/A DPRINTF(Activity, "Activating stage.\n"); 8662733Sktlim@umich.edu cpu->activateStage(O3CPU::IEWIdx); 8672292SN/A} 8682292SN/A 8692292SN/Atemplate <class Impl> 8702292SN/Ainline void 8712292SN/ADefaultIEW<Impl>::deactivateStage() 8722292SN/A{ 8732292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 8742733Sktlim@umich.edu cpu->deactivateStage(O3CPU::IEWIdx); 8752292SN/A} 8762292SN/A 8772292SN/Atemplate<class Impl> 8782292SN/Avoid 8792292SN/ADefaultIEW<Impl>::dispatch(unsigned tid) 8802292SN/A{ 8812292SN/A // If status is Running or idle, 8822292SN/A // call dispatchInsts() 8832292SN/A // If status is Unblocking, 8842292SN/A // buffer any instructions coming from rename 8852292SN/A // continue trying to empty skid buffer 8862292SN/A // check if stall conditions have passed 8872292SN/A 8882292SN/A if (dispatchStatus[tid] == Blocked) { 8892292SN/A ++iewBlockCycles; 8902292SN/A 8912292SN/A } else if (dispatchStatus[tid] == Squashing) { 8922292SN/A ++iewSquashCycles; 8932292SN/A } 8942292SN/A 8952292SN/A // Dispatch should try to dispatch as many instructions as its bandwidth 8962292SN/A // will allow, as long as it is not currently blocked. 8972292SN/A if (dispatchStatus[tid] == Running || 8982292SN/A dispatchStatus[tid] == Idle) { 8992292SN/A DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run " 9002292SN/A "dispatch.\n", tid); 9012292SN/A 9022292SN/A dispatchInsts(tid); 9032292SN/A } else if (dispatchStatus[tid] == Unblocking) { 9042292SN/A // Make sure that the skid buffer has something in it if the 9052292SN/A // status is unblocking. 9062292SN/A assert(!skidsEmpty()); 9072292SN/A 9082292SN/A // If the status was unblocking, then instructions from the skid 9092292SN/A // buffer were used. Remove those instructions and handle 9102292SN/A // the rest of unblocking. 9112292SN/A dispatchInsts(tid); 9122292SN/A 9132292SN/A ++iewUnblockCycles; 9142292SN/A 9152292SN/A if (validInstsFromRename() && dispatchedAllInsts) { 9162292SN/A // Add the current inputs to the skid buffer so they can be 9172292SN/A // reprocessed when this stage unblocks. 9182292SN/A skidInsert(tid); 9192292SN/A } 9202292SN/A 9212292SN/A unblock(tid); 9222292SN/A } 9232292SN/A} 9242292SN/A 9252292SN/Atemplate <class Impl> 9262292SN/Avoid 9272292SN/ADefaultIEW<Impl>::dispatchInsts(unsigned tid) 9282292SN/A{ 9292292SN/A dispatchedAllInsts = true; 9302292SN/A 9312292SN/A // Obtain instructions from skid buffer if unblocking, or queue from rename 9322292SN/A // otherwise. 9332292SN/A std::queue<DynInstPtr> &insts_to_dispatch = 9342292SN/A dispatchStatus[tid] == Unblocking ? 9352292SN/A skidBuffer[tid] : insts[tid]; 9362292SN/A 9372292SN/A int insts_to_add = insts_to_dispatch.size(); 9382292SN/A 9392292SN/A DynInstPtr inst; 9402292SN/A bool add_to_iq = false; 9412292SN/A int dis_num_inst = 0; 9422292SN/A 9432292SN/A // Loop through the instructions, putting them in the instruction 9442292SN/A // queue. 9452292SN/A for ( ; dis_num_inst < insts_to_add && 9462820Sktlim@umich.edu dis_num_inst < dispatchWidth; 9472292SN/A ++dis_num_inst) 9482292SN/A { 9492292SN/A inst = insts_to_dispatch.front(); 9502292SN/A 9512292SN/A if (dispatchStatus[tid] == Unblocking) { 9522292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid " 9532292SN/A "buffer\n", tid); 9542292SN/A } 9552292SN/A 9562292SN/A // Make sure there's a valid instruction there. 9572292SN/A assert(inst); 9582292SN/A 9592292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %#x [sn:%lli] [tid:%i] to " 9602292SN/A "IQ.\n", 9612292SN/A tid, inst->readPC(), inst->seqNum, inst->threadNumber); 9622292SN/A 9632292SN/A // Be sure to mark these instructions as ready so that the 9642292SN/A // commit stage can go ahead and execute them, and mark 9652292SN/A // them as issued so the IQ doesn't reprocess them. 9662292SN/A 9672292SN/A // Check for squashed instructions. 9682292SN/A if (inst->isSquashed()) { 9692292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, " 9702292SN/A "not adding to IQ.\n", tid); 9712292SN/A 9722292SN/A ++iewDispSquashedInsts; 9732292SN/A 9742292SN/A insts_to_dispatch.pop(); 9752292SN/A 9762292SN/A //Tell Rename That An Instruction has been processed 9772292SN/A if (inst->isLoad() || inst->isStore()) { 9782292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 9792292SN/A } 9802292SN/A toRename->iewInfo[tid].dispatched++; 9812292SN/A 9822292SN/A continue; 9832292SN/A } 9842292SN/A 9852292SN/A // Check for full conditions. 9862292SN/A if (instQueue.isFull(tid)) { 9872292SN/A DPRINTF(IEW, "[tid:%i]: Issue: IQ has become full.\n", tid); 9882292SN/A 9892292SN/A // Call function to start blocking. 9902292SN/A block(tid); 9912292SN/A 9922292SN/A // Set unblock to false. Special case where we are using 9932292SN/A // skidbuffer (unblocking) instructions but then we still 9942292SN/A // get full in the IQ. 9952292SN/A toRename->iewUnblock[tid] = false; 9962292SN/A 9972292SN/A dispatchedAllInsts = false; 9982292SN/A 9992292SN/A ++iewIQFullEvents; 10002292SN/A break; 10012292SN/A } else if (ldstQueue.isFull(tid)) { 10022292SN/A DPRINTF(IEW, "[tid:%i]: Issue: LSQ has become full.\n",tid); 10032292SN/A 10042292SN/A // Call function to start blocking. 10052292SN/A block(tid); 10062292SN/A 10072292SN/A // Set unblock to false. Special case where we are using 10082292SN/A // skidbuffer (unblocking) instructions but then we still 10092292SN/A // get full in the IQ. 10102292SN/A toRename->iewUnblock[tid] = false; 10112292SN/A 10122292SN/A dispatchedAllInsts = false; 10132292SN/A 10142292SN/A ++iewLSQFullEvents; 10152292SN/A break; 10162292SN/A } 10172292SN/A 10182292SN/A // Otherwise issue the instruction just fine. 10192292SN/A if (inst->isLoad()) { 10202292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10212292SN/A "encountered, adding to LSQ.\n", tid); 10222292SN/A 10232292SN/A // Reserve a spot in the load store queue for this 10242292SN/A // memory access. 10252292SN/A ldstQueue.insertLoad(inst); 10262292SN/A 10272292SN/A ++iewDispLoadInsts; 10282292SN/A 10292292SN/A add_to_iq = true; 10302292SN/A 10312292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10322292SN/A } else if (inst->isStore()) { 10332292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10342292SN/A "encountered, adding to LSQ.\n", tid); 10352292SN/A 10362292SN/A ldstQueue.insertStore(inst); 10372292SN/A 10382292SN/A ++iewDispStoreInsts; 10392292SN/A 10402336SN/A if (inst->isStoreConditional()) { 10412336SN/A // Store conditionals need to be set as "canCommit()" 10422336SN/A // so that commit can process them when they reach the 10432336SN/A // head of commit. 10442348SN/A // @todo: This is somewhat specific to Alpha. 10452292SN/A inst->setCanCommit(); 10462292SN/A instQueue.insertNonSpec(inst); 10472292SN/A add_to_iq = false; 10482292SN/A 10492292SN/A ++iewDispNonSpecInsts; 10502292SN/A } else { 10512292SN/A add_to_iq = true; 10522292SN/A } 10532292SN/A 10542292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10552292SN/A#if FULL_SYSTEM 10562292SN/A } else if (inst->isMemBarrier() || inst->isWriteBarrier()) { 10572326SN/A // Same as non-speculative stores. 10582292SN/A inst->setCanCommit(); 10592292SN/A instQueue.insertBarrier(inst); 10602292SN/A add_to_iq = false; 10612292SN/A#endif 10622292SN/A } else if (inst->isNonSpeculative()) { 10632292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction " 10642292SN/A "encountered, skipping.\n", tid); 10652292SN/A 10662326SN/A // Same as non-speculative stores. 10672292SN/A inst->setCanCommit(); 10682292SN/A 10692292SN/A // Specifically insert it as nonspeculative. 10702292SN/A instQueue.insertNonSpec(inst); 10712292SN/A 10722292SN/A ++iewDispNonSpecInsts; 10732292SN/A 10742292SN/A add_to_iq = false; 10752292SN/A } else if (inst->isNop()) { 10762292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, " 10772292SN/A "skipping.\n", tid); 10782292SN/A 10792292SN/A inst->setIssued(); 10802292SN/A inst->setExecuted(); 10812292SN/A inst->setCanCommit(); 10822292SN/A 10832326SN/A instQueue.recordProducer(inst); 10842292SN/A 10852727Sktlim@umich.edu iewExecutedNop[tid]++; 10862301SN/A 10872292SN/A add_to_iq = false; 10882292SN/A } else if (inst->isExecuted()) { 10892292SN/A assert(0 && "Instruction shouldn't be executed.\n"); 10902292SN/A DPRINTF(IEW, "Issue: Executed branch encountered, " 10912292SN/A "skipping.\n"); 10922292SN/A 10932292SN/A inst->setIssued(); 10942292SN/A inst->setCanCommit(); 10952292SN/A 10962326SN/A instQueue.recordProducer(inst); 10972292SN/A 10982292SN/A add_to_iq = false; 10992292SN/A } else { 11002292SN/A add_to_iq = true; 11012292SN/A } 11022292SN/A 11032292SN/A // If the instruction queue is not full, then add the 11042292SN/A // instruction. 11052292SN/A if (add_to_iq) { 11062292SN/A instQueue.insert(inst); 11072292SN/A } 11082292SN/A 11092292SN/A insts_to_dispatch.pop(); 11102292SN/A 11112292SN/A toRename->iewInfo[tid].dispatched++; 11122292SN/A 11132292SN/A ++iewDispatchedInsts; 11142292SN/A } 11152292SN/A 11162292SN/A if (!insts_to_dispatch.empty()) { 11172292SN/A DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n"); 11182292SN/A block(tid); 11192292SN/A toRename->iewUnblock[tid] = false; 11202292SN/A } 11212292SN/A 11222292SN/A if (dispatchStatus[tid] == Idle && dis_num_inst) { 11232292SN/A dispatchStatus[tid] = Running; 11242292SN/A 11252292SN/A updatedQueues = true; 11262292SN/A } 11272292SN/A 11282292SN/A dis_num_inst = 0; 11292292SN/A} 11302292SN/A 11312292SN/Atemplate <class Impl> 11322292SN/Avoid 11332292SN/ADefaultIEW<Impl>::printAvailableInsts() 11342292SN/A{ 11352292SN/A int inst = 0; 11362292SN/A 11372292SN/A cout << "Available Instructions: "; 11382292SN/A 11392292SN/A while (fromIssue->insts[inst]) { 11402292SN/A 11412292SN/A if (inst%3==0) cout << "\n\t"; 11422292SN/A 11432292SN/A cout << "PC: " << fromIssue->insts[inst]->readPC() 11442292SN/A << " TN: " << fromIssue->insts[inst]->threadNumber 11452292SN/A << " SN: " << fromIssue->insts[inst]->seqNum << " | "; 11462292SN/A 11472292SN/A inst++; 11482292SN/A 11492292SN/A } 11502292SN/A 11512292SN/A cout << "\n"; 11522292SN/A} 11532292SN/A 11542292SN/Atemplate <class Impl> 11552292SN/Avoid 11562292SN/ADefaultIEW<Impl>::executeInsts() 11572292SN/A{ 11582292SN/A wbNumInst = 0; 11592292SN/A wbCycle = 0; 11602292SN/A 11612292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 11622292SN/A 11632292SN/A while (threads != (*activeThreads).end()) { 11642292SN/A unsigned tid = *threads++; 11652292SN/A fetchRedirect[tid] = false; 11662292SN/A } 11672292SN/A 11682698Sktlim@umich.edu // Uncomment this if you want to see all available instructions. 11692698Sktlim@umich.edu// printAvailableInsts(); 11701062SN/A 11711062SN/A // Execute/writeback any instructions that are available. 11722333SN/A int insts_to_execute = fromIssue->size; 11732292SN/A int inst_num = 0; 11742333SN/A for (; inst_num < insts_to_execute; 11752326SN/A ++inst_num) { 11761062SN/A 11772292SN/A DPRINTF(IEW, "Execute: Executing instructions from IQ.\n"); 11781062SN/A 11792333SN/A DynInstPtr inst = instQueue.getInstToExecute(); 11801062SN/A 11812292SN/A DPRINTF(IEW, "Execute: Processing PC %#x, [tid:%i] [sn:%i].\n", 11822292SN/A inst->readPC(), inst->threadNumber,inst->seqNum); 11831062SN/A 11841062SN/A // Check if the instruction is squashed; if so then skip it 11851062SN/A if (inst->isSquashed()) { 11862292SN/A DPRINTF(IEW, "Execute: Instruction was squashed.\n"); 11871062SN/A 11881062SN/A // Consider this instruction executed so that commit can go 11891062SN/A // ahead and retire the instruction. 11901062SN/A inst->setExecuted(); 11911062SN/A 11922292SN/A // Not sure if I should set this here or just let commit try to 11932292SN/A // commit any squashed instructions. I like the latter a bit more. 11942292SN/A inst->setCanCommit(); 11951062SN/A 11961062SN/A ++iewExecSquashedInsts; 11971062SN/A 11982820Sktlim@umich.edu decrWb(inst->seqNum); 11991062SN/A continue; 12001062SN/A } 12011062SN/A 12022292SN/A Fault fault = NoFault; 12031062SN/A 12041062SN/A // Execute instruction. 12051062SN/A // Note that if the instruction faults, it will be handled 12061062SN/A // at the commit stage. 12072292SN/A if (inst->isMemRef() && 12082292SN/A (!inst->isDataPrefetch() && !inst->isInstPrefetch())) { 12092292SN/A DPRINTF(IEW, "Execute: Calculating address for memory " 12101062SN/A "reference.\n"); 12111062SN/A 12121062SN/A // Tell the LDSTQ to execute this instruction (if it is a load). 12131062SN/A if (inst->isLoad()) { 12142292SN/A // Loads will mark themselves as executed, and their writeback 12152292SN/A // event adds the instruction to the queue to commit 12162292SN/A fault = ldstQueue.executeLoad(inst); 12171062SN/A } else if (inst->isStore()) { 12181681SN/A ldstQueue.executeStore(inst); 12191062SN/A 12202292SN/A // If the store had a fault then it may not have a mem req 12212669Sktlim@umich.edu if (inst->req && !(inst->req->getFlags() & LOCKED)) { 12222292SN/A inst->setExecuted(); 12232292SN/A 12242292SN/A instToCommit(inst); 12252292SN/A } 12262326SN/A 12272326SN/A // Store conditionals will mark themselves as 12282326SN/A // executed, and their writeback event will add the 12292326SN/A // instruction to the queue to commit. 12301062SN/A } else { 12312292SN/A panic("Unexpected memory type!\n"); 12321062SN/A } 12331062SN/A 12341062SN/A } else { 12351062SN/A inst->execute(); 12361062SN/A 12372292SN/A inst->setExecuted(); 12382292SN/A 12392292SN/A instToCommit(inst); 12401062SN/A } 12411062SN/A 12422301SN/A updateExeInstStats(inst); 12431681SN/A 12442326SN/A // Check if branch prediction was correct, if not then we need 12452326SN/A // to tell commit to squash in flight instructions. Only 12462326SN/A // handle this if there hasn't already been something that 12472107SN/A // redirects fetch in this group of instructions. 12481681SN/A 12492292SN/A // This probably needs to prioritize the redirects if a different 12502292SN/A // scheduler is used. Currently the scheduler schedules the oldest 12512292SN/A // instruction first, so the branch resolution order will be correct. 12522292SN/A unsigned tid = inst->threadNumber; 12531062SN/A 12542292SN/A if (!fetchRedirect[tid]) { 12551062SN/A 12561062SN/A if (inst->mispredicted()) { 12572292SN/A fetchRedirect[tid] = true; 12581062SN/A 12592292SN/A DPRINTF(IEW, "Execute: Branch mispredict detected.\n"); 12602292SN/A DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x.\n", 12611062SN/A inst->nextPC); 12621062SN/A 12631062SN/A // If incorrect, then signal the ROB that it must be squashed. 12642292SN/A squashDueToBranch(inst, tid); 12651062SN/A 12661062SN/A if (inst->predTaken()) { 12671062SN/A predictedTakenIncorrect++; 12682292SN/A } else { 12692292SN/A predictedNotTakenIncorrect++; 12701062SN/A } 12712292SN/A } else if (ldstQueue.violation(tid)) { 12722292SN/A fetchRedirect[tid] = true; 12731062SN/A 12742326SN/A // If there was an ordering violation, then get the 12752326SN/A // DynInst that caused the violation. Note that this 12762292SN/A // clears the violation signal. 12772292SN/A DynInstPtr violator; 12782292SN/A violator = ldstQueue.getMemDepViolator(tid); 12791062SN/A 12802292SN/A DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: " 12811062SN/A "%#x, inst PC: %#x. Addr is: %#x.\n", 12821062SN/A violator->readPC(), inst->readPC(), inst->physEffAddr); 12831062SN/A 12841062SN/A // Tell the instruction queue that a violation has occured. 12851062SN/A instQueue.violation(inst, violator); 12861062SN/A 12871062SN/A // Squash. 12882292SN/A squashDueToMemOrder(inst,tid); 12891062SN/A 12901062SN/A ++memOrderViolationEvents; 12912292SN/A } else if (ldstQueue.loadBlocked(tid) && 12922292SN/A !ldstQueue.isLoadBlockedHandled(tid)) { 12932292SN/A fetchRedirect[tid] = true; 12942292SN/A 12952292SN/A DPRINTF(IEW, "Load operation couldn't execute because the " 12962292SN/A "memory system is blocked. PC: %#x [sn:%lli]\n", 12972292SN/A inst->readPC(), inst->seqNum); 12982292SN/A 12992292SN/A squashDueToMemBlocked(inst, tid); 13001062SN/A } 13011062SN/A } 13021062SN/A } 13032292SN/A 13042348SN/A // Update and record activity if we processed any instructions. 13052292SN/A if (inst_num) { 13062292SN/A if (exeStatus == Idle) { 13072292SN/A exeStatus = Running; 13082292SN/A } 13092292SN/A 13102292SN/A updatedQueues = true; 13112292SN/A 13122292SN/A cpu->activityThisCycle(); 13132292SN/A } 13142292SN/A 13152292SN/A // Need to reset this in case a writeback event needs to write into the 13162292SN/A // iew queue. That way the writeback event will write into the correct 13172292SN/A // spot in the queue. 13182292SN/A wbNumInst = 0; 13192107SN/A} 13202107SN/A 13212292SN/Atemplate <class Impl> 13222107SN/Avoid 13232292SN/ADefaultIEW<Impl>::writebackInsts() 13242107SN/A{ 13252326SN/A // Loop through the head of the time buffer and wake any 13262326SN/A // dependents. These instructions are about to write back. Also 13272326SN/A // mark scoreboard that this instruction is finally complete. 13282326SN/A // Either have IEW have direct access to scoreboard, or have this 13292326SN/A // as part of backwards communication. 13302107SN/A for (int inst_num = 0; inst_num < issueWidth && 13312292SN/A toCommit->insts[inst_num]; inst_num++) { 13322107SN/A DynInstPtr inst = toCommit->insts[inst_num]; 13332301SN/A int tid = inst->threadNumber; 13342107SN/A 13352698Sktlim@umich.edu DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %#x.\n", 13362698Sktlim@umich.edu inst->seqNum, inst->readPC()); 13372107SN/A 13382301SN/A iewInstsToCommit[tid]++; 13392301SN/A 13402292SN/A // Some instructions will be sent to commit without having 13412292SN/A // executed because they need commit to handle them. 13422292SN/A // E.g. Uncached loads have not actually executed when they 13432292SN/A // are first sent to commit. Instead commit must tell the LSQ 13442292SN/A // when it's ready to execute the uncached load. 13452292SN/A if (!inst->isSquashed() && inst->isExecuted()) { 13462301SN/A int dependents = instQueue.wakeDependents(inst); 13472107SN/A 13482292SN/A for (int i = 0; i < inst->numDestRegs(); i++) { 13492292SN/A //mark as Ready 13502292SN/A DPRINTF(IEW,"Setting Destination Register %i\n", 13512292SN/A inst->renamedDestRegIdx(i)); 13522292SN/A scoreboard->setReg(inst->renamedDestRegIdx(i)); 13532107SN/A } 13542301SN/A 13552348SN/A if (dependents) { 13562348SN/A producerInst[tid]++; 13572348SN/A consumerInst[tid]+= dependents; 13582348SN/A } 13592326SN/A writebackCount[tid]++; 13602107SN/A } 13612820Sktlim@umich.edu 13622820Sktlim@umich.edu decrWb(inst->seqNum); 13632107SN/A } 13641060SN/A} 13651060SN/A 13661681SN/Atemplate<class Impl> 13671060SN/Avoid 13682292SN/ADefaultIEW<Impl>::tick() 13691060SN/A{ 13702292SN/A wbNumInst = 0; 13712292SN/A wbCycle = 0; 13721060SN/A 13732292SN/A wroteToTimeBuffer = false; 13742292SN/A updatedQueues = false; 13751060SN/A 13762292SN/A sortInsts(); 13771060SN/A 13782326SN/A // Free function units marked as being freed this cycle. 13792326SN/A fuPool->processFreeUnits(); 13801062SN/A 13812292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 13821060SN/A 13832326SN/A // Check stall and squash signals, dispatch any instructions. 13842292SN/A while (threads != (*activeThreads).end()) { 13852292SN/A unsigned tid = *threads++; 13861060SN/A 13872292SN/A DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid); 13881060SN/A 13892292SN/A checkSignalsAndUpdate(tid); 13902292SN/A dispatch(tid); 13911060SN/A } 13921060SN/A 13932292SN/A if (exeStatus != Squashing) { 13942292SN/A executeInsts(); 13951060SN/A 13962292SN/A writebackInsts(); 13972292SN/A 13982292SN/A // Have the instruction queue try to schedule any ready instructions. 13992292SN/A // (In actuality, this scheduling is for instructions that will 14002292SN/A // be executed next cycle.) 14012292SN/A instQueue.scheduleReadyInsts(); 14022292SN/A 14032292SN/A // Also should advance its own time buffers if the stage ran. 14042292SN/A // Not the best place for it, but this works (hopefully). 14052292SN/A issueToExecQueue.advance(); 14062292SN/A } 14072292SN/A 14082292SN/A bool broadcast_free_entries = false; 14092292SN/A 14102292SN/A if (updatedQueues || exeStatus == Running || updateLSQNextCycle) { 14112292SN/A exeStatus = Idle; 14122292SN/A updateLSQNextCycle = false; 14132292SN/A 14142292SN/A broadcast_free_entries = true; 14152292SN/A } 14162292SN/A 14172292SN/A // Writeback any stores using any leftover bandwidth. 14181681SN/A ldstQueue.writebackStores(); 14191681SN/A 14201061SN/A // Check the committed load/store signals to see if there's a load 14211061SN/A // or store to commit. Also check if it's being told to execute a 14221061SN/A // nonspeculative instruction. 14231681SN/A // This is pretty inefficient... 14242292SN/A 14252292SN/A threads = (*activeThreads).begin(); 14262292SN/A while (threads != (*activeThreads).end()) { 14272292SN/A unsigned tid = (*threads++); 14282292SN/A 14292292SN/A DPRINTF(IEW,"Processing [tid:%i]\n",tid); 14302292SN/A 14312348SN/A // Update structures based on instructions committed. 14322292SN/A if (fromCommit->commitInfo[tid].doneSeqNum != 0 && 14332292SN/A !fromCommit->commitInfo[tid].squash && 14342292SN/A !fromCommit->commitInfo[tid].robSquashing) { 14352292SN/A 14362292SN/A ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid); 14372292SN/A 14382292SN/A ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid); 14392292SN/A 14402292SN/A updateLSQNextCycle = true; 14412292SN/A instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid); 14422292SN/A } 14432292SN/A 14442292SN/A if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) { 14452292SN/A 14462292SN/A //DPRINTF(IEW,"NonspecInst from thread %i",tid); 14472292SN/A if (fromCommit->commitInfo[tid].uncached) { 14482292SN/A instQueue.replayMemInst(fromCommit->commitInfo[tid].uncachedLoad); 14492292SN/A } else { 14502292SN/A instQueue.scheduleNonSpec( 14512292SN/A fromCommit->commitInfo[tid].nonSpecSeqNum); 14522292SN/A } 14532292SN/A } 14542292SN/A 14552292SN/A if (broadcast_free_entries) { 14562292SN/A toFetch->iewInfo[tid].iqCount = 14572292SN/A instQueue.getCount(tid); 14582292SN/A toFetch->iewInfo[tid].ldstqCount = 14592292SN/A ldstQueue.getCount(tid); 14602292SN/A 14612292SN/A toRename->iewInfo[tid].usedIQ = true; 14622292SN/A toRename->iewInfo[tid].freeIQEntries = 14632292SN/A instQueue.numFreeEntries(); 14642292SN/A toRename->iewInfo[tid].usedLSQ = true; 14652292SN/A toRename->iewInfo[tid].freeLSQEntries = 14662292SN/A ldstQueue.numFreeEntries(tid); 14672292SN/A 14682292SN/A wroteToTimeBuffer = true; 14692292SN/A } 14702292SN/A 14712292SN/A DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n", 14722292SN/A tid, toRename->iewInfo[tid].dispatched); 14731061SN/A } 14741061SN/A 14752292SN/A DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i). " 14762292SN/A "LSQ has %i free entries.\n", 14772292SN/A instQueue.numFreeEntries(), instQueue.hasReadyInsts(), 14782292SN/A ldstQueue.numFreeEntries()); 14792292SN/A 14802292SN/A updateStatus(); 14812292SN/A 14822292SN/A if (wroteToTimeBuffer) { 14832292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 14842292SN/A cpu->activityThisCycle(); 14851061SN/A } 14861060SN/A} 14871060SN/A 14882301SN/Atemplate <class Impl> 14891060SN/Avoid 14902301SN/ADefaultIEW<Impl>::updateExeInstStats(DynInstPtr &inst) 14911060SN/A{ 14922301SN/A int thread_number = inst->threadNumber; 14931060SN/A 14942301SN/A // 14952301SN/A // Pick off the software prefetches 14962301SN/A // 14972301SN/A#ifdef TARGET_ALPHA 14982301SN/A if (inst->isDataPrefetch()) 14992727Sktlim@umich.edu iewExecutedSwp[thread_number]++; 15002301SN/A else 15012727Sktlim@umich.edu iewIewExecutedcutedInsts++; 15022301SN/A#else 15032669Sktlim@umich.edu iewExecutedInsts++; 15042301SN/A#endif 15051060SN/A 15062301SN/A // 15072301SN/A // Control operations 15082301SN/A // 15092301SN/A if (inst->isControl()) 15102727Sktlim@umich.edu iewExecutedBranches[thread_number]++; 15111060SN/A 15122301SN/A // 15132301SN/A // Memory operations 15142301SN/A // 15152301SN/A if (inst->isMemRef()) { 15162727Sktlim@umich.edu iewExecutedRefs[thread_number]++; 15171060SN/A 15182301SN/A if (inst->isLoad()) { 15192301SN/A iewExecLoadInsts[thread_number]++; 15201060SN/A } 15211060SN/A } 15221060SN/A} 1523