ruby: changes to simple network
authorNilay Vaish <nilay@cs.wisc.edu>
Tue, 2 Oct 2012 19:35:45 +0000 (14:35 -0500)
committerNilay Vaish <nilay@cs.wisc.edu>
Tue, 2 Oct 2012 19:35:45 +0000 (14:35 -0500)
This patch makes the Switch structure inherit from BasicRouter, as is
done in two other networks.

13 files changed:
configs/ruby/Ruby.py
src/mem/ruby/network/BasicRouter.hh
src/mem/ruby/network/Topology.cc
src/mem/ruby/network/Topology.hh
src/mem/ruby/network/garnet/flexible-pipeline/GarnetRouter.py
src/mem/ruby/network/garnet/flexible-pipeline/Router.cc
src/mem/ruby/network/garnet/flexible-pipeline/Router.hh
src/mem/ruby/network/simple/PerfectSwitch.cc
src/mem/ruby/network/simple/PerfectSwitch.hh
src/mem/ruby/network/simple/SimpleNetwork.cc
src/mem/ruby/network/simple/SimpleNetwork.py
src/mem/ruby/network/simple/Switch.cc
src/mem/ruby/network/simple/Switch.hh

index a8fc94d3db9ff73c54176af9c0e7dfc17db0b106..bcb939165f15ed1cc841d1b44c856a5c36c6a3e1 100644 (file)
@@ -135,7 +135,7 @@ def create_system(options, system, piobus = None, dma_ports = []):
         class NetworkClass(SimpleNetwork): pass
         class IntLinkClass(SimpleIntLink): pass
         class ExtLinkClass(SimpleExtLink): pass
-        class RouterClass(BasicRouter): pass
+        class RouterClass(Switch): pass
 
     #
     # Important: the topology must be instantiated before the network and after
index 67dc21c654d02e373b3598c3e69559df314cd000..220d3527abe4d5b9dbcd5ef22cad75c590650d78 100644 (file)
@@ -53,7 +53,7 @@ class BasicRouter : public SimObject
     //
     // ID in relation to other routers in the system
     //
-    int m_id;
+    uint32_t m_id;
 };
 
 inline std::ostream&
index e9f5ae13a329e8a6b8b8f77854a91770c65e2782..082b2c4ac91746639fdd2f8fa023e53ceeb5e33a 100644 (file)
@@ -32,7 +32,6 @@
 #include "mem/protocol/MachineType.hh"
 #include "mem/ruby/common/NetDest.hh"
 #include "mem/ruby/network/BasicLink.hh"
-#include "mem/ruby/network/BasicRouter.hh"
 #include "mem/ruby/network/Network.hh"
 #include "mem/ruby/network/Topology.hh"
 #include "mem/ruby/slicc_interface/AbstractController.hh"
@@ -41,8 +40,6 @@ using namespace std;
 
 const int INFINITE_LATENCY = 10000; // Yes, this is a big hack
 
-class BasicRouter;
-
 // Note: In this file, we use the first 2*m_nodes SwitchIDs to
 // represent the input and output endpoint links.  These really are
 // not 'switches', as they will not have a Switch object allocated for
index 1c675b9390d194d4e12ac4b27bd48de5a96abe72..578340ab9c8a7435350929a02cfd7820db14c793 100644 (file)
@@ -46,6 +46,7 @@
 
 #include "mem/protocol/LinkDirection.hh"
 #include "mem/ruby/common/TypeDefines.hh"
+#include "mem/ruby/network/BasicRouter.hh"
 #include "params/Topology.hh"
 #include "sim/sim_object.hh"
 
index b626471a60e96bfeec2c0d683fa0f737abdd2e77..a39348c46b63499ea80011aaf91b783d54ced80e 100644 (file)
@@ -39,5 +39,3 @@ class GarnetRouter(BasicRouter):
                               "virtual channels per virtual network")
     virt_nets = Param.Int(Parent.number_of_virtual_networks,
                           "number of virtual networks")
