Eden Avivi has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/33815 )

Change subject: cpu-o3: convert fetch to new style stats
......................................................................

cpu-o3: convert fetch to new style stats

Change-Id: Ib50a303570ac1dd45ff11a32a823f47a6c4c02cd
---
M src/cpu/o3/cpu.cc
M src/cpu/o3/fetch.hh
M src/cpu/o3/fetch_impl.hh
3 files changed, 173 insertions(+), 200 deletions(-)



diff --git a/src/cpu/o3/cpu.cc b/src/cpu/o3/cpu.cc
index d911490..7a88c4e 100644
--- a/src/cpu/o3/cpu.cc
+++ b/src/cpu/o3/cpu.cc
@@ -441,7 +441,6 @@
         .precision(6);
     totalIpc =  sum(committedInsts) / numCycles;

-    this->fetch.regStats();
     this->decode.regStats();
     this->rename.regStats();
     this->iew.regStats();
diff --git a/src/cpu/o3/fetch.hh b/src/cpu/o3/fetch.hh
index 77c6336..112bd87 100644
--- a/src/cpu/o3/fetch.hh
+++ b/src/cpu/o3/fetch.hh
@@ -222,8 +222,6 @@
     /** Returns the name of fetch. */
     std::string name() const;

-    /** Registers statistics. */
-    void regStats();

     /** Registers probes. */
     void regProbePoints();
