Andreas Sandberg has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/35616 )

Change subject: sim, stats: Move global stats to Root
......................................................................

sim, stats: Move global stats to Root

Global stats are currently exposed using the legacy stat system (i.e.,
without a parent group). This change moves global stats from
stat_control.cc to a group that gets exported from the Root object.

The implementation adds the Root::Stats class which has a single
global instance. This instance is exposed to the rest of the simulator
using the global rootStats symbol. The intention is that objects that
need global statistics in formulas access them through the rootStats
object.

The global names simSeconds, simTicks, simFreq, and hostSeconds are
now references to their respective members in the rootStats object.

Change-Id: I267b5244a0bcca93dd2dcf03388e7085bdd79c9e
Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35616
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Maintainer: Jason Lowe-Power <power...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/sim/SConscript
M src/sim/root.cc
M src/sim/root.hh
M src/sim/stat_control.cc
M src/sim/stat_control.hh
A src/sim/stats.cc
M src/sim/stats.hh
7 files changed, 164 insertions(+), 105 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/SConscript b/src/sim/SConscript
index 6bda828..78d9bf5 100644
--- a/src/sim/SConscript
+++ b/src/sim/SConscript
@@ -81,6 +81,7 @@
 Source('mathexpr.cc')
 Source('power_state.cc')
 Source('power_domain.cc')
+Source('stats.cc')

 GTest('byteswap.test', 'byteswap.test.cc', '../base/types.cc')
 GTest('guest_abi.test', 'guest_abi.test.cc')
diff --git a/src/sim/root.cc b/src/sim/root.cc
index 5a17442..e1c6a7b 100644
--- a/src/sim/root.cc
+++ b/src/sim/root.cc
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2020 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
  * Copyright (c) 2002-2005 The Regents of The University of Michigan
  * Copyright (c) 2011 Advanced Micro Devices, Inc.
  * All rights reserved.
@@ -27,6 +39,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

+#include "base/hostinfo.hh"
 #include "base/logging.hh"
 #include "base/trace.hh"
 #include "config/the_isa.hh"
@@ -36,6 +49,56 @@
 #include "sim/root.hh"

 Root *Root::_root = NULL;
+Root::Stats Root::Stats::instance;
+Root::Stats &rootStats = Root::Stats::instance;
+
+Root::Stats::Stats()
+    : Stats::Group(nullptr),
+    simSeconds(this, "sim_seconds", "Number of seconds simulated"),
+    simTicks(this, "sim_ticks", "Number of ticks simulated"),
+    finalTick(this, "final_tick",
+              "Number of ticks from beginning of simulation "
+              "(restored from checkpoints and never reset)"),
+    simFreq(this, "sim_freq", "Frequency of simulated ticks"),
+    hostSeconds(this, "host_seconds", "Real time elapsed on the host"),
+    hostTickRate(this, "host_tick_rate", "Simulator tick rate (ticks/s)"),
+ hostMemory(this, "host_mem_usage", "Number of bytes of host memory used"),
+
+    statTime(true),
+    startTick(0)
+{
+    simFreq.scalar(SimClock::Frequency);
+    simTicks.functor([this]() { return curTick() - startTick; });
+    finalTick.functor(curTick);
+
+    hostMemory
+        .functor(memUsage)
+        .prereq(hostMemory)
+        ;
+
+    hostSeconds
+        .functor([this]() {
+                Time now;
+                now.setTimer();
+                return now - statTime;
+            })
+        .precision(2)
+        ;
+
+    hostTickRate.precision(0);
+
+    simSeconds = simTicks / simFreq;
+    hostTickRate = simTicks / hostSeconds;
+}
+
+void
+Root::Stats::resetStats()
+{
+    statTime.setTimer();
+    startTick = curTick();
+
+    Stats::Group::resetStats();
+}

 /*
  * This function is called periodically by an event in M5 and ensures that
@@ -112,6 +175,12 @@
     lastTime.setTimer();

     simQuantum = p->sim_quantum;
+
+    // Some of the statistics are global and need to be accessed by
+    // stat formulas. The most convenient way to implement that is by
+    // having a single global stat group for global stats. Merge that
+    // group into the root object here.
+    mergeStatGroup(&Root::Stats::instance);
 }

 void
diff --git a/src/sim/root.hh b/src/sim/root.hh
index 0638559..a88673a 100644
--- a/src/sim/root.hh
+++ b/src/sim/root.hh
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2020 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
  * Copyright (c) 2011 Advanced Micro Devices, Inc.
  * All rights reserved.
  *
@@ -39,6 +51,7 @@
 #ifndef __SIM_ROOT_HH__
 #define __SIM_ROOT_HH__

+#include "base/statistics.hh"
 #include "base/time.hh"
 #include "params/Root.hh"
 #include "sim/eventq.hh"
@@ -76,6 +89,32 @@
         return _root;
     }

+  public: // Global statistics
+    struct Stats : public ::Stats::Group
+    {
+        void resetStats() override;
+
+        ::Stats::Formula simSeconds;
+        ::Stats::Value simTicks;
+        ::Stats::Value finalTick;
+        ::Stats::Value simFreq;
+        ::Stats::Value hostSeconds;
+
+        ::Stats::Formula hostTickRate;
+        ::Stats::Value hostMemory;
+
+        static Stats instance;
+
+      private:
+        Stats();
+
+        Stats(const Stats &) = delete;
+        Stats &operator=(const Stats &) = delete;
+
+        Time statTime;
+        Tick startTick;
+    };
+
   public:

     /// Check whether time syncing is enabled.
@@ -108,4 +147,10 @@
     void serialize(CheckpointOut &cp) const override;
 };

+/**
+ * Global simulator statistics that are not associated with a
+ * specific SimObject.
+ */
+extern Root::Stats &rootStats;
+
 #endif // __SIM_ROOT_HH__
