iew_impl.hh revision 2669
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. 271689SN/A */ 281689SN/A 291060SN/A// @todo: Fix the instantaneous communication among all the stages within 301060SN/A// iew. There's a clear delay between issue and execute, yet backwards 311689SN/A// communication happens simultaneously. 321060SN/A 331060SN/A#include <queue> 341060SN/A 351060SN/A#include "base/timebuf.hh" 362292SN/A#include "cpu/o3/fu_pool.hh" 371717SN/A#include "cpu/o3/iew.hh" 381060SN/A 392292SN/Ausing namespace std; 402292SN/A 411681SN/Atemplate<class Impl> 422292SN/ADefaultIEW<Impl>::DefaultIEW(Params *params) 432326SN/A : // @todo: Make this into a parameter. 441061SN/A issueToExecQueue(5, 5), 451060SN/A instQueue(params), 461061SN/A ldstQueue(params), 472292SN/A fuPool(params->fuPool), 482292SN/A commitToIEWDelay(params->commitToIEWDelay), 492292SN/A renameToIEWDelay(params->renameToIEWDelay), 502292SN/A issueToExecuteDelay(params->issueToExecuteDelay), 512292SN/A issueReadWidth(params->issueWidth), 522292SN/A issueWidth(params->issueWidth), 532292SN/A executeWidth(params->executeWidth), 542307SN/A numThreads(params->numberOfThreads), 552307SN/A switchedOut(false) 561060SN/A{ 572292SN/A _status = Active; 582292SN/A exeStatus = Running; 592292SN/A wbStatus = Idle; 601060SN/A 611060SN/A // Setup wire to read instructions coming from issue. 621060SN/A fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay); 631060SN/A 641060SN/A // Instruction queue needs the queue between issue and execute. 651060SN/A instQueue.setIssueToExecuteQueue(&issueToExecQueue); 661681SN/A 672292SN/A instQueue.setIEW(this); 681681SN/A ldstQueue.setIEW(this); 692292SN/A 702292SN/A for (int i=0; i < numThreads; i++) { 712292SN/A dispatchStatus[i] = Running; 722292SN/A stalls[i].commit = false; 732292SN/A fetchRedirect[i] = false; 742292SN/A } 752292SN/A 762292SN/A updateLSQNextCycle = false; 772292SN/A 782292SN/A skidBufferMax = (3 * (renameToIEWDelay * params->renameWidth)) + issueWidth; 792292SN/A} 802292SN/A 812292SN/Atemplate <class Impl> 822292SN/Astd::string 832292SN/ADefaultIEW<Impl>::name() const 842292SN/A{ 852292SN/A return cpu->name() + ".iew"; 861060SN/A} 871060SN/A 881681SN/Atemplate <class Impl> 891062SN/Avoid 902292SN/ADefaultIEW<Impl>::regStats() 911062SN/A{ 922301SN/A using namespace Stats; 932301SN/A 941062SN/A instQueue.regStats(); 951062SN/A 961062SN/A iewIdleCycles 971062SN/A .name(name() + ".iewIdleCycles") 981062SN/A .desc("Number of cycles IEW is idle"); 991062SN/A 1001062SN/A iewSquashCycles 1011062SN/A .name(name() + ".iewSquashCycles") 1021062SN/A .desc("Number of cycles IEW is squashing"); 1031062SN/A 1041062SN/A iewBlockCycles 1051062SN/A .name(name() + ".iewBlockCycles") 1061062SN/A .desc("Number of cycles IEW is blocking"); 1071062SN/A 1081062SN/A iewUnblockCycles 1091062SN/A .name(name() + ".iewUnblockCycles") 1101062SN/A .desc("Number of cycles IEW is unblocking"); 1111062SN/A 1121062SN/A iewDispatchedInsts 1131062SN/A .name(name() + ".iewDispatchedInsts") 1141062SN/A .desc("Number of instructions dispatched to IQ"); 1151062SN/A 1161062SN/A iewDispSquashedInsts 1171062SN/A .name(name() + ".iewDispSquashedInsts") 1181062SN/A .desc("Number of squashed instructions skipped by dispatch"); 1191062SN/A 1201062SN/A iewDispLoadInsts 1211062SN/A .name(name() + ".iewDispLoadInsts") 1221062SN/A .desc("Number of dispatched load instructions"); 1231062SN/A 1241062SN/A iewDispStoreInsts 1251062SN/A .name(name() + ".iewDispStoreInsts") 1261062SN/A .desc("Number of dispatched store instructions"); 1271062SN/A 1281062SN/A iewDispNonSpecInsts 1291062SN/A .name(name() + ".iewDispNonSpecInsts") 1301062SN/A .desc("Number of dispatched non-speculative instructions"); 1311062SN/A 1321062SN/A iewIQFullEvents 1331062SN/A .name(name() + ".iewIQFullEvents") 1341062SN/A .desc("Number of times the IQ has become full, causing a stall"); 1351062SN/A 1362292SN/A iewLSQFullEvents 1372292SN/A .name(name() + ".iewLSQFullEvents") 1382292SN/A .desc("Number of times the LSQ has become full, causing a stall"); 1392292SN/A 1401062SN/A iewExecutedInsts 1411062SN/A .name(name() + ".iewExecutedInsts") 1421062SN/A .desc("Number of executed instructions"); 1431062SN/A 1441062SN/A iewExecLoadInsts 1452301SN/A .init(cpu->number_of_threads) 1461062SN/A .name(name() + ".iewExecLoadInsts") 1472301SN/A .desc("Number of load instructions executed") 1482301SN/A .flags(total); 1491062SN/A 1501062SN/A iewExecSquashedInsts 1511062SN/A .name(name() + ".iewExecSquashedInsts") 1521062SN/A .desc("Number of squashed instructions skipped in execute"); 1531062SN/A 1541062SN/A memOrderViolationEvents 1551062SN/A .name(name() + ".memOrderViolationEvents") 1561062SN/A .desc("Number of memory order violations"); 1571062SN/A 1581062SN/A predictedTakenIncorrect 1591062SN/A .name(name() + ".predictedTakenIncorrect") 1601062SN/A .desc("Number of branches that were predicted taken incorrectly"); 1612292SN/A 1622292SN/A predictedNotTakenIncorrect 1632292SN/A .name(name() + ".predictedNotTakenIncorrect") 1642292SN/A .desc("Number of branches that were predicted not taken incorrectly"); 1652292SN/A 1662292SN/A branchMispredicts 1672292SN/A .name(name() + ".branchMispredicts") 1682292SN/A .desc("Number of branch mispredicts detected at execute"); 1692292SN/A 1702292SN/A branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect; 1712301SN/A 1722326SN/A exeSwp 1732301SN/A .init(cpu->number_of_threads) 1742301SN/A .name(name() + ".EXEC:swp") 1752301SN/A .desc("number of swp insts executed") 1762301SN/A .flags(total) 1772301SN/A ; 1782301SN/A 1792326SN/A exeNop 1802301SN/A .init(cpu->number_of_threads) 1812301SN/A .name(name() + ".EXEC:nop") 1822301SN/A .desc("number of nop insts executed") 1832301SN/A .flags(total) 1842301SN/A ; 1852301SN/A 1862326SN/A exeRefs 1872301SN/A .init(cpu->number_of_threads) 1882301SN/A .name(name() + ".EXEC:refs") 1892301SN/A .desc("number of memory reference insts executed") 1902301SN/A .flags(total) 1912301SN/A ; 1922301SN/A 1932326SN/A exeBranches 1942301SN/A .init(cpu->number_of_threads) 1952301SN/A .name(name() + ".EXEC:branches") 1962301SN/A .desc("Number of branches executed") 1972301SN/A .flags(total) 1982301SN/A ; 1992301SN/A 2002326SN/A issueRate 2012301SN/A .name(name() + ".EXEC:rate") 2022301SN/A .desc("Inst execution rate") 2032301SN/A .flags(total) 2042301SN/A ; 2052326SN/A issueRate = iewExecutedInsts / cpu->numCycles; 2062301SN/A 2072301SN/A iewExecStoreInsts 2082301SN/A .name(name() + ".EXEC:stores") 2092301SN/A .desc("Number of stores executed") 2102301SN/A .flags(total) 2112301SN/A ; 2122326SN/A iewExecStoreInsts = exeRefs - iewExecLoadInsts; 2132301SN/A/* 2142301SN/A for (int i=0; i<Num_OpClasses; ++i) { 2152301SN/A stringstream subname; 2162301SN/A subname << opClassStrings[i] << "_delay"; 2172301SN/A issue_delay_dist.subname(i, subname.str()); 2182301SN/A } 2192301SN/A*/ 2202301SN/A // 2212301SN/A // Other stats 2222301SN/A // 2232301SN/A 2242301SN/A iewInstsToCommit 2252301SN/A .init(cpu->number_of_threads) 2262301SN/A .name(name() + ".WB:sent") 2272301SN/A .desc("cumulative count of insts sent to commit") 2282301SN/A .flags(total) 2292301SN/A ; 2302301SN/A 2312326SN/A writebackCount 2322301SN/A .init(cpu->number_of_threads) 2332301SN/A .name(name() + ".WB:count") 2342301SN/A .desc("cumulative count of insts written-back") 2352301SN/A .flags(total) 2362301SN/A ; 2372301SN/A 2382326SN/A producerInst 2392301SN/A .init(cpu->number_of_threads) 2402301SN/A .name(name() + ".WB:producers") 2412301SN/A .desc("num instructions producing a value") 2422301SN/A .flags(total) 2432301SN/A ; 2442301SN/A 2452326SN/A consumerInst 2462301SN/A .init(cpu->number_of_threads) 2472301SN/A .name(name() + ".WB:consumers") 2482301SN/A .desc("num instructions consuming a value") 2492301SN/A .flags(total) 2502301SN/A ; 2512301SN/A 2522326SN/A wbPenalized 2532301SN/A .init(cpu->number_of_threads) 2542301SN/A .name(name() + ".WB:penalized") 2552301SN/A .desc("number of instrctions required to write to 'other' IQ") 2562301SN/A .flags(total) 2572301SN/A ; 2582301SN/A 2592326SN/A wbPenalizedRate 2602301SN/A .name(name() + ".WB:penalized_rate") 2612301SN/A .desc ("fraction of instructions written-back that wrote to 'other' IQ") 2622301SN/A .flags(total) 2632301SN/A ; 2642301SN/A 2652326SN/A wbPenalizedRate = wbPenalized / writebackCount; 2662301SN/A 2672326SN/A wbFanout 2682301SN/A .name(name() + ".WB:fanout") 2692301SN/A .desc("average fanout of values written-back") 2702301SN/A .flags(total) 2712301SN/A ; 2722301SN/A 2732326SN/A wbFanout = producerInst / consumerInst; 2742301SN/A 2752326SN/A wbRate 2762301SN/A .name(name() + ".WB:rate") 2772301SN/A .desc("insts written-back per cycle") 2782301SN/A .flags(total) 2792301SN/A ; 2802326SN/A wbRate = writebackCount / cpu->numCycles; 2811062SN/A} 2821062SN/A 2831681SN/Atemplate<class Impl> 2841060SN/Avoid 2852292SN/ADefaultIEW<Impl>::initStage() 2861060SN/A{ 2872292SN/A for (int tid=0; tid < numThreads; tid++) { 2882292SN/A toRename->iewInfo[tid].usedIQ = true; 2892292SN/A toRename->iewInfo[tid].freeIQEntries = 2902292SN/A instQueue.numFreeEntries(tid); 2912292SN/A 2922292SN/A toRename->iewInfo[tid].usedLSQ = true; 2932292SN/A toRename->iewInfo[tid].freeLSQEntries = 2942292SN/A ldstQueue.numFreeEntries(tid); 2952292SN/A } 2962292SN/A} 2972292SN/A 2982292SN/Atemplate<class Impl> 2992292SN/Avoid 3002292SN/ADefaultIEW<Impl>::setCPU(FullCPU *cpu_ptr) 3012292SN/A{ 3022292SN/A DPRINTF(IEW, "Setting CPU pointer.\n"); 3031060SN/A cpu = cpu_ptr; 3041060SN/A 3051060SN/A instQueue.setCPU(cpu_ptr); 3061061SN/A ldstQueue.setCPU(cpu_ptr); 3072292SN/A 3082292SN/A cpu->activateStage(FullCPU::IEWIdx); 3091060SN/A} 3101060SN/A 3111681SN/Atemplate<class Impl> 3121060SN/Avoid 3132292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 3141060SN/A{ 3152292SN/A DPRINTF(IEW, "Setting time buffer pointer.\n"); 3161060SN/A timeBuffer = tb_ptr; 3171060SN/A 3181060SN/A // Setup wire to read information from time buffer, from commit. 3191060SN/A fromCommit = timeBuffer->getWire(-commitToIEWDelay); 3201060SN/A 3211060SN/A // Setup wire to write information back to previous stages. 3221060SN/A toRename = timeBuffer->getWire(0); 3231060SN/A 3242292SN/A toFetch = timeBuffer->getWire(0); 3252292SN/A 3261060SN/A // Instruction queue also needs main time buffer. 3271060SN/A instQueue.setTimeBuffer(tb_ptr); 3281060SN/A} 3291060SN/A 3301681SN/Atemplate<class Impl> 3311060SN/Avoid 3322292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3331060SN/A{ 3342292SN/A DPRINTF(IEW, "Setting rename queue pointer.\n"); 3351060SN/A renameQueue = rq_ptr; 3361060SN/A 3371060SN/A // Setup wire to read information from rename queue. 3381060SN/A fromRename = renameQueue->getWire(-renameToIEWDelay); 3391060SN/A} 3401060SN/A 3411681SN/Atemplate<class Impl> 3421060SN/Avoid 3432292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3441060SN/A{ 3452292SN/A DPRINTF(IEW, "Setting IEW queue pointer.\n"); 3461060SN/A iewQueue = iq_ptr; 3471060SN/A 3481060SN/A // Setup wire to write instructions to commit. 3491060SN/A toCommit = iewQueue->getWire(0); 3501060SN/A} 3511060SN/A 3521681SN/Atemplate<class Impl> 3531060SN/Avoid 3542292SN/ADefaultIEW<Impl>::setActiveThreads(list<unsigned> *at_ptr) 3551060SN/A{ 3562292SN/A DPRINTF(IEW, "Setting active threads list pointer.\n"); 3572292SN/A activeThreads = at_ptr; 3582292SN/A 3592292SN/A ldstQueue.setActiveThreads(at_ptr); 3602292SN/A instQueue.setActiveThreads(at_ptr); 3611060SN/A} 3621060SN/A 3631681SN/Atemplate<class Impl> 3641060SN/Avoid 3652292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr) 3661060SN/A{ 3672292SN/A DPRINTF(IEW, "Setting scoreboard pointer.\n"); 3682292SN/A scoreboard = sb_ptr; 3691060SN/A} 3701060SN/A 3712292SN/A#if 0 3721681SN/Atemplate<class Impl> 3731060SN/Avoid 3742292SN/ADefaultIEW<Impl>::setPageTable(PageTable *pt_ptr) 3751681SN/A{ 3762292SN/A ldstQueue.setPageTable(pt_ptr); 3772107SN/A} 3782292SN/A#endif 3791681SN/A 3802307SN/Atemplate <class Impl> 3812307SN/Avoid 3822307SN/ADefaultIEW<Impl>::switchOut() 3832307SN/A{ 3842316SN/A cpu->signalSwitched(); 3851681SN/A} 3861681SN/A 3872316SN/Atemplate <class Impl> 3881681SN/Avoid 3892316SN/ADefaultIEW<Impl>::doSwitchOut() 3901681SN/A{ 3912307SN/A switchedOut = true; 3921681SN/A 3932307SN/A instQueue.switchOut(); 3942307SN/A ldstQueue.switchOut(); 3952307SN/A fuPool->switchOut(); 3962307SN/A 3972307SN/A for (int i = 0; i < numThreads; i++) { 3982307SN/A while (!insts[i].empty()) 3992307SN/A insts[i].pop(); 4002307SN/A while (!skidBuffer[i].empty()) 4012307SN/A skidBuffer[i].pop(); 4022307SN/A } 4031681SN/A} 4041681SN/A 4052307SN/Atemplate <class Impl> 4061681SN/Avoid 4072307SN/ADefaultIEW<Impl>::takeOverFrom() 4081060SN/A{ 4092307SN/A _status = Active; 4102307SN/A exeStatus = Running; 4112307SN/A wbStatus = Idle; 4122307SN/A switchedOut = false; 4131060SN/A 4142307SN/A instQueue.takeOverFrom(); 4152307SN/A ldstQueue.takeOverFrom(); 4162307SN/A fuPool->takeOverFrom(); 4171060SN/A 4182307SN/A initStage(); 4192307SN/A cpu->activityThisCycle(); 4201060SN/A 4212307SN/A for (int i=0; i < numThreads; i++) { 4222307SN/A dispatchStatus[i] = Running; 4232307SN/A stalls[i].commit = false; 4242307SN/A fetchRedirect[i] = false; 4252307SN/A } 4261060SN/A 4272307SN/A updateLSQNextCycle = false; 4282307SN/A 4292307SN/A // @todo: Fix hardcoded number 4302307SN/A for (int i = 0; i < 6; ++i) { 4312307SN/A issueToExecQueue.advance(); 4321060SN/A } 4331060SN/A} 4341060SN/A 4351681SN/Atemplate<class Impl> 4361060SN/Avoid 4372292SN/ADefaultIEW<Impl>::squash(unsigned tid) 4382107SN/A{ 4392292SN/A DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", 4402292SN/A tid); 4412107SN/A 4422292SN/A // Tell the IQ to start squashing. 4432292SN/A instQueue.squash(tid); 4442107SN/A 4452292SN/A // Tell the LDSTQ to start squashing. 4462326SN/A ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid); 4472107SN/A 4482292SN/A updatedQueues = true; 4492107SN/A 4502292SN/A // Clear the skid buffer in case it has any data in it. 4512292SN/A while (!skidBuffer[tid].empty()) { 4522107SN/A 4532292SN/A if (skidBuffer[tid].front()->isLoad() || 4542292SN/A skidBuffer[tid].front()->isStore() ) { 4552292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 4562292SN/A } 4572107SN/A 4582292SN/A toRename->iewInfo[tid].dispatched++; 4592107SN/A 4602292SN/A skidBuffer[tid].pop(); 4612292SN/A } 4622107SN/A 4632292SN/A while (!insts[tid].empty()) { 4642292SN/A if (insts[tid].front()->isLoad() || 4652292SN/A insts[tid].front()->isStore() ) { 4662292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 4672292SN/A } 4682292SN/A 4692292SN/A toRename->iewInfo[tid].dispatched++; 4702292SN/A 4712292SN/A insts[tid].pop(); 4722107SN/A } 4732107SN/A} 4742107SN/A 4752107SN/Atemplate<class Impl> 4762107SN/Avoid 4772292SN/ADefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, unsigned tid) 4782292SN/A{ 4792292SN/A DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %#x " 4802292SN/A "[sn:%i].\n", tid, inst->readPC(), inst->seqNum); 4812292SN/A 4822292SN/A toCommit->squash[tid] = true; 4832292SN/A toCommit->squashedSeqNum[tid] = inst->seqNum; 4842292SN/A toCommit->mispredPC[tid] = inst->readPC(); 4852292SN/A toCommit->nextPC[tid] = inst->readNextPC(); 4862292SN/A toCommit->branchMispredict[tid] = true; 4872292SN/A toCommit->branchTaken[tid] = inst->readNextPC() != 4882292SN/A (inst->readPC() + sizeof(TheISA::MachInst)); 4892292SN/A 4902292SN/A toCommit->includeSquashInst[tid] = false; 4912292SN/A 4922292SN/A wroteToTimeBuffer = true; 4932292SN/A} 4942292SN/A 4952292SN/Atemplate<class Impl> 4962292SN/Avoid 4972292SN/ADefaultIEW<Impl>::squashDueToMemOrder(DynInstPtr &inst, unsigned tid) 4982292SN/A{ 4992292SN/A DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, " 5002292SN/A "PC: %#x [sn:%i].\n", tid, inst->readPC(), inst->seqNum); 5012292SN/A 5022292SN/A toCommit->squash[tid] = true; 5032292SN/A toCommit->squashedSeqNum[tid] = inst->seqNum; 5042292SN/A toCommit->nextPC[tid] = inst->readNextPC(); 5052292SN/A 5062292SN/A toCommit->includeSquashInst[tid] = false; 5072292SN/A 5082292SN/A wroteToTimeBuffer = true; 5092292SN/A} 5102292SN/A 5112292SN/Atemplate<class Impl> 5122292SN/Avoid 5132292SN/ADefaultIEW<Impl>::squashDueToMemBlocked(DynInstPtr &inst, unsigned tid) 5142292SN/A{ 5152292SN/A DPRINTF(IEW, "[tid:%i]: Memory blocked, squashing load and younger insts, " 5162292SN/A "PC: %#x [sn:%i].\n", tid, inst->readPC(), inst->seqNum); 5172292SN/A 5182292SN/A toCommit->squash[tid] = true; 5192292SN/A toCommit->squashedSeqNum[tid] = inst->seqNum; 5202292SN/A toCommit->nextPC[tid] = inst->readPC(); 5212292SN/A 5222292SN/A toCommit->includeSquashInst[tid] = true; 5232292SN/A 5242292SN/A ldstQueue.setLoadBlockedHandled(tid); 5252292SN/A 5262292SN/A wroteToTimeBuffer = true; 5272292SN/A} 5282292SN/A 5292292SN/Atemplate<class Impl> 5302292SN/Avoid 5312292SN/ADefaultIEW<Impl>::block(unsigned tid) 5322292SN/A{ 5332292SN/A DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid); 5342292SN/A 5352292SN/A if (dispatchStatus[tid] != Blocked && 5362292SN/A dispatchStatus[tid] != Unblocking) { 5372292SN/A toRename->iewBlock[tid] = true; 5382292SN/A wroteToTimeBuffer = true; 5392292SN/A } 5402292SN/A 5412292SN/A // Add the current inputs to the skid buffer so they can be 5422292SN/A // reprocessed when this stage unblocks. 5432292SN/A skidInsert(tid); 5442292SN/A 5452292SN/A dispatchStatus[tid] = Blocked; 5462292SN/A} 5472292SN/A 5482292SN/Atemplate<class Impl> 5492292SN/Avoid 5502292SN/ADefaultIEW<Impl>::unblock(unsigned tid) 5512292SN/A{ 5522292SN/A DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid " 5532292SN/A "buffer %u.\n",tid, tid); 5542292SN/A 5552292SN/A // If the skid bufffer is empty, signal back to previous stages to unblock. 5562292SN/A // Also switch status to running. 5572292SN/A if (skidBuffer[tid].empty()) { 5582292SN/A toRename->iewUnblock[tid] = true; 5592292SN/A wroteToTimeBuffer = true; 5602292SN/A DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid); 5612292SN/A dispatchStatus[tid] = Running; 5622292SN/A } 5632292SN/A} 5642292SN/A 5652292SN/Atemplate<class Impl> 5662292SN/Avoid 5672292SN/ADefaultIEW<Impl>::wakeDependents(DynInstPtr &inst) 5681060SN/A{ 5691681SN/A instQueue.wakeDependents(inst); 5701060SN/A} 5711060SN/A 5722292SN/Atemplate<class Impl> 5732292SN/Avoid 5742292SN/ADefaultIEW<Impl>::rescheduleMemInst(DynInstPtr &inst) 5752292SN/A{ 5762292SN/A instQueue.rescheduleMemInst(inst); 5772292SN/A} 5781681SN/A 5791681SN/Atemplate<class Impl> 5801060SN/Avoid 5812292SN/ADefaultIEW<Impl>::replayMemInst(DynInstPtr &inst) 5821060SN/A{ 5832292SN/A instQueue.replayMemInst(inst); 5842292SN/A} 5851060SN/A 5862292SN/Atemplate<class Impl> 5872292SN/Avoid 5882292SN/ADefaultIEW<Impl>::instToCommit(DynInstPtr &inst) 5892292SN/A{ 5902292SN/A // First check the time slot that this instruction will write 5912292SN/A // to. If there are free write ports at the time, then go ahead 5922292SN/A // and write the instruction to that time. If there are not, 5932292SN/A // keep looking back to see where's the first time there's a 5942326SN/A // free slot. 5952292SN/A while ((*iewQueue)[wbCycle].insts[wbNumInst]) { 5962292SN/A ++wbNumInst; 5972292SN/A if (wbNumInst == issueWidth) { 5982292SN/A ++wbCycle; 5992292SN/A wbNumInst = 0; 6002292SN/A } 6012292SN/A 6022292SN/A assert(wbCycle < 5); 6032292SN/A } 6042292SN/A 6052292SN/A // Add finished instruction to queue to commit. 6062292SN/A (*iewQueue)[wbCycle].insts[wbNumInst] = inst; 6072292SN/A (*iewQueue)[wbCycle].size++; 6082292SN/A} 6092292SN/A 6102292SN/Atemplate <class Impl> 6112292SN/Aunsigned 6122292SN/ADefaultIEW<Impl>::validInstsFromRename() 6132292SN/A{ 6142292SN/A unsigned inst_count = 0; 6152292SN/A 6162292SN/A for (int i=0; i<fromRename->size; i++) { 6172292SN/A if (!fromRename->insts[i]->squashed) 6182292SN/A inst_count++; 6192292SN/A } 6202292SN/A 6212292SN/A return inst_count; 6222292SN/A} 6232292SN/A 6242292SN/Atemplate<class Impl> 6252292SN/Avoid 6262292SN/ADefaultIEW<Impl>::skidInsert(unsigned tid) 6272292SN/A{ 6282292SN/A DynInstPtr inst = NULL; 6292292SN/A 6302292SN/A while (!insts[tid].empty()) { 6312292SN/A inst = insts[tid].front(); 6322292SN/A 6332292SN/A insts[tid].pop(); 6342292SN/A 6352292SN/A DPRINTF(Decode,"[tid:%i]: Inserting [sn:%lli] PC:%#x into " 6362292SN/A "dispatch skidBuffer %i\n",tid, inst->seqNum, 6372292SN/A inst->readPC(),tid); 6382292SN/A 6392292SN/A skidBuffer[tid].push(inst); 6402292SN/A } 6412292SN/A 6422292SN/A assert(skidBuffer[tid].size() <= skidBufferMax && 6432292SN/A "Skidbuffer Exceeded Max Size"); 6442292SN/A} 6452292SN/A 6462292SN/Atemplate<class Impl> 6472292SN/Aint 6482292SN/ADefaultIEW<Impl>::skidCount() 6492292SN/A{ 6502292SN/A int max=0; 6512292SN/A 6522292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6532292SN/A 6542292SN/A while (threads != (*activeThreads).end()) { 6552292SN/A unsigned thread_count = skidBuffer[*threads++].size(); 6562292SN/A if (max < thread_count) 6572292SN/A max = thread_count; 6582292SN/A } 6592292SN/A 6602292SN/A return max; 6612292SN/A} 6622292SN/A 6632292SN/Atemplate<class Impl> 6642292SN/Abool 6652292SN/ADefaultIEW<Impl>::skidsEmpty() 6662292SN/A{ 6672292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6682292SN/A 6692292SN/A while (threads != (*activeThreads).end()) { 6702292SN/A if (!skidBuffer[*threads++].empty()) 6712292SN/A return false; 6722292SN/A } 6732292SN/A 6742292SN/A return true; 6751062SN/A} 6761062SN/A 6771681SN/Atemplate <class Impl> 6781062SN/Avoid 6792292SN/ADefaultIEW<Impl>::updateStatus() 6801062SN/A{ 6812292SN/A bool any_unblocking = false; 6821062SN/A 6832292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 6841062SN/A 6852292SN/A threads = (*activeThreads).begin(); 6861062SN/A 6872292SN/A while (threads != (*activeThreads).end()) { 6882292SN/A unsigned tid = *threads++; 6891062SN/A 6902292SN/A if (dispatchStatus[tid] == Unblocking) { 6912292SN/A any_unblocking = true; 6922292SN/A break; 6932292SN/A } 6942292SN/A } 6951062SN/A 6962292SN/A // If there are no ready instructions waiting to be scheduled by the IQ, 6972292SN/A // and there's no stores waiting to write back, and dispatch is not 6982292SN/A // unblocking, then there is no internal activity for the IEW stage. 6992292SN/A if (_status == Active && !instQueue.hasReadyInsts() && 7002292SN/A !ldstQueue.willWB() && !any_unblocking) { 7012292SN/A DPRINTF(IEW, "IEW switching to idle\n"); 7021062SN/A 7032292SN/A deactivateStage(); 7041062SN/A 7052292SN/A _status = Inactive; 7062292SN/A } else if (_status == Inactive && (instQueue.hasReadyInsts() || 7072292SN/A ldstQueue.willWB() || 7082292SN/A any_unblocking)) { 7092292SN/A // Otherwise there is internal activity. Set to active. 7102292SN/A DPRINTF(IEW, "IEW switching to active\n"); 7111062SN/A 7122292SN/A activateStage(); 7131062SN/A 7142292SN/A _status = Active; 7151062SN/A } 7161062SN/A} 7171062SN/A 7181681SN/Atemplate <class Impl> 7191062SN/Avoid 7202292SN/ADefaultIEW<Impl>::resetEntries() 7211062SN/A{ 7222292SN/A instQueue.resetEntries(); 7232292SN/A ldstQueue.resetEntries(); 7242292SN/A} 7251062SN/A 7262292SN/Atemplate <class Impl> 7272292SN/Avoid 7282292SN/ADefaultIEW<Impl>::readStallSignals(unsigned tid) 7292292SN/A{ 7302292SN/A if (fromCommit->commitBlock[tid]) { 7312292SN/A stalls[tid].commit = true; 7322292SN/A } 7331062SN/A 7342292SN/A if (fromCommit->commitUnblock[tid]) { 7352292SN/A assert(stalls[tid].commit); 7362292SN/A stalls[tid].commit = false; 7372292SN/A } 7382292SN/A} 7392292SN/A 7402292SN/Atemplate <class Impl> 7412292SN/Abool 7422292SN/ADefaultIEW<Impl>::checkStall(unsigned tid) 7432292SN/A{ 7442292SN/A bool ret_val(false); 7452292SN/A 7462292SN/A if (stalls[tid].commit) { 7472292SN/A DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid); 7482292SN/A ret_val = true; 7492292SN/A } else if (instQueue.isFull(tid)) { 7502292SN/A DPRINTF(IEW,"[tid:%i]: Stall: IQ is full.\n",tid); 7512292SN/A ret_val = true; 7522292SN/A } else if (ldstQueue.isFull(tid)) { 7532292SN/A DPRINTF(IEW,"[tid:%i]: Stall: LSQ is full\n",tid); 7542292SN/A 7552292SN/A if (ldstQueue.numLoads(tid) > 0 ) { 7562292SN/A 7572292SN/A DPRINTF(IEW,"[tid:%i]: LSQ oldest load: [sn:%i] \n", 7582292SN/A tid,ldstQueue.getLoadHeadSeqNum(tid)); 7592292SN/A } 7602292SN/A 7612292SN/A if (ldstQueue.numStores(tid) > 0) { 7622292SN/A 7632292SN/A DPRINTF(IEW,"[tid:%i]: LSQ oldest store: [sn:%i] \n", 7642292SN/A tid,ldstQueue.getStoreHeadSeqNum(tid)); 7652292SN/A } 7662292SN/A 7672292SN/A ret_val = true; 7682292SN/A } else if (ldstQueue.isStalled(tid)) { 7692292SN/A DPRINTF(IEW,"[tid:%i]: Stall: LSQ stall detected.\n",tid); 7702292SN/A ret_val = true; 7712292SN/A } 7722292SN/A 7732292SN/A return ret_val; 7742292SN/A} 7752292SN/A 7762292SN/Atemplate <class Impl> 7772292SN/Avoid 7782292SN/ADefaultIEW<Impl>::checkSignalsAndUpdate(unsigned tid) 7792292SN/A{ 7802292SN/A // Check if there's a squash signal, squash if there is 7812292SN/A // Check stall signals, block if there is. 7822292SN/A // If status was Blocked 7832292SN/A // if so then go to unblocking 7842292SN/A // If status was Squashing 7852292SN/A // check if squashing is not high. Switch to running this cycle. 7862292SN/A 7872292SN/A readStallSignals(tid); 7882292SN/A 7892292SN/A if (fromCommit->commitInfo[tid].squash) { 7902292SN/A squash(tid); 7912292SN/A 7922292SN/A if (dispatchStatus[tid] == Blocked || 7932292SN/A dispatchStatus[tid] == Unblocking) { 7942292SN/A toRename->iewUnblock[tid] = true; 7952292SN/A wroteToTimeBuffer = true; 7962292SN/A } 7972292SN/A 7982292SN/A dispatchStatus[tid] = Squashing; 7992292SN/A 8002292SN/A fetchRedirect[tid] = false; 8012292SN/A return; 8022292SN/A } 8032292SN/A 8042292SN/A if (fromCommit->commitInfo[tid].robSquashing) { 8052292SN/A DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n"); 8062292SN/A 8072292SN/A dispatchStatus[tid] = Squashing; 8082292SN/A 8092292SN/A return; 8102292SN/A } 8112292SN/A 8122292SN/A if (checkStall(tid)) { 8132292SN/A block(tid); 8142292SN/A dispatchStatus[tid] = Blocked; 8152292SN/A return; 8162292SN/A } 8172292SN/A 8182292SN/A if (dispatchStatus[tid] == Blocked) { 8192292SN/A // Status from previous cycle was blocked, but there are no more stall 8202292SN/A // conditions. Switch over to unblocking. 8212292SN/A DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n", 8222292SN/A tid); 8232292SN/A 8242292SN/A dispatchStatus[tid] = Unblocking; 8252292SN/A 8262292SN/A unblock(tid); 8272292SN/A 8282292SN/A return; 8292292SN/A } 8302292SN/A 8312292SN/A if (dispatchStatus[tid] == Squashing) { 8322292SN/A // Switch status to running if rename isn't being told to block or 8332292SN/A // squash this cycle. 8342292SN/A DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n", 8352292SN/A tid); 8362292SN/A 8372292SN/A dispatchStatus[tid] = Running; 8382292SN/A 8392292SN/A return; 8402292SN/A } 8412292SN/A} 8422292SN/A 8432292SN/Atemplate <class Impl> 8442292SN/Avoid 8452292SN/ADefaultIEW<Impl>::sortInsts() 8462292SN/A{ 8472292SN/A int insts_from_rename = fromRename->size; 8482326SN/A#ifdef DEBUG 8492292SN/A for (int i = 0; i < numThreads; i++) 8502292SN/A assert(insts[i].empty()); 8512326SN/A#endif 8522292SN/A for (int i = 0; i < insts_from_rename; ++i) { 8532292SN/A insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]); 8542292SN/A } 8552292SN/A} 8562292SN/A 8572292SN/Atemplate <class Impl> 8582292SN/Avoid 8592292SN/ADefaultIEW<Impl>::wakeCPU() 8602292SN/A{ 8612292SN/A cpu->wakeCPU(); 8622292SN/A} 8632292SN/A 8642292SN/Atemplate <class Impl> 8652292SN/Avoid 8662292SN/ADefaultIEW<Impl>::activityThisCycle() 8672292SN/A{ 8682292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 8692292SN/A cpu->activityThisCycle(); 8702292SN/A} 8712292SN/A 8722292SN/Atemplate <class Impl> 8732292SN/Ainline void 8742292SN/ADefaultIEW<Impl>::activateStage() 8752292SN/A{ 8762292SN/A DPRINTF(Activity, "Activating stage.\n"); 8772292SN/A cpu->activateStage(FullCPU::IEWIdx); 8782292SN/A} 8792292SN/A 8802292SN/Atemplate <class Impl> 8812292SN/Ainline void 8822292SN/ADefaultIEW<Impl>::deactivateStage() 8832292SN/A{ 8842292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 8852292SN/A cpu->deactivateStage(FullCPU::IEWIdx); 8862292SN/A} 8872292SN/A 8882292SN/Atemplate<class Impl> 8892292SN/Avoid 8902292SN/ADefaultIEW<Impl>::dispatch(unsigned tid) 8912292SN/A{ 8922292SN/A // If status is Running or idle, 8932292SN/A // call dispatchInsts() 8942292SN/A // If status is Unblocking, 8952292SN/A // buffer any instructions coming from rename 8962292SN/A // continue trying to empty skid buffer 8972292SN/A // check if stall conditions have passed 8982292SN/A 8992292SN/A if (dispatchStatus[tid] == Blocked) { 9002292SN/A ++iewBlockCycles; 9012292SN/A 9022292SN/A } else if (dispatchStatus[tid] == Squashing) { 9032292SN/A ++iewSquashCycles; 9042292SN/A } 9052292SN/A 9062292SN/A // Dispatch should try to dispatch as many instructions as its bandwidth 9072292SN/A // will allow, as long as it is not currently blocked. 9082292SN/A if (dispatchStatus[tid] == Running || 9092292SN/A dispatchStatus[tid] == Idle) { 9102292SN/A DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run " 9112292SN/A "dispatch.\n", tid); 9122292SN/A 9132292SN/A dispatchInsts(tid); 9142292SN/A } else if (dispatchStatus[tid] == Unblocking) { 9152292SN/A // Make sure that the skid buffer has something in it if the 9162292SN/A // status is unblocking. 9172292SN/A assert(!skidsEmpty()); 9182292SN/A 9192292SN/A // If the status was unblocking, then instructions from the skid 9202292SN/A // buffer were used. Remove those instructions and handle 9212292SN/A // the rest of unblocking. 9222292SN/A dispatchInsts(tid); 9232292SN/A 9242292SN/A ++iewUnblockCycles; 9252292SN/A 9262292SN/A if (validInstsFromRename() && dispatchedAllInsts) { 9272292SN/A // Add the current inputs to the skid buffer so they can be 9282292SN/A // reprocessed when this stage unblocks. 9292292SN/A skidInsert(tid); 9302292SN/A } 9312292SN/A 9322292SN/A unblock(tid); 9332292SN/A } 9342292SN/A} 9352292SN/A 9362292SN/Atemplate <class Impl> 9372292SN/Avoid 9382292SN/ADefaultIEW<Impl>::dispatchInsts(unsigned tid) 9392292SN/A{ 9402292SN/A dispatchedAllInsts = true; 9412292SN/A 9422292SN/A // Obtain instructions from skid buffer if unblocking, or queue from rename 9432292SN/A // otherwise. 9442292SN/A std::queue<DynInstPtr> &insts_to_dispatch = 9452292SN/A dispatchStatus[tid] == Unblocking ? 9462292SN/A skidBuffer[tid] : insts[tid]; 9472292SN/A 9482292SN/A int insts_to_add = insts_to_dispatch.size(); 9492292SN/A 9502292SN/A DynInstPtr inst; 9512292SN/A bool add_to_iq = false; 9522292SN/A int dis_num_inst = 0; 9532292SN/A 9542292SN/A // Loop through the instructions, putting them in the instruction 9552292SN/A // queue. 9562292SN/A for ( ; dis_num_inst < insts_to_add && 9572292SN/A dis_num_inst < issueReadWidth; 9582292SN/A ++dis_num_inst) 9592292SN/A { 9602292SN/A inst = insts_to_dispatch.front(); 9612292SN/A 9622292SN/A if (dispatchStatus[tid] == Unblocking) { 9632292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid " 9642292SN/A "buffer\n", tid); 9652292SN/A } 9662292SN/A 9672292SN/A // Make sure there's a valid instruction there. 9682292SN/A assert(inst); 9692292SN/A 9702292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %#x [sn:%lli] [tid:%i] to " 9712292SN/A "IQ.\n", 9722292SN/A tid, inst->readPC(), inst->seqNum, inst->threadNumber); 9732292SN/A 9742292SN/A // Be sure to mark these instructions as ready so that the 9752292SN/A // commit stage can go ahead and execute them, and mark 9762292SN/A // them as issued so the IQ doesn't reprocess them. 9772292SN/A 9782292SN/A // Check for squashed instructions. 9792292SN/A if (inst->isSquashed()) { 9802292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, " 9812292SN/A "not adding to IQ.\n", tid); 9822292SN/A 9832292SN/A ++iewDispSquashedInsts; 9842292SN/A 9852292SN/A insts_to_dispatch.pop(); 9862292SN/A 9872292SN/A //Tell Rename That An Instruction has been processed 9882292SN/A if (inst->isLoad() || inst->isStore()) { 9892292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 9902292SN/A } 9912292SN/A toRename->iewInfo[tid].dispatched++; 9922292SN/A 9932292SN/A continue; 9942292SN/A } 9952292SN/A 9962292SN/A // Check for full conditions. 9972292SN/A if (instQueue.isFull(tid)) { 9982292SN/A DPRINTF(IEW, "[tid:%i]: Issue: IQ has become full.\n", tid); 9992292SN/A 10002292SN/A // Call function to start blocking. 10012292SN/A block(tid); 10022292SN/A 10032292SN/A // Set unblock to false. Special case where we are using 10042292SN/A // skidbuffer (unblocking) instructions but then we still 10052292SN/A // get full in the IQ. 10062292SN/A toRename->iewUnblock[tid] = false; 10072292SN/A 10082292SN/A dispatchedAllInsts = false; 10092292SN/A 10102292SN/A ++iewIQFullEvents; 10112292SN/A break; 10122292SN/A } else if (ldstQueue.isFull(tid)) { 10132292SN/A DPRINTF(IEW, "[tid:%i]: Issue: LSQ 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 dispatchedAllInsts = false; 10242292SN/A 10252292SN/A ++iewLSQFullEvents; 10262292SN/A break; 10272292SN/A } 10282292SN/A 10292292SN/A // Otherwise issue the instruction just fine. 10302292SN/A if (inst->isLoad()) { 10312292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10322292SN/A "encountered, adding to LSQ.\n", tid); 10332292SN/A 10342292SN/A // Reserve a spot in the load store queue for this 10352292SN/A // memory access. 10362292SN/A ldstQueue.insertLoad(inst); 10372292SN/A 10382292SN/A ++iewDispLoadInsts; 10392292SN/A 10402292SN/A add_to_iq = true; 10412292SN/A 10422292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10432292SN/A } else if (inst->isStore()) { 10442292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10452292SN/A "encountered, adding to LSQ.\n", tid); 10462292SN/A 10472292SN/A ldstQueue.insertStore(inst); 10482292SN/A 10492292SN/A ++iewDispStoreInsts; 10502292SN/A 10512336SN/A if (inst->isStoreConditional()) { 10522336SN/A // Store conditionals need to be set as "canCommit()" 10532336SN/A // so that commit can process them when they reach the 10542336SN/A // head of commit. 10552292SN/A inst->setCanCommit(); 10562292SN/A instQueue.insertNonSpec(inst); 10572292SN/A add_to_iq = false; 10582292SN/A 10592292SN/A ++iewDispNonSpecInsts; 10602292SN/A } else { 10612292SN/A add_to_iq = true; 10622292SN/A } 10632292SN/A 10642292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10652292SN/A#if FULL_SYSTEM 10662292SN/A } else if (inst->isMemBarrier() || inst->isWriteBarrier()) { 10672326SN/A // Same as non-speculative stores. 10682292SN/A inst->setCanCommit(); 10692292SN/A instQueue.insertBarrier(inst); 10702292SN/A add_to_iq = false; 10712292SN/A#endif 10722292SN/A } else if (inst->isNonSpeculative()) { 10732292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction " 10742292SN/A "encountered, skipping.\n", tid); 10752292SN/A 10762326SN/A // Same as non-speculative stores. 10772292SN/A inst->setCanCommit(); 10782292SN/A 10792292SN/A // Specifically insert it as nonspeculative. 10802292SN/A instQueue.insertNonSpec(inst); 10812292SN/A 10822292SN/A ++iewDispNonSpecInsts; 10832292SN/A 10842292SN/A add_to_iq = false; 10852292SN/A } else if (inst->isNop()) { 10862292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, " 10872292SN/A "skipping.\n", tid); 10882292SN/A 10892292SN/A inst->setIssued(); 10902292SN/A inst->setExecuted(); 10912292SN/A inst->setCanCommit(); 10922292SN/A 10932326SN/A instQueue.recordProducer(inst); 10942292SN/A 10952326SN/A exeNop[tid]++; 10962301SN/A 10972292SN/A add_to_iq = false; 10982292SN/A } else if (inst->isExecuted()) { 10992292SN/A assert(0 && "Instruction shouldn't be executed.\n"); 11002292SN/A DPRINTF(IEW, "Issue: Executed branch encountered, " 11012292SN/A "skipping.\n"); 11022292SN/A 11032292SN/A inst->setIssued(); 11042292SN/A inst->setCanCommit(); 11052292SN/A 11062326SN/A instQueue.recordProducer(inst); 11072292SN/A 11082292SN/A add_to_iq = false; 11092292SN/A } else { 11102292SN/A add_to_iq = true; 11112292SN/A } 11122292SN/A 11132292SN/A // If the instruction queue is not full, then add the 11142292SN/A // instruction. 11152292SN/A if (add_to_iq) { 11162292SN/A instQueue.insert(inst); 11172292SN/A } 11182292SN/A 11192292SN/A insts_to_dispatch.pop(); 11202292SN/A 11212292SN/A toRename->iewInfo[tid].dispatched++; 11222292SN/A 11232292SN/A ++iewDispatchedInsts; 11242292SN/A } 11252292SN/A 11262292SN/A if (!insts_to_dispatch.empty()) { 11272292SN/A DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n"); 11282292SN/A block(tid); 11292292SN/A toRename->iewUnblock[tid] = false; 11302292SN/A } 11312292SN/A 11322292SN/A if (dispatchStatus[tid] == Idle && dis_num_inst) { 11332292SN/A dispatchStatus[tid] = Running; 11342292SN/A 11352292SN/A updatedQueues = true; 11362292SN/A } 11372292SN/A 11382292SN/A dis_num_inst = 0; 11392292SN/A} 11402292SN/A 11412292SN/Atemplate <class Impl> 11422292SN/Avoid 11432292SN/ADefaultIEW<Impl>::printAvailableInsts() 11442292SN/A{ 11452292SN/A int inst = 0; 11462292SN/A 11472292SN/A cout << "Available Instructions: "; 11482292SN/A 11492292SN/A while (fromIssue->insts[inst]) { 11502292SN/A 11512292SN/A if (inst%3==0) cout << "\n\t"; 11522292SN/A 11532292SN/A cout << "PC: " << fromIssue->insts[inst]->readPC() 11542292SN/A << " TN: " << fromIssue->insts[inst]->threadNumber 11552292SN/A << " SN: " << fromIssue->insts[inst]->seqNum << " | "; 11562292SN/A 11572292SN/A inst++; 11582292SN/A 11592292SN/A } 11602292SN/A 11612292SN/A cout << "\n"; 11622292SN/A} 11632292SN/A 11642292SN/Atemplate <class Impl> 11652292SN/Avoid 11662292SN/ADefaultIEW<Impl>::executeInsts() 11672292SN/A{ 11682292SN/A wbNumInst = 0; 11692292SN/A wbCycle = 0; 11702292SN/A 11712292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 11722292SN/A 11732292SN/A while (threads != (*activeThreads).end()) { 11742292SN/A unsigned tid = *threads++; 11752292SN/A fetchRedirect[tid] = false; 11762292SN/A } 11772292SN/A 11782292SN/A#if 0 11792292SN/A printAvailableInsts(); 11802292SN/A#endif 11811062SN/A 11821062SN/A // Execute/writeback any instructions that are available. 11832333SN/A int insts_to_execute = fromIssue->size; 11842292SN/A int inst_num = 0; 11852333SN/A for (; inst_num < insts_to_execute; 11862326SN/A ++inst_num) { 11871062SN/A 11882292SN/A DPRINTF(IEW, "Execute: Executing instructions from IQ.\n"); 11891062SN/A 11902333SN/A DynInstPtr inst = instQueue.getInstToExecute(); 11911062SN/A 11922292SN/A DPRINTF(IEW, "Execute: Processing PC %#x, [tid:%i] [sn:%i].\n", 11932292SN/A inst->readPC(), inst->threadNumber,inst->seqNum); 11941062SN/A 11951062SN/A // Check if the instruction is squashed; if so then skip it 11961062SN/A if (inst->isSquashed()) { 11972292SN/A DPRINTF(IEW, "Execute: Instruction was squashed.\n"); 11981062SN/A 11991062SN/A // Consider this instruction executed so that commit can go 12001062SN/A // ahead and retire the instruction. 12011062SN/A inst->setExecuted(); 12021062SN/A 12032292SN/A // Not sure if I should set this here or just let commit try to 12042292SN/A // commit any squashed instructions. I like the latter a bit more. 12052292SN/A inst->setCanCommit(); 12061062SN/A 12071062SN/A ++iewExecSquashedInsts; 12081062SN/A 12091062SN/A continue; 12101062SN/A } 12111062SN/A 12122292SN/A Fault fault = NoFault; 12131062SN/A 12141062SN/A // Execute instruction. 12151062SN/A // Note that if the instruction faults, it will be handled 12161062SN/A // at the commit stage. 12172292SN/A if (inst->isMemRef() && 12182292SN/A (!inst->isDataPrefetch() && !inst->isInstPrefetch())) { 12192292SN/A DPRINTF(IEW, "Execute: Calculating address for memory " 12201062SN/A "reference.\n"); 12211062SN/A 12221062SN/A // Tell the LDSTQ to execute this instruction (if it is a load). 12231062SN/A if (inst->isLoad()) { 12242292SN/A // Loads will mark themselves as executed, and their writeback 12252292SN/A // event adds the instruction to the queue to commit 12262292SN/A fault = ldstQueue.executeLoad(inst); 12271062SN/A } else if (inst->isStore()) { 12281681SN/A ldstQueue.executeStore(inst); 12291062SN/A 12302292SN/A // If the store had a fault then it may not have a mem req 12312669Sktlim@umich.edu if (inst->req && !(inst->req->getFlags() & LOCKED)) { 12322292SN/A inst->setExecuted(); 12332292SN/A 12342292SN/A instToCommit(inst); 12352292SN/A } 12362326SN/A 12372326SN/A // Store conditionals will mark themselves as 12382326SN/A // executed, and their writeback event will add the 12392326SN/A // instruction to the queue to commit. 12401062SN/A } else { 12412292SN/A panic("Unexpected memory type!\n"); 12421062SN/A } 12431062SN/A 12441062SN/A } else { 12451062SN/A inst->execute(); 12461062SN/A 12472292SN/A inst->setExecuted(); 12482292SN/A 12492292SN/A instToCommit(inst); 12501062SN/A } 12511062SN/A 12522301SN/A updateExeInstStats(inst); 12531681SN/A 12542326SN/A // Check if branch prediction was correct, if not then we need 12552326SN/A // to tell commit to squash in flight instructions. Only 12562326SN/A // handle this if there hasn't already been something that 12572107SN/A // redirects fetch in this group of instructions. 12581681SN/A 12592292SN/A // This probably needs to prioritize the redirects if a different 12602292SN/A // scheduler is used. Currently the scheduler schedules the oldest 12612292SN/A // instruction first, so the branch resolution order will be correct. 12622292SN/A unsigned tid = inst->threadNumber; 12631062SN/A 12642292SN/A if (!fetchRedirect[tid]) { 12651062SN/A 12661062SN/A if (inst->mispredicted()) { 12672292SN/A fetchRedirect[tid] = true; 12681062SN/A 12692292SN/A DPRINTF(IEW, "Execute: Branch mispredict detected.\n"); 12702292SN/A DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x.\n", 12711062SN/A inst->nextPC); 12721062SN/A 12731062SN/A // If incorrect, then signal the ROB that it must be squashed. 12742292SN/A squashDueToBranch(inst, tid); 12751062SN/A 12761062SN/A if (inst->predTaken()) { 12771062SN/A predictedTakenIncorrect++; 12782292SN/A } else { 12792292SN/A predictedNotTakenIncorrect++; 12801062SN/A } 12812292SN/A } else if (ldstQueue.violation(tid)) { 12822292SN/A fetchRedirect[tid] = true; 12831062SN/A 12842326SN/A // If there was an ordering violation, then get the 12852326SN/A // DynInst that caused the violation. Note that this 12862292SN/A // clears the violation signal. 12872292SN/A DynInstPtr violator; 12882292SN/A violator = ldstQueue.getMemDepViolator(tid); 12891062SN/A 12902292SN/A DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: " 12911062SN/A "%#x, inst PC: %#x. Addr is: %#x.\n", 12921062SN/A violator->readPC(), inst->readPC(), inst->physEffAddr); 12931062SN/A 12941062SN/A // Tell the instruction queue that a violation has occured. 12951062SN/A instQueue.violation(inst, violator); 12961062SN/A 12971062SN/A // Squash. 12982292SN/A squashDueToMemOrder(inst,tid); 12991062SN/A 13001062SN/A ++memOrderViolationEvents; 13012292SN/A } else if (ldstQueue.loadBlocked(tid) && 13022292SN/A !ldstQueue.isLoadBlockedHandled(tid)) { 13032292SN/A fetchRedirect[tid] = true; 13042292SN/A 13052292SN/A DPRINTF(IEW, "Load operation couldn't execute because the " 13062292SN/A "memory system is blocked. PC: %#x [sn:%lli]\n", 13072292SN/A inst->readPC(), inst->seqNum); 13082292SN/A 13092292SN/A squashDueToMemBlocked(inst, tid); 13101062SN/A } 13111062SN/A } 13121062SN/A } 13132292SN/A 13142292SN/A if (inst_num) { 13152292SN/A if (exeStatus == Idle) { 13162292SN/A exeStatus = Running; 13172292SN/A } 13182292SN/A 13192292SN/A updatedQueues = true; 13202292SN/A 13212292SN/A cpu->activityThisCycle(); 13222292SN/A } 13232292SN/A 13242292SN/A // Need to reset this in case a writeback event needs to write into the 13252292SN/A // iew queue. That way the writeback event will write into the correct 13262292SN/A // spot in the queue. 13272292SN/A wbNumInst = 0; 13282107SN/A} 13292107SN/A 13302292SN/Atemplate <class Impl> 13312107SN/Avoid 13322292SN/ADefaultIEW<Impl>::writebackInsts() 13332107SN/A{ 13342326SN/A // Loop through the head of the time buffer and wake any 13352326SN/A // dependents. These instructions are about to write back. Also 13362326SN/A // mark scoreboard that this instruction is finally complete. 13372326SN/A // Either have IEW have direct access to scoreboard, or have this 13382326SN/A // as part of backwards communication. 13392107SN/A for (int inst_num = 0; inst_num < issueWidth && 13402292SN/A toCommit->insts[inst_num]; inst_num++) { 13412107SN/A DynInstPtr inst = toCommit->insts[inst_num]; 13422301SN/A int tid = inst->threadNumber; 13432107SN/A 13442292SN/A DPRINTF(IEW, "Sending instructions to commit, PC %#x.\n", 13452107SN/A inst->readPC()); 13462107SN/A 13472301SN/A iewInstsToCommit[tid]++; 13482301SN/A 13492292SN/A // Some instructions will be sent to commit without having 13502292SN/A // executed because they need commit to handle them. 13512292SN/A // E.g. Uncached loads have not actually executed when they 13522292SN/A // are first sent to commit. Instead commit must tell the LSQ 13532292SN/A // when it's ready to execute the uncached load. 13542292SN/A if (!inst->isSquashed() && inst->isExecuted()) { 13552301SN/A int dependents = instQueue.wakeDependents(inst); 13562107SN/A 13572292SN/A for (int i = 0; i < inst->numDestRegs(); i++) { 13582292SN/A //mark as Ready 13592292SN/A DPRINTF(IEW,"Setting Destination Register %i\n", 13602292SN/A inst->renamedDestRegIdx(i)); 13612292SN/A scoreboard->setReg(inst->renamedDestRegIdx(i)); 13622107SN/A } 13632301SN/A 13642326SN/A producerInst[tid]++; 13652326SN/A consumerInst[tid]+= dependents; 13662326SN/A writebackCount[tid]++; 13672107SN/A } 13682107SN/A } 13691060SN/A} 13701060SN/A 13711681SN/Atemplate<class Impl> 13721060SN/Avoid 13732292SN/ADefaultIEW<Impl>::tick() 13741060SN/A{ 13752292SN/A wbNumInst = 0; 13762292SN/A wbCycle = 0; 13771060SN/A 13782292SN/A wroteToTimeBuffer = false; 13792292SN/A updatedQueues = false; 13801060SN/A 13812292SN/A sortInsts(); 13821060SN/A 13832326SN/A // Free function units marked as being freed this cycle. 13842326SN/A fuPool->processFreeUnits(); 13851062SN/A 13862292SN/A list<unsigned>::iterator threads = (*activeThreads).begin(); 13871060SN/A 13882326SN/A // Check stall and squash signals, dispatch any instructions. 13892292SN/A while (threads != (*activeThreads).end()) { 13902292SN/A unsigned tid = *threads++; 13911060SN/A 13922292SN/A DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid); 13931060SN/A 13942292SN/A checkSignalsAndUpdate(tid); 13952292SN/A dispatch(tid); 13961060SN/A } 13971060SN/A 13982292SN/A if (exeStatus != Squashing) { 13992292SN/A executeInsts(); 14001060SN/A 14012292SN/A writebackInsts(); 14022292SN/A 14032292SN/A // Have the instruction queue try to schedule any ready instructions. 14042292SN/A // (In actuality, this scheduling is for instructions that will 14052292SN/A // be executed next cycle.) 14062292SN/A instQueue.scheduleReadyInsts(); 14072292SN/A 14082292SN/A // Also should advance its own time buffers if the stage ran. 14092292SN/A // Not the best place for it, but this works (hopefully). 14102292SN/A issueToExecQueue.advance(); 14112292SN/A } 14122292SN/A 14132292SN/A bool broadcast_free_entries = false; 14142292SN/A 14152292SN/A if (updatedQueues || exeStatus == Running || updateLSQNextCycle) { 14162292SN/A exeStatus = Idle; 14172292SN/A updateLSQNextCycle = false; 14182292SN/A 14192292SN/A broadcast_free_entries = true; 14202292SN/A } 14212292SN/A 14222292SN/A // Writeback any stores using any leftover bandwidth. 14231681SN/A ldstQueue.writebackStores(); 14241681SN/A 14251061SN/A // Check the committed load/store signals to see if there's a load 14261061SN/A // or store to commit. Also check if it's being told to execute a 14271061SN/A // nonspeculative instruction. 14281681SN/A // This is pretty inefficient... 14292292SN/A 14302292SN/A threads = (*activeThreads).begin(); 14312292SN/A while (threads != (*activeThreads).end()) { 14322292SN/A unsigned tid = (*threads++); 14332292SN/A 14342292SN/A DPRINTF(IEW,"Processing [tid:%i]\n",tid); 14352292SN/A 14362292SN/A if (fromCommit->commitInfo[tid].doneSeqNum != 0 && 14372292SN/A !fromCommit->commitInfo[tid].squash && 14382292SN/A !fromCommit->commitInfo[tid].robSquashing) { 14392292SN/A 14402292SN/A ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid); 14412292SN/A 14422292SN/A ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid); 14432292SN/A 14442292SN/A updateLSQNextCycle = true; 14452292SN/A instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid); 14462292SN/A } 14472292SN/A 14482292SN/A if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) { 14492292SN/A 14502292SN/A //DPRINTF(IEW,"NonspecInst from thread %i",tid); 14512292SN/A if (fromCommit->commitInfo[tid].uncached) { 14522292SN/A instQueue.replayMemInst(fromCommit->commitInfo[tid].uncachedLoad); 14532292SN/A } else { 14542292SN/A instQueue.scheduleNonSpec( 14552292SN/A fromCommit->commitInfo[tid].nonSpecSeqNum); 14562292SN/A } 14572292SN/A } 14582292SN/A 14592292SN/A if (broadcast_free_entries) { 14602292SN/A toFetch->iewInfo[tid].iqCount = 14612292SN/A instQueue.getCount(tid); 14622292SN/A toFetch->iewInfo[tid].ldstqCount = 14632292SN/A ldstQueue.getCount(tid); 14642292SN/A 14652292SN/A toRename->iewInfo[tid].usedIQ = true; 14662292SN/A toRename->iewInfo[tid].freeIQEntries = 14672292SN/A instQueue.numFreeEntries(); 14682292SN/A toRename->iewInfo[tid].usedLSQ = true; 14692292SN/A toRename->iewInfo[tid].freeLSQEntries = 14702292SN/A ldstQueue.numFreeEntries(tid); 14712292SN/A 14722292SN/A wroteToTimeBuffer = true; 14732292SN/A } 14742292SN/A 14752292SN/A DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n", 14762292SN/A tid, toRename->iewInfo[tid].dispatched); 14771061SN/A } 14781061SN/A 14792292SN/A DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i). " 14802292SN/A "LSQ has %i free entries.\n", 14812292SN/A instQueue.numFreeEntries(), instQueue.hasReadyInsts(), 14822292SN/A ldstQueue.numFreeEntries()); 14832292SN/A 14842292SN/A updateStatus(); 14852292SN/A 14862292SN/A if (wroteToTimeBuffer) { 14872292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 14882292SN/A cpu->activityThisCycle(); 14891061SN/A } 14901060SN/A} 14911060SN/A 14922301SN/Atemplate <class Impl> 14931060SN/Avoid 14942301SN/ADefaultIEW<Impl>::updateExeInstStats(DynInstPtr &inst) 14951060SN/A{ 14962301SN/A int thread_number = inst->threadNumber; 14971060SN/A 14982301SN/A // 14992301SN/A // Pick off the software prefetches 15002301SN/A // 15012301SN/A#ifdef TARGET_ALPHA 15022301SN/A if (inst->isDataPrefetch()) 15032326SN/A exeSwp[thread_number]++; 15042301SN/A else 15052301SN/A iewExecutedInsts++; 15062301SN/A#else 15072669Sktlim@umich.edu iewExecutedInsts++; 15082301SN/A#endif 15091060SN/A 15102301SN/A // 15112301SN/A // Control operations 15122301SN/A // 15132301SN/A if (inst->isControl()) 15142326SN/A exeBranches[thread_number]++; 15151060SN/A 15162301SN/A // 15172301SN/A // Memory operations 15182301SN/A // 15192301SN/A if (inst->isMemRef()) { 15202326SN/A exeRefs[thread_number]++; 15211060SN/A 15222301SN/A if (inst->isLoad()) { 15232301SN/A iewExecLoadInsts[thread_number]++; 15241060SN/A } 15251060SN/A } 15261060SN/A} 1527