@@ -330,7 +328,8 @@
                          const DynInstPtr squashInst, ThreadID tid);

     /** Squashes a specific thread and resets the PC. Also tells the CPU to
- * remove any instructions between fetch and decode that should be sqaushed.
+     * remove any instructions between fetch and decode
+     *  that should be sqaushed.
      */
     void squashFromDecode(const TheISA::PCState &newPC,
                           const DynInstPtr squashInst,
@@ -545,58 +544,65 @@

     /** Event used to delay fault generation of translation faults */
     FinishTranslationEvent finishTranslationEvent;
-
- // @todo: Consider making these vectors and tracking on a per thread basis.
-    /** Stat for total number of cycles stalled due to an icache miss. */
-    Stats::Scalar icacheStallCycles;
-    /** Stat for total number of fetched instructions. */
-    Stats::Scalar fetchedInsts;
-    /** Total number of fetched branches. */
-    Stats::Scalar fetchedBranches;
-    /** Stat for total number of predicted branches. */
-    Stats::Scalar predictedBranches;
-    /** Stat for total number of cycles spent fetching. */
-    Stats::Scalar fetchCycles;
-    /** Stat for total number of cycles spent squashing. */
-    Stats::Scalar fetchSquashCycles;
-    /** Stat for total number of cycles spent waiting for translation */
-    Stats::Scalar fetchTlbCycles;
- /** Stat for total number of cycles spent blocked due to other stages in
-     * the pipeline.
-     */
-    Stats::Scalar fetchIdleCycles;
-    /** Total number of cycles spent blocked. */
-    Stats::Scalar fetchBlockedCycles;
-    /** Total number of cycles spent in any other state. */
-    Stats::Scalar fetchMiscStallCycles;
-    /** Total number of cycles spent in waiting for drains. */
-    Stats::Scalar fetchPendingDrainCycles;
-    /** Total number of stall cycles caused by no active threads to run. */
-    Stats::Scalar fetchNoActiveThreadStallCycles;
-    /** Total number of stall cycles caused by pending traps. */
-    Stats::Scalar fetchPendingTrapStallCycles;
- /** Total number of stall cycles caused by pending quiesce instructions. */
-    Stats::Scalar fetchPendingQuiesceStallCycles;
-    /** Total number of stall cycles caused by I-cache wait retrys. */
-    Stats::Scalar fetchIcacheWaitRetryStallCycles;
-    /** Stat for total number of fetched cache lines. */
-    Stats::Scalar fetchedCacheLines;
-    /** Total number of outstanding icache accesses that were dropped
-     * due to a squash.
-     */
-    Stats::Scalar fetchIcacheSquashes;
-    /** Total number of outstanding tlb accesses that were dropped
-     * due to a squash.
-     */
-    Stats::Scalar fetchTlbSquashes;
-    /** Distribution of number of instructions fetched each cycle. */
-    Stats::Distribution fetchNisnDist;
-    /** Rate of how often fetch was idle. */
-    Stats::Formula idleRate;
-    /** Number of branch fetches per cycle. */
-    Stats::Formula branchRate;
-    /** Number of instruction fetched per cycle. */
-    Stats::Formula fetchRate;
+    protected:
+    struct FetchStatGroup : public Stats::Group
+    {
+        FetchStatGroup(O3CPU *cpu, DefaultFetch *fetch);
+        // @todo: Consider making these
+        // vectors and tracking on a per thread basis.
+ /** Stat for total number of cycles stalled due to an icache miss. */
+        Stats::Scalar icacheStallCycles;
+        /** Stat for total number of fetched instructions. */
+        Stats::Scalar fetchedInsts;
+        /** Total number of fetched branches. */
+        Stats::Scalar fetchedBranches;
+        /** Stat for total number of predicted branches. */
+        Stats::Scalar predictedBranches;
+        /** Stat for total number of cycles spent fetching. */
+        Stats::Scalar fetchCycles;
+        /** Stat for total number of cycles spent squashing. */
+        Stats::Scalar fetchSquashCycles;
+ /** Stat for total number of cycles spent waiting for translation */
+        Stats::Scalar fetchTlbCycles;
+        /** Stat for total number of cycles
+         *  spent blocked due to other stages in
+         * the pipeline.
+         */
+        Stats::Scalar fetchIdleCycles;
+        /** Total number of cycles spent blocked. */
+        Stats::Scalar fetchBlockedCycles;
+        /** Total number of cycles spent in any other state. */
+        Stats::Scalar fetchMiscStallCycles;
+        /** Total number of cycles spent in waiting for drains. */
+        Stats::Scalar fetchPendingDrainCycles;
+ /** Total number of stall cycles caused by no active threads to run. */
+        Stats::Scalar fetchNoActiveThreadStallCycles;
+        /** Total number of stall cycles caused by pending traps. */
+        Stats::Scalar fetchPendingTrapStallCycles;
+        /** Total number of stall cycles
+         *  caused by pending quiesce instructions. */
+        Stats::Scalar fetchPendingQuiesceStallCycles;
+        /** Total number of stall cycles caused by I-cache wait retrys. */
+        Stats::Scalar fetchIcacheWaitRetryStallCycles;
+        /** Stat for total number of fetched cache lines. */
+        Stats::Scalar fetchedCacheLines;
+        /** Total number of outstanding icache accesses that were dropped
+         * due to a squash.
+         */
+        Stats::Scalar fetchIcacheSquashes;
+        /** Total number of outstanding tlb accesses that were dropped
+         * due to a squash.
+         */
+        Stats::Scalar fetchTlbSquashes;
+        /** Distribution of number of instructions fetched each cycle. */
+        Stats::Distribution fetchNisnDist;
+        /** Rate of how often fetch was idle. */
+        Stats::Formula idleRate;
+        /** Number of branch fetches per cycle. */
+        Stats::Formula branchRate;
+        /** Number of instruction fetched per cycle. */
+        Stats::Formula fetchRate;
+    } fetchStats;
 };

 #endif //__CPU_O3_FETCH_HH__
diff --git a/src/cpu/o3/fetch_impl.hh b/src/cpu/o3/fetch_impl.hh
index 7ecab54..b702601 100644
--- a/src/cpu/o3/fetch_impl.hh
+++ b/src/cpu/o3/fetch_impl.hh
@@ -95,7 +95,7 @@
       numThreads(params->numThreads),
       numFetchingThreads(params->smtNumFetchingThreads),
       icachePort(this, _cpu),
