ruby: replace g_ruby_start with per-RubySystem m_start_cycle
authorBrandon Potter <brandon.potter@amd.com>
Fri, 10 Jul 2015 21:05:23 +0000 (16:05 -0500)
committerBrandon Potter <brandon.potter@amd.com>
Fri, 10 Jul 2015 21:05:23 +0000 (16:05 -0500)
This patch begins the process of removing global variables from the Ruby
source with the goal of eventually allowing users to create multiple Ruby
instances in a single simulation.  Currently, users cannot do so because
several global variables and static members are referenced by the RubySystem
object in a way that assumes that there will only ever be a single RubySystem.
These need to be replaced with per-RubySystem equivalents.

This specific patch replaces the global var g_ruby_start, which is used
to calculate throughput statistics for Throttles in simple networks and
links in Garnet networks, with a RubySystem instance var m_start_cycle.

src/mem/ruby/common/Global.cc
src/mem/ruby/common/Global.hh
src/mem/ruby/network/Network.cc
src/mem/ruby/network/garnet/fixed-pipeline/GarnetNetwork_d.cc
src/mem/ruby/network/garnet/flexible-pipeline/GarnetNetwork.cc
src/mem/ruby/network/simple/Switch.cc
src/mem/ruby/network/simple/Throttle.cc
src/mem/ruby/network/simple/Throttle.hh
src/mem/ruby/system/System.cc
src/mem/ruby/system/System.hh

index 3fdbd28b63a2a66b25ad36e7c7d0a25c7330bfa6..407e373075cd8a2c00eb79457e5064baea3c666b 100644 (file)
@@ -32,4 +32,3 @@ using namespace std;
 
 RubySystem* g_system_ptr = 0;
 vector<map<uint32_t, AbstractController *> > g_abs_controls;
-Cycles g_ruby_start;
index d3f8029638f667431680c35f200a4998c0e33230..e6f943aafb119515c621df8a0faafdcb702bfb8d 100644 (file)
@@ -41,8 +41,4 @@ extern RubySystem* g_system_ptr;
 class AbstractController;
 extern std::vector<std::map<uint32_t, AbstractController *> > g_abs_controls;
 
-// A globally visible time at which the actual execution started. Meant only
-// for components with in Ruby. Initialized in RubySystem::startup().
-extern Cycles g_ruby_start;
-
 #endif // __MEM_RUBY_COMMON_GLOBAL_HH__
index 5f1fff1959cc6901499e33f365025abed7c71593..2d611cd7eb6d68c72650770e7f5311f45d1ad1e8 100644 (file)
@@ -65,7 +65,7 @@ Network::Network(const Params *p)
         m_ordered[i] = false;
     }
 
