fetch.hh revision 8462
11689SN/A/* 27849SAli.Saidi@ARM.com * Copyright (c) 2010 ARM Limited 37849SAli.Saidi@ARM.com * All rights reserved 47849SAli.Saidi@ARM.com * 57849SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 67849SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 77849SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 87849SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 97849SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 107849SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 117849SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 127849SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 137849SAli.Saidi@ARM.com * 142329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 271689SN/A * 281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 412756Sksewell@umich.edu * Korey Sewell 421689SN/A */ 431689SN/A 442292SN/A#ifndef __CPU_O3_FETCH_HH__ 452292SN/A#define __CPU_O3_FETCH_HH__ 461060SN/A 478229Snate@binkert.org#include "arch/predecoder.hh" 482669Sktlim@umich.edu#include "arch/utility.hh" 491461SN/A#include "base/statistics.hh" 506658Snate@binkert.org#include "config/the_isa.hh" 511060SN/A#include "cpu/pc_event.hh" 528229Snate@binkert.org#include "cpu/timebuf.hh" 537849SAli.Saidi@ARM.com#include "cpu/translation.hh" 543348Sbinkertn@umich.edu#include "mem/packet.hh" 552669Sktlim@umich.edu#include "mem/port.hh" 561461SN/A#include "sim/eventq.hh" 571060SN/A 585529Snate@binkert.orgclass DerivO3CPUParams; 595529Snate@binkert.org 601060SN/A/** 612329SN/A * DefaultFetch class handles both single threaded and SMT fetch. Its 622329SN/A * width is specified by the parameters; each cycle it tries to fetch 632329SN/A * that many instructions. It supports using a branch predictor to 642329SN/A * predict direction and targets. 652348SN/A * It supports the idling functionality of the CPU by indicating to 662329SN/A * the CPU when it is active and inactive. 671060SN/A */ 681060SN/Atemplate <class Impl> 692292SN/Aclass DefaultFetch 701060SN/A{ 711060SN/A public: 721060SN/A /** Typedefs from Impl. */ 731061SN/A typedef typename Impl::CPUPol CPUPol; 741060SN/A typedef typename Impl::DynInst DynInst; 751061SN/A typedef typename Impl::DynInstPtr DynInstPtr; 762733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 771060SN/A 782292SN/A /** Typedefs from the CPU policy. */ 791061SN/A typedef typename CPUPol::BPredUnit BPredUnit; 801061SN/A typedef typename CPUPol::FetchStruct FetchStruct; 811061SN/A typedef typename CPUPol::TimeStruct TimeStruct; 821060SN/A 831060SN/A /** Typedefs from ISA. */ 842107SN/A typedef TheISA::MachInst MachInst; 852292SN/A typedef TheISA::ExtMachInst ExtMachInst; 862632Sstever@eecs.umich.edu 872698Sktlim@umich.edu /** IcachePort class for DefaultFetch. Handles doing the 882698Sktlim@umich.edu * communication with the cache/memory. 892698Sktlim@umich.edu */ 902669Sktlim@umich.edu class IcachePort : public Port 912669Sktlim@umich.edu { 922669Sktlim@umich.edu protected: 932698Sktlim@umich.edu /** Pointer to fetch. */ 942669Sktlim@umich.edu DefaultFetch<Impl> *fetch; 952669Sktlim@umich.edu 962669Sktlim@umich.edu public: 972698Sktlim@umich.edu /** Default constructor. */ 985494Sstever@gmail.com IcachePort(DefaultFetch<Impl> *_fetch) 995606Snate@binkert.org : Port(_fetch->name() + "-iport", _fetch->cpu), fetch(_fetch) 1002669Sktlim@umich.edu { } 1012669Sktlim@umich.edu 1023647Srdreslin@umich.edu bool snoopRangeSent; 1033647Srdreslin@umich.edu 1044302Sktlim@umich.edu virtual void setPeer(Port *port); 1054302Sktlim@umich.edu 1062669Sktlim@umich.edu protected: 1072698Sktlim@umich.edu /** Atomic version of receive. Panics. */ 1082669Sktlim@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 1092669Sktlim@umich.edu 1102698Sktlim@umich.edu /** Functional version of receive. Panics. */ 1112669Sktlim@umich.edu virtual void recvFunctional(PacketPtr pkt); 1122669Sktlim@umich.edu 1132698Sktlim@umich.edu /** Receives status change. Other than range changing, panics. */ 1142669Sktlim@umich.edu virtual void recvStatusChange(Status status); 1152669Sktlim@umich.edu 1162698Sktlim@umich.edu /** Returns the address ranges of this device. */ 1172669Sktlim@umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 1184475Sstever@eecs.umich.edu bool &snoop) 1194475Sstever@eecs.umich.edu { resp.clear(); snoop = true; } 1202669Sktlim@umich.edu 1212698Sktlim@umich.edu /** Timing version of receive. Handles setting fetch to the 1222698Sktlim@umich.edu * proper status to start fetching. */ 1232669Sktlim@umich.edu virtual bool recvTiming(PacketPtr pkt); 1242669Sktlim@umich.edu 1252698Sktlim@umich.edu /** Handles doing a retry of a failed fetch. */ 1262669Sktlim@umich.edu virtual void recvRetry(); 1272669Sktlim@umich.edu }; 1281060SN/A 1297849SAli.Saidi@ARM.com class FetchTranslation : public BaseTLB::Translation 1307849SAli.Saidi@ARM.com { 1317849SAli.Saidi@ARM.com protected: 1327849SAli.Saidi@ARM.com DefaultFetch<Impl> *fetch; 1337849SAli.Saidi@ARM.com 1347849SAli.Saidi@ARM.com public: 1357849SAli.Saidi@ARM.com FetchTranslation(DefaultFetch<Impl> *_fetch) 1367849SAli.Saidi@ARM.com : fetch(_fetch) 1377849SAli.Saidi@ARM.com {} 1387849SAli.Saidi@ARM.com 1397849SAli.Saidi@ARM.com void 1407944SGiacomo.Gabrielli@arm.com markDelayed() 1417944SGiacomo.Gabrielli@arm.com {} 1427944SGiacomo.Gabrielli@arm.com 1437944SGiacomo.Gabrielli@arm.com void 1447849SAli.Saidi@ARM.com finish(Fault fault, RequestPtr req, ThreadContext *tc, 1457849SAli.Saidi@ARM.com BaseTLB::Mode mode) 1467849SAli.Saidi@ARM.com { 1477849SAli.Saidi@ARM.com assert(mode == BaseTLB::Execute); 1487849SAli.Saidi@ARM.com fetch->finishTranslation(fault, req); 1497849SAli.Saidi@ARM.com delete this; 1507849SAli.Saidi@ARM.com } 1517849SAli.Saidi@ARM.com }; 1522935Sksewell@umich.edu 1538462Sgeoffrey.blake@arm.com private: 1548462Sgeoffrey.blake@arm.com /* Event to delay delivery of a fetch translation result in case of 1558462Sgeoffrey.blake@arm.com * a fault and the nop to carry the fault cannot be generated 1568462Sgeoffrey.blake@arm.com * immediately */ 1578462Sgeoffrey.blake@arm.com class FinishTranslationEvent : public Event 1588462Sgeoffrey.blake@arm.com { 1598462Sgeoffrey.blake@arm.com private: 1608462Sgeoffrey.blake@arm.com DefaultFetch<Impl> *fetch; 1618462Sgeoffrey.blake@arm.com Fault fault; 1628462Sgeoffrey.blake@arm.com RequestPtr req; 1638462Sgeoffrey.blake@arm.com 1648462Sgeoffrey.blake@arm.com public: 1658462Sgeoffrey.blake@arm.com FinishTranslationEvent(DefaultFetch<Impl> *_fetch) 1668462Sgeoffrey.blake@arm.com : fetch(_fetch) 1678462Sgeoffrey.blake@arm.com {} 1688462Sgeoffrey.blake@arm.com 1698462Sgeoffrey.blake@arm.com void setFault(Fault _fault) 1708462Sgeoffrey.blake@arm.com { 1718462Sgeoffrey.blake@arm.com fault = _fault; 1728462Sgeoffrey.blake@arm.com } 1738462Sgeoffrey.blake@arm.com 1748462Sgeoffrey.blake@arm.com void setReq(RequestPtr _req) 1758462Sgeoffrey.blake@arm.com { 1768462Sgeoffrey.blake@arm.com req = _req; 1778462Sgeoffrey.blake@arm.com } 1788462Sgeoffrey.blake@arm.com 1798462Sgeoffrey.blake@arm.com /** Process the delayed finish translation */ 1808462Sgeoffrey.blake@arm.com void process() 1818462Sgeoffrey.blake@arm.com { 1828462Sgeoffrey.blake@arm.com assert(fetch->numInst < fetch->fetchWidth); 1838462Sgeoffrey.blake@arm.com fetch->finishTranslation(fault, req); 1848462Sgeoffrey.blake@arm.com } 1858462Sgeoffrey.blake@arm.com 1868462Sgeoffrey.blake@arm.com const char *description() const 1878462Sgeoffrey.blake@arm.com { 1888462Sgeoffrey.blake@arm.com return "FullO3CPU FetchFinishTranslation"; 1898462Sgeoffrey.blake@arm.com } 1908462Sgeoffrey.blake@arm.com }; 1918462Sgeoffrey.blake@arm.com 1921060SN/A public: 1932329SN/A /** Overall fetch status. Used to determine if the CPU can 1942329SN/A * deschedule itsef due to a lack of activity. 1952292SN/A */ 1962292SN/A enum FetchStatus { 1972292SN/A Active, 1982292SN/A Inactive 1992292SN/A }; 2002292SN/A 2012292SN/A /** Individual thread status. */ 2022292SN/A enum ThreadStatus { 2031060SN/A Running, 2041060SN/A Idle, 2051060SN/A Squashing, 2061060SN/A Blocked, 2072292SN/A Fetching, 2082292SN/A TrapPending, 2092292SN/A QuiescePending, 2102307SN/A SwitchOut, 2117849SAli.Saidi@ARM.com ItlbWait, 2122669Sktlim@umich.edu IcacheWaitResponse, 2132696Sktlim@umich.edu IcacheWaitRetry, 2148460SAli.Saidi@ARM.com IcacheAccessComplete, 2158460SAli.Saidi@ARM.com NoGoodAddr 2161060SN/A }; 2171060SN/A 2182292SN/A /** Fetching Policy, Add new policies here.*/ 2192292SN/A enum FetchPriority { 2202292SN/A SingleThread, 2212292SN/A RoundRobin, 2222292SN/A Branch, 2232292SN/A IQ, 2242292SN/A LSQ 2252292SN/A }; 2261060SN/A 2272292SN/A private: 2282292SN/A /** Fetch status. */ 2292292SN/A FetchStatus _status; 2302292SN/A 2312292SN/A /** Per-thread status. */ 2322292SN/A ThreadStatus fetchStatus[Impl::MaxThreads]; 2332292SN/A 2342292SN/A /** Fetch policy. */ 2352292SN/A FetchPriority fetchPolicy; 2362292SN/A 2372292SN/A /** List that has the threads organized by priority. */ 2386221Snate@binkert.org std::list<ThreadID> priorityList; 2391060SN/A 2401060SN/A public: 2412292SN/A /** DefaultFetch constructor. */ 2425529Snate@binkert.org DefaultFetch(O3CPU *_cpu, DerivO3CPUParams *params); 2431684SN/A 2442292SN/A /** Returns the name of fetch. */ 2452292SN/A std::string name() const; 2461684SN/A 2472292SN/A /** Registers statistics. */ 2481062SN/A void regStats(); 2491062SN/A 2502871Sktlim@umich.edu /** Returns the icache port. */ 2512871Sktlim@umich.edu Port *getIcachePort() { return icachePort; } 2522871Sktlim@umich.edu 2532292SN/A /** Sets the main backwards communication time buffer pointer. */ 2541060SN/A void setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer); 2551060SN/A 2562292SN/A /** Sets pointer to list of active threads. */ 2576221Snate@binkert.org void setActiveThreads(std::list<ThreadID> *at_ptr); 2582292SN/A 2592292SN/A /** Sets pointer to time buffer used to communicate to the next stage. */ 2601060SN/A void setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr); 2611060SN/A 2622292SN/A /** Initialize stage. */ 2632292SN/A void initStage(); 2642292SN/A 2654302Sktlim@umich.edu /** Tells the fetch stage that the Icache is set. */ 2664302Sktlim@umich.edu void setIcache(); 2674302Sktlim@umich.edu 2682292SN/A /** Processes cache completion event. */ 2692669Sktlim@umich.edu void processCacheCompletion(PacketPtr pkt); 2702292SN/A 2712843Sktlim@umich.edu /** Begins the drain of the fetch stage. */ 2722863Sktlim@umich.edu bool drain(); 2732843Sktlim@umich.edu 2742843Sktlim@umich.edu /** Resumes execution after a drain. */ 2752843Sktlim@umich.edu void resume(); 2762843Sktlim@umich.edu 2772843Sktlim@umich.edu /** Tells fetch stage to prepare to be switched out. */ 2782307SN/A void switchOut(); 2792307SN/A 2802348SN/A /** Takes over from another CPU's thread. */ 2812307SN/A void takeOverFrom(); 2822307SN/A 2832348SN/A /** Checks if the fetch stage is switched out. */ 2842307SN/A bool isSwitchedOut() { return switchedOut; } 2852307SN/A 2862348SN/A /** Tells fetch to wake up from a quiesce instruction. */ 2872292SN/A void wakeFromQuiesce(); 2881060SN/A 2891061SN/A private: 2902329SN/A /** Changes the status of this stage to active, and indicates this 2912329SN/A * to the CPU. 2922292SN/A */ 2932292SN/A inline void switchToActive(); 2942292SN/A 2952329SN/A /** Changes the status of this stage to inactive, and indicates 2962329SN/A * this to the CPU. 2972292SN/A */ 2982292SN/A inline void switchToInactive(); 2992292SN/A 3001061SN/A /** 3011061SN/A * Looks up in the branch predictor to see if the next PC should be 3021061SN/A * either next PC+=MachInst or a branch target. 3031763SN/A * @param next_PC Next PC variable passed in by reference. It is 3041061SN/A * expected to be set to the current PC; it will be updated with what 3051061SN/A * the next PC will be. 3062935Sksewell@umich.edu * @param next_NPC Used for ISAs which use delay slots. 3071061SN/A * @return Whether or not a branch was predicted as taken. 3081061SN/A */ 3097720Sgblack@eecs.umich.edu bool lookupAndUpdateNextPC(DynInstPtr &inst, TheISA::PCState &pc); 3101062SN/A 3111062SN/A /** 3121062SN/A * Fetches the cache line that contains fetch_PC. Returns any 3131062SN/A * fault that happened. Puts the data into the class variable 3141062SN/A * cacheData. 3157764Sgblack@eecs.umich.edu * @param vaddr The memory address that is being fetched from. 3162292SN/A * @param ret_fault The fault reference that will be set to the result of 3172292SN/A * the icache access. 3182292SN/A * @param tid Thread id. 3197764Sgblack@eecs.umich.edu * @param pc The actual PC of the current instruction. 3201062SN/A * @return Any fault that occured. 3211062SN/A */ 3227849SAli.Saidi@ARM.com bool fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc); 3237849SAli.Saidi@ARM.com void finishTranslation(Fault fault, RequestPtr mem_req); 3241062SN/A 3257847Sminkyu.jeong@arm.com 3267847Sminkyu.jeong@arm.com /** Check if an interrupt is pending and that we need to handle 3277847Sminkyu.jeong@arm.com */ 3287847Sminkyu.jeong@arm.com bool 3297847Sminkyu.jeong@arm.com checkInterrupt(Addr pc) 3307847Sminkyu.jeong@arm.com { 3317847Sminkyu.jeong@arm.com return (interruptPending && (THE_ISA != ALPHA_ISA || !(pc & 0x3))); 3327847Sminkyu.jeong@arm.com } 3337847Sminkyu.jeong@arm.com 3342292SN/A /** Squashes a specific thread and resets the PC. */ 3357720Sgblack@eecs.umich.edu inline void doSquash(const TheISA::PCState &newPC, ThreadID tid); 3361684SN/A 3372292SN/A /** Squashes a specific thread and resets the PC. Also tells the CPU to 3382292SN/A * remove any instructions between fetch and decode that should be sqaushed. 3392292SN/A */ 3407720Sgblack@eecs.umich.edu void squashFromDecode(const TheISA::PCState &newPC, 3416221Snate@binkert.org const InstSeqNum &seq_num, ThreadID tid); 3422292SN/A 3432292SN/A /** Checks if a thread is stalled. */ 3446221Snate@binkert.org bool checkStall(ThreadID tid) const; 3452292SN/A 3462292SN/A /** Updates overall fetch stage status; to be called at the end of each 3472292SN/A * cycle. */ 3482292SN/A FetchStatus updateFetchStatus(); 3491684SN/A 3501684SN/A public: 3512292SN/A /** Squashes a specific thread and resets the PC. Also tells the CPU to 3522292SN/A * remove any instructions that are not in the ROB. The source of this 3532292SN/A * squash should be the commit stage. 3542292SN/A */ 3558138SAli.Saidi@ARM.com void squash(const TheISA::PCState &newPC, const InstSeqNum &seq_num, 3568138SAli.Saidi@ARM.com DynInstPtr &squashInst, ThreadID tid); 3571684SN/A 3582292SN/A /** Ticks the fetch stage, processing all inputs signals and fetching 3592292SN/A * as many instructions as possible. 3602292SN/A */ 3611684SN/A void tick(); 3621684SN/A 3632292SN/A /** Checks all input signals and updates the status as necessary. 3642292SN/A * @return: Returns if the status has changed due to input signals. 3652292SN/A */ 3666221Snate@binkert.org bool checkSignalsAndUpdate(ThreadID tid); 3671684SN/A 3682292SN/A /** Does the actual fetching of instructions and passing them on to the 3692292SN/A * next stage. 3702292SN/A * @param status_change fetch() sets this variable if there was a status 3712292SN/A * change (ie switching to IcacheMissStall). 3722292SN/A */ 3732292SN/A void fetch(bool &status_change); 3742292SN/A 3752292SN/A /** Align a PC to the start of an I-cache block. */ 3761062SN/A Addr icacheBlockAlignPC(Addr addr) 3771062SN/A { 3781062SN/A return (addr & ~(cacheBlkMask)); 3791062SN/A } 3801061SN/A 3811060SN/A private: 3827764Sgblack@eecs.umich.edu DynInstPtr buildInst(ThreadID tid, StaticInstPtr staticInst, 3837764Sgblack@eecs.umich.edu StaticInstPtr curMacroop, TheISA::PCState thisPC, 3847764Sgblack@eecs.umich.edu TheISA::PCState nextPC, bool trace); 3857764Sgblack@eecs.umich.edu 3862698Sktlim@umich.edu /** Handles retrying the fetch access. */ 3872696Sktlim@umich.edu void recvRetry(); 3882696Sktlim@umich.edu 3892292SN/A /** Returns the appropriate thread to fetch, given the fetch policy. */ 3906221Snate@binkert.org ThreadID getFetchingThread(FetchPriority &fetch_priority); 3912292SN/A 3922292SN/A /** Returns the appropriate thread to fetch using a round robin policy. */ 3936221Snate@binkert.org ThreadID roundRobin(); 3942292SN/A 3952292SN/A /** Returns the appropriate thread to fetch using the IQ count policy. */ 3966221Snate@binkert.org ThreadID iqCount(); 3972292SN/A 3982292SN/A /** Returns the appropriate thread to fetch using the LSQ count policy. */ 3996221Snate@binkert.org ThreadID lsqCount(); 4002292SN/A 4016221Snate@binkert.org /** Returns the appropriate thread to fetch using the branch count 4026221Snate@binkert.org * policy. */ 4036221Snate@binkert.org ThreadID branchCount(); 4042292SN/A 4058462Sgeoffrey.blake@arm.com /** Pipeline the next I-cache access to the current one. */ 4068462Sgeoffrey.blake@arm.com void pipelineIcacheAccesses(ThreadID tid); 4078462Sgeoffrey.blake@arm.com 4088462Sgeoffrey.blake@arm.com /** Profile the reasons of fetch stall. */ 4098462Sgeoffrey.blake@arm.com void profileStall(ThreadID tid); 4108462Sgeoffrey.blake@arm.com 4112292SN/A private: 4122733Sktlim@umich.edu /** Pointer to the O3CPU. */ 4132733Sktlim@umich.edu O3CPU *cpu; 4141060SN/A 4151060SN/A /** Time buffer interface. */ 4161060SN/A TimeBuffer<TimeStruct> *timeBuffer; 4171060SN/A 4181060SN/A /** Wire to get decode's information from backwards time buffer. */ 4191060SN/A typename TimeBuffer<TimeStruct>::wire fromDecode; 4201060SN/A 4211060SN/A /** Wire to get rename's information from backwards time buffer. */ 4221060SN/A typename TimeBuffer<TimeStruct>::wire fromRename; 4231060SN/A 4241060SN/A /** Wire to get iew's information from backwards time buffer. */ 4251060SN/A typename TimeBuffer<TimeStruct>::wire fromIEW; 4261060SN/A 4271060SN/A /** Wire to get commit's information from backwards time buffer. */ 4281060SN/A typename TimeBuffer<TimeStruct>::wire fromCommit; 4291060SN/A 4301060SN/A /** Internal fetch instruction queue. */ 4311060SN/A TimeBuffer<FetchStruct> *fetchQueue; 4321060SN/A 4331060SN/A //Might be annoying how this name is different than the queue. 4341060SN/A /** Wire used to write any information heading to decode. */ 4351060SN/A typename TimeBuffer<FetchStruct>::wire toDecode; 4361060SN/A 4371060SN/A /** Icache interface. */ 4382669Sktlim@umich.edu IcachePort *icachePort; 4391060SN/A 4401061SN/A /** BPredUnit. */ 4411061SN/A BPredUnit branchPred; 4421061SN/A 4434182Sgblack@eecs.umich.edu /** Predecoder. */ 4444182Sgblack@eecs.umich.edu TheISA::Predecoder predecoder; 4454182Sgblack@eecs.umich.edu 4467720Sgblack@eecs.umich.edu TheISA::PCState pc[Impl::MaxThreads]; 4472292SN/A 4487764Sgblack@eecs.umich.edu Addr fetchOffset[Impl::MaxThreads]; 4497764Sgblack@eecs.umich.edu 4507764Sgblack@eecs.umich.edu StaticInstPtr macroop[Impl::MaxThreads]; 4517764Sgblack@eecs.umich.edu 4528314Sgeoffrey.blake@arm.com /** Can the fetch stage redirect from an interrupt on this instruction? */ 4538314Sgeoffrey.blake@arm.com bool delayedCommit[Impl::MaxThreads]; 4548314Sgeoffrey.blake@arm.com 4552678Sktlim@umich.edu /** Memory request used to access cache. */ 4562678Sktlim@umich.edu RequestPtr memReq[Impl::MaxThreads]; 4572292SN/A 4582292SN/A /** Variable that tracks if fetch has written to the time buffer this 4592292SN/A * cycle. Used to tell CPU if there is activity this cycle. 4602292SN/A */ 4612292SN/A bool wroteToTimeBuffer; 4622292SN/A 4632292SN/A /** Tracks how many instructions has been fetched this cycle. */ 4642292SN/A int numInst; 4652292SN/A 4662292SN/A /** Source of possible stalls. */ 4672292SN/A struct Stalls { 4682292SN/A bool decode; 4692292SN/A bool rename; 4702292SN/A bool iew; 4712292SN/A bool commit; 4722292SN/A }; 4732292SN/A 4742292SN/A /** Tracks which stages are telling fetch to stall. */ 4752292SN/A Stalls stalls[Impl::MaxThreads]; 4761060SN/A 4771060SN/A /** Decode to fetch delay, in ticks. */ 4781060SN/A unsigned decodeToFetchDelay; 4791060SN/A 4801060SN/A /** Rename to fetch delay, in ticks. */ 4811060SN/A unsigned renameToFetchDelay; 4821060SN/A 4831060SN/A /** IEW to fetch delay, in ticks. */ 4841060SN/A unsigned iewToFetchDelay; 4851060SN/A 4861060SN/A /** Commit to fetch delay, in ticks. */ 4871060SN/A unsigned commitToFetchDelay; 4881060SN/A 4891060SN/A /** The width of fetch in instructions. */ 4901060SN/A unsigned fetchWidth; 4911060SN/A 4922696Sktlim@umich.edu /** Is the cache blocked? If so no threads can access it. */ 4932696Sktlim@umich.edu bool cacheBlocked; 4942696Sktlim@umich.edu 4952696Sktlim@umich.edu /** The packet that is waiting to be retried. */ 4962696Sktlim@umich.edu PacketPtr retryPkt; 4972696Sktlim@umich.edu 4982696Sktlim@umich.edu /** The thread that is waiting on the cache to tell fetch to retry. */ 4996221Snate@binkert.org ThreadID retryTid; 5002696Sktlim@umich.edu 5011060SN/A /** Cache block size. */ 5021062SN/A int cacheBlkSize; 5031060SN/A 5041060SN/A /** Mask to get a cache block's address. */ 5051062SN/A Addr cacheBlkMask; 5061060SN/A 5071062SN/A /** The cache line being fetched. */ 5082292SN/A uint8_t *cacheData[Impl::MaxThreads]; 5091060SN/A 5102893Sktlim@umich.edu /** The PC of the cacheline that has been loaded. */ 5112893Sktlim@umich.edu Addr cacheDataPC[Impl::MaxThreads]; 5122893Sktlim@umich.edu 5132906Sktlim@umich.edu /** Whether or not the cache data is valid. */ 5142906Sktlim@umich.edu bool cacheDataValid[Impl::MaxThreads]; 5152906Sktlim@umich.edu 5161060SN/A /** Size of instructions. */ 5171060SN/A int instSize; 5181060SN/A 5191060SN/A /** Icache stall statistics. */ 5202292SN/A Counter lastIcacheStall[Impl::MaxThreads]; 5211062SN/A 5222292SN/A /** List of Active Threads */ 5236221Snate@binkert.org std::list<ThreadID> *activeThreads; 5242292SN/A 5252292SN/A /** Number of threads. */ 5266221Snate@binkert.org ThreadID numThreads; 5272292SN/A 5282292SN/A /** Number of threads that are actively fetching. */ 5296221Snate@binkert.org ThreadID numFetchingThreads; 5302292SN/A 5312292SN/A /** Thread ID being fetched. */ 5326221Snate@binkert.org ThreadID threadFetched; 5332292SN/A 5342348SN/A /** Checks if there is an interrupt pending. If there is, fetch 5352348SN/A * must stop once it is not fetching PAL instructions. 5362348SN/A */ 5372292SN/A bool interruptPending; 5382292SN/A 5392843Sktlim@umich.edu /** Is there a drain pending. */ 5402843Sktlim@umich.edu bool drainPending; 5412843Sktlim@umich.edu 5422348SN/A /** Records if fetch is switched out. */ 5432307SN/A bool switchedOut; 5442307SN/A 5458462Sgeoffrey.blake@arm.com /** Set to true if a pipelined I-cache request should be issued. */ 5468462Sgeoffrey.blake@arm.com bool issuePipelinedIfetch[Impl::MaxThreads]; 5478462Sgeoffrey.blake@arm.com 5488462Sgeoffrey.blake@arm.com /** Event used to delay fault generation of translation faults */ 5498462Sgeoffrey.blake@arm.com FinishTranslationEvent finishTranslationEvent; 5508462Sgeoffrey.blake@arm.com 5512292SN/A // @todo: Consider making these vectors and tracking on a per thread basis. 5522292SN/A /** Stat for total number of cycles stalled due to an icache miss. */ 5535999Snate@binkert.org Stats::Scalar icacheStallCycles; 5542292SN/A /** Stat for total number of fetched instructions. */ 5555999Snate@binkert.org Stats::Scalar fetchedInsts; 5562727Sktlim@umich.edu /** Total number of fetched branches. */ 5575999Snate@binkert.org Stats::Scalar fetchedBranches; 5582292SN/A /** Stat for total number of predicted branches. */ 5595999Snate@binkert.org Stats::Scalar predictedBranches; 5602292SN/A /** Stat for total number of cycles spent fetching. */ 5615999Snate@binkert.org Stats::Scalar fetchCycles; 5622292SN/A /** Stat for total number of cycles spent squashing. */ 5635999Snate@binkert.org Stats::Scalar fetchSquashCycles; 5647849SAli.Saidi@ARM.com /** Stat for total number of cycles spent waiting for translation */ 5657849SAli.Saidi@ARM.com Stats::Scalar fetchTlbCycles; 5662292SN/A /** Stat for total number of cycles spent blocked due to other stages in 5672292SN/A * the pipeline. 5682292SN/A */ 5695999Snate@binkert.org Stats::Scalar fetchIdleCycles; 5702348SN/A /** Total number of cycles spent blocked. */ 5715999Snate@binkert.org Stats::Scalar fetchBlockedCycles; 5722348SN/A /** Total number of cycles spent in any other state. */ 5735999Snate@binkert.org Stats::Scalar fetchMiscStallCycles; 5748462Sgeoffrey.blake@arm.com /** Total number of cycles spent in waiting for drains. */ 5758462Sgeoffrey.blake@arm.com Stats::Scalar fetchPendingDrainCycles; 5768462Sgeoffrey.blake@arm.com /** Total number of stall cycles caused by no active threads to run. */ 5778462Sgeoffrey.blake@arm.com Stats::Scalar fetchNoActiveThreadStallCycles; 5788462Sgeoffrey.blake@arm.com /** Total number of stall cycles caused by pending traps. */ 5798462Sgeoffrey.blake@arm.com Stats::Scalar fetchPendingTrapStallCycles; 5808462Sgeoffrey.blake@arm.com /** Total number of stall cycles caused by pending quiesce instructions. */ 5818462Sgeoffrey.blake@arm.com Stats::Scalar fetchPendingQuiesceStallCycles; 5828462Sgeoffrey.blake@arm.com /** Total number of stall cycles caused by I-cache wait retrys. */ 5838462Sgeoffrey.blake@arm.com Stats::Scalar fetchIcacheWaitRetryStallCycles; 5842292SN/A /** Stat for total number of fetched cache lines. */ 5855999Snate@binkert.org Stats::Scalar fetchedCacheLines; 5862348SN/A /** Total number of outstanding icache accesses that were dropped 5872348SN/A * due to a squash. 5882348SN/A */ 5895999Snate@binkert.org Stats::Scalar fetchIcacheSquashes; 5908064SAli.Saidi@ARM.com /** Total number of outstanding tlb accesses that were dropped 5918064SAli.Saidi@ARM.com * due to a squash. 5928064SAli.Saidi@ARM.com */ 5938064SAli.Saidi@ARM.com Stats::Scalar fetchTlbSquashes; 5942292SN/A /** Distribution of number of instructions fetched each cycle. */ 5955999Snate@binkert.org Stats::Distribution fetchNisnDist; 5962348SN/A /** Rate of how often fetch was idle. */ 5972292SN/A Stats::Formula idleRate; 5982348SN/A /** Number of branch fetches per cycle. */ 5992292SN/A Stats::Formula branchRate; 6002348SN/A /** Number of instruction fetched per cycle. */ 6012292SN/A Stats::Formula fetchRate; 6021060SN/A}; 6031060SN/A 6042292SN/A#endif //__CPU_O3_FETCH_HH__ 605