cpu: convert loop_predictor to new style stats
authorEmily Brickey <esbrickey@ucdavis.edu>
Tue, 1 Sep 2020 21:02:58 +0000 (14:02 -0700)
committerEmily Brickey <esbrickey@ucdavis.edu>
Thu, 3 Sep 2020 18:14:53 +0000 (18:14 +0000)
Change-Id: Ib0383fc6d5f884fd6c020bcd938eee2f802ad412
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33935
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/cpu/pred/loop_predictor.cc
src/cpu/pred/loop_predictor.hh

index 4b23fd1f933392c764b97e34aa86eeb46452dc78..5dad79713382fbe876273bd9982ebbe23e0ae0c8 100644 (file)
@@ -57,7 +57,8 @@ LoopPredictor::LoopPredictor(LoopPredictorParams *p)
     restrictAllocation(p->restrictAllocation),
     initialLoopIter(p->initialLoopIter),
     initialLoopAge(p->initialLoopAge),
-    optionalAgeReset(p->optionalAgeReset)
+    optionalAgeReset(p->optionalAgeReset),
+    stats(this)
 {
     assert(initialLoopAge <= ((1 << loopTableAgeBits) - 1));
 }
@@ -314,9 +315,9 @@ void
 LoopPredictor::updateStats(bool taken, BranchInfo* bi)
 {
     if (taken == bi->loopPred) {
-        loopPredictorCorrect++;
+        stats.correct++;
     } else {
-        loopPredictorWrong++;
+        stats.wrong++;
     }
 }
 
@@ -344,18 +345,13 @@ LoopPredictor::condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
     loopUpdate(branch_pc, taken, bi, tage_pred);
 }
 
-void
-LoopPredictor::regStats()
+LoopPredictor::LoopPredictorStats::LoopPredictorStats(Stats::Group *parent)
+    : Stats::Group(parent),
+      ADD_STAT(correct, "Number of times the loop predictor is"
+          " the provider and the prediction is correct"),
+      ADD_STAT(wrong, "Number of times the loop predictor is the"
+          " provider and the prediction is wrong")
 {
-    loopPredictorCorrect
-        .name(name() + ".loopPredictorCorrect")
-        .desc("Number of times the loop predictor is the provider and "
-              "the prediction is correct");
-
-    loopPredictorWrong
-        .name(name() + ".loopPredictorWrong")
-        .desc("Number of times the loop predictor is the provider and "
-              "the prediction is wrong");
 }
 
 size_t
index e6af53d2a1d317f7f4ec0c05ca0427ed37b6d02b..b26bc7139c74066df4affbb85325080ade5572c7 100644 (file)
@@ -83,9 +83,11 @@ class LoopPredictor : public SimObject
     const unsigned initialLoopAge;
     const bool optionalAgeReset;
 
-    // stats
-    Stats::Scalar loopPredictorCorrect;
-    Stats::Scalar loopPredictorWrong;
+    struct LoopPredictorStats : public Stats::Group {
+        LoopPredictorStats(Stats::Group *parent);
+        Stats::Scalar correct;
+        Stats::Scalar wrong;
+    } stats;
 
     /**
      * Updates an unsigned counter based on up/down parameter
@@ -250,11 +252,6 @@ class LoopPredictor : public SimObject
      */
     void init() override;
 
-    /**
-     * Register stats for this object
-     */
-    void regStats() override;
-
     LoopPredictor(LoopPredictorParams *p);
 
     size_t getSizeInBits() const;