SimpleNetwork.cc revision 6285
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 626285Snate@binkert.orgSimpleNetwork::SimpleNetwork(const string & name) 636285Snate@binkert.org : Network(name) 646285Snate@binkert.org{ 656285Snate@binkert.org m_virtual_networks = 0; 666285Snate@binkert.org m_topology_ptr = NULL; 676285Snate@binkert.org} 686285Snate@binkert.org 696285Snate@binkert.orgvoid SimpleNetwork::init(const vector<string> & argv) 706285Snate@binkert.org{ 716285Snate@binkert.org 726285Snate@binkert.org Network::init(argv); 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++) { 906285Snate@binkert.org cerr << "Creating new MessageBuffer for " << node << " " << j << endl; 916285Snate@binkert.org m_toNetQueues[node][j] = new MessageBuffer; 926285Snate@binkert.org m_fromNetQueues[node][j] = new MessageBuffer; 936285Snate@binkert.org } 946285Snate@binkert.org } 956285Snate@binkert.org 966285Snate@binkert.org // Setup the network switches 976285Snate@binkert.org // m_topology_ptr = new Topology(this, m_nodes); 986285Snate@binkert.org m_topology_ptr->makeTopology(); 996285Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 1006285Snate@binkert.org for (int i=0; i<number_of_switches; i++) { 1016285Snate@binkert.org m_switch_ptr_vector.insertAtBottom(new Switch(i, this)); 1026285Snate@binkert.org } 1036285Snate@binkert.org m_topology_ptr->createLinks(false); // false because this isn't a reconfiguration 1046285Snate@binkert.org} 1056285Snate@binkert.org/* 1066145Snate@binkert.orgSimpleNetwork::SimpleNetwork(int nodes) 1076145Snate@binkert.org{ 1086145Snate@binkert.org m_nodes = MachineType_base_number(MachineType_NUM); 1096145Snate@binkert.org 1106285Snate@binkert.org m_virtual_networks = RubyConfig::getNumberOfVirtualNetworks(); 1116145Snate@binkert.org m_endpoint_switches.setSize(m_nodes); 1126145Snate@binkert.org 1136145Snate@binkert.org m_in_use.setSize(m_virtual_networks); 1146145Snate@binkert.org m_ordered.setSize(m_virtual_networks); 1156145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1166145Snate@binkert.org m_in_use[i] = false; 1176145Snate@binkert.org m_ordered[i] = false; 1186145Snate@binkert.org } 1196145Snate@binkert.org 1206145Snate@binkert.org // Allocate to and from queues 1216145Snate@binkert.org m_toNetQueues.setSize(m_nodes); 1226145Snate@binkert.org m_fromNetQueues.setSize(m_nodes); 1236145Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1246145Snate@binkert.org m_toNetQueues[node].setSize(m_virtual_networks); 1256145Snate@binkert.org m_fromNetQueues[node].setSize(m_virtual_networks); 1266145Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1276145Snate@binkert.org m_toNetQueues[node][j] = new MessageBuffer; 1286145Snate@binkert.org m_fromNetQueues[node][j] = new MessageBuffer; 1296145Snate@binkert.org } 1306145Snate@binkert.org } 1316145Snate@binkert.org 1326145Snate@binkert.org // Setup the network switches 1336145Snate@binkert.org m_topology_ptr = new Topology(this, m_nodes); 1346145Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 1356145Snate@binkert.org for (int i=0; i<number_of_switches; i++) { 1366145Snate@binkert.org m_switch_ptr_vector.insertAtBottom(new Switch(i, this)); 1376145Snate@binkert.org } 1386145Snate@binkert.org m_topology_ptr->createLinks(false); // false because this isn't a reconfiguration 1396145Snate@binkert.org} 1406285Snate@binkert.org*/ 1416145Snate@binkert.orgvoid SimpleNetwork::reset() 1426145Snate@binkert.org{ 1436145Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1446145Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1456145Snate@binkert.org m_toNetQueues[node][j]->clear(); 1466145Snate@binkert.org m_fromNetQueues[node][j]->clear(); 1476145Snate@binkert.org } 1486145Snate@binkert.org } 1496145Snate@binkert.org 1506145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++){ 1516145Snate@binkert.org m_switch_ptr_vector[i]->clearBuffers(); 1526145Snate@binkert.org } 1536145Snate@binkert.org} 1546145Snate@binkert.org 1556145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1566145Snate@binkert.org{ 1576145Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1586145Snate@binkert.org m_toNetQueues[i].deletePointers(); 1596145Snate@binkert.org m_fromNetQueues[i].deletePointers(); 1606145Snate@binkert.org } 1616145Snate@binkert.org m_switch_ptr_vector.deletePointers(); 1626145Snate@binkert.org m_buffers_to_free.deletePointers(); 1636145Snate@binkert.org delete m_topology_ptr; 1646145Snate@binkert.org} 1656145Snate@binkert.org 1666145Snate@binkert.org// From a switch to an endpoint node 1676145Snate@binkert.orgvoid SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1686145Snate@binkert.org{ 1696145Snate@binkert.org assert(dest < m_nodes); 1706145Snate@binkert.org assert(src < m_switch_ptr_vector.size()); 1716145Snate@binkert.org assert(m_switch_ptr_vector[src] != NULL); 1726145Snate@binkert.org if(!isReconfiguration){ 1736145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier); 1746145Snate@binkert.org m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 1756145Snate@binkert.org } else { 1766145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1776145Snate@binkert.org } 1786145Snate@binkert.org} 1796145Snate@binkert.org 1806145Snate@binkert.org// From an endpoint node to a switch 1816145Snate@binkert.orgvoid SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration) 1826145Snate@binkert.org{ 1836145Snate@binkert.org assert(src < m_nodes); 1846145Snate@binkert.org if(!isReconfiguration){ 1856145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 1866145Snate@binkert.org } else { 1876145Snate@binkert.org // do nothing 1886145Snate@binkert.org } 1896145Snate@binkert.org} 1906145Snate@binkert.org 1916145Snate@binkert.org// From a switch to a switch 1926145Snate@binkert.orgvoid SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1936145Snate@binkert.org{ 1946145Snate@binkert.org if(!isReconfiguration){ 1956145Snate@binkert.org // Create a set of new MessageBuffers 1966145Snate@binkert.org Vector<MessageBuffer*> queues; 1976145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1986145Snate@binkert.org // allocate a buffer 1996145Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 2006145Snate@binkert.org buffer_ptr->setOrdering(true); 2016285Snate@binkert.org if (m_buffer_size > 0) { 2026285Snate@binkert.org buffer_ptr->setSize(m_buffer_size); 2036145Snate@binkert.org } 2046145Snate@binkert.org queues.insertAtBottom(buffer_ptr); 2056145Snate@binkert.org // remember to deallocate it 2066145Snate@binkert.org m_buffers_to_free.insertAtBottom(buffer_ptr); 2076145Snate@binkert.org } 2086145Snate@binkert.org 2096145Snate@binkert.org // Connect it to the two switches 2106145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(queues); 2116145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier); 2126145Snate@binkert.org } else { 2136145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 2146145Snate@binkert.org } 2156145Snate@binkert.org} 2166145Snate@binkert.org 2176145Snate@binkert.orgvoid SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 2186145Snate@binkert.org{ 2196145Snate@binkert.org ASSERT(id < m_nodes); 2206145Snate@binkert.org ASSERT(network_num < m_virtual_networks); 2216145Snate@binkert.org 2226145Snate@binkert.org if (ordered) { 2236145Snate@binkert.org m_ordered[network_num] = true; 2246145Snate@binkert.org } 2256145Snate@binkert.org m_in_use[network_num] = true; 2266145Snate@binkert.org} 2276145Snate@binkert.org 2286145Snate@binkert.orgMessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 2296145Snate@binkert.org{ 2306145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2316145Snate@binkert.org return m_toNetQueues[id][network_num]; 2326145Snate@binkert.org} 2336145Snate@binkert.org 2346145Snate@binkert.orgMessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 2356145Snate@binkert.org{ 2366145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2376145Snate@binkert.org return m_fromNetQueues[id][network_num]; 2386145Snate@binkert.org} 2396145Snate@binkert.org 2406145Snate@binkert.orgconst Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const 2416145Snate@binkert.org{ 2426145Snate@binkert.org assert(id >= 0); 2436145Snate@binkert.org assert(id < m_nodes); 2446145Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2456145Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2466145Snate@binkert.org} 2476145Snate@binkert.org 2486145Snate@binkert.orgvoid SimpleNetwork::printStats(ostream& out) const 2496145Snate@binkert.org{ 2506145Snate@binkert.org out << endl; 2516145Snate@binkert.org out << "Network Stats" << endl; 2526145Snate@binkert.org out << "-------------" << endl; 2536145Snate@binkert.org out << endl; 2546145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2556145Snate@binkert.org m_switch_ptr_vector[i]->printStats(out); 2566145Snate@binkert.org } 2576145Snate@binkert.org} 2586145Snate@binkert.org 2596145Snate@binkert.orgvoid SimpleNetwork::clearStats() 2606145Snate@binkert.org{ 2616145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2626145Snate@binkert.org m_switch_ptr_vector[i]->clearStats(); 2636145Snate@binkert.org } 2646145Snate@binkert.org} 2656145Snate@binkert.org 2666145Snate@binkert.orgvoid SimpleNetwork::printConfig(ostream& out) const 2676145Snate@binkert.org{ 2686145Snate@binkert.org out << endl; 2696145Snate@binkert.org out << "Network Configuration" << endl; 2706145Snate@binkert.org out << "---------------------" << endl; 2716145Snate@binkert.org out << "network: SIMPLE_NETWORK" << endl; 2726285Snate@binkert.org out << "topology: " << m_topology_ptr->getName() << endl; 2736145Snate@binkert.org out << endl; 2746145Snate@binkert.org 2756145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 2766145Snate@binkert.org out << "virtual_net_" << i << ": "; 2776145Snate@binkert.org if (m_in_use[i]) { 2786145Snate@binkert.org out << "active, "; 2796145Snate@binkert.org if (m_ordered[i]) { 2806145Snate@binkert.org out << "ordered" << endl; 2816145Snate@binkert.org } else { 2826145Snate@binkert.org out << "unordered" << endl; 2836145Snate@binkert.org } 2846145Snate@binkert.org } else { 2856145Snate@binkert.org out << "inactive" << endl; 2866145Snate@binkert.org } 2876145Snate@binkert.org } 2886145Snate@binkert.org out << endl; 2896145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2906145Snate@binkert.org m_switch_ptr_vector[i]->printConfig(out); 2916145Snate@binkert.org } 2926145Snate@binkert.org 2936285Snate@binkert.org m_topology_ptr->printConfig(out); 2946145Snate@binkert.org} 2956145Snate@binkert.org 2966145Snate@binkert.orgvoid SimpleNetwork::print(ostream& out) const 2976145Snate@binkert.org{ 2986145Snate@binkert.org out << "[SimpleNetwork]"; 2996145Snate@binkert.org} 300