cpu.hh

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

HH
732
字号
/* * Copyright (c) 2004, 2005 * 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_CPU_HH__#define __CPU_O3_CPU_HH__#include <iostream>#include <list>#include <queue>#include <set>#include <vector>#include "arch/types.hh"#include "base/statistics.hh"#include "base/timebuf.hh"#include "config/full_system.hh"#include "config/use_checker.hh"#include "cpu/activity.hh"#include "cpu/base.hh"#include "cpu/simple_thread.hh"#include "cpu/o3/comm.hh"#include "cpu/o3/cpu_policy.hh"#include "cpu/o3/scoreboard.hh"#include "cpu/o3/thread_state.hh"//#include "cpu/o3/thread_context.hh"#include "sim/process.hh"template <class>class Checker;class ThreadContext;template <class>class O3ThreadContext;class Checkpoint;class MemObject;class Process;class BaseO3CPU : public BaseCPU{    //Stuff that's pretty ISA independent will go here.  public:    typedef BaseCPU::Params Params;    BaseO3CPU(Params *params);    void regStats();    /** Sets this CPU's ID. */    void setCpuId(int id) { cpu_id = id; }    /** Reads this CPU's ID. */    int readCpuId() { return cpu_id; }  protected:    int cpu_id;};/** * FullO3CPU class, has each of the stages (fetch through commit) * within it, as well as all of the time buffers between stages.  The * tick() function for the CPU is defined here. */template <class Impl>class FullO3CPU : public BaseO3CPU{  public:    // Typedefs from the Impl here.    typedef typename Impl::CPUPol CPUPolicy;    typedef typename Impl::DynInstPtr DynInstPtr;    typedef typename Impl::O3CPU O3CPU;    typedef typename Impl::Params Params;    typedef O3ThreadState<Impl> Thread;    typedef typename std::list<DynInstPtr>::iterator ListIt;    friend class O3ThreadContext<Impl>;  public:    enum Status {        Running,        Idle,        Halted,        Blocked,        SwitchedOut    };    TheISA::ITB * itb;    TheISA::DTB * dtb;    /** Overall CPU status. */    Status _status;    /** Per-thread status in CPU, used for SMT.  */    Status _threadStatus[Impl::MaxThreads];  private:    class TickEvent : public Event    {      private:        /** Pointer to the CPU. */        FullO3CPU<Impl> *cpu;      public:        /** Constructs a tick event. */        TickEvent(FullO3CPU<Impl> *c);        /** Processes a tick event, calling tick() on the CPU. */        void process();        /** Returns the description of the tick event. */        const char *description() const;    };    /** The tick event used for scheduling CPU ticks. */    TickEvent tickEvent;    /** Schedule tick event, regardless of its current state. */    void scheduleTickEvent(int delay)    {        if (tickEvent.squashed())            tickEvent.reschedule(nextCycle(curTick + ticks(delay)));        else if (!tickEvent.scheduled())            tickEvent.schedule(nextCycle(curTick + ticks(delay)));    }    /** Unschedule tick event, regardless of its current state. */    void unscheduleTickEvent()    {        if (tickEvent.scheduled())            tickEvent.squash();    }    class ActivateThreadEvent : public Event    {      private:        /** Number of Thread to Activate */        int tid;        /** Pointer to the CPU. */        FullO3CPU<Impl> *cpu;      public:        /** Constructs the event. */        ActivateThreadEvent();        /** Initialize Event */        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);        /** Processes the event, calling activateThread() on the CPU. */        void process();        /** Returns the description of the event. */        const char *description() const;    };    /** Schedule thread to activate , regardless of its current state. */    void scheduleActivateThreadEvent(int tid, int delay)    {        // Schedule thread to activate, regardless of its current state.        if (activateThreadEvent[tid].squashed())            activateThreadEvent[tid].                reschedule(nextCycle(curTick + ticks(delay)));        else if (!activateThreadEvent[tid].scheduled())            activateThreadEvent[tid].                schedule(nextCycle(curTick + ticks(delay)));    }    /** Unschedule actiavte thread event, regardless of its current state. */    void unscheduleActivateThreadEvent(int tid)    {        if (activateThreadEvent[tid].scheduled())            activateThreadEvent[tid].squash();    }    /** The tick event used for scheduling CPU ticks. */    ActivateThreadEvent activateThreadEvent[Impl::MaxThreads];    class DeallocateContextEvent : public Event    {      private:        /** Number of Thread to deactivate */        int tid;        /** Should the thread be removed from the CPU? */        bool remove;        /** Pointer to the CPU. */        FullO3CPU<Impl> *cpu;      public:        /** Constructs the event. */        DeallocateContextEvent();        /** Initialize Event */        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);        /** Processes the event, calling activateThread() on the CPU. */        void process();        /** Sets whether the thread should also be removed from the CPU. */        void setRemove(bool _remove) { remove = _remove; }        /** Returns the description of the event. */        const char *description() const;    };    /** Schedule cpu to deallocate thread context.*/    void scheduleDeallocateContextEvent(int tid, bool remove, int delay)    {        // Schedule thread to activate, regardless of its current state.        if (deallocateContextEvent[tid].squashed())            deallocateContextEvent[tid].                reschedule(nextCycle(curTick + ticks(delay)));        else if (!deallocateContextEvent[tid].scheduled())            deallocateContextEvent[tid].                schedule(nextCycle(curTick + ticks(delay)));    }    /** Unschedule thread deallocation in CPU */    void unscheduleDeallocateContextEvent(int tid)    {        if (deallocateContextEvent[tid].scheduled())            deallocateContextEvent[tid].squash();    }    /** The tick event used for scheduling CPU ticks. */    DeallocateContextEvent deallocateContextEvent[Impl::MaxThreads];  public:    /** Constructs a CPU with the given parameters. */    FullO3CPU(O3CPU *o3_cpu, Params *params);    /** Destructor. */    ~FullO3CPU();    /** Registers statistics. */    void fullCPURegStats();    void demapPage(Addr vaddr, uint64_t asn)    {        this->itb->demapPage(vaddr, asn);        this->dtb->demapPage(vaddr, asn);    }    void demapInstPage(Addr vaddr, uint64_t asn)    {        this->itb->demapPage(vaddr, asn);    }    void demapDataPage(Addr vaddr, uint64_t asn)    {        this->dtb->demapPage(vaddr, asn);    }    /** Translates instruction requestion. */    Fault translateInstReq(RequestPtr &req, Thread *thread)    {        return this->itb->translate(req, thread->getTC());    }    /** Translates data read request. */    Fault translateDataReadReq(RequestPtr &req, Thread *thread)    {        return this->dtb->translate(req, thread->getTC(), false);    }    /** Translates data write request. */    Fault translateDataWriteReq(RequestPtr &req, Thread *thread)    {        return this->dtb->translate(req, thread->getTC(), true);    }    /** Returns a specific port. */    Port *getPort(const std::string &if_name, int idx);    /** Ticks CPU, calling tick() on each stage, and checking the overall     *  activity to see if the CPU should deschedule itself.     */    void tick();    /** Initialize the CPU */    void init();    /** Returns the Number of Active Threads in the CPU */    int numActiveThreads()    { return activeThreads.size(); }    /** Add Thread to Active Threads List */    void activateThread(unsigned tid);    /** Remove Thread from Active Threads List */    void deactivateThread(unsigned tid);    /** Setup CPU to insert a thread's context */    void insertThread(unsigned tid);    /** Remove all of a thread's context from CPU */    void removeThread(unsigned tid);    /** Count the Total Instructions Committed in the CPU. */    virtual Counter totalInstructions() const    {        Counter total(0);        for (int i=0; i < thread.size(); i++)            total += thread[i]->numInst;        return total;    }    /** Add Thread to Active Threads List. */    void activateContext(int tid, int delay);    /** Remove Thread from Active Threads List */    void suspendContext(int tid);    /** Remove Thread from Active Threads List &&     *  Possibly Remove Thread Context from CPU.     */    bool deallocateContext(int tid, bool remove, int delay = 1);    /** Remove Thread from Active Threads List &&     *  Remove Thread Context from CPU.     */    void haltContext(int tid);    /** Activate a Thread When CPU Resources are Available. */    void activateWhenReady(int tid);    /** Add or Remove a Thread Context in the CPU. */    void doContextSwitch();    /** Update The Order In Which We Process Threads. */    void updateThreadPriority();    /** Serialize state. */    virtual void serialize(std::ostream &os);    /** Unserialize from a checkpoint. */

⌨️ 快捷键说明

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