-      finishTranslationEvent(this)
+      finishTranslationEvent(this), fetchStats(_cpu, this)
 {
     if (numThreads > Impl::MaxThreads)
         fatal("numThreads (%d) is larger than compiled limit (%d),\n"
@@ -164,128 +164,97 @@
 }

 template <class Impl>
-void
-DefaultFetch<Impl>::regStats()
+DefaultFetch<Impl>::
+FetchStatGroup::FetchStatGroup(O3CPU *cpu, DefaultFetch *fetch)
+    : Stats::Group(cpu, "fetch"),
+    ADD_STAT(icacheStallCycles,
+     "Number of cycles fetch is stalled on an Icache miss"),
+    ADD_STAT(fetchedInsts, "Number of instructions fetch has processed"),
+    ADD_STAT(fetchedBranches, "Number of branches that fetch encountered"),
+    ADD_STAT(predictedBranches,
+     "Number of branches that fetch has predicted taken"),
+    ADD_STAT(fetchCycles,
+     "Number of cycles fetch has run and was not squashing or blocked"),
+ ADD_STAT(fetchSquashCycles, "Number of cycles fetch has spent squashing"),
+    ADD_STAT(fetchTlbCycles,
+     "Number of cycles fetch has spent waiting for tlb"),
+    ADD_STAT(fetchIdleCycles, "Number of cycles fetch was idle"),
+ ADD_STAT(fetchBlockedCycles, "Number of cycles fetch has spent blocked"),
+    ADD_STAT(fetchMiscStallCycles,
+     "Number of cycles fetch has spent waiting on interrupts,"
+      "or bad addresses, or out of MSHRs"),
+    ADD_STAT(fetchPendingDrainCycles,
+     "Number of cycles fetch has spent waiting on pipes to drain"),
+    ADD_STAT(fetchNoActiveThreadStallCycles,
+     "Number of stall cycles due to no active thread to fetch from"),
+    ADD_STAT(fetchPendingTrapStallCycles,
+     "Number of stall cycles due to pending traps"),
+    ADD_STAT(fetchPendingQuiesceStallCycles,
+     "Number of stall cycles due to pending quiesce instructions"),
+    ADD_STAT(fetchIcacheWaitRetryStallCycles,
+     "Number of stall cycles due to full MSHR"),
+    ADD_STAT(fetchedCacheLines, "Number of cache lines fetched"),
+    ADD_STAT(fetchIcacheSquashes,
+     "Number of outstanding Icache misses that were squashed"),
+    ADD_STAT(fetchTlbSquashes,
+     "Number of outstanding ITLB misses that were squashed"),
+    ADD_STAT(fetchNisnDist,
+     "Number of instructions fetched each cycle (Total)"),
+    ADD_STAT(idleRate, "Percent of cycles fetch was idle",
+     fetchIdleCycles * 100 / cpu->numCycles),
+    ADD_STAT(branchRate, "Number of branch fetches per cycle",
+     fetchedBranches / cpu->numCycles),
+    ADD_STAT(fetchRate, "Number of inst fetches per cycle",
+     fetchedInsts / cpu->numCycles)
 {
-    icacheStallCycles
-        .name(name() + ".icacheStallCycles")
-        .desc("Number of cycles fetch is stalled on an Icache miss")
-        .prereq(icacheStallCycles);
-
-    fetchedInsts
-        .name(name() + ".Insts")
-        .desc("Number of instructions fetch has processed")
-        .prereq(fetchedInsts);
-
-    fetchedBranches
-        .name(name() + ".Branches")
-        .desc("Number of branches that fetch encountered")
-        .prereq(fetchedBranches);
-
-    predictedBranches
-        .name(name() + ".predictedBranches")
-        .desc("Number of branches that fetch has predicted taken")
-        .prereq(predictedBranches);
-
-    fetchCycles
-        .name(name() + ".Cycles")
-        .desc("Number of cycles fetch has run and was not squashing or"
-              " blocked")
-        .prereq(fetchCycles);
-
-    fetchSquashCycles
-        .name(name() + ".SquashCycles")
-        .desc("Number of cycles fetch has spent squashing")
-        .prereq(fetchSquashCycles);
-
-    fetchTlbCycles
-        .name(name() + ".TlbCycles")
-        .desc("Number of cycles fetch has spent waiting for tlb")
-        .prereq(fetchTlbCycles);
-
-    fetchIdleCycles
-        .name(name() + ".IdleCycles")
-        .desc("Number of cycles fetch was idle")
-        .prereq(fetchIdleCycles);
-
-    fetchBlockedCycles
-        .name(name() + ".BlockedCycles")
-        .desc("Number of cycles fetch has spent blocked")
-        .prereq(fetchBlockedCycles);
-
-    fetchedCacheLines
-        .name(name() + ".CacheLines")
-        .desc("Number of cache lines fetched")
-        .prereq(fetchedCacheLines);
-
-    fetchMiscStallCycles
-        .name(name() + ".MiscStallCycles")
-        .desc("Number of cycles fetch has spent waiting on interrupts, or "
-              "bad addresses, or out of MSHRs")
-        .prereq(fetchMiscStallCycles);
-
-    fetchPendingDrainCycles
-        .name(name() + ".PendingDrainCycles")
-        .desc("Number of cycles fetch has spent waiting on pipes to drain")
-        .prereq(fetchPendingDrainCycles);
-
-    fetchNoActiveThreadStallCycles
-        .name(name() + ".NoActiveThreadStallCycles")
- .desc("Number of stall cycles due to no active thread to fetch from")
-        .prereq(fetchNoActiveThreadStallCycles);
-
-    fetchPendingTrapStallCycles
-        .name(name() + ".PendingTrapStallCycles")
-        .desc("Number of stall cycles due to pending traps")
-        .prereq(fetchPendingTrapStallCycles);
-
-    fetchPendingQuiesceStallCycles
-        .name(name() + ".PendingQuiesceStallCycles")
-        .desc("Number of stall cycles due to pending quiesce instructions")
-        .prereq(fetchPendingQuiesceStallCycles);
-
-    fetchIcacheWaitRetryStallCycles
-        .name(name() + ".IcacheWaitRetryStallCycles")
-        .desc("Number of stall cycles due to full MSHR")
-        .prereq(fetchIcacheWaitRetryStallCycles);
-
-    fetchIcacheSquashes
-        .name(name() + ".IcacheSquashes")
-        .desc("Number of outstanding Icache misses that were squashed")
-        .prereq(fetchIcacheSquashes);
-
-    fetchTlbSquashes
-        .name(name() + ".ItlbSquashes")
-        .desc("Number of outstanding ITLB misses that were squashed")
-        .prereq(fetchTlbSquashes);
-
-    fetchNisnDist
-        .init(/* base value */ 0,
-              /* last value */ fetchWidth,
+        icacheStallCycles
+            .prereq(icacheStallCycles);
+        fetchedInsts
+            .prereq(fetchedInsts);
+        fetchedBranches
+            .prereq(fetchedBranches);
+        predictedBranches
+            .prereq(predictedBranches);
+        fetchCycles
+            .prereq(fetchCycles);
+        fetchSquashCycles
+            .prereq(fetchSquashCycles);
+        fetchTlbCycles
+            .prereq(fetchTlbCycles);
+        fetchIdleCycles
+            .prereq(fetchIdleCycles);
+        fetchBlockedCycles
+            .prereq(fetchBlockedCycles);
+        fetchedCacheLines
+            .prereq(fetchedCacheLines);
+        fetchMiscStallCycles
+            .prereq(fetchMiscStallCycles);
+        fetchPendingDrainCycles
+            .prereq(fetchPendingDrainCycles);
+        fetchNoActiveThreadStallCycles
+            .prereq(fetchNoActiveThreadStallCycles);
+        fetchPendingTrapStallCycles
+            .prereq(fetchPendingTrapStallCycles);
+        fetchPendingQuiesceStallCycles
+            .prereq(fetchPendingQuiesceStallCycles);
+        fetchIcacheWaitRetryStallCycles
+            .prereq(fetchIcacheWaitRetryStallCycles);
+        fetchIcacheSquashes
+            .prereq(fetchIcacheSquashes);
+        fetchTlbSquashes
+            .prereq(fetchTlbSquashes);
+        fetchNisnDist
+            .init(/* base value */ 0,
+              /* last value */ fetch->fetchWidth,
               /* bucket size */ 1)
-        .name(name() + ".rateDist")
-        .desc("Number of instructions fetched each cycle (Total)")
-        .flags(Stats::pdf);
-
-    idleRate
-        .name(name() + ".idleRate")
-        .desc("Percent of cycles fetch was idle")
-        .prereq(idleRate);
-    idleRate = fetchIdleCycles * 100 / cpu->numCycles;
-
-    branchRate
-        .name(name() + ".branchRate")
-        .desc("Number of branch fetches per cycle")
-        .flags(Stats::total);
-    branchRate = fetchedBranches / cpu->numCycles;
-
-    fetchRate
-        .name(name() + ".rate")
-        .desc("Number of inst fetches per cycle")
-        .flags(Stats::total);
-    fetchRate = fetchedInsts / cpu->numCycles;
+            .flags(Stats::pdf);
+        idleRate
+            .prereq(idleRate);
+        branchRate
+            .flags(Stats::total);
+        fetchRate
+            .flags(Stats::total);
 }
-
 template<class Impl>
 void
 DefaultFetch<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer)
@@ -298,7 +267,6 @@
     fromIEW = timeBuffer->getWire(-iewToFetchDelay);
     fromCommit = timeBuffer->getWire(-commitToFetchDelay);
 }
