Melissa Jost has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/67392?usp=email )

Change subject: cpu: Move numInsts, numOps, ipc, cpi to BaseCPU
......................................................................

cpu: Move numInsts, numOps, ipc, cpi to BaseCPU

In BaseCPU::BaseCPUStats, numInsts and numOps track per CPU core
committed instructions and operations.

In BaseCPU::FetchCPUStats, numInsts and numOps track per thread
fetched instructions and operations.

In BaseCPU::CommitCPUStats, numInsts and numOps track per thread
committed instructions and operations.

In BaseSimpleCPU, the countInst() function has been split into
countInst(), countFetchInst(), and countCommitInst(). The stat count
incrementation of countInst() has been removed and delegated to the
other two functions. countFetchInst() increments numInsts and numOps
of the FetchCPUStats group for a thread. countCommitInst() increments
the numInsts and numOps of the CommitCPUStats group for a thread and
of the BaseCPUStats group for a CPU core. These functions are called
in the appropriate stage within timing.cc and atomic.cc. The call to
countInst() is left unchanged. countFetchInst() is called in
preExecute(). countCommitInst() is called in postExecute().

For MinorCPU, only the commit level numInsts and numOps stats have been
implemented.

IPC and CPI stats have been added to BaseCPUStats (core level) and
CommitCPUStats (thread level). The formulas for the IPC and CPI stats
in CommitCPUStats are set in the BaseCPU constructor, after the
CommitCPUStats stat group object has been created.

Change-Id: If893b331fe4a6908e4b4caf4a30f1b0aeb4c4266
---
M src/cpu/base.cc
M src/cpu/base.hh
M src/cpu/minor/execute.cc
M src/cpu/minor/stats.cc
M src/cpu/minor/stats.hh
M src/cpu/simple/base.cc
M src/cpu/simple/base.hh
M src/cpu/simple/exec_context.hh
8 files changed, 135 insertions(+), 40 deletions(-)



diff --git a/src/cpu/base.cc b/src/cpu/base.cc
index 0c43248..77ecfa9 100644
--- a/src/cpu/base.cc
+++ b/src/cpu/base.cc
@@ -185,7 +185,11 @@
     for (int i = 0; i < numThreads; i++) {
         fetchStats.emplace_back(new FetchCPUStats(this, i));
         executeStats.emplace_back(new ExecuteCPUStats(this, i));
-        commitStats.emplace_back(new CommitCPUStats(this, i));
+        // create commitStat object for thread i and set ipc, cpi formulas
+        CommitCPUStats* commitStatptr = new CommitCPUStats(this, i);
+        commitStatptr->ipc = commitStatptr->numInsts / baseStats.numCycles;
+        commitStatptr->cpi = baseStats.numCycles / commitStatptr->numInsts;
+        commitStats.emplace_back(commitStatptr);
     }
 }

@@ -379,13 +383,28 @@
 BaseCPU::
 BaseCPUStats::BaseCPUStats(statistics::Group *parent)
     : statistics::Group(parent),
+      ADD_STAT(numInsts, statistics::units::Count::get(),
+               "Number of instructions committed (core level)"),
+      ADD_STAT(numOps, statistics::units::Count::get(),
+ "Number of ops (including micro ops) committed (core level)"),
       ADD_STAT(numCycles, statistics::units::Cycle::get(),
                "Number of cpu cycles simulated"),
+      ADD_STAT(cpi, statistics::units::Rate<
+                statistics::units::Cycle, statistics::units::Count>::get(),
+               "CPI: cycles per instruction (core level)"),
+      ADD_STAT(ipc, statistics::units::Rate<
+                statistics::units::Count, statistics::units::Cycle>::get(),
+               "IPC: instructions per cycle (core level)"),
       ADD_STAT(numWorkItemsStarted, statistics::units::Count::get(),
                "Number of work items this cpu started"),
       ADD_STAT(numWorkItemsCompleted, statistics::units::Count::get(),
                "Number of work items this cpu completed")
 {
+    cpi.precision(6);
+    cpi = numCycles / numInsts;
+
+    ipc.precision(6);
+    ipc = numInsts / numCycles;
 }

 void
@@ -792,6 +811,10 @@
 BaseCPU::
 FetchCPUStats::FetchCPUStats(statistics::Group *parent, int thread_id)
