ruby: network: move getNumNodes() to base class

All the implementations were doing the same things.
This commit is contained in:
Nilay Vaish 2014-09-01 16:55:42 -05:00
parent cc2cc58869
commit 00dbadcbb0
10 changed files with 47 additions and 75 deletions

View file

@ -49,6 +49,35 @@ Network::Network(const Params *p)
m_topology_ptr = new Topology(p->routers.size(), p->ext_links, m_topology_ptr = new Topology(p->routers.size(), p->ext_links,
p->int_links); p->int_links);
// Allocate to and from queues
// Queues that are getting messages from protocol
m_toNetQueues.resize(m_nodes);
// Queues that are feeding the protocol
m_fromNetQueues.resize(m_nodes);
for (int node = 0; node < m_nodes; node++) {
// Setting number of virtual message buffers per Network Queue
m_toNetQueues[node].resize(m_virtual_networks);
m_fromNetQueues[node].resize(m_virtual_networks);
// Instantiating the Message Buffers that
// interact with the coherence protocol
for (int j = 0; j < m_virtual_networks; j++) {
m_toNetQueues[node][j] = new MessageBuffer();
m_fromNetQueues[node][j] = new MessageBuffer();
}
}
m_in_use.resize(m_virtual_networks);
m_ordered.resize(m_virtual_networks);
for (int i = 0; i < m_virtual_networks; i++) {
m_in_use[i] = false;
m_ordered[i] = false;
}
p->ruby_system->registerNetwork(this); p->ruby_system->registerNetwork(this);
// Initialize the controller's network pointers // Initialize the controller's network pointers
@ -63,6 +92,19 @@ Network::Network(const Params *p)
Stats::registerDumpCallback(new StatsCallback(this)); Stats::registerDumpCallback(new StatsCallback(this));
} }
Network::~Network()
{
for (int node = 0; node < m_nodes; node++) {
// Delete the Message Buffers
for (int j = 0; j < m_virtual_networks; j++) {
delete m_toNetQueues[node][j];
delete m_fromNetQueues[node][j];
}
}
delete m_topology_ptr;
}
void void
Network::init() Network::init()
{ {

View file

@ -60,13 +60,15 @@ class Network : public ClockedObject
public: public:
typedef RubyNetworkParams Params; typedef RubyNetworkParams Params;
Network(const Params *p); Network(const Params *p);
virtual ~Network() {}
const Params * params() const const Params * params() const
{ return dynamic_cast<const Params *>(_params);} { return dynamic_cast<const Params *>(_params);}
virtual ~Network();
virtual void init(); virtual void init();
static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; } static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
int getNumNodes() const { return m_nodes; }
static uint32_t MessageSizeType_to_int(MessageSizeType size_type); static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
// returns the queue requested for the given component // returns the queue requested for the given component
@ -74,7 +76,7 @@ class Network : public ClockedObject
int netNumber, std::string vnet_type) = 0; int netNumber, std::string vnet_type) = 0;
virtual MessageBuffer* getFromNetQueue(NodeID id, bool ordered, virtual MessageBuffer* getFromNetQueue(NodeID id, bool ordered,
int netNumber, std::string vnet_type) = 0; int netNumber, std::string vnet_type) = 0;
virtual int getNumNodes() {return 1;}
virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link, virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
LinkDirection direction, LinkDirection direction,

View file

@ -58,34 +58,6 @@ BaseGarnetNetwork::BaseGarnetNetwork(const Params *p)
fatal("Garnet only supports uniform bw across all links and NIs\n"); fatal("Garnet only supports uniform bw across all links and NIs\n");
} }
} }
// Allocate to and from queues
// Queues that are getting messages from protocol
m_toNetQueues.resize(m_nodes);
// Queues that are feeding the protocol
m_fromNetQueues.resize(m_nodes);
m_in_use.resize(m_virtual_networks);
m_ordered.resize(m_virtual_networks);
for (int i = 0; i < m_virtual_networks; i++) {
m_in_use[i] = false;
m_ordered[i] = false;
}
for (int node = 0; node < m_nodes; node++) {
// Setting number of virtual message buffers per Network Queue
m_toNetQueues[node].resize(m_virtual_networks);
m_fromNetQueues[node].resize(m_virtual_networks);
// Instantiating the Message Buffers that
// interact with the coherence protocol
for (int j = 0; j < m_virtual_networks; j++) {
m_toNetQueues[node][j] = new MessageBuffer();
m_fromNetQueues[node][j] = new MessageBuffer();
}
}
} }
void void

View file