diff --git a/src/sim/stat_control.cc b/src/sim/stat_control.cc
index 5b66786..8189bfe 100644
--- a/src/sim/stat_control.cc
+++ b/src/sim/stat_control.cc
@@ -50,115 +50,19 @@
 #include <list>

 #include "base/callback.hh"
-#include "base/hostinfo.hh"
 #include "base/statistics.hh"
 #include "base/time.hh"
 #include "sim/global_event.hh"

 using namespace std;

-Stats::Formula simSeconds;
-Stats::Value simTicks;
-Stats::Value finalTick;
-Stats::Value simFreq;
-Stats::Value hostSeconds;
-
 namespace Stats {

-Time statTime(true);
-Tick startTick;
-
 GlobalEvent *dumpEvent;

-double
-statElapsedTime()
-{
-    Time now;
-    now.setTimer();
-
-    Time elapsed = now - statTime;
-    return elapsed;
-}
-
-Tick
-statElapsedTicks()
-{
-    return curTick() - startTick;
-}
-
-Tick
-statFinalTick()
-{
-    return curTick();
-}
-
-struct Global
-{
-    Stats::Formula hostTickRate;
-    Stats::Value hostMemory;
-
-    Global();
-};
-
-Global::Global()
-{
-    simSeconds
-        .name("sim_seconds")
-        .desc("Number of seconds simulated")
-        ;
-
-    simFreq
-        .scalar(SimClock::Frequency)
-        .name("sim_freq")
-        .desc("Frequency of simulated ticks")
-        ;
-
-    simTicks
-        .functor(statElapsedTicks)
-        .name("sim_ticks")
-        .desc("Number of ticks simulated")
-        ;
-
-    finalTick
-        .functor(statFinalTick)
-        .name("final_tick")
-        .desc("Number of ticks from beginning of simulation "
-              "(restored from checkpoints and never reset)")
-        ;
-
-    hostMemory
-        .functor(memUsage)
-        .name("host_mem_usage")
-        .desc("Number of bytes of host memory used")
-        .prereq(hostMemory)
-        ;
-
-    hostSeconds
-        .functor(statElapsedTime)
-        .name("host_seconds")
-        .desc("Real time elapsed on the host")
-        .precision(2)
-        ;
-
-    hostTickRate
-        .name("host_tick_rate")
-        .desc("Simulator tick rate (ticks/s)")
-        .precision(0)
-        ;
-
-    simSeconds = simTicks / simFreq;
-    hostTickRate = simTicks / hostSeconds;
-
-    registerResetCallback([]() {
-        statTime.setTimer();
-        startTick = curTick();
-    });
-}
-
 void
 initSimStats()
 {
-    static Global global;
 }

 /**
diff --git a/src/sim/stat_control.hh b/src/sim/stat_control.hh
index 3b869ad..55930b4 100644
--- a/src/sim/stat_control.hh
+++ b/src/sim/stat_control.hh
@@ -46,11 +46,6 @@

 namespace Stats {

-double statElapsedTime();
-
-Tick statElapsedTicks();
-
-Tick statFinalTick();

 void initSimStats();

diff --git a/src/sim/stats.cc b/src/sim/stats.cc
new file mode 100644
index 0000000..b5a3ca1
--- /dev/null
+++ b/src/sim/stats.cc
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2020 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sim/stats.hh"
+
+#include "sim/root.hh"
+
+Stats::Formula &simSeconds = rootStats.simSeconds;
+Stats::Value &simTicks = rootStats.simTicks;
+Stats::Value &simFreq = rootStats.simFreq;
+Stats::Value &hostSeconds = rootStats.hostSeconds;
diff --git a/src/sim/stats.hh b/src/sim/stats.hh
index 4e17f64..a46539e 100644
--- a/src/sim/stats.hh
+++ b/src/sim/stats.hh
@@ -31,9 +31,9 @@

 #include "base/statistics.hh"

-extern Stats::Formula simSeconds;
-extern Stats::Value simTicks;
-extern Stats::Value simFreq;
-extern Stats::Value hostSeconds;
+extern Stats::Formula &simSeconds;
+extern Stats::Value &simTicks;
+extern Stats::Value &simFreq;
+extern Stats::Value &hostSeconds;

 #endif // __SIM_SIM_STATS_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/35616
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: I267b5244a0bcca93dd2dcf03388e7085bdd79c9e
Gerrit-Change-Number: 35616
Gerrit-PatchSet: 3
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Ciro Santilli <ciro.santi...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to