: statistics::Group(parent, csprintf("fetchStats%i", thread_id).c_str()),
+    ADD_STAT(numInsts, statistics::units::Count::get(),
+             "Number of instructions fetched (thread level)"),
+    ADD_STAT(numOps, statistics::units::Count::get(),
+             "Number of ops (including micro ops) fetched (thread level)"),
     ADD_STAT(numBranches, statistics::units::Count::get(),
              "Number of branches fetched"),
     ADD_STAT(numFetchSuspends, statistics::units::Count::get(),
@@ -880,6 +903,16 @@
 BaseCPU::
 CommitCPUStats::CommitCPUStats(statistics::Group *parent, int thread_id)
: statistics::Group(parent, csprintf("commitStats%i", thread_id).c_str()),
+    ADD_STAT(numInsts, statistics::units::Count::get(),
+             "Number of instructions committed (thread level)"),
+    ADD_STAT(numOps, statistics::units::Count::get(),
+ "Number of ops (including micro ops) committed (thread level)"),
+    ADD_STAT(cpi, statistics::units::Rate<
+                statistics::units::Cycle, statistics::units::Count>::get(),
+             "CPI: cycles per instruction (thread level)"),
+    ADD_STAT(ipc, statistics::units::Rate<
+                statistics::units::Count, statistics::units::Cycle>::get(),
+             "IPC: instructions per cycle (thread level)"),
     ADD_STAT(numMemRefs, statistics::units::Count::get(),
             "Number of memory references committed"),
     ADD_STAT(numFpInsts, statistics::units::Count::get(),
@@ -897,6 +930,9 @@
     ADD_STAT(committedControl, statistics::units::Count::get(),
              "Class of control type instructions committed")
 {
+    cpi.precision(6);
+    ipc.precision(6);
+
     committedInstType
         .init(enums::Num_OpClass)
         .flags(statistics::total | statistics::pdf | statistics::dist);
diff --git a/src/cpu/base.hh b/src/cpu/base.hh
index 8bfcf74..15ae0de 100644
--- a/src/cpu/base.hh
+++ b/src/cpu/base.hh
@@ -616,8 +616,14 @@
     struct BaseCPUStats : public statistics::Group
     {
         BaseCPUStats(statistics::Group *parent);
+        // Number of CPU insts and ops committed at CPU core level
+        statistics::Scalar numInsts;
+        statistics::Scalar numOps;
         // Number of CPU cycles simulated
         statistics::Scalar numCycles;
+        /* CPI/IPC for total cycle counts and macro insts */
+        statistics::Formula cpi;
+        statistics::Formula ipc;
         statistics::Scalar numWorkItemsStarted;
         statistics::Scalar numWorkItemsCompleted;
     } baseStats;
@@ -666,6 +672,12 @@
     {
         FetchCPUStats(statistics::Group *parent, int thread_id);

+        /* Total number of instructions fetched */
+        statistics::Scalar numInsts;
+
+        /* Total number of operations fetched */
+        statistics::Scalar numOps;
+
         /* Total number of branches fetched */
         statistics::Scalar numBranches;

@@ -725,6 +737,14 @@
     {
         CommitCPUStats(statistics::Group *parent, int thread_id);

+        /* Number of simulated instructions committed */
+        statistics::Scalar numInsts;
+        statistics::Scalar numOps;
+
+        /* CPI/IPC for total cycle counts and macro insts */
+        statistics::Formula cpi;
+        statistics::Formula ipc;
+
         /* Number of committed memory references. */
         statistics::Scalar numMemRefs;

diff --git a/src/cpu/minor/execute.cc b/src/cpu/minor/execute.cc
index 5c0354b..2908c22 100644
--- a/src/cpu/minor/execute.cc
+++ b/src/cpu/minor/execute.cc
@@ -871,14 +871,16 @@
     {
         thread->numInst++;
         thread->threadStats.numInsts++;
-        cpu.stats.numInsts++;
+        cpu.commitStats[inst->id.threadId]->numInsts++;
+        cpu.baseStats.numInsts++;

         /* Act on events related to instruction counts */
         thread->comInstEventQueue.serviceEvents(thread->numInst);
     }
     thread->numOp++;
     thread->threadStats.numOps++;
-    cpu.stats.numOps++;
+    cpu.commitStats[inst->id.threadId]->numOps++;
+    cpu.baseStats.numOps++;
     cpu.commitStats[inst->id.threadId]
         ->committedInstType[inst->staticInst->opClass()]++;

diff --git a/src/cpu/minor/stats.cc b/src/cpu/minor/stats.cc
index b20ce95..e31cbe9 100644
--- a/src/cpu/minor/stats.cc
+++ b/src/cpu/minor/stats.cc
@@ -45,29 +45,13 @@

 MinorStats::MinorStats(BaseCPU *base_cpu)
     : statistics::Group(base_cpu),
-    ADD_STAT(numInsts, statistics::units::Count::get(),
-             "Number of instructions committed"),
-    ADD_STAT(numOps, statistics::units::Count::get(),
-             "Number of ops (including micro ops) committed"),
     ADD_STAT(quiesceCycles, statistics::units::Cycle::get(),
"Total number of cycles that CPU has spent quiesced or waiting "
-             "for an interrupt"),
-    ADD_STAT(cpi, statistics::units::Rate<
-                statistics::units::Cycle, statistics::units::Count>::get(),
-             "CPI: cycles per instruction"),
-    ADD_STAT(ipc, statistics::units::Rate<
-                statistics::units::Count, statistics::units::Cycle>::get(),
-             "IPC: instructions per cycle")
+             "for an interrupt")

 {
     quiesceCycles.prereq(quiesceCycles);

-    cpi.precision(6);
-    cpi = base_cpu->baseStats.numCycles / numInsts;
-
-    ipc.precision(6);
-    ipc = numInsts / base_cpu->baseStats.numCycles;
-
 }

 } // namespace minor
diff --git a/src/cpu/minor/stats.hh b/src/cpu/minor/stats.hh
index f7d5e71..98ac80f 100644
--- a/src/cpu/minor/stats.hh
+++ b/src/cpu/minor/stats.hh
@@ -59,19 +59,9 @@
 {
     MinorStats(BaseCPU *parent);

-    /** Number of simulated instructions */
-    statistics::Scalar numInsts;
-
-    /** Number of simulated insts and microops */
-    statistics::Scalar numOps;
-
     /** Number of cycles in quiescent state */
     statistics::Scalar quiesceCycles;

-    /** CPI/IPC for total cycle counts and macro insts */
-    statistics::Formula cpi;
-    statistics::Formula ipc;
-
 };

 } // namespace minor
diff --git a/src/cpu/simple/base.cc b/src/cpu/simple/base.cc
index 70da659..8ebf2ec 100644
--- a/src/cpu/simple/base.cc
+++ b/src/cpu/simple/base.cc
@@ -154,10 +154,36 @@

     if (!curStaticInst->isMicroop() || curStaticInst->isLastMicroop()) {
         t_info.numInst++;
-        t_info.execContextStats.numInsts++;
     }
     t_info.numOp++;
-    t_info.execContextStats.numOps++;
+}
+
+void
+BaseSimpleCPU::countFetchInst()
+{
+    SimpleExecContext& t_info = *threadInfo[curThread];
+
+    if (!curStaticInst->isMicroop() || curStaticInst->isLastMicroop()) {
+        // increment thread level numInsts fetched count
+        fetchStats[t_info.thread->threadId()]->numInsts++;
+    }
+    // increment thread level numOps fetched count
+    fetchStats[t_info.thread->threadId()]->numOps++;
+}
+
+void
+BaseSimpleCPU::countCommitInst()
+{
+    SimpleExecContext& t_info = *threadInfo[curThread];
+
+    if (!curStaticInst->isMicroop() || curStaticInst->isLastMicroop()) {
+        // increment thread level and core level numInsts count
+        commitStats[t_info.thread->threadId()]->numInsts++;
+        baseStats.numInsts++;
+    }
+    // increment thread level and core level numOps count
+    commitStats[t_info.thread->threadId()]->numOps++;
+    baseStats.numOps++;
 }

 Counter
@@ -376,6 +402,9 @@
         if (predict_taken)
             ++t_info.execContextStats.numPredictedBranches;
     }