@ -108,15 +108,10 @@ GarnetNetwork_d::init()
GarnetNetwork_d::~GarnetNetwork_d() GarnetNetwork_d::~GarnetNetwork_d()
{ {
for (int i = 0; i < m_nodes; i++) {
deletePointers(m_toNetQueues[i]);
deletePointers(m_fromNetQueues[i]);
}
deletePointers(m_routers); deletePointers(m_routers);
deletePointers(m_nis); deletePointers(m_nis);
deletePointers(m_links); deletePointers(m_links);
deletePointers(m_creditlinks); deletePointers(m_creditlinks);
delete m_topology_ptr;
} }
/* /*

View file

@ -52,11 +52,8 @@ class GarnetNetwork_d : public BaseGarnetNetwork
GarnetNetwork_d(const Params *p); GarnetNetwork_d(const Params *p);
~GarnetNetwork_d(); ~GarnetNetwork_d();
void init(); void init();
int getNumNodes() { return m_nodes; }
int getBuffersPerDataVC() {return m_buffers_per_data_vc; } int getBuffersPerDataVC() {return m_buffers_per_data_vc; }
int getBuffersPerCtrlVC() {return m_buffers_per_ctrl_vc; } int getBuffersPerCtrlVC() {return m_buffers_per_ctrl_vc; }

View file

@ -114,8 +114,8 @@ NetworkInterface_d::addNode(vector<MessageBuffer *>& in,
assert(in.size() == m_virtual_networks); assert(in.size() == m_virtual_networks);
inNode_ptr = in; inNode_ptr = in;
outNode_ptr = out; outNode_ptr = out;
for (int j = 0; j < m_virtual_networks; j++) {
for (int j = 0; j < m_virtual_networks; j++) {
// the protocol injects messages into the NI // the protocol injects messages into the NI
inNode_ptr[j]->setConsumer(this); inNode_ptr[j]->setConsumer(this);
inNode_ptr[j]->setReceiver(this); inNode_ptr[j]->setReceiver(this);

View file

@ -88,14 +88,9 @@ GarnetNetwork::init()
GarnetNetwork::~GarnetNetwork() GarnetNetwork::~GarnetNetwork()
{ {
for (int i = 0; i < m_nodes; i++) {
deletePointers(m_toNetQueues[i]);
deletePointers(m_fromNetQueues[i]);
}
deletePointers(m_routers); deletePointers(m_routers);
deletePointers(m_nis); deletePointers(m_nis);
deletePointers(m_links); deletePointers(m_links);
delete m_topology_ptr;
} }
void void

View file

@ -50,12 +50,10 @@ class GarnetNetwork : public BaseGarnetNetwork
GarnetNetwork(const Params *p); GarnetNetwork(const Params *p);
~GarnetNetwork(); ~GarnetNetwork();
void init(); void init();
int getBufferSize() { return m_buffer_size; } int getBufferSize() { return m_buffer_size; }
int getNumPipeStages() {return m_number_of_pipe_stages; } int getNumPipeStages() {return m_number_of_pipe_stages; }
int getNumNodes(){ return m_nodes; }
void collateStats(); void collateStats();
void regStats(); void regStats();

View file

@ -53,30 +53,8 @@ SimpleNetwork::SimpleNetwork(const Params *p)
// Note: the parent Network Object constructor is called before the // Note: the parent Network Object constructor is called before the
// SimpleNetwork child constructor. Therefore, the member variables // SimpleNetwork child constructor. Therefore, the member variables
// used below should already be initialized. // used below should already be initialized.
m_endpoint_switches.resize(m_nodes); m_endpoint_switches.resize(m_nodes);
m_in_use.resize(m_virtual_networks);
m_ordered.resize(m_virtual_networks);
for (int i = 0; i < m_virtual_networks; i++) {
m_in_use[i] = false;
m_ordered[i] = false;
}
// Allocate to and from queues
m_toNetQueues.resize(m_nodes);
m_fromNetQueues.resize(m_nodes);
for (int node = 0; node < m_nodes; node++) {
m_toNetQueues[node].resize(m_virtual_networks);
m_fromNetQueues[node].resize(m_virtual_networks);
for (int j = 0; j < m_virtual_networks; j++) {
m_toNetQueues[node][j] =
new MessageBuffer(csprintf("toNet node %d j %d", node, j));
m_fromNetQueues[node][j] =
new MessageBuffer(csprintf("fromNet node %d j %d", node, j));
}
}
// record the routers // record the routers
for (vector<BasicRouter*>::const_iterator i = p->routers.begin(); for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
i != p->routers.end(); ++i) { i != p->routers.end(); ++i) {
@ -99,13 +77,8 @@ SimpleNetwork::init()
SimpleNetwork::~SimpleNetwork() SimpleNetwork::~SimpleNetwork()
{ {
for (int i = 0; i < m_nodes; i++) {
deletePointers(m_toNetQueues[i]);
deletePointers(m_fromNetQueues[i]);
}
deletePointers(m_switches); deletePointers(m_switches);
deletePointers(m_buffers_to_free); deletePointers(m_buffers_to_free);
// delete m_topology_ptr;
} }
// From a switch to an endpoint node // From a switch to an endpoint node

View file

@ -63,8 +63,6 @@ class SimpleNetwork : public Network
bool isVNetOrdered(int vnet) { return m_ordered[vnet]; } bool isVNetOrdered(int vnet) { return m_ordered[vnet]; }
bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; } bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; }
int getNumNodes() {return m_nodes; }
// Methods used by Topology to setup the network // Methods used by Topology to setup the network
void makeOutLink(SwitchID src, NodeID dest, BasicLink* link, void makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
LinkDirection direction, LinkDirection direction,