inorder: inst count mgmt
[gem5.git] / src / cpu / o3 / commit.hh
index c39bc10f98cc0f0da201feb02e234ff67d3f3aba..d93b85984fbfdbfbf8ebab05ea3898723286a7e7 100644 (file)
 #ifndef __CPU_O3_COMMIT_HH__
 #define __CPU_O3_COMMIT_HH__
 
-#include "arch/faults.hh"
 #include "base/statistics.hh"
 #include "base/timebuf.hh"
 #include "cpu/exetrace.hh"
 #include "cpu/inst_seq.hh"
 
+class DerivO3CPUParams;
+
 template <class>
 class O3ThreadState;
 
@@ -70,7 +71,6 @@ class DefaultCommit
     // Typedefs from the Impl.
     typedef typename Impl::O3CPU O3CPU;
     typedef typename Impl::DynInstPtr DynInstPtr;
-    typedef typename Impl::Params Params;
     typedef typename Impl::CPUPol CPUPol;
 
     typedef typename CPUPol::RenameMap RenameMap;
@@ -92,13 +92,13 @@ class DefaultCommit
     class TrapEvent : public Event {
       private:
         DefaultCommit<Impl> *commit;
-        unsigned tid;
+        ThreadID tid;
 
       public:
-        TrapEvent(DefaultCommit<Impl> *_commit, unsigned _tid);
+        TrapEvent(DefaultCommit<Impl> *_commit, ThreadID _tid);
 
         void process();
-        const char *description();
+        const char *description() const;
     };
 
     /** Overall commit status. Used to determine if the CPU can deschedule
@@ -137,7 +137,7 @@ class DefaultCommit
 
   public:
     /** Construct a DefaultCommit with the given parameters. */
-    DefaultCommit(Params *params);
+    DefaultCommit(O3CPU *_cpu, DerivO3CPUParams *params);
 
     /** Returns the name of the DefaultCommit. */
     std::string name() const;
@@ -145,9 +145,6 @@ class DefaultCommit
     /** Registers statistics. */
     void regStats();
 
-    /** Sets the CPU pointer. */
-    void setCPU(O3CPU *cpu_ptr);
-
     /** Sets the list of threads. */
     void setThreads(std::vector<Thread *> &threads);
 
@@ -162,13 +159,12 @@ class DefaultCommit
     /** Sets the pointer to the queue coming from IEW. */
     void setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr);
 
-    void setFetchStage(Fetch *fetch_stage);
-
-    Fetch *fetchStage;
-
     /** Sets the pointer to the IEW stage. */
     void setIEWStage(IEW *iew_stage);
 
+    /** Skid buffer between rename and commit. */
+    std::queue<DynInstPtr> skidBuffer;
+
     /** The pointer to the IEW stage. Used solely to ensure that
      * various events (traps, interrupts, syscalls) do not occur until
      * all stores have written back.
@@ -176,7 +172,7 @@ class DefaultCommit
     IEW *iewStage;
 
     /** Sets pointer to list of active threads. */
-    void setActiveThreads(std::list<unsigned> *at_ptr);
+    void setActiveThreads(std::list<ThreadID> *at_ptr);
 
     /** Sets pointer to the commited state rename map. */
     void setRenameMap(RenameMap rm_ptr[Impl::MaxThreads]);
@@ -208,15 +204,15 @@ class DefaultCommit
     void commit();
 
     /** Returns the number of free ROB entries for a specific thread. */
-    unsigned numROBFreeEntries(unsigned tid);
+    size_t numROBFreeEntries(ThreadID tid);
 
     /** Generates an event to schedule a squash due to a trap. */
-    void generateTrapEvent(unsigned tid);
+    void generateTrapEvent(ThreadID tid);
 
     /** Records that commit needs to initiate a squash due to an
      * external state update through the TC.
      */
-    void generateTCEvent(unsigned tid);
+    void generateTCEvent(ThreadID tid);
 
   private:
     /** Updates the overall status of commit with the nextStatus, and
@@ -241,13 +237,18 @@ class DefaultCommit
     bool changedROBEntries();
 
     /** Squashes all in flight instructions. */
-    void squashAll(unsigned tid);
+    void squashAll(ThreadID tid);
 
     /** Handles squashing due to a trap. */
-    void squashFromTrap(unsigned tid);
+    void squashFromTrap(ThreadID tid);
 
     /** Handles squashing due to an TC write. */