-
 template<class Impl>
 void
 DefaultFetch<Impl>::setActiveThreads(std::list<ThreadID> *at_ptr)
@@ -394,7 +362,7 @@
     // to return.
     if (fetchStatus[tid] != IcacheWaitResponse ||
         pkt->req != memReq[tid]) {
-        ++fetchIcacheSquashes;
+        ++fetchStats.fetchIcacheSquashes;
         delete pkt;
         return;
     }
@@ -587,10 +555,10 @@
     inst->setPredTarg(nextPC);
     inst->setPredTaken(predict_taken);

-    ++fetchedBranches;
+    ++fetchStats.fetchedBranches;

     if (predict_taken) {
-        ++predictedBranches;
+        ++fetchStats.predictedBranches;
     }

     return predict_taken;
@@ -663,7 +631,7 @@
         mem_req->getVaddr() != memReq[tid]->getVaddr()) {
         DPRINTF(Fetch, "[tid:%i] Ignoring itlb completed after squash\n",
                 tid);
-        ++fetchTlbSquashes;
+        ++fetchStats.fetchTlbSquashes;
         return;
     }

@@ -689,7 +657,7 @@
         fetchBufferValid[tid] = false;
         DPRINTF(Fetch, "Fetch: Doing instruction read.\n");

-        fetchedCacheLines++;
+        fetchStats.fetchedCacheLines++;

         // Access the cache.
         if (!icachePort.sendTimingReq(data_pkt)) {
@@ -802,7 +770,7 @@
     // some opportunities to handle interrupts may be missed.
     delayedCommit[tid] = true;

-    ++fetchSquashCycles;
+    ++fetchStats.fetchSquashCycles;
 }

 template<class Impl>
