inst_queue.hh

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

HH
503
字号
/* * 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 * */#ifndef __CPU_O3_INST_QUEUE_HH__#define __CPU_O3_INST_QUEUE_HH__#include <list>#include <map>#include <queue>#include <vector>#include "base/statistics.hh"#include "base/timebuf.hh"#include "cpu/inst_seq.hh"#include "cpu/o3/dep_graph.hh"#include "cpu/op_class.hh"#include "sim/host.hh"class FUPool;class MemInterface;/** * A standard instruction queue class.  It holds ready instructions, in * order, in seperate priority queues to facilitate the scheduling of * instructions.  The IQ uses a separate linked list to track dependencies. * Similar to the rename map and the free list, it expects that * floating point registers have their indices start after the integer * registers (ie with 96 int and 96 fp registers, regs 0-95 are integer * and 96-191 are fp).  This remains true even for both logical and * physical register indices. The IQ depends on the memory dependence unit to * track when memory operations are ready in terms of ordering; register * dependencies are tracked normally. Right now the IQ also handles the * execution timing; this is mainly to allow back-to-back scheduling without * requiring IEW to be able to peek into the IQ. At the end of the execution * latency, the instruction is put into the queue to execute, where it will * have the execute() function called on it. * @todo: Make IQ able to handle multiple FU pools. */template <class Impl>class InstructionQueue{  public:    //Typedefs from the Impl.    typedef typename Impl::O3CPU O3CPU;    typedef typename Impl::DynInstPtr DynInstPtr;    typedef typename Impl::Params Params;    typedef typename Impl::CPUPol::IEW IEW;    typedef typename Impl::CPUPol::MemDepUnit MemDepUnit;    typedef typename Impl::CPUPol::IssueStruct IssueStruct;    typedef typename Impl::CPUPol::TimeStruct TimeStruct;    // Typedef of iterator through the list of instructions.    typedef typename std::list<DynInstPtr>::iterator ListIt;    friend class Impl::O3CPU;    /** FU completion event class. */    class FUCompletion : public Event {      private:        /** Executing instruction. */        DynInstPtr inst;        /** Index of the FU used for executing. */        int fuIdx;        /** Pointer back to the instruction queue. */        InstructionQueue<Impl> *iqPtr;        /** Should the FU be added to the list to be freed upon         * completing this event.         */        bool freeFU;      public:        /** Construct a FU completion event. */        FUCompletion(DynInstPtr &_inst, int fu_idx,                     InstructionQueue<Impl> *iq_ptr);        virtual void process();        virtual const char *description() const;        void setFreeFU() { freeFU = true; }    };    /** Constructs an IQ. */    InstructionQueue(O3CPU *cpu_ptr, IEW *iew_ptr, Params *params);    /** Destructs the IQ. */    ~InstructionQueue();    /** Returns the name of the IQ. */    std::string name() const;    /** Registers statistics. */    void regStats();    /** Resets all instruction queue state. */    void resetState();    /** Sets active threads list. */    void setActiveThreads(std::list<unsigned> *at_ptr);    /** Sets the timer buffer between issue and execute. */    void setIssueToExecuteQueue(TimeBuffer<IssueStruct> *i2eQueue);    /** Sets the global time buffer. */    void setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr);    /** Switches out the instruction queue. */    void switchOut();    /** Takes over execution from another CPU's thread. */    void takeOverFrom();    /** Returns if the IQ is switched out. */    bool isSwitchedOut() { return switchedOut; }    /** Number of entries needed for given amount of threads. */    int entryAmount(int num_threads);    /** Resets max entries for all threads. */    void resetEntries();    /** Returns total number of free entries. */    unsigned numFreeEntries();    /** Returns number of free entries for a thread. */    unsigned numFreeEntries(unsigned tid);    /** Returns whether or not the IQ is full. */    bool isFull();    /** Returns whether or not the IQ is full for a specific thread. */    bool isFull(unsigned tid);    /** Returns if there are any ready instructions in the IQ. */    bool hasReadyInsts();    /** Inserts a new instruction into the IQ. */    void insert(DynInstPtr &new_inst);    /** Inserts a new, non-speculative instruction into the IQ. */    void insertNonSpec(DynInstPtr &new_inst);    /** Inserts a memory or write barrier into the IQ to make sure     *  loads and stores are ordered properly.     */    void insertBarrier(DynInstPtr &barr_inst);    /** Returns the oldest scheduled instruction, and removes it from     * the list of instructions waiting to execute.     */    DynInstPtr getInstToExecute();    /**     * Records the instruction as the producer of a register without     * adding it to the rest of the IQ.     */    void recordProducer(DynInstPtr &inst)    { addToProducers(inst); }    /** Process FU completion event. */    void processFUCompletion(DynInstPtr &inst, int fu_idx);    /**     * Schedules ready instructions, adding the ready ones (oldest first) to     * the queue to execute.     */    void scheduleReadyInsts();    /** Schedules a single specific non-speculative instruction. */    void scheduleNonSpec(const InstSeqNum &inst);    /**     * Commits all instructions up to and including the given sequence number,     * for a specific thread.     */    void commit(const InstSeqNum &inst, unsigned tid = 0);    /** Wakes all dependents of a completed instruction. */    int wakeDependents(DynInstPtr &completed_inst);    /** Adds a ready memory instruction to the ready list. */    void addReadyMemInst(DynInstPtr &ready_inst);    /**     * Reschedules a memory instruction. It will be ready to issue once     * replayMemInst() is called.     */    void rescheduleMemInst(DynInstPtr &resched_inst);    /** Replays a memory instruction. It must be rescheduled first. */    void replayMemInst(DynInstPtr &replay_inst);    /** Completes a memory operation. */    void completeMemInst(DynInstPtr &completed_inst);    /** Indicates an ordering violation between a store and a load. */    void violation(DynInstPtr &store, DynInstPtr &faulting_load);    /**     * Squashes instructions for a thread. Squashing information is obtained     * from the time buffer.     */    void squash(unsigned tid);    /** Returns the number of used entries for a thread. */    unsigned getCount(unsigned tid) { return count[tid]; };    /** Debug function to print all instructions. */    void printInsts();  private:    /** Does the actual squashing. */    void doSquash(unsigned tid);    /////////////////////////    // Various pointers    /////////////////////////    /** Pointer to the CPU. */    O3CPU *cpu;    /** Cache interface. */

⌨️ 快捷键说明

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