-    void squashFromTC(unsigned tid);
+    void squashFromTC(ThreadID tid);
+
+#if FULL_SYSTEM
+    /** Handles processing an interrupt. */
+    void handleInterrupt();
+#endif // FULL_SYSTEM
 
     /** Commits as many instructions as possible. */
     void commitInsts();
@@ -260,43 +261,56 @@ class DefaultCommit
     /** Gets instructions from rename and inserts them into the ROB. */
     void getInsts();
 
+    /** Insert all instructions from rename into skidBuffer */
+    void skidInsert();
+
     /** Marks completed instructions using information sent from IEW. */
     void markCompletedInsts();
 
     /** Gets the thread to commit, based on the SMT policy. */
-    int getCommittingThread();
+    ThreadID getCommittingThread();
 
     /** Returns the thread ID to use based on a round robin policy. */
-    int roundRobin();
+    ThreadID roundRobin();
 
     /** Returns the thread ID to use based on an oldest instruction policy. */
-    int oldestReady();
+    ThreadID oldestReady();
 
   public:
     /** Returns the PC of the head instruction of the ROB.
      * @todo: Probably remove this function as it returns only thread 0.
      */
-    uint64_t readPC() { return PC[0]; }
+    Addr readPC() { return PC[0]; }
 
     /** Returns the PC of a specific thread. */
-    uint64_t readPC(unsigned tid) { return PC[tid]; }
+    Addr readPC(ThreadID tid) { return PC[tid]; }
 
     /** Sets the PC of a specific thread. */
-    void setPC(uint64_t val, unsigned tid) { PC[tid] = val; }
+    void setPC(Addr val, ThreadID tid) { PC[tid] = val; }
+
+    /** Reads the micro PC of a specific thread. */
+    Addr readMicroPC(ThreadID tid) { return microPC[tid]; }
+
+    /** Sets the micro PC of a specific thread */
+    void setMicroPC(Addr val, ThreadID tid) { microPC[tid] = val; }
 
     /** Reads the next PC of a specific thread. */
-    uint64_t readNextPC(unsigned tid) { return nextPC[tid]; }
+    Addr readNextPC(ThreadID tid) { return nextPC[tid]; }
 
     /** Sets the next PC of a specific thread. */
-    void setNextPC(uint64_t val, unsigned tid) { nextPC[tid] = val; }
+    void setNextPC(Addr val, ThreadID tid) { nextPC[tid] = val; }
 
-#if THE_ISA != ALPHA_ISA
     /** Reads the next NPC of a specific thread. */
-    uint64_t readNextPC(unsigned tid) { return nextNPC[tid]; }
+    Addr readNextNPC(ThreadID tid) { return nextNPC[tid]; }
 
     /** Sets the next NPC of a specific thread. */
-    void setNextPC(uint64_t val, unsigned tid) { nextNPC[tid] = val; }
-#endif
+    void setNextNPC(Addr val, ThreadID tid) { nextNPC[tid] = val; }
+
+    /** Reads the micro PC of a specific thread. */
+    Addr readNextMicroPC(ThreadID tid) { return nextMicroPC[tid]; }
+
+    /** Sets the micro PC of a specific thread */
+    void setNextMicroPC(Addr val, ThreadID tid) { nextMicroPC[tid] = val; }
 
   private:
     /** Time buffer interface. */
@@ -335,10 +349,6 @@ class DefaultCommit
     /** Vector of all of the threads. */
     std::vector<Thread *> thread;
 
-    Fault fetchFault;
-
-    int fetchTrapWait;
-
     /** Records that commit has written to the time buffer this cycle. Used for
      * the CPU to determine if it can deschedule itself if there is no activity.
      */
@@ -350,7 +360,7 @@ class DefaultCommit
     bool changedROBNumEntries[Impl::MaxThreads];
 
     /** A counter of how many threads are currently squashing. */
-    int squashCounter;
+    ThreadID squashCounter;
 
     /** Records if a thread has to squash this cycle due to a trap. */
     bool trapSquash[Impl::MaxThreads];
@@ -359,7 +369,7 @@ class DefaultCommit
     bool tcSquash[Impl::MaxThreads];
 
     /** Priority List used for Commit Policy */
-    std::list<unsigned> priority_list;
+    std::list<ThreadID> priority_list;
 
     /** IEW to Commit delay, in ticks. */
     unsigned iewToCommitDelay;