@@ -931,7 +899,7 @@
     }

     // Record number of instructions fetched this cycle for distribution.
-    fetchNisnDist.sample(numInst);
+    fetchStats.fetchNisnDist.sample(numInst);

     if (status_change) {
         // Change the fetch stage status if there was a status change.
@@ -1203,23 +1171,23 @@
             fetchCacheLine(fetchAddr, tid, thisPC.instAddr());

             if (fetchStatus[tid] == IcacheWaitResponse)
-                ++icacheStallCycles;
+                ++fetchStats.icacheStallCycles;
             else if (fetchStatus[tid] == ItlbWait)
-                ++fetchTlbCycles;
+                ++fetchStats.fetchTlbCycles;
             else
-                ++fetchMiscStallCycles;
+                ++fetchStats.fetchMiscStallCycles;
             return;
} else if ((checkInterrupt(thisPC.instAddr()) && !delayedCommit[tid])) {
             // Stall CPU if an interrupt is posted and we're not issuing
// an delayed commit micro-op currently (delayed commit instructions
             // are not interruptable by interrupts, only faults)
-            ++fetchMiscStallCycles;
+            ++fetchStats.fetchMiscStallCycles;
             DPRINTF(Fetch, "[tid:%i] Fetch is stalled!\n", tid);
             return;
         }
     } else {
         if (fetchStatus[tid] == Idle) {
-            ++fetchIdleCycles;
+            ++fetchStats.fetchIdleCycles;
             DPRINTF(Fetch, "[tid:%i] Fetch is idle!\n", tid);
         }

@@ -1227,7 +1195,7 @@
         return;
     }

