From feeb3b2d672557b1470e02a502a5f334a795eaab Mon Sep 17 00:00:00 2001 From: "Erin (Jianghua) Le" Date: Wed, 9 Oct 2024 19:49:43 -0700 Subject: [PATCH] cpu: fix simInsts and simOps not resetting (#1615) This PR fixes the bug where simInsts and simOps don't reset when m5.stats.reset() is called. The stats hostInstRate and hostOpRate are affected by this change as well, as they depend on simInsts and simOps respectively. This is related to issue 1443 linked [here](https://github.com/gem5/gem5/issues/1443). --- src/cpu/base.cc | 4 ++-- src/cpu/base.hh | 28 ++++++++++++++++++++++++++-- src/cpu/o3/probe/elastic_trace.cc | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/cpu/base.cc b/src/cpu/base.cc index 94d1a6e8e3..cc093e7000 100644 --- a/src/cpu/base.cc +++ b/src/cpu/base.cc @@ -859,13 +859,13 @@ BaseCPU::GlobalStats::GlobalStats(statistics::Group *parent) "Simulator op (including micro ops) rate (op/s)") { simInsts - .functor(BaseCPU::numSimulatedInsts) + .functor(BaseCPU::GlobalStats::numSimulatedInsts) .precision(0) .prereq(simInsts) ; simOps - .functor(BaseCPU::numSimulatedOps) + .functor(BaseCPU::GlobalStats::numSimulatedOps) .precision(0) .prereq(simOps) ; diff --git a/src/cpu/base.hh b/src/cpu/base.hh index 0be0eda344..28cd90f3e2 100644 --- a/src/cpu/base.hh +++ b/src/cpu/base.hh @@ -156,6 +156,30 @@ class BaseCPU : public ClockedObject statistics::Formula hostInstRate; statistics::Formula hostOpRate; + + Counter previousInsts = 0; + Counter previousOps = 0; + + static Counter + numSimulatedInsts() + { + return totalNumSimulatedInsts() - (globalStats->previousInsts); + } + + static Counter + numSimulatedOps() + { + return totalNumSimulatedOps() - (globalStats->previousOps); + } + + void + resetStats() override + { + previousInsts = totalNumSimulatedInsts(); + previousOps = totalNumSimulatedOps(); + + statistics::Group::resetStats(); + } }; /** @@ -609,7 +633,7 @@ class BaseCPU : public ClockedObject static int numSimulatedCPUs() { return cpuList.size(); } static Counter - numSimulatedInsts() + totalNumSimulatedInsts() { Counter total = 0; @@ -621,7 +645,7 @@ class BaseCPU : public ClockedObject } static Counter - numSimulatedOps() + totalNumSimulatedOps() { Counter total = 0; diff --git a/src/cpu/o3/probe/elastic_trace.cc b/src/cpu/o3/probe/elastic_trace.cc index a56ef17749..2988e83038 100644 --- a/src/cpu/o3/probe/elastic_trace.cc +++ b/src/cpu/o3/probe/elastic_trace.cc @@ -122,7 +122,7 @@ ElasticTrace::regEtraceListeners() { assert(!allProbesReg); inform("@%llu: No. of instructions committed = %llu, registering elastic" - " probe listeners", curTick(), cpu->numSimulatedInsts()); + " probe listeners", curTick(), cpu->totalNumSimulatedInsts()); // Create new listeners: provide method to be called upon a notify() for // each probe point. listeners.push_back(new ProbeListenerArg(this,