SimpleNetwork.cc revision 6762
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 m_toNetQueues[node][j] = new MessageBuffer; 916285Snate@binkert.org m_fromNetQueues[node][j] = new MessageBuffer; 926285Snate@binkert.org } 936285Snate@binkert.org } 946285Snate@binkert.org 956285Snate@binkert.org // Setup the network switches 966285Snate@binkert.org // m_topology_ptr = new Topology(this, m_nodes); 976285Snate@binkert.org m_topology_ptr->makeTopology(); 986285Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 996285Snate@binkert.org for (int i=0; i<number_of_switches; i++) { 1006285Snate@binkert.org m_switch_ptr_vector.insertAtBottom(new Switch(i, this)); 1016285Snate@binkert.org } 1026285Snate@binkert.org m_topology_ptr->createLinks(false); // false because this isn't a reconfiguration 1036285Snate@binkert.org} 1046145Snate@binkert.org 1056145Snate@binkert.orgvoid SimpleNetwork::reset() 1066145Snate@binkert.org{ 1076145Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1086145Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1096145Snate@binkert.org m_toNetQueues[node][j]->clear(); 1106145Snate@binkert.org m_fromNetQueues[node][j]->clear(); 1116145Snate@binkert.org } 1126145Snate@binkert.org } 1136145Snate@binkert.org 1146145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++){ 1156145Snate@binkert.org m_switch_ptr_vector[i]->clearBuffers(); 1166145Snate@binkert.org } 1176145Snate@binkert.org} 1186145Snate@binkert.org 1196145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1206145Snate@binkert.org{ 1216145Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1226145Snate@binkert.org m_toNetQueues[i].deletePointers(); 1236145Snate@binkert.org m_fromNetQueues[i].deletePointers(); 1246145Snate@binkert.org } 1256145Snate@binkert.org m_switch_ptr_vector.deletePointers(); 1266145Snate@binkert.org m_buffers_to_free.deletePointers(); 1276762SBrad.Beckmann@amd.com // delete m_topology_ptr; 1286145Snate@binkert.org} 1296145Snate@binkert.org 1306145Snate@binkert.org// From a switch to an endpoint node 1316145Snate@binkert.orgvoid SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1326145Snate@binkert.org{ 1336145Snate@binkert.org assert(dest < m_nodes); 1346145Snate@binkert.org assert(src < m_switch_ptr_vector.size()); 1356145Snate@binkert.org assert(m_switch_ptr_vector[src] != NULL); 1366145Snate@binkert.org if(!isReconfiguration){ 1376145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier); 1386145Snate@binkert.org m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 1396145Snate@binkert.org } else { 1406145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1416145Snate@binkert.org } 1426145Snate@binkert.org} 1436145Snate@binkert.org 1446145Snate@binkert.org// From an endpoint node to a switch 1456145Snate@binkert.orgvoid SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration) 1466145Snate@binkert.org{ 1476145Snate@binkert.org assert(src < m_nodes); 1486145Snate@binkert.org if(!isReconfiguration){ 1496145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 1506145Snate@binkert.org } else { 1516145Snate@binkert.org // do nothing 1526145Snate@binkert.org } 1536145Snate@binkert.org} 1546145Snate@binkert.org 1556145Snate@binkert.org// From a switch to a switch 1566145Snate@binkert.orgvoid SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1576145Snate@binkert.org{ 1586145Snate@binkert.org if(!isReconfiguration){ 1596145Snate@binkert.org // Create a set of new MessageBuffers 1606145Snate@binkert.org Vector<MessageBuffer*> queues; 1616145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1626145Snate@binkert.org // allocate a buffer 1636145Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 1646145Snate@binkert.org buffer_ptr->setOrdering(true); 1656285Snate@binkert.org if (m_buffer_size > 0) { 1666285Snate@binkert.org buffer_ptr->setSize(m_buffer_size); 1676145Snate@binkert.org } 1686145Snate@binkert.org queues.insertAtBottom(buffer_ptr); 1696145Snate@binkert.org // remember to deallocate it 1706145Snate@binkert.org m_buffers_to_free.insertAtBottom(buffer_ptr); 1716145Snate@binkert.org } 1726145Snate@binkert.org 1736145Snate@binkert.org // Connect it to the two switches 1746145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(queues); 1756145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier); 1766145Snate@binkert.org } else { 1776145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1786145Snate@binkert.org } 1796145Snate@binkert.org} 1806145Snate@binkert.org 1816145Snate@binkert.orgvoid SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 1826145Snate@binkert.org{ 1836145Snate@binkert.org ASSERT(id < m_nodes); 1846145Snate@binkert.org ASSERT(network_num < m_virtual_networks); 1856145Snate@binkert.org 1866145Snate@binkert.org if (ordered) { 1876145Snate@binkert.org m_ordered[network_num] = true; 1886145Snate@binkert.org } 1896145Snate@binkert.org m_in_use[network_num] = true; 1906145Snate@binkert.org} 1916145Snate@binkert.org 1926145Snate@binkert.orgMessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 1936145Snate@binkert.org{ 1946145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 1956145Snate@binkert.org return m_toNetQueues[id][network_num]; 1966145Snate@binkert.org} 1976145Snate@binkert.org 1986145Snate@binkert.orgMessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 1996145Snate@binkert.org{ 2006145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2016145Snate@binkert.org return m_fromNetQueues[id][network_num]; 2026145Snate@binkert.org} 2036145Snate@binkert.org 2046145Snate@binkert.orgconst Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const 2056145Snate@binkert.org{ 2066145Snate@binkert.org assert(id >= 0); 2076145Snate@binkert.org assert(id < m_nodes); 2086145Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2096145Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2106145Snate@binkert.org} 2116145Snate@binkert.org 2126145Snate@binkert.orgvoid SimpleNetwork::printStats(ostream& out) const 2136145Snate@binkert.org{ 2146145Snate@binkert.org out << endl; 2156145Snate@binkert.org out << "Network Stats" << endl; 2166145Snate@binkert.org out << "-------------" << endl; 2176145Snate@binkert.org out << endl; 2186145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2196145Snate@binkert.org m_switch_ptr_vector[i]->printStats(out); 2206145Snate@binkert.org } 2216145Snate@binkert.org} 2226145Snate@binkert.org 2236145Snate@binkert.orgvoid SimpleNetwork::clearStats() 2246145Snate@binkert.org{ 2256145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2266145Snate@binkert.org m_switch_ptr_vector[i]->clearStats(); 2276145Snate@binkert.org } 2286145Snate@binkert.org} 2296145Snate@binkert.org 2306145Snate@binkert.orgvoid SimpleNetwork::printConfig(ostream& out) const 2316145Snate@binkert.org{ 2326145Snate@binkert.org out << endl; 2336145Snate@binkert.org out << "Network Configuration" << endl; 2346145Snate@binkert.org out << "---------------------" << endl; 2356145Snate@binkert.org out << "network: SIMPLE_NETWORK" << endl; 2366285Snate@binkert.org out << "topology: " << m_topology_ptr->getName() << endl; 2376145Snate@binkert.org out << endl; 2386145Snate@binkert.org 2396145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 2406145Snate@binkert.org out << "virtual_net_" << i << ": "; 2416145Snate@binkert.org if (m_in_use[i]) { 2426145Snate@binkert.org out << "active, "; 2436145Snate@binkert.org if (m_ordered[i]) { 2446145Snate@binkert.org out << "ordered" << endl; 2456145Snate@binkert.org } else { 2466145Snate@binkert.org out << "unordered" << endl; 2476145Snate@binkert.org } 2486145Snate@binkert.org } else { 2496145Snate@binkert.org out << "inactive" << endl; 2506145Snate@binkert.org } 2516145Snate@binkert.org } 2526145Snate@binkert.org out << endl; 2536145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2546145Snate@binkert.org m_switch_ptr_vector[i]->printConfig(out); 2556145Snate@binkert.org } 2566145Snate@binkert.org 2576285Snate@binkert.org m_topology_ptr->printConfig(out); 2586145Snate@binkert.org} 2596145Snate@binkert.org 2606145Snate@binkert.orgvoid SimpleNetwork::print(ostream& out) const 2616145Snate@binkert.org{ 2626145Snate@binkert.org out << "[SimpleNetwork]"; 2636145Snate@binkert.org} 264