fetch.hh
来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· HH 代码 · 共 486 行 · 第 1/2 页
HH
486 行
/* * Copyright (c) 2004, 2005, 2006 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any * purpose, so long as the copyright notice above, this grant of * permission, and the disclaimer below appear in all copies made; and * so long as the name of The University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. * * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. * * Authors: Kevin T. Lim * Korey L. Sewell */#ifndef __CPU_O3_FETCH_HH__#define __CPU_O3_FETCH_HH__#include "arch/utility.hh"#include "arch/predecoder.hh"#include "base/statistics.hh"#include "base/timebuf.hh"#include "cpu/pc_event.hh"#include "mem/packet.hh"#include "mem/port.hh"#include "sim/eventq.hh"/** * DefaultFetch class handles both single threaded and SMT fetch. Its * width is specified by the parameters; each cycle it tries to fetch * that many instructions. It supports using a branch predictor to * predict direction and targets. * It supports the idling functionality of the CPU by indicating to * the CPU when it is active and inactive. */template <class Impl>class DefaultFetch{ public: /** Typedefs from Impl. */ typedef typename Impl::CPUPol CPUPol; typedef typename Impl::DynInst DynInst; typedef typename Impl::DynInstPtr DynInstPtr; typedef typename Impl::O3CPU O3CPU; typedef typename Impl::Params Params; /** Typedefs from the CPU policy. */ typedef typename CPUPol::BPredUnit BPredUnit; typedef typename CPUPol::FetchStruct FetchStruct; typedef typename CPUPol::TimeStruct TimeStruct; /** Typedefs from ISA. */ typedef TheISA::MachInst MachInst; typedef TheISA::ExtMachInst ExtMachInst; /** IcachePort class for DefaultFetch. Handles doing the * communication with the cache/memory. */ class IcachePort : public Port { protected: /** Pointer to fetch. */ DefaultFetch<Impl> *fetch; public: /** Default constructor. */ IcachePort(DefaultFetch<Impl> *_fetch) : Port(_fetch->name() + "-iport"), fetch(_fetch) { } bool snoopRangeSent; virtual void setPeer(Port *port); protected: /** Atomic version of receive. Panics. */ virtual Tick recvAtomic(PacketPtr pkt); /** Functional version of receive. Panics. */ virtual void recvFunctional(PacketPtr pkt); /** Receives status change. Other than range changing, panics. */ virtual void recvStatusChange(Status status); /** Returns the address ranges of this device. */ virtual void getDeviceAddressRanges(AddrRangeList &resp, bool &snoop) { resp.clear(); snoop = true; } /** Timing version of receive. Handles setting fetch to the * proper status to start fetching. */ virtual bool recvTiming(PacketPtr pkt); /** Handles doing a retry of a failed fetch. */ virtual void recvRetry(); }; public: /** Overall fetch status. Used to determine if the CPU can * deschedule itsef due to a lack of activity. */ enum FetchStatus { Active, Inactive }; /** Individual thread status. */ enum ThreadStatus { Running, Idle, Squashing, Blocked, Fetching, TrapPending, QuiescePending, SwitchOut, IcacheWaitResponse, IcacheWaitRetry, IcacheAccessComplete }; /** Fetching Policy, Add new policies here.*/ enum FetchPriority { SingleThread, RoundRobin, Branch, IQ, LSQ }; private: /** Fetch status. */ FetchStatus _status; /** Per-thread status. */ ThreadStatus fetchStatus[Impl::MaxThreads]; /** Fetch policy. */ FetchPriority fetchPolicy; /** List that has the threads organized by priority. */ std::list<unsigned> priorityList; public: /** DefaultFetch constructor. */ DefaultFetch(O3CPU *_cpu, Params *params); /** Returns the name of fetch. */ std::string name() const; /** Registers statistics. */ void regStats(); /** Returns the icache port. */ Port *getIcachePort() { return icachePort; } /** Sets the main backwards communication time buffer pointer. */ void setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer); /** Sets pointer to list of active threads. */ void setActiveThreads(std::list<unsigned> *at_ptr); /** Sets pointer to time buffer used to communicate to the next stage. */ void setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr); /** Initialize stage. */ void initStage(); /** Tells the fetch stage that the Icache is set. */ void setIcache(); /** Processes cache completion event. */ void processCacheCompletion(PacketPtr pkt); /** Begins the drain of the fetch stage. */ bool drain(); /** Resumes execution after a drain. */ void resume(); /** Tells fetch stage to prepare to be switched out. */ void switchOut(); /** Takes over from another CPU's thread. */ void takeOverFrom(); /** Checks if the fetch stage is switched out. */ bool isSwitchedOut() { return switchedOut; } /** Tells fetch to wake up from a quiesce instruction. */ void wakeFromQuiesce(); private: /** Changes the status of this stage to active, and indicates this * to the CPU. */ inline void switchToActive(); /** Changes the status of this stage to inactive, and indicates * this to the CPU. */ inline void switchToInactive(); /** * Looks up in the branch predictor to see if the next PC should be * either next PC+=MachInst or a branch target. * @param next_PC Next PC variable passed in by reference. It is * expected to be set to the current PC; it will be updated with what * the next PC will be. * @param next_NPC Used for ISAs which use delay slots. * @return Whether or not a branch was predicted as taken. */ bool lookupAndUpdateNextPC(DynInstPtr &inst, Addr &next_PC, Addr &next_NPC, Addr &next_MicroPC); /** * Fetches the cache line that contains fetch_PC. Returns any * fault that happened. Puts the data into the class variable * cacheData. * @param fetch_PC The PC address that is being fetched from. * @param ret_fault The fault reference that will be set to the result of * the icache access. * @param tid Thread id. * @return Any fault that occured. */ bool fetchCacheLine(Addr fetch_PC, Fault &ret_fault, unsigned tid);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?