-    ++fetchCycles;
+    ++fetchStats.fetchCycles;

     TheISA::PCState nextPC = thisPC;

@@ -1297,7 +1265,7 @@
                     staticInst = decoder[tid]->decode(thisPC);

                     // Increment stat of fetched instructions.
-                    ++fetchedInsts;
+                    ++fetchStats.fetchedInsts;

                     if (staticInst->isMacroop()) {
                         curMacroop = staticInst;
@@ -1626,35 +1594,35 @@
     // @todo Per-thread stats

     if (stalls[tid].drain) {
-        ++fetchPendingDrainCycles;
+        ++fetchStats.fetchPendingDrainCycles;
         DPRINTF(Fetch, "Fetch is waiting for a drain!\n");
     } else if (activeThreads->empty()) {
-        ++fetchNoActiveThreadStallCycles;
+        ++fetchStats.fetchNoActiveThreadStallCycles;
         DPRINTF(Fetch, "Fetch has no active thread!\n");
     } else if (fetchStatus[tid] == Blocked) {
-        ++fetchBlockedCycles;
+        ++fetchStats.fetchBlockedCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is blocked!\n", tid);
     } else if (fetchStatus[tid] == Squashing) {
-        ++fetchSquashCycles;
+        ++fetchStats.fetchSquashCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is squashing!\n", tid);
     } else if (fetchStatus[tid] == IcacheWaitResponse) {
-        ++icacheStallCycles;
+        ++fetchStats.icacheStallCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is waiting cache response!\n",
                 tid);
     } else if (fetchStatus[tid] == ItlbWait) {
-        ++fetchTlbCycles;
+        ++fetchStats.fetchTlbCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is waiting ITLB walk to "
                 "finish!\n", tid);
     } else if (fetchStatus[tid] == TrapPending) {
-        ++fetchPendingTrapStallCycles;
+        ++fetchStats.fetchPendingTrapStallCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is waiting for a pending trap!\n",
                 tid);
     } else if (fetchStatus[tid] == QuiescePending) {
-        ++fetchPendingQuiesceStallCycles;
+        ++fetchStats.fetchPendingQuiesceStallCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is waiting for a pending quiesce "
                 "instruction!\n", tid);
     } else if (fetchStatus[tid] == IcacheWaitRetry) {
-        ++fetchIcacheWaitRetryStallCycles;
+        ++fetchStats.fetchIcacheWaitRetryStallCycles;
         DPRINTF(Fetch, "[tid:%i] Fetch is waiting for an I-cache retry!\n",
                 tid);
     } else if (fetchStatus[tid] == NoGoodAddr) {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/33815
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib50a303570ac1dd45ff11a32a823f47a6c4c02cd
Gerrit-Change-Number: 33815
Gerrit-PatchSet: 1
Gerrit-Owner: Eden Avivi <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to