+
+    // increment the fetch instruction stat counters
+    countFetchInst();
 }

 void
@@ -443,6 +472,9 @@
         ->committedInstType[curStaticInst->opClass()]++;
commitStats[t_info.thread->threadId()]->updateComCtrlStats(curStaticInst);

+    /* increment the committed numInsts and numOps stats */
+    countCommitInst();
+
     if (FullSystem)
         traceFunctions(instAddr);

diff --git a/src/cpu/simple/base.hh b/src/cpu/simple/base.hh
index df5290c..46a25a0 100644
--- a/src/cpu/simple/base.hh
+++ b/src/cpu/simple/base.hh
@@ -182,6 +182,8 @@
     }

     void countInst();
+    void countFetchInst();
+    void countCommitInst();
     Counter totalInsts() const override;
     Counter totalOps() const override;

diff --git a/src/cpu/simple/exec_context.hh b/src/cpu/simple/exec_context.hh
index 42d6181..c0927fc 100644
--- a/src/cpu/simple/exec_context.hh
+++ b/src/cpu/simple/exec_context.hh
@@ -86,10 +86,6 @@
             : statistics::Group(cpu,
                            csprintf("exec_context.thread_%i",
                                     thread->threadId()).c_str()),
-              ADD_STAT(numInsts, statistics::units::Count::get(),
-                       "Number of instructions committed"),
-              ADD_STAT(numOps, statistics::units::Count::get(),
-                       "Number of ops (including micro ops) committed"),
               ADD_STAT(numMatAluAccesses, statistics::units::Count::get(),
                        "Number of matrix alu accesses"),
               ADD_STAT(numCallsReturns, statistics::units::Count::get(),
@@ -140,10 +136,6 @@
                 .prereq(numBranchMispred);
         }

-        // Number of simulated instructions
-        statistics::Scalar numInsts;
-        statistics::Scalar numOps;
-
         // Number of matrix alu accesses
         statistics::Scalar numMatAluAccesses;


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/67392?usp=email 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: If893b331fe4a6908e4b4caf4a30f1b0aeb4c4266
Gerrit-Change-Number: 67392
Gerrit-PatchSet: 1
Gerrit-Owner: Melissa Jost <melissakj...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to