cpu.hh

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· HH 代码 · 共 732 行 · 第 1/2 页

HH
732
字号
    virtual void unserialize(Checkpoint *cp, const std::string &section);  public:    /** Executes a syscall on this cycle.     *  ---------------------------------------     *  Note: this is a virtual function. CPU-Specific     *  functionality defined in derived classes     */    virtual void syscall(int tid) { panic("Unimplemented!"); }    /** Starts draining the CPU's pipeline of all instructions in     * order to stop all memory accesses. */    virtual unsigned int drain(Event *drain_event);    /** Resumes execution after a drain. */    virtual void resume();    /** Signals to this CPU that a stage has completed switching out. */    void signalDrained();    /** Switches out this CPU. */    virtual void switchOut();    /** Takes over from another CPU. */    virtual void takeOverFrom(BaseCPU *oldCPU);    /** Get the current instruction sequence number, and increment it. */    InstSeqNum getAndIncrementInstSeq()    { return globalSeqNum++; }#if FULL_SYSTEM    /** Update the Virt and Phys ports of all ThreadContexts to     * reflect change in memory connections. */    void updateMemPorts();    /** Check if this address is a valid instruction address. */    bool validInstAddr(Addr addr) { return true; }    /** Check if this address is a valid data address. */    bool validDataAddr(Addr addr) { return true; }    /** Get instruction asid. */    int getInstAsid(unsigned tid)    { return regFile.miscRegs[tid].getInstAsid(); }    /** Get data asid. */    int getDataAsid(unsigned tid)    { return regFile.miscRegs[tid].getDataAsid(); }#else    /** Get instruction asid. */    int getInstAsid(unsigned tid)    { return thread[tid]->getInstAsid(); }    /** Get data asid. */    int getDataAsid(unsigned tid)    { return thread[tid]->getDataAsid(); }#endif    /** Register accessors.  Index refers to the physical register index. */    uint64_t readIntReg(int reg_idx);    TheISA::FloatReg readFloatReg(int reg_idx);    TheISA::FloatReg readFloatReg(int reg_idx, int width);    TheISA::FloatRegBits readFloatRegBits(int reg_idx);    TheISA::FloatRegBits readFloatRegBits(int reg_idx, int width);    void setIntReg(int reg_idx, uint64_t val);    void setFloatReg(int reg_idx, TheISA::FloatReg val);    void setFloatReg(int reg_idx, TheISA::FloatReg val, int width);    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val, int width);    uint64_t readArchIntReg(int reg_idx, unsigned tid);    float readArchFloatRegSingle(int reg_idx, unsigned tid);    double readArchFloatRegDouble(int reg_idx, unsigned tid);    uint64_t readArchFloatRegInt(int reg_idx, unsigned tid);    /** Architectural register accessors.  Looks up in the commit     * rename table to obtain the true physical index of the     * architected register first, then accesses that physical     * register.     */    void setArchIntReg(int reg_idx, uint64_t val, unsigned tid);    void setArchFloatRegSingle(int reg_idx, float val, unsigned tid);    void setArchFloatRegDouble(int reg_idx, double val, unsigned tid);    void setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid);    /** Reads the commit PC of a specific thread. */    Addr readPC(unsigned tid);    /** Sets the commit PC of a specific thread. */    void setPC(Addr new_PC, unsigned tid);    /** Reads the commit micro PC of a specific thread. */    Addr readMicroPC(unsigned tid);    /** Sets the commmit micro PC of a specific thread. */    void setMicroPC(Addr new_microPC, unsigned tid);    /** Reads the next PC of a specific thread. */    Addr readNextPC(unsigned tid);    /** Sets the next PC of a specific thread. */    void setNextPC(Addr val, unsigned tid);    /** Reads the next NPC of a specific thread. */    Addr readNextNPC(unsigned tid);    /** Sets the next NPC of a specific thread. */    void setNextNPC(Addr val, unsigned tid);    /** Reads the commit next micro PC of a specific thread. */    Addr readNextMicroPC(unsigned tid);    /** Sets the commit next micro PC of a specific thread. */    void setNextMicroPC(Addr val, unsigned tid);    /** Function to add instruction onto the head of the list of the     *  instructions.  Used when new instructions are fetched.     */    ListIt addInst(DynInstPtr &inst);    /** Function to tell the CPU that an instruction has completed. */    void instDone(unsigned tid);    /** Add Instructions to the CPU Remove List*/    void addToRemoveList(DynInstPtr &inst);    /** Remove an instruction from the front end of the list.  There's     *  no restriction on location of the instruction.     */    void removeFrontInst(DynInstPtr &inst);    /** Remove all instructions that are not currently in the ROB.     *  There's also an option to not squash delay slot instructions.*/    void removeInstsNotInROB(unsigned tid);    /** Remove all instructions younger than the given sequence number. */    void removeInstsUntil(const InstSeqNum &seq_num,unsigned tid);    /** Removes the instruction pointed to by the iterator. */    inline void squashInstIt(const ListIt &instIt, const unsigned &tid);    /** Cleans up all instructions on the remove list. */    void cleanUpRemovedInsts();    /** Debug function to print all instructions on the list. */    void dumpInsts();  public:    /** List of all the instructions in flight. */    std::list<DynInstPtr> instList;    /** List of all the instructions that will be removed at the end of this     *  cycle.     */    std::queue<ListIt> removeList;#ifdef DEBUG    /** Debug structure to keep track of the sequence numbers still in     * flight.     */    std::set<InstSeqNum> snList;#endif    /** Records if instructions need to be removed this cycle due to     *  being retired or squashed.     */    bool removeInstsThisCycle;  protected:    /** The fetch stage. */    typename CPUPolicy::Fetch fetch;    /** The decode stage. */    typename CPUPolicy::Decode decode;    /** The dispatch stage. */    typename CPUPolicy::Rename rename;    /** The issue/execute/writeback stages. */    typename CPUPolicy::IEW iew;    /** The commit stage. */    typename CPUPolicy::Commit commit;    /** The register file. */    typename CPUPolicy::RegFile regFile;    /** The free list. */    typename CPUPolicy::FreeList freeList;    /** The rename map. */    typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];    /** The commit rename map. */    typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];    /** The re-order buffer. */    typename CPUPolicy::ROB rob;    /** Active Threads List */    std::list<unsigned> activeThreads;    /** Integer Register Scoreboard */    Scoreboard scoreboard;  public:    /** Enum to give each stage a specific index, so when calling     *  activateStage() or deactivateStage(), they can specify which stage     *  is being activated/deactivated.     */    enum StageIdx {        FetchIdx,        DecodeIdx,        RenameIdx,        IEWIdx,        CommitIdx,        NumStages };    /** Typedefs from the Impl to get the structs that each of the     *  time buffers should use.     */    typedef typename CPUPolicy::TimeStruct TimeStruct;    typedef typename CPUPolicy::FetchStruct FetchStruct;    typedef typename CPUPolicy::DecodeStruct DecodeStruct;    typedef typename CPUPolicy::RenameStruct RenameStruct;    typedef typename CPUPolicy::IEWStruct IEWStruct;    /** The main time buffer to do backwards communication. */    TimeBuffer<TimeStruct> timeBuffer;    /** The fetch stage's instruction queue. */    TimeBuffer<FetchStruct> fetchQueue;    /** The decode stage's instruction queue. */    TimeBuffer<DecodeStruct> decodeQueue;    /** The rename stage's instruction queue. */    TimeBuffer<RenameStruct> renameQueue;    /** The IEW stage's instruction queue. */    TimeBuffer<IEWStruct> iewQueue;  private:    /** The activity recorder; used to tell if the CPU has any     * activity remaining or if it can go to idle and deschedule     * itself.     */    ActivityRecorder activityRec;  public:    /** Records that there was time buffer activity this cycle. */    void activityThisCycle() { activityRec.activity(); }    /** Changes a stage's status to active within the activity recorder. */    void activateStage(const StageIdx idx)    { activityRec.activateStage(idx); }    /** Changes a stage's status to inactive within the activity recorder. */    void deactivateStage(const StageIdx idx)    { activityRec.deactivateStage(idx); }    /** Wakes the CPU, rescheduling the CPU if it's not already active. */    void wakeCPU();    /** Gets a free thread id. Use if thread ids change across system. */    int getFreeTid();  public:    /** Returns a pointer to a thread context. */    ThreadContext *tcBase(unsigned tid)    {        return thread[tid]->getTC();    }    /** The global sequence number counter. */    InstSeqNum globalSeqNum;//[Impl::MaxThreads];#if USE_CHECKER    /** Pointer to the checker, which can dynamically verify     * instruction results at run time.  This can be set to NULL if it     * is not being used.     */    Checker<DynInstPtr> *checker;#endif#if FULL_SYSTEM    /** Pointer to the system. */    System *system;    /** Pointer to physical memory. */    PhysicalMemory *physmem;#endif    /** Event to call process() on once draining has completed. */    Event *drainEvent;    /** Counter of how many stages have completed draining. */    int drainCount;    /** Pointers to all of the threads in the CPU. */    std::vector<Thread *> thread;    /** Whether or not the CPU should defer its registration. */    bool deferRegistration;    /** Is there a context switch pending? */    bool contextSwitch;    /** Threads Scheduled to Enter CPU */    std::list<int> cpuWaitList;    /** The cycle that the CPU was last running, used for statistics. */    Tick lastRunningCycle;    /** The cycle that the CPU was last activated by a new thread*/    Tick lastActivatedCycle;    /** Number of Threads CPU can process */    unsigned numThreads;    /** Mapping for system thread id to cpu id */    std::map<unsigned,unsigned> threadMap;    /** Available thread ids in the cpu*/    std::vector<unsigned> tids;    /** Stat for total number of times the CPU is descheduled. */    Stats::Scalar<> timesIdled;    /** Stat for total number of cycles the CPU spends descheduled. */    Stats::Scalar<> idleCycles;    /** Stat for the number of committed instructions per thread. */    Stats::Vector<> committedInsts;    /** Stat for the total number of committed instructions. */    Stats::Scalar<> totalCommittedInsts;    /** Stat for the CPI per thread. */    Stats::Formula cpi;    /** Stat for the total CPI. */    Stats::Formula totalCpi;    /** Stat for the IPC per thread. */    Stats::Formula ipc;    /** Stat for the total IPC. */    Stats::Formula totalIpc;};#endif // __CPU_O3_CPU_HH__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?