Hoa Nguyen has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/38055 )

Change subject: mem-ruby: Update stats style for SimpleNetwork
......................................................................

mem-ruby: Update stats style for SimpleNetwork

Change-Id: I7d54ed02d01a3811b41dce794e308b8b77576c92
Signed-off-by: Hoa Nguyen <hoangu...@ucdavis.edu>
---
M src/mem/ruby/network/simple/SimpleNetwork.cc
M src/mem/ruby/network/simple/SimpleNetwork.hh
M src/mem/ruby/network/simple/Switch.cc
M src/mem/ruby/network/simple/Switch.hh
M src/mem/ruby/network/simple/Throttle.cc
M src/mem/ruby/network/simple/Throttle.hh
6 files changed, 120 insertions(+), 61 deletions(-)



diff --git a/src/mem/ruby/network/simple/SimpleNetwork.cc b/src/mem/ruby/network/simple/SimpleNetwork.cc
index 3a15a57..0cee7df 100644
--- a/src/mem/ruby/network/simple/SimpleNetwork.cc
+++ b/src/mem/ruby/network/simple/SimpleNetwork.cc
@@ -57,12 +57,15 @@
 SimpleNetwork::SimpleNetwork(const Params &p)
     : Network(p), m_buffer_size(p.buffer_size),
       m_endpoint_bandwidth(p.endpoint_bandwidth),
-      m_adaptive_routing(p.adaptive_routing)
+      m_adaptive_routing(p.adaptive_routing),
+      networkStats(this)
 {
     // record the routers
     for (vector<BasicRouter*>::const_iterator i = p.routers.begin();
          i != p.routers.end(); ++i) {
         Switch* s = safe_cast<Switch*>(*i);
+        //s->addStatGroup(csprintf("router_%i", m_switches.size()).c_str(),
+        //                &(s->switchStats));
         m_switches.push_back(s);
         s->init_net_ptr(this);
     }
@@ -144,24 +147,29 @@

     for (MessageSizeType type = MessageSizeType_FIRST;
          type < MessageSizeType_NUM; ++type) {
-        m_msg_counts[(unsigned int) type]
-            .name(name() + ".msg_count." + MessageSizeType_to_string(type))
-            .flags(Stats::nozero)
+        networkStats.m_msg_counts[(unsigned int) type] =
+            new Stats::Formula(&networkStats,
+ csprintf("msg_count.%s", MessageSizeType_to_string(type)).c_str());
+        networkStats.m_msg_counts[(unsigned int) type]
+            ->flags(Stats::nozero)
             ;
-        m_msg_bytes[(unsigned int) type]
-            .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
-            .flags(Stats::nozero)
+
+        networkStats.m_msg_bytes[(unsigned int) type] =
+            new Stats::Formula(&networkStats,
+ csprintf("msg_byte.%s", MessageSizeType_to_string(type)).c_str());
+        networkStats.m_msg_bytes[(unsigned int) type]
+            ->flags(Stats::nozero)
             ;

         // Now state what the formula is.
         for (int i = 0; i < m_switches.size(); i++) {
-            m_msg_counts[(unsigned int) type] +=
+            *(networkStats.m_msg_counts[(unsigned int) type]) +=
                 sum(m_switches[i]->getMsgCount(type));
         }

-        m_msg_bytes[(unsigned int) type] =
-            m_msg_counts[(unsigned int) type] * Stats::constant(
-                    Network::MessageSizeType_to_int(type));
+        *(networkStats.m_msg_bytes[(unsigned int) type]) =
+            *(networkStats.m_msg_counts[(unsigned int) type]) *
+                Stats::constant(Network::MessageSizeType_to_int(type));
     }
 }

@@ -213,3 +221,10 @@
     }
     return num_functional_writes;
 }
