SimpleNetwork.cc revision 6876
16145Snate@binkert.org
26145Snate@binkert.org/*
36145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
46145Snate@binkert.org * All rights reserved.
56145Snate@binkert.org *
66145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76145Snate@binkert.org * modification, are permitted provided that the following conditions are
86145Snate@binkert.org * met: redistributions of source code must retain the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126145Snate@binkert.org * documentation and/or other materials provided with the distribution;
136145Snate@binkert.org * neither the name of the copyright holders nor the names of its
146145Snate@binkert.org * contributors may be used to endorse or promote products derived from
156145Snate@binkert.org * this software without specific prior written permission.
166145Snate@binkert.org *
176145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286145Snate@binkert.org */
296145Snate@binkert.org
306145Snate@binkert.org/*
316284Snate@binkert.org * SimpleNetwork.cc
326145Snate@binkert.org *
336284Snate@binkert.org * Description: See SimpleNetwork.hh
346145Snate@binkert.org *
356145Snate@binkert.org * $Id$
366145Snate@binkert.org *
376145Snate@binkert.org */
386145Snate@binkert.org
396154Snate@binkert.org#include "mem/ruby/network/simple/SimpleNetwork.hh"
406154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
416154Snate@binkert.org#include "mem/ruby/system/System.hh"
426154Snate@binkert.org#include "mem/ruby/network/simple/Switch.hh"
436154Snate@binkert.org#include "mem/ruby/common/NetDest.hh"
446154Snate@binkert.org#include "mem/ruby/network/simple/Topology.hh"
456154Snate@binkert.org#include "mem/protocol/TopologyType.hh"
466154Snate@binkert.org#include "mem/protocol/MachineType.hh"
476154Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh"
486154Snate@binkert.org#include "mem/protocol/Protocol.hh"
496154Snate@binkert.org#include "mem/gems_common/Map.hh"
506145Snate@binkert.org
516284Snate@binkert.org// ***BIG HACK*** - This is actually code that _should_ be in Network.cc
526145Snate@binkert.org
536145Snate@binkert.org// Note: Moved to Princeton Network
546145Snate@binkert.org// calls new to abstract away from the network
556145Snate@binkert.org/*
566145Snate@binkert.orgNetwork* Network::createNetwork(int nodes)
576145Snate@binkert.org{
586145Snate@binkert.org  return new SimpleNetwork(nodes);
596145Snate@binkert.org}
606145Snate@binkert.org*/
616145Snate@binkert.org
626876Ssteve.reinhardt@amd.comSimpleNetwork::SimpleNetwork(const Params *p)
636876Ssteve.reinhardt@amd.com    : Network(p)
646285Snate@binkert.org{
656285Snate@binkert.org  m_virtual_networks = 0;
666285Snate@binkert.org  m_topology_ptr = NULL;
676285Snate@binkert.org}
686285Snate@binkert.org
696876Ssteve.reinhardt@amd.comvoid SimpleNetwork::init()
706285Snate@binkert.org{
716285Snate@binkert.org
726876Ssteve.reinhardt@amd.com  Network::init();
736285Snate@binkert.org
746285Snate@binkert.org  m_endpoint_switches.setSize(m_nodes);
756285Snate@binkert.org
766285Snate@binkert.org  m_in_use.setSize(m_virtual_networks);
776285Snate@binkert.org  m_ordered.setSize(m_virtual_networks);
786285Snate@binkert.org  for (int i = 0; i < m_virtual_networks; i++) {
796285Snate@binkert.org    m_in_use[i] = false;
806285Snate@binkert.org    m_ordered[i] = false;
816285Snate@binkert.org  }
826285Snate@binkert.org
836285Snate@binkert.org  // Allocate to and from queues
846285Snate@binkert.org  m_toNetQueues.setSize(m_nodes);
856285Snate@binkert.org  m_fromNetQueues.setSize(m_nodes);
866285Snate@binkert.org  for (int node = 0; node < m_nodes; node++) {
876285Snate@binkert.org    m_toNetQueues[node].setSize(m_virtual_networks);
886285Snate@binkert.org    m_fromNetQueues[node].setSize(m_virtual_networks);
896285Snate@binkert.org    for (int j = 0; j < m_virtual_networks; j++) {
906795SBrad.Beckmann@amd.com      m_toNetQueues[node][j] = new MessageBuffer(
916781SBrad.Beckmann@amd.com                   "toNet node "+int_to_string(node)+" j "+int_to_string(j));
926795SBrad.Beckmann@amd.com      m_fromNetQueues[node][j] = new MessageBuffer(
936781SBrad.Beckmann@amd.com                   "fromNet node "+int_to_string(node)+" j "+int_to_string(j));
946285Snate@binkert.org    }
956285Snate@binkert.org  }
966285Snate@binkert.org
976285Snate@binkert.org  // Setup the network switches
986285Snate@binkert.org  //  m_topology_ptr = new Topology(this, m_nodes);
996285Snate@binkert.org  m_topology_ptr->makeTopology();
1006285Snate@binkert.org  int number_of_switches = m_topology_ptr->numSwitches();
1016285Snate@binkert.org  for (int i=0; i<number_of_switches; i++) {
1026285Snate@binkert.org    m_switch_ptr_vector.insertAtBottom(new Switch(i, this));
1036285Snate@binkert.org  }
1046285Snate@binkert.org  m_topology_ptr->createLinks(false);  // false because this isn't a reconfiguration
1056285Snate@binkert.org}
1066145Snate@binkert.org
1076145Snate@binkert.orgvoid SimpleNetwork::reset()
1086145Snate@binkert.org{
1096145Snate@binkert.org  for (int node = 0; node < m_nodes; node++) {
1106145Snate@binkert.org    for (int j = 0; j < m_virtual_networks; j++) {
1116145Snate@binkert.org      m_toNetQueues[node][j]->clear();
1126145Snate@binkert.org      m_fromNetQueues[node][j]->clear();
1136145Snate@binkert.org    }
1146145Snate@binkert.org  }
1156145Snate@binkert.org
1166145Snate@binkert.org  for(int i=0; i<m_switch_ptr_vector.size(); i++){
1176145Snate@binkert.org    m_switch_ptr_vector[i]->clearBuffers();
1186145Snate@binkert.org  }
1196145Snate@binkert.org}
1206145Snate@binkert.org
1216145Snate@binkert.orgSimpleNetwork::~SimpleNetwork()
1226145Snate@binkert.org{
1236145Snate@binkert.org  for (int i = 0; i < m_nodes; i++) {
1246145Snate@binkert.org    m_toNetQueues[i].deletePointers();
1256145Snate@binkert.org    m_fromNetQueues[i].deletePointers();
1266145Snate@binkert.org  }
1276145Snate@binkert.org  m_switch_ptr_vector.deletePointers();
1286145Snate@binkert.org  m_buffers_to_free.deletePointers();
1296762SBrad.Beckmann@amd.com  // delete m_topology_ptr;
1306145Snate@binkert.org}
1316145Snate@binkert.org
1326145Snate@binkert.org// From a switch to an endpoint node
1336145Snate@binkert.orgvoid SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration)
1346145Snate@binkert.org{
1356145Snate@binkert.org  assert(dest < m_nodes);
1366145Snate@binkert.org  assert(src < m_switch_ptr_vector.size());
1376145Snate@binkert.org  assert(m_switch_ptr_vector[src] != NULL);
1386145Snate@binkert.org  if(!isReconfiguration){
1396145Snate@binkert.org    m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier);
1406145Snate@binkert.org    m_endpoint_switches[dest] = m_switch_ptr_vector[src];
1416145Snate@binkert.org  } else {
1426145Snate@binkert.org    m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
1436145Snate@binkert.org  }
1446145Snate@binkert.org}
1456145Snate@binkert.org
1466145Snate@binkert.org// From an endpoint node to a switch
1476145Snate@binkert.orgvoid SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration)
1486145Snate@binkert.org{
1496145Snate@binkert.org  assert(src < m_nodes);
1506145Snate@binkert.org  if(!isReconfiguration){
1516145Snate@binkert.org    m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]);
1526145Snate@binkert.org  } else {
1536145Snate@binkert.org    // do nothing
1546145Snate@binkert.org  }
1556145Snate@binkert.org}
1566145Snate@binkert.org
1576145Snate@binkert.org// From a switch to a switch
1586145Snate@binkert.orgvoid SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration)
1596145Snate@binkert.org{
1606145Snate@binkert.org  if(!isReconfiguration){
1616145Snate@binkert.org    // Create a set of new MessageBuffers
1626145Snate@binkert.org    Vector<MessageBuffer*> queues;
1636145Snate@binkert.org    for (int i = 0; i < m_virtual_networks; i++) {
1646145Snate@binkert.org      // allocate a buffer
1656145Snate@binkert.org      MessageBuffer* buffer_ptr = new MessageBuffer;
1666145Snate@binkert.org      buffer_ptr->setOrdering(true);
1676285Snate@binkert.org      if (m_buffer_size > 0) {
1686285Snate@binkert.org        buffer_ptr->setSize(m_buffer_size);
1696145Snate@binkert.org      }
1706145Snate@binkert.org      queues.insertAtBottom(buffer_ptr);
1716145Snate@binkert.org      // remember to deallocate it
1726145Snate@binkert.org      m_buffers_to_free.insertAtBottom(buffer_ptr);
1736145Snate@binkert.org    }
1746145Snate@binkert.org
1756145Snate@binkert.org    // Connect it to the two switches
1766145Snate@binkert.org    m_switch_ptr_vector[dest]->addInPort(queues);
1776145Snate@binkert.org    m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier);
1786145Snate@binkert.org  } else {
1796145Snate@binkert.org    m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
1806145Snate@binkert.org  }
1816145Snate@binkert.org}
1826145Snate@binkert.org
1836145Snate@binkert.orgvoid SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
1846145Snate@binkert.org{
1856145Snate@binkert.org  ASSERT(id < m_nodes);
1866145Snate@binkert.org  ASSERT(network_num < m_virtual_networks);
1876145Snate@binkert.org
1886145Snate@binkert.org  if (ordered) {
1896145Snate@binkert.org    m_ordered[network_num] = true;
1906145Snate@binkert.org  }
1916145Snate@binkert.org  m_in_use[network_num] = true;
1926145Snate@binkert.org}
1936145Snate@binkert.org
1946145Snate@binkert.orgMessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num)
1956145Snate@binkert.org{
1966145Snate@binkert.org  checkNetworkAllocation(id, ordered, network_num);
1976145Snate@binkert.org  return m_toNetQueues[id][network_num];
1986145Snate@binkert.org}
1996145Snate@binkert.org
2006145Snate@binkert.orgMessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num)
2016145Snate@binkert.org{
2026145Snate@binkert.org  checkNetworkAllocation(id, ordered, network_num);
2036145Snate@binkert.org  return m_fromNetQueues[id][network_num];
2046145Snate@binkert.org}
2056145Snate@binkert.org
2066145Snate@binkert.orgconst Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const
2076145Snate@binkert.org{
2086145Snate@binkert.org  assert(id >= 0);
2096145Snate@binkert.org  assert(id < m_nodes);
2106145Snate@binkert.org  assert(m_endpoint_switches[id] != NULL);
2116145Snate@binkert.org  return m_endpoint_switches[id]->getThrottles();
2126145Snate@binkert.org}
2136145Snate@binkert.org
2146145Snate@binkert.orgvoid SimpleNetwork::printStats(ostream& out) const
2156145Snate@binkert.org{
2166145Snate@binkert.org  out << endl;
2176145Snate@binkert.org  out << "Network Stats" << endl;
2186145Snate@binkert.org  out << "-------------" << endl;
2196145Snate@binkert.org  out << endl;
2206145Snate@binkert.org  for(int i=0; i<m_switch_ptr_vector.size(); i++) {
2216145Snate@binkert.org    m_switch_ptr_vector[i]->printStats(out);
2226145Snate@binkert.org  }
2236145Snate@binkert.org}
2246145Snate@binkert.org
2256145Snate@binkert.orgvoid SimpleNetwork::clearStats()
2266145Snate@binkert.org{
2276145Snate@binkert.org  for(int i=0; i<m_switch_ptr_vector.size(); i++) {
2286145Snate@binkert.org    m_switch_ptr_vector[i]->clearStats();
2296145Snate@binkert.org  }
2306145Snate@binkert.org}
2316145Snate@binkert.org
2326145Snate@binkert.orgvoid SimpleNetwork::printConfig(ostream& out) const
2336145Snate@binkert.org{
2346145Snate@binkert.org  out << endl;
2356145Snate@binkert.org  out << "Network Configuration" << endl;
2366145Snate@binkert.org  out << "---------------------" << endl;
2376145Snate@binkert.org  out << "network: SIMPLE_NETWORK" << endl;
2386285Snate@binkert.org  out << "topology: " << m_topology_ptr->getName() << endl;
2396145Snate@binkert.org  out << endl;
2406145Snate@binkert.org
2416145Snate@binkert.org  for (int i = 0; i < m_virtual_networks; i++) {
2426145Snate@binkert.org    out << "virtual_net_" << i << ": ";
2436145Snate@binkert.org    if (m_in_use[i]) {
2446145Snate@binkert.org      out << "active, ";
2456145Snate@binkert.org      if (m_ordered[i]) {
2466145Snate@binkert.org        out << "ordered" << endl;
2476145Snate@binkert.org      } else {
2486145Snate@binkert.org        out << "unordered" << endl;
2496145Snate@binkert.org      }
2506145Snate@binkert.org    } else {
2516145Snate@binkert.org      out << "inactive" << endl;
2526145Snate@binkert.org    }
2536145Snate@binkert.org  }
2546145Snate@binkert.org  out << endl;
2556145Snate@binkert.org  for(int i=0; i<m_switch_ptr_vector.size(); i++) {
2566145Snate@binkert.org    m_switch_ptr_vector[i]->printConfig(out);
2576145Snate@binkert.org  }
2586145Snate@binkert.org
2596285Snate@binkert.org  m_topology_ptr->printConfig(out);
2606145Snate@binkert.org}
2616145Snate@binkert.org
2626145Snate@binkert.orgvoid SimpleNetwork::print(ostream& out) const
2636145Snate@binkert.org{
2646145Snate@binkert.org  out << "[SimpleNetwork]";
2656145Snate@binkert.org}
2666876Ssteve.reinhardt@amd.com
2676876Ssteve.reinhardt@amd.com
2686876Ssteve.reinhardt@amd.comSimpleNetwork *
2696876Ssteve.reinhardt@amd.comSimpleNetworkParams::create()
2706876Ssteve.reinhardt@amd.com{
2716876Ssteve.reinhardt@amd.com    return new SimpleNetwork(this);
2726876Ssteve.reinhardt@amd.com}
273