summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2019-09-23 18:21:20 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2019-09-26 13:22:55 +0000
commit911c0959351a2c959e9a3a63a14af0599e637460 (patch)
tree0b116ddb32da99fee26105d82042af9dbe0e5e74 /src
parent7e52bf014adefe6be8ea0da53192bf77f6131c9b (diff)
downloadgem5-911c0959351a2c959e9a3a63a14af0599e637460.tar.xz
sim: Convert power modelling framework to new-style stats
Change-Id: I1dd3ea3d37bb4464637222aa5bc5d88cc7d9b66a Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21143 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Diffstat (limited to 'src')
-rw-r--r--src/sim/clock_domain.cc25
-rw-r--r--src/sim/clock_domain.hh27
-rw-r--r--src/sim/clocked_object.cc56
-rw-r--r--src/sim/clocked_object.hh21
-rw-r--r--src/sim/voltage_domain.cc23
-rw-r--r--src/sim/voltage_domain.hh17
6 files changed, 89 insertions, 80 deletions
diff --git a/src/sim/clock_domain.cc b/src/sim/clock_domain.cc
index 46dbcbaac..246ea0e57 100644
--- a/src/sim/clock_domain.cc
+++ b/src/sim/clock_domain.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2014 ARM Limited
+ * Copyright (c) 2013-2014, 2019 ARM Limited
* Copyright (c) 2013 Cornell University
* All rights reserved
*
@@ -55,20 +55,21 @@
#include "sim/clocked_object.hh"
#include "sim/voltage_domain.hh"
-void
-ClockDomain::regStats()
+ClockDomain::ClockDomainStats::ClockDomainStats(ClockDomain &cd)
+ : Stats::Group(&cd),
+ ADD_STAT(clock, "Clock period in ticks")
{
- SimObject::regStats();
-
- using namespace Stats;
-
// Expose the current clock period as a stat for observability in
// the dumps
- currentClock
- .scalar(_clockPeriod)
- .name(params()->name + ".clock")
- .desc("Clock period in ticks")
- ;
+ clock.scalar(cd._clockPeriod);
+}
+
+ClockDomain::ClockDomain(const Params *p, VoltageDomain *voltage_domain)
+ : SimObject(p),
+ _clockPeriod(0),
+ _voltageDomain(voltage_domain),
+ stats(*this)
+{
}
double
diff --git a/src/sim/clock_domain.hh b/src/sim/clock_domain.hh
index 6ba8b6396..bee6bb217 100644
--- a/src/sim/clock_domain.hh
+++ b/src/sim/clock_domain.hh
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2014 ARM Limited
+ * Copyright (c) 2013-2014, 2019 ARM Limited
* Copyright (c) 2013 Cornell University
* All rights reserved
*
@@ -72,14 +72,6 @@ class Clocked;
*/
class ClockDomain : public SimObject
{
-
- private:
-
- /**
- * Stat to report clock period of clock domain
- */
- Stats::Value currentClock;
-
protected:
/**
@@ -108,12 +100,7 @@ class ClockDomain : public SimObject
public:
typedef ClockDomainParams Params;
- ClockDomain(const Params *p, VoltageDomain *voltage_domain) :
- SimObject(p),
- _clockPeriod(0),
- _voltageDomain(voltage_domain) {}
-
- void regStats();
+ ClockDomain(const Params *p, VoltageDomain *voltage_domain);
/**
* Get the clock period.
@@ -157,6 +144,16 @@ class ClockDomain : public SimObject
void addDerivedDomain(DerivedClockDomain *clock_domain)
{ children.push_back(clock_domain); }
+ private:
+ struct ClockDomainStats : public Stats::Group
+ {
+ ClockDomainStats(ClockDomain &cd);
+
+ /**
+ * Stat to report clock period of clock domain
+ */
+ Stats::Value clock;
+ } stats;
};
/**
diff --git a/src/sim/clocked_object.cc b/src/sim/clocked_object.cc
index 6982966aa..32850fea4 100644
--- a/src/sim/clocked_object.cc
+++ b/src/sim/clocked_object.cc
@@ -46,7 +46,8 @@
ClockedObject::ClockedObject(const ClockedObjectParams *p) :
SimObject(p), Clocked(*p->clk_domain),
_currPwrState(p->default_p_state),
- prvEvalTick(0)
+ prvEvalTick(0),
+ stats(*this)
{
// Register the power_model with the object
for (auto & power_model: p->power_model)
@@ -103,7 +104,7 @@ ClockedObject::pwrState(Enums::PwrState p)
_currPwrState = p;
- numPwrStateTransitions++;
+ stats.numPwrStateTransitions++;
}
void
@@ -112,13 +113,13 @@ ClockedObject::computeStats()
// Calculate time elapsed from last (valid) state change
Tick elapsed_time = curTick() - prvEvalTick;
- pwrStateResidencyTicks[_currPwrState] += elapsed_time;
+ stats.pwrStateResidencyTicks[_currPwrState] += elapsed_time;
// Time spent in CLK_GATED state, this might change depending on
// transition to other low power states in respective simulation
// objects.
if (_currPwrState == Enums::PwrState::CLK_GATED) {
- pwrStateClkGateDist.sample(elapsed_time);
+ stats.pwrStateClkGateDist.sample(elapsed_time);
}
prvEvalTick = curTick();
@@ -130,7 +131,7 @@ ClockedObject::pwrStateWeights() const
// Get residency stats
std::vector<double> ret;
Stats::VCounter residencies;
- pwrStateResidencyTicks.value(residencies);
+ stats.pwrStateResidencyTicks.value(residencies);
// Account for current state too!
Tick elapsed_time = curTick() - prvEvalTick;
@@ -139,38 +140,45 @@ ClockedObject::pwrStateWeights() const
ret.resize(Enums::PwrState::Num_PwrState);
for (unsigned i = 0; i < Enums::PwrState::Num_PwrState; i++)
ret[i] = residencies[i] / \
- (pwrStateResidencyTicks.total() + elapsed_time);
+ (stats.pwrStateResidencyTicks.total() + elapsed_time);
return ret;
}
+
+ClockedObject::ClockedObjectStats::ClockedObjectStats(ClockedObject &co)
+ : Stats::Group(&co),
+ clockedObject(co),
+ ADD_STAT(numPwrStateTransitions,
+ "Number of power state transitions"),
+ ADD_STAT(pwrStateClkGateDist,
+ "Distribution of time spent in the clock gated state"),
+ ADD_STAT(pwrStateResidencyTicks,
+ "Cumulative time (in ticks) in various power states")
+{
+}
+
void
-ClockedObject::regStats()
+ClockedObject::ClockedObjectStats::regStats()
{
- SimObject::regStats();
+ Stats::Group::regStats();
using namespace Stats;
- numPwrStateTransitions
- .name(params()->name + ".numPwrStateTransitions")
- .desc("Number of power state transitions")
- .flags(nozero)
- ;
+ const ClockedObjectParams *p = clockedObject.params();
+
+ numPwrStateTransitions.flags(nozero);
// Each sample is time in ticks
- unsigned num_bins = std::max(params()->p_state_clk_gate_bins, 10U);
+ unsigned num_bins = std::max(p->p_state_clk_gate_bins, 10U);
pwrStateClkGateDist
- .init(params()->p_state_clk_gate_min, params()->p_state_clk_gate_max,
- (params()->p_state_clk_gate_max / num_bins))
- .name(params()->name + ".pwrStateClkGateDist")
- .desc("Distribution of time spent in the clock gated state")
+ .init(p->p_state_clk_gate_min, p->p_state_clk_gate_max,
+ (p->p_state_clk_gate_max / num_bins))
.flags(pdf | nozero | nonan)
;
pwrStateResidencyTicks
.init(Enums::PwrState::Num_PwrState)
- .name(params()->name + ".pwrStateResidencyTicks")
- .desc("Cumulative time (in ticks) in various power states")
.flags(nozero)
;
for (int i = 0; i < Enums::PwrState::Num_PwrState; i++) {
@@ -178,6 +186,12 @@ ClockedObject::regStats()
}
numPwrStateTransitions = 0;
+}
+
+void
+ClockedObject::ClockedObjectStats::preDumpStats()
+{
+ Stats::Group::preDumpStats();
/**
* For every stats dump, the power state residency and other distribution
@@ -187,5 +201,5 @@ ClockedObject::regStats()
* next dump window which might have rather unpleasant effects (like
* perturbing the distribution stats).
*/
- registerDumpCallback(new ClockedObjectDumpCallback(this));
+ clockedObject.computeStats();
}
diff --git a/src/sim/clocked_object.hh b/src/sim/clocked_object.hh
index d41f71a17..ba1750ea1 100644
--- a/src/sim/clocked_object.hh
+++ b/src/sim/clocked_object.hh
@@ -270,7 +270,6 @@ class ClockedObject : public SimObject, public Clocked
void computeStats();
void pwrState(Enums::PwrState);
- void regStats() override;
protected:
@@ -279,18 +278,18 @@ class ClockedObject : public SimObject, public Clocked
Tick prvEvalTick;
- Stats::Scalar numPwrStateTransitions;
- Stats::Distribution pwrStateClkGateDist;
- Stats::Vector pwrStateResidencyTicks;
+ struct ClockedObjectStats : public Stats::Group
+ {
+ ClockedObjectStats(ClockedObject &co);
-};
+ void regStats() override;
+ void preDumpStats() override;
-class ClockedObjectDumpCallback : public Callback
-{
- ClockedObject *co;
- public:
- ClockedObjectDumpCallback(ClockedObject *co_t) : co(co_t) {}
- virtual void process() { co->computeStats(); };
+ ClockedObject &clockedObject;
+ Stats::Scalar numPwrStateTransitions;
+ Stats::Distribution pwrStateClkGateDist;
+ Stats::Vector pwrStateResidencyTicks;
+ } stats;
};
#endif //__SIM_CLOCKED_OBJECT_HH__
diff --git a/src/sim/voltage_domain.cc b/src/sim/voltage_domain.cc
index 6f32dc7c0..ca86478f1 100644
--- a/src/sim/voltage_domain.cc
+++ b/src/sim/voltage_domain.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2014 ARM Limited
+ * Copyright (c) 2012-2014, 2019 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -49,7 +49,7 @@
#include "sim/sim_object.hh"
VoltageDomain::VoltageDomain(const Params *p)
- : SimObject(p), voltageOpPoints(p->voltage), _perfLevel(0)
+ : SimObject(p), voltageOpPoints(p->voltage), _perfLevel(0), stats(*this)
{
fatal_if(voltageOpPoints.empty(), "DVFS: Empty set of voltages for "\
"voltage domain %s\n", name());
@@ -127,18 +127,6 @@ VoltageDomain::startup() {
}
}
-void
-VoltageDomain::regStats()
-{
- SimObject::regStats();
-
- currentVoltage
- .method(this, &VoltageDomain::voltage)
- .name(params()->name + ".voltage")
- .desc("Voltage in Volts")
- ;
-}
-
VoltageDomain *
VoltageDomainParams::create()
{
@@ -157,3 +145,10 @@ VoltageDomain::unserialize(CheckpointIn &cp)
UNSERIALIZE_SCALAR(_perfLevel);
perfLevel(_perfLevel);
}
+
+VoltageDomain::VoltageDomainStats::VoltageDomainStats(VoltageDomain &vd)
+ : Stats::Group(&vd),
+ ADD_STAT(voltage, "Voltage in Volts")
+{
+ voltage.method(&vd, &VoltageDomain::voltage);
+}
diff --git a/src/sim/voltage_domain.hh b/src/sim/voltage_domain.hh
index e7e4f8180..2702647d5 100644
--- a/src/sim/voltage_domain.hh
+++ b/src/sim/voltage_domain.hh
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012 ARM Limited
+ * Copyright (c) 2012, 2019 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -126,8 +126,6 @@ class VoltageDomain : public SimObject
*/
bool sanitiseVoltages();
- void regStats() override;
-
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
@@ -143,10 +141,15 @@ class VoltageDomain : public SimObject
const Voltages voltageOpPoints;
PerfLevel _perfLevel;
- /**
- * Stat for reporting voltage of the domain
- */
- Stats::Value currentVoltage;
+ struct VoltageDomainStats : public Stats::Group
+ {
+ VoltageDomainStats(VoltageDomain &vd);
+
+ /**
+ * Stat for reporting voltage of the domain
+ */
+ Stats::Value voltage;
+ } stats;
/**
* List of associated SrcClockDomains that are connected to this voltage