-
-
index 88361d35a7e82244c2f570a1e0717618f3f481dc..44dd6a50159a93a33c6c85d1b135897f8c165ef1 100644 (file)
@@ -43,7 +43,6 @@ using m5::stl_helpers::deletePointers;
 Router::Router(const Params *p)
     : BasicRouter(p), FlexibleConsumer(this)
 {
-    m_id = p->router_id;
     m_virtual_networks = p->virt_nets;
     m_vc_per_vnet = p->vcs_per_vnet;
     m_round_robin_inport = 0;
index 5042844044554ff43addb030cf162acb765e8707..93578b597532faf7b9288101adbfccd390883044 100644 (file)
@@ -75,7 +75,6 @@ class Router : public BasicRouter, public FlexibleConsumer
     }
 
   private:
-    int m_id;
     int m_virtual_networks, m_num_vcs, m_vc_per_vnet;
     GarnetNetwork *m_net_ptr;
     std::vector<int> m_vc_round_robin; // For scheduling of out source queues
index 0ead3ac30b9af26e8faca5543139a0dd5a9b9e3c..2c845683d035dae56cfbf684970f318fb4c76d96 100644 (file)
@@ -33,9 +33,8 @@
 #include "mem/ruby/buffers/MessageBuffer.hh"
 #include "mem/ruby/network/simple/PerfectSwitch.hh"
 #include "mem/ruby/network/simple/SimpleNetwork.hh"
-#include "mem/ruby/profiler/Profiler.hh"
+#include "mem/ruby/network/simple/Switch.hh"
 #include "mem/ruby/slicc_interface/NetworkMessage.hh"
-#include "mem/ruby/system/System.hh"
 
 using namespace std;
 
@@ -48,14 +47,19 @@ operator<(const LinkOrder& l1, const LinkOrder& l2)
     return (l1.m_value < l2.m_value);
 }
 
-PerfectSwitch::PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr)
-    : Consumer(network_ptr)
+PerfectSwitch::PerfectSwitch(SwitchID sid, Switch *sw, uint32_t virt_nets)
+    : Consumer(sw)
 {
-    m_virtual_networks = network_ptr->getNumberOfVirtualNetworks();
     m_switch_id = sid;
     m_round_robin_start = 0;
-    m_network_ptr = network_ptr;
     m_wakeups_wo_switch = 0;
+    m_virtual_networks = virt_nets;
+}
+
+void
+PerfectSwitch::init(SimpleNetwork *network_ptr)
+{
+    m_network_ptr = network_ptr;
 
     for(int i = 0;i < m_virtual_networks;++i)
     {
index 65a52eb082c2d019b6f63ce88844b681c270b833..695c848bcf4e157e5ba93ed527152ee88e47cc9d 100644 (file)
 #include <vector>
 
 #include "mem/ruby/common/Consumer.hh"
-#include "mem/ruby/common/Global.hh"
 
 class MessageBuffer;
 class NetDest;
 class SimpleNetwork;
+class Switch;
 
 struct LinkOrder
 {
@@ -56,12 +56,13 @@ struct LinkOrder
 class PerfectSwitch : public Consumer
 {
   public:
-    PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr);
+    PerfectSwitch(SwitchID sid, Switch *, uint32_t);
     ~PerfectSwitch();
 
     std::string name()
     { return csprintf("PerfectSwitch-%i", m_switch_id); }
 
+    void init(SimpleNetwork *);
     void addInPort(const std::vector<MessageBuffer*>& in);
     void addOutPort(const std::vector<MessageBuffer*>& out,
         const NetDest& routing_table_entry);
@@ -90,9 +91,11 @@ class PerfectSwitch : public Consumer
     std::vector<std::vector<MessageBuffer*> > m_out;
     std::vector<NetDest> m_routing_table;
     std::vector<LinkOrder> m_link_order;
-    int m_virtual_networks;
+
+    uint32_t m_virtual_networks;
     int m_round_robin_start;
     int m_wakeups_wo_switch;
+
     SimpleNetwork* m_network_ptr;
     std::vector<int> m_pending_message_count;
 };
index 84d2ee97f6597015fe2afb936332771e17040796..7aa8e62f97665edfbe8422c8c7910881c6b8dc5d 100644 (file)
@@ -78,6 +78,15 @@ SimpleNetwork::SimpleNetwork(const Params *p)
                 new MessageBuffer(csprintf("fromNet node %d j %d", node, j));
         }
     }
+
+    // record the routers
+    for (vector<BasicRouter*>::const_iterator i =
+             m_topology_ptr->params()->routers.begin();
+         i != m_topology_ptr->params()->routers.end(); ++i) {
+        Switch* s = safe_cast<Switch*>(*i);
+        m_switch_ptr_vector.push_back(s);
+        s->init_net_ptr(this);
+    }
 }
 
 void