+
+SimpleNetwork::
+NetworkStats::NetworkStats(Stats::Group *parent)
+    : Stats::Group(parent)
+{
+
+}
\ No newline at end of file
diff --git a/src/mem/ruby/network/simple/SimpleNetwork.hh b/src/mem/ruby/network/simple/SimpleNetwork.hh
index aee5ef5..e76b7d1 100644
--- a/src/mem/ruby/network/simple/SimpleNetwork.hh
+++ b/src/mem/ruby/network/simple/SimpleNetwork.hh
@@ -90,9 +90,15 @@
     const int m_endpoint_bandwidth;
     const bool m_adaptive_routing;

-    //Statistical variables
-    Stats::Formula m_msg_counts[MessageSizeType_NUM];
-    Stats::Formula m_msg_bytes[MessageSizeType_NUM];
+
+    struct NetworkStats : public Stats::Group
+    {
+        NetworkStats(Stats::Group *parent);
+
+        //Statistical variables
+        Stats::Formula* m_msg_counts[MessageSizeType_NUM];
+        Stats::Formula* m_msg_bytes[MessageSizeType_NUM];
+    } networkStats;
 };

 inline std::ostream&
diff --git a/src/mem/ruby/network/simple/Switch.cc b/src/mem/ruby/network/simple/Switch.cc
index 68887ac..62d12e2 100644
--- a/src/mem/ruby/network/simple/Switch.cc
+++ b/src/mem/ruby/network/simple/Switch.cc
@@ -52,8 +52,9 @@
 using m5::stl_helpers::operator<<;

 Switch::Switch(const Params &p)
-  : BasicRouter(p), perfectSwitch(m_id, this, p.virt_nets),
-    m_num_connected_buffers(0)
+  : BasicRouter(p),
+    perfectSwitch(m_id, this, p.virt_nets), m_num_connected_buffers(0),
+    switchStats(this, m_id)
 {
     m_port_buffers.reserve(p.port_buffers.size());
     for (auto& buffer : p.port_buffers) {
@@ -108,32 +109,35 @@
     BasicRouter::regStats();

     for (auto& throttle : throttles) {
-        throttle.regStats(name());
+        throttle.regStats();
     }

-    m_avg_utilization.name(name() + ".percent_links_utilized");
     for (const auto& throttle : throttles) {
-        m_avg_utilization += throttle.getUtilization();
+        switchStats.m_avg_utilization += throttle.getUtilization();
     }
-    m_avg_utilization /= Stats::constant(throttles.size());
+    switchStats.m_avg_utilization /= Stats::constant(throttles.size());

     for (unsigned int type = MessageSizeType_FIRST;
          type < MessageSizeType_NUM; ++type) {
-        m_msg_counts[type]
-            .name(name() + ".msg_count." +
-                MessageSizeType_to_string(MessageSizeType(type)))
-            .flags(Stats::nozero)
+        switchStats.m_msg_counts[type] = new Stats::Formula(&switchStats,
+            csprintf("msg_count.%s",
+                MessageSizeType_to_string(MessageSizeType(type))).c_str());
+        switchStats.m_msg_counts[type]
+            ->flags(Stats::nozero)
             ;
-        m_msg_bytes[type]
-            .name(name() + ".msg_bytes." +
-                MessageSizeType_to_string(MessageSizeType(type)))
-            .flags(Stats::nozero)
+
+        switchStats.m_msg_bytes[type] = new Stats::Formula(&switchStats,
+            csprintf("msg_bytes.%s",
+                MessageSizeType_to_string(MessageSizeType(type))).c_str());
+        switchStats.m_msg_bytes[type]
+            ->flags(Stats::nozero)
             ;

         for (const auto& throttle : throttles) {
-            m_msg_counts[type] += throttle.getMsgCount(type);
+ *(switchStats.m_msg_counts[type]) += throttle.getMsgCount(type);
         }
-        m_msg_bytes[type] = m_msg_counts[type] * Stats::constant(
+        *(switchStats.m_msg_bytes[type]) =
+            *(switchStats.m_msg_counts[type]) * Stats::constant(
                 Network::MessageSizeType_to_int(MessageSizeType(type)));
     }
 }
@@ -183,3 +187,11 @@
     }
     return num_functional_writes;
 }