@@ -384,7 +394,7 @@ class DefaultCommit
     unsigned numRobs;
 
     /** Number of Active Threads */
-    unsigned numThreads;
+    ThreadID numThreads;
 
     /** Is a drain pending. */
     bool drainPending;
@@ -397,28 +407,43 @@ class DefaultCommit
      */
     Tick trapLatency;
 
-    Tick fetchTrapLatency;
-
-    Tick fetchFaultTick;
+    /** The interrupt fault. */
+    Fault interrupt;
 
     /** The commit PC of each thread.  Refers to the instruction that
      * is currently being processed/committed.
      */
     Addr PC[Impl::MaxThreads];
 
+    /** The commit micro PC of each thread.  Refers to the instruction that
+     * is currently being processed/committed.
+     */
+    Addr microPC[Impl::MaxThreads];
+
     /** The next PC of each thread. */
     Addr nextPC[Impl::MaxThreads];
 
-#if THE_ISA != ALPHA_ISA
     /** The next NPC of each thread. */
     Addr nextNPC[Impl::MaxThreads];
-#endif
+
+    /** The next micro PC of each thread. */
+    Addr nextMicroPC[Impl::MaxThreads];
 
     /** The sequence number of the youngest valid instruction in the ROB. */
     InstSeqNum youngestSeqNum[Impl::MaxThreads];
 
+    /** Records if there is a trap currently in flight. */
+    bool trapInFlight[Impl::MaxThreads];
+
+    /** Records if there were any stores committed this cycle. */
+    bool committedStores[Impl::MaxThreads];
+
+    /** Records if commit should check if the ROB is truly empty (see
+        commit_impl.hh). */
+    bool checkEmptyROB[Impl::MaxThreads];
+
     /** Pointer to the list of active threads. */
-    std::list<unsigned> *activeThreads;
+    std::list<ThreadID> *activeThreads;
 
     /** Rename map interface. */
     RenameMap *renameMap[Impl::MaxThreads];
@@ -427,40 +452,40 @@ class DefaultCommit
     void updateComInstStats(DynInstPtr &inst);
 
     /** Stat for the total number of committed instructions. */
-    Stats::Scalar<> commitCommittedInsts;
+    Stats::Scalar commitCommittedInsts;
     /** Stat for the total number of squashed instructions discarded by commit.
      */
-    Stats::Scalar<> commitSquashedInsts;
+    Stats::Scalar commitSquashedInsts;
     /** Stat for the total number of times commit is told to squash.
      * @todo: Actually increment this stat.
      */
-    Stats::Scalar<> commitSquashEvents;
+    Stats::Scalar commitSquashEvents;
     /** Stat for the total number of times commit has had to stall due to a non-
      * speculative instruction reaching the head of the ROB.
      */
-    Stats::Scalar<> commitNonSpecStalls;
+    Stats::Scalar commitNonSpecStalls;
     /** Stat for the total number of branch mispredicts that caused a squash. */
-    Stats::Scalar<> branchMispredicts;
+    Stats::Scalar branchMispredicts;
     /** Distribution of the number of committed instructions each cycle. */
-    Stats::Distribution<> numCommittedDist;
+    Stats::Distribution numCommittedDist;
 
     /** Total number of instructions committed. */
-    Stats::Vector<> statComInst;
+    Stats::Vector statComInst;
     /** Total number of software prefetches committed. */
-    Stats::Vector<> statComSwp;
+    Stats::Vector statComSwp;
     /** Stat for the total number of committed memory references. */
-    Stats::Vector<> statComRefs;
+    Stats::Vector statComRefs;
     /** Stat for the total number of committed loads. */
-    Stats::Vector<> statComLoads;
+    Stats::Vector statComLoads;
     /** Total number of committed memory barriers. */
-    Stats::Vector<> statComMembars;
+    Stats::Vector statComMembars;
     /** Total number of committed branches. */
-    Stats::Vector<> statComBranches;
+    Stats::Vector statComBranches;
 
     /** Number of cycles where the commit bandwidth limit is reached. */
-    Stats::Scalar<> commitEligibleSamples;
+    Stats::Scalar commitEligibleSamples;
     /** Number of instructions not committed due to bandwidth limits. */
-    Stats::Vector<> commitEligible;
+    Stats::Vector commitEligible;
 };
 
 #endif // __CPU_O3_COMMIT_HH__