@@ -88,11 +97,6 @@ SimpleNetwork::init()
     // The topology pointer should have already been initialized in
     // the parent class network constructor.
     assert(m_topology_ptr != NULL);
-    int number_of_switches = m_topology_ptr->numSwitches();
-    for (int i = 0; i < number_of_switches; i++) {
-        m_switch_ptr_vector.push_back(new Switch(i, this));
-    }
-
     // false because this isn't a reconfiguration
     m_topology_ptr->createLinks(this, false);
 }
@@ -282,15 +286,14 @@ SimpleNetwork::printStats(ostream& out) const
         
         if (total_msg_counts[type] > 0) {
             out << "total_msg_count_" << type << ": " << total_msg_counts[type] 
-                << " " << total_msg_counts[type] * 
-                uint64(RubySystem::getNetwork()->MessageSizeType_to_int(type))
+                << " " << total_msg_counts[type] *
+                uint64(MessageSizeType_to_int(type))
                 << endl;
             
             total_msgs += total_msg_counts[type];
             
             total_bytes += total_msg_counts[type] * 
-                uint64(RubySystem::getNetwork()->MessageSizeType_to_int(type));
-            
+                uint64(MessageSizeType_to_int(type));
         }
     }
     
index 6394ee01ab29ecdedd4ad7e1c6ae143b99b83322..0603546ce8268b77ba3f7a1a4a999f48d43bf0fe 100644 (file)
@@ -28,7 +28,9 @@
 #          Brad Beckmann
 
 from m5.params import *
+from m5.proxy import *
 from Network import RubyNetwork
+from BasicRouter import BasicRouter
 
 class SimpleNetwork(RubyNetwork):
     type = 'SimpleNetwork'
@@ -36,3 +38,9 @@ class SimpleNetwork(RubyNetwork):
         "default buffer size; 0 indicates infinite buffering");
     endpoint_bandwidth = Param.Int(1000, "bandwidth adjustment factor");
     adaptive_routing = Param.Bool(False, "enable adaptive routing");
+
+class Switch(BasicRouter):
+    type = 'Switch'
+    cxx_class = 'Switch'
+    virt_nets = Param.Int(Parent.number_of_virtual_networks,
+                          "number of virtual networks")
index 42a4efae3c84a8fb8ed0e58050df72aa5e7a6d89..5c2f5a7170fbd66a68fe7e08630ae0f23418efd2 100644 (file)
@@ -41,10 +41,9 @@ using namespace std;
 using m5::stl_helpers::deletePointers;
 using m5::stl_helpers::operator<<;
 
-Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr)
+Switch::Switch(const Params *p) : BasicRouter(p)
 {
-    m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr);
-    m_switch_id = sid;
+    m_perfect_switch_ptr = new PerfectSwitch(m_id, this, p->virt_nets);
 }
 
 Switch::~Switch()
@@ -58,6 +57,13 @@ Switch::~Switch()
     deletePointers(m_buffers_to_free);
 }
 