-    p->ruby_system->registerNetwork(this);
+    params()->ruby_system->registerNetwork(this);
 
     // Initialize the controller's network pointers
     for (std::vector<BasicExtLink*>::const_iterator i = p->ext_links.begin();
index 35732edad20e7fbc071bbc1c28010a187d47706c..d16db76ca6edd8f5aa3a4e1d65d2bbc7d34d2e47 100644 (file)
@@ -40,6 +40,7 @@
 #include "mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.hh"
 #include "mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.hh"
 #include "mem/ruby/network/garnet/fixed-pipeline/Router_d.hh"
+#include "mem/ruby/system/System.hh"
 
 using namespace std;
 using m5::stl_helpers::deletePointers;
@@ -223,15 +224,16 @@ GarnetNetwork_d::regStats()
 void
 GarnetNetwork_d::collateStats()
 {
+    RubySystem *rs = params()->ruby_system;
+    double time_delta = double(curCycle() - rs->getStartCycle());
+
     for (int i = 0; i < m_links.size(); i++) {
         m_average_link_utilization +=
-            (double(m_links[i]->getLinkUtilization())) /
-            (double(curCycle() - g_ruby_start));
+            (double(m_links[i]->getLinkUtilization())) / time_delta;
 
         vector<unsigned int> vc_load = m_links[i]->getVcLoad();
         for (int j = 0; j < vc_load.size(); j++) {
-            m_average_vc_load[j] +=
-                ((double)vc_load[j] / (double)(curCycle() - g_ruby_start));
+            m_average_vc_load[j] += ((double)vc_load[j] / time_delta);
         }
     }
 
index 8951f75135c95f70ca04e5d3c6ee45ecc48acedf..091a0077d81ac30d11bc2744d9ca44d52500c6ef 100644 (file)
@@ -40,6 +40,7 @@
 #include "mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.hh"
 #include "mem/ruby/network/garnet/flexible-pipeline/NetworkLink.hh"
 #include "mem/ruby/network/garnet/flexible-pipeline/Router.hh"
+#include "mem/ruby/system/System.hh"
 
 using namespace std;
 using m5::stl_helpers::deletePointers;
@@ -227,10 +228,12 @@ GarnetNetwork::regStats()
 void
 GarnetNetwork::collateStats()
 {
+    RubySystem *rs = params()->ruby_system;
+    double time_delta = double(curCycle() - rs->getStartCycle());
+
     for (int i = 0; i < m_links.size(); i++) {
         m_average_link_utilization +=
-            (double(m_links[i]->getLinkUtilization())) /
-            (double(curCycle() - g_ruby_start));
+            (double(m_links[i]->getLinkUtilization())) / time_delta;
 
         vector<unsigned int> vc_load = m_links[i]->getVcLoad();
         for (int j = 0; j < vc_load.size(); j++) {
index 416a222bb5767fd4af216756bdfa92baef211082..431a7b28f0bb50e51d6ec8ed49fb45b498db0c23 100644 (file)
@@ -81,7 +81,8 @@ Switch::addOutPort(const vector<MessageBuffer*>& out,
                    Cycles link_latency, int bw_multiplier)
 {
     // Create a throttle
-    Throttle* throttle_ptr = new Throttle(m_id, m_throttles.size(),
+    RubySystem *rs = m_network_ptr->params()->ruby_system;
+    Throttle* throttle_ptr = new Throttle(m_id, rs, m_throttles.size(),
                                           link_latency, bw_multiplier,
                                           m_network_ptr->getEndpointBandwidth(),
                                           this);
index d722c91ea2049fdffcd0d53792b300abb571be94..f0cd6bd166f854a525ece49beb53a74979d30e8c 100644 (file)
@@ -46,19 +46,19 @@ const int PRIORITY_SWITCH_LIMIT = 128;
 
 static int network_message_to_size(Message* net_msg_ptr);
 
-Throttle::Throttle(int sID, NodeID node, Cycles link_latency,
+Throttle::Throttle(int sID, RubySystem *rs, NodeID node, Cycles link_latency,
                    int link_bandwidth_multiplier, int endpoint_bandwidth,
                    ClockedObject *em)
-    : Consumer(em)
+    : Consumer(em), m_ruby_system(rs)
 {
     init(node, link_latency, link_bandwidth_multiplier, endpoint_bandwidth);
     m_sID = sID;
 }
 
-Throttle::Throttle(NodeID node, Cycles link_latency,
+Throttle::Throttle(RubySystem *rs, NodeID node, Cycles link_latency,
                    int link_bandwidth_multiplier, int endpoint_bandwidth,
                    ClockedObject *em)
-    : Consumer(em)
+    : Consumer(em), m_ruby_system(rs)
 {
     init(node, link_latency, link_bandwidth_multiplier, endpoint_bandwidth);
     m_sID = 0;
@@ -245,8 +245,10 @@ Throttle::clearStats()
 void
 Throttle::collateStats()
 {
-    m_link_utilization = 100.0 * m_link_utilization_proxy
-        / (double(g_system_ptr->curCycle() - g_ruby_start));
+    double time_delta = double(m_ruby_system->curCycle() -
+                               m_ruby_system->getStartCycle());
+
+    m_link_utilization = 100.0 * m_link_utilization_proxy / time_delta;
 }
 
 void
index 797511702befaf7fa0be7e85f246969eb944e225..19b0fcd35b8a7cb6130d1f29a5a1ec1207e031b3 100644 (file)
@@ -52,11 +52,12 @@ class MessageBuffer;
 class Throttle : public Consumer
 {
   public:
-    Throttle(int sID, NodeID node, Cycles link_latency,
+    Throttle(int sID, RubySystem *rs, NodeID node, Cycles link_latency,
+             int link_bandwidth_multiplier, int endpoint_bandwidth,
+             ClockedObject *em);
+    Throttle(RubySystem *rs, NodeID node, Cycles link_latency,
              int link_bandwidth_multiplier, int endpoint_bandwidth,
              ClockedObject *em);
-    Throttle(NodeID node, Cycles link_latency, int link_bandwidth_multiplier,
-             int endpoint_bandwidth, ClockedObject *em);
     ~Throttle() {}
 
     std::string name()
@@ -103,6 +104,7 @@ class Throttle : public Consumer
     Cycles m_link_latency;
     int m_wakeups_wo_switch;
     int m_endpoint_bandwidth;
+    RubySystem *m_ruby_system;
 
     // Statistical variables
     Stats::Scalar m_link_utilization;
index 2f1d9013c02b30e141c71ff5e93f77069150a595..1cdc3879e204e4eeed997420eb0ab0c99f35c2da 100644 (file)
@@ -338,7 +338,7 @@ RubySystem::RubyEvent::process()
 void
 RubySystem::resetStats()
 {
-    g_ruby_start = curCycle();
+    m_start_cycle = curCycle();
 }
 
 bool
index a59ade39893bdb84f6abaaa2dfb9ce409c73b157..0030b503335e1061fe3bae387e9c71a1fb9ae8c2 100644 (file)
@@ -78,6 +78,7 @@ class RubySystem : public ClockedObject
     static bool getCooldownEnabled() { return m_cooldown_enabled; }
 
     SimpleMemory *getPhysMem() { return m_phys_mem; }
+    Cycles getStartCycle() { return m_start_cycle; }
     const bool getAccessBackingStore() { return m_access_backing_store; }
 
     // Public Methods
@@ -135,6 +136,7 @@ class RubySystem : public ClockedObject
 
     Network* m_network;
     std::vector<AbstractController *> m_abs_cntrl_vec;
+    Cycles m_start_cycle;
 
   public:
     Profiler* m_profiler;