+
+Switch::
+SwitchStats::SwitchStats(Stats::Group *parent, const SwitchID &switchID)
+    : Stats::Group(parent),
+      m_avg_utilization(this, "percent_links_utilized")
+{
+
+}
\ No newline at end of file
diff --git a/src/mem/ruby/network/simple/Switch.hh b/src/mem/ruby/network/simple/Switch.hh
index aac5952..dfa230f 100644
--- a/src/mem/ruby/network/simple/Switch.hh
+++ b/src/mem/ruby/network/simple/Switch.hh
@@ -73,7 +73,7 @@
     void collateStats();
     void regStats();
     const Stats::Formula & getMsgCount(unsigned int type) const
-    { return m_msg_counts[type]; }
+    { return *(switchStats.m_msg_counts[type]); }

     void print(std::ostream& out) const;
     void init_net_ptr(SimpleNetwork* net_ptr) { m_network_ptr = net_ptr; }
@@ -93,10 +93,17 @@
     unsigned m_num_connected_buffers;
     std::vector<MessageBuffer*> m_port_buffers;

-    // Statistical variables
-    Stats::Formula m_avg_utilization;
-    Stats::Formula m_msg_counts[MessageSizeType_NUM];
-    Stats::Formula m_msg_bytes[MessageSizeType_NUM];
+
+  public:
+    struct SwitchStats : public Stats::Group
+    {
+        SwitchStats(Stats::Group *parent, const SwitchID &switchID);
+
+        // Statistical variables
+        Stats::Formula m_avg_utilization;
+        Stats::Formula* m_msg_counts[MessageSizeType_NUM];
+        Stats::Formula* m_msg_bytes[MessageSizeType_NUM];
+    } switchStats;
 };

 inline std::ostream&
diff --git a/src/mem/ruby/network/simple/Throttle.cc b/src/mem/ruby/network/simple/Throttle.cc
index 5ed918c..6c0aa08 100644
--- a/src/mem/ruby/network/simple/Throttle.cc
+++ b/src/mem/ruby/network/simple/Throttle.cc
@@ -51,8 +51,10 @@
Throttle::Throttle(int sID, RubySystem *rs, NodeID node, Cycles link_latency,
                    int link_bandwidth_multiplier, int endpoint_bandwidth,
                    Switch *em)
-    : Consumer(em), m_switch_id(sID), m_switch(em), m_node(node),
-      m_ruby_system(rs)
+    : Consumer(em),
+      m_switch_id(sID), m_switch(em), m_node(node),
+      m_ruby_system(rs),
+      throttleStats(em, node)
 {
     m_vnets = 0;

@@ -122,7 +124,8 @@
                          m_switch->cyclesToTicks(m_link_latency));

             // Count the message
-            m_msg_counts[net_msg_ptr->getMessageSize()][vnet]++;
+            (*(throttleStats.
+                m_msg_counts[net_msg_ptr->getMessageSize()]))[vnet]++;
             DPRINTF(RubyNetwork, "%s\n", *out);
         }

@@ -200,26 +203,27 @@
 }

 void
-Throttle::regStats(string parent)
+Throttle::regStats()
 {
-    m_link_utilization
- .name(parent + csprintf(".throttle%i", m_node) + ".link_utilization");
-
     for (MessageSizeType type = MessageSizeType_FIRST;
          type < MessageSizeType_NUM; ++type) {
-        m_msg_counts[(unsigned int)type]
-            .init(Network::getNumberOfVirtualNetworks())
- .name(parent + csprintf(".throttle%i", m_node) + ".msg_count." +
-                    MessageSizeType_to_string(type))
-            .flags(Stats::nozero)
-            ;
-        m_msg_bytes[(unsigned int) type]
- .name(parent + csprintf(".throttle%i", m_node) + ".msg_bytes." +
-                    MessageSizeType_to_string(type))
+        throttleStats.m_msg_counts[(unsigned int)type] =
+            new Stats::Vector(&throttleStats,
+ csprintf("msg_count.%s", MessageSizeType_to_string(type)).c_str());
+        throttleStats.m_msg_counts[(unsigned int)type]
+            ->init(Network::getNumberOfVirtualNetworks())
             .flags(Stats::nozero)
             ;

- m_msg_bytes[(unsigned int) type] = m_msg_counts[type] * Stats::constant(
+        throttleStats.m_msg_bytes[(unsigned int) type] =
+            new Stats::Formula(&throttleStats,
+ csprintf("msg_bytes.%s", MessageSizeType_to_string(type)).c_str());
+        throttleStats.m_msg_bytes[(unsigned int) type]
+            ->flags(Stats::nozero)
+            ;
+
+        *(throttleStats.m_msg_bytes[(unsigned int) type]) =
+            *(throttleStats.m_msg_counts[type]) * Stats::constant(
                 Network::MessageSizeType_to_int(type));
     }
 }
@@ -236,7 +240,8 @@
     double time_delta = double(m_ruby_system->curCycle() -
                                m_ruby_system->getStartCycle());

-    m_link_utilization = 100.0 * m_link_utilization_proxy / time_delta;
+    throttleStats.m_link_utilization =
+        100.0 * m_link_utilization_proxy / time_delta;
 }

 void
@@ -259,3 +264,11 @@

     return size;
 }
+
+Throttle::
+ThrottleStats::ThrottleStats(Stats::Group *parent, const NodeID &nodeID)
+    : Stats::Group(parent, csprintf("throttle%i", nodeID).c_str()),
+      m_link_utilization(this, "link_utilization")
+{
+
+}
diff --git a/src/mem/ruby/network/simple/Throttle.hh b/src/mem/ruby/network/simple/Throttle.hh
index bf70c30..0d92041 100644
--- a/src/mem/ruby/network/simple/Throttle.hh
+++ b/src/mem/ruby/network/simple/Throttle.hh
@@ -66,9 +66,9 @@

     // The average utilization (a fraction) since last clearStats()
     const Stats::Scalar & getUtilization() const
-    { return m_link_utilization; }
+    { return throttleStats.m_link_utilization; }
     const Stats::Vector & getMsgCount(unsigned int type) const
-    { return m_msg_counts[type]; }
+    { return *(throttleStats.m_msg_counts[type]); }

     int getLinkBandwidth() const
     { return m_endpoint_bandwidth * m_link_bandwidth_multiplier; }
@@ -77,7 +77,7 @@

     void clearStats();
     void collateStats();
-    void regStats(std::string name);
+    void regStats();
     void print(std::ostream& out) const;

   private:
@@ -105,12 +105,18 @@
     int m_endpoint_bandwidth;
     RubySystem *m_ruby_system;

-    // Statistical variables
-    Stats::Scalar m_link_utilization;
-    Stats::Vector m_msg_counts[MessageSizeType_NUM];
-    Stats::Formula m_msg_bytes[MessageSizeType_NUM];
-
     double m_link_utilization_proxy;
+
+
+    struct ThrottleStats : public Stats::Group
+    {
+        ThrottleStats(Stats::Group *parent, const NodeID &nodeID);
+
+        // Statistical variables
+        Stats::Scalar m_link_utilization;
+        Stats::Vector* m_msg_counts[MessageSizeType_NUM];
+        Stats::Formula* m_msg_bytes[MessageSizeType_NUM];
+    } throttleStats;
 };

 inline std::ostream&

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/38055
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: I7d54ed02d01a3811b41dce794e308b8b77576c92
Gerrit-Change-Number: 38055
Gerrit-PatchSet: 1
Gerrit-Owner: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
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