+void
+Switch::init()
+{
+    BasicRouter::init();
+    m_perfect_switch_ptr->init(m_network_ptr);
+}
+
 void
 Switch::addInPort(const vector<MessageBuffer*>& in)
 {
@@ -68,14 +74,10 @@ void
 Switch::addOutPort(const vector<MessageBuffer*>& out,
     const NetDest& routing_table_entry, int link_latency, int bw_multiplier)
 {
-    Throttle* throttle_ptr = NULL;
-    SimpleNetwork* net_ptr = 
-        safe_cast<SimpleNetwork*>(RubySystem::getNetwork());
-
     // Create a throttle
-    throttle_ptr = new Throttle(m_switch_id, m_throttles.size(), link_latency,
-                                bw_multiplier, net_ptr->getEndpointBandwidth(),
-                                net_ptr);
+    Throttle* throttle_ptr = new Throttle(m_id, m_throttles.size(),
+        link_latency, bw_multiplier, m_network_ptr->getEndpointBandwidth(),
+        this);
     m_throttles.push_back(throttle_ptr);
 
     // Create one buffer per vnet (these are intermediaryQueues)
@@ -84,12 +86,12 @@ Switch::addOutPort(const vector<MessageBuffer*>& out,
         MessageBuffer* buffer_ptr = new MessageBuffer;
         // Make these queues ordered
         buffer_ptr->setOrdering(true);
-        if (net_ptr->getBufferSize() > 0) {
-            buffer_ptr->resize(net_ptr->getBufferSize());
+        if (m_network_ptr->getBufferSize() > 0) {
+            buffer_ptr->resize(m_network_ptr->getBufferSize());
         }
         intermediateBuffers.push_back(buffer_ptr);
         m_buffers_to_free.push_back(buffer_ptr);
-  }
+    }
 
     // Hook the queues to the PerfectSwitch
     m_perfect_switch_ptr->addOutPort(intermediateBuffers, routing_table_entry);
@@ -137,9 +139,9 @@ Switch::getThrottles() const
 void
 Switch::printStats(std::ostream& out) const
 {
-    ccprintf(out, "switch_%d_inlinks: %d\n", m_switch_id,
+    ccprintf(out, "switch_%d_inlinks: %d\n", m_id,
         m_perfect_switch_ptr->getInLinks());
-    ccprintf(out, "switch_%d_outlinks: %d\n", m_switch_id,
+    ccprintf(out, "switch_%d_outlinks: %d\n", m_id,
         m_perfect_switch_ptr->getOutLinks());
 
     // Average link utilizations
@@ -157,13 +159,13 @@ Switch::printStats(std::ostream& out) const
         throttle_count == 0 ? 0 : average_utilization / throttle_count;
 
     // Individual link utilizations
-    out << "links_utilized_percent_switch_" << m_switch_id << ": "
+    out << "links_utilized_percent_switch_" << m_id << ": "
         << average_utilization << endl;
 
     for (int link = 0; link < m_throttles.size(); link++) {
         Throttle* throttle_ptr = m_throttles[link];
         if (throttle_ptr != NULL) {
-            out << "  links_utilized_percent_switch_" << m_switch_id
+            out << "  links_utilized_percent_switch_" << m_id
                 << "_link_" << link << ": "
                 << throttle_ptr->getUtilization() << " bw: "
                 << throttle_ptr->getLinkBandwidth()
@@ -187,9 +189,9 @@ Switch::printStats(std::ostream& out) const
             if (sum == 0)
                 continue;
 
-            out << "  outgoing_messages_switch_" << m_switch_id
+            out << "  outgoing_messages_switch_" << m_id
                 << "_link_" << link << "_" << type << ": " << sum << " "
-                << sum * RubySystem::getNetwork()->MessageSizeType_to_int(type)
+                << sum * m_network_ptr->MessageSizeType_to_int(type)
                 << " ";
             out << mct;
             out << " base_latency: "
@@ -215,3 +217,9 @@ Switch::print(std::ostream& out) const
     // FIXME printing
     out << "[Switch]";
 }
+
+Switch *
+SwitchParams::create()
+{
+    return new Switch(this);
+}
index 0bc1e5eca1ffadb3640a075209c3e174f5653f3f..9946e5cc122ba752bf61a26a70c16b098a9f3512 100644 (file)
 #include <iostream>
 #include <vector>
 
+#include "mem/ruby/network/BasicRouter.hh"
+#include "params/Switch.hh"
+
 class MessageBuffer;
 class PerfectSwitch;
 class NetDest;
 class SimpleNetwork;
 class Throttle;
 
-class Switch
+class Switch : public BasicRouter
 {
   public:
-    Switch(SwitchID sid, SimpleNetwork* network_ptr);
+    typedef SwitchParams Params;
+    Switch(const Params *p);
     ~Switch();
 
+    void init();
     void addInPort(const std::vector<MessageBuffer*>& in);
     void addOutPort(const std::vector<MessageBuffer*>& out,
         const NetDest& routing_table_entry, int link_latency,
@@ -67,6 +72,7 @@ class Switch
     void printStats(std::ostream& out) const;
     void clearStats();
     void print(std::ostream& out) const;
+    void init_net_ptr(SimpleNetwork* net_ptr) { m_network_ptr = net_ptr; }
 
   private:
     // Private copy constructor and assignment operator
@@ -77,7 +83,6 @@ class Switch
     SimpleNetwork* m_network_ptr;
     std::vector<Throttle*> m_throttles;
     std::vector<MessageBuffer*> m_buffers_to_free;
-    SwitchID m_switch_id;
 };
 
 inline std::ostream&