SimpleNetwork.cc revision 6284
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 626145Snate@binkert.orgSimpleNetwork::SimpleNetwork(int nodes) 636145Snate@binkert.org{ 646145Snate@binkert.org m_nodes = MachineType_base_number(MachineType_NUM); 656145Snate@binkert.org 666145Snate@binkert.org m_virtual_networks = NUMBER_OF_VIRTUAL_NETWORKS; 676145Snate@binkert.org m_endpoint_switches.setSize(m_nodes); 686145Snate@binkert.org 696145Snate@binkert.org m_in_use.setSize(m_virtual_networks); 706145Snate@binkert.org m_ordered.setSize(m_virtual_networks); 716145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 726145Snate@binkert.org m_in_use[i] = false; 736145Snate@binkert.org m_ordered[i] = false; 746145Snate@binkert.org } 756145Snate@binkert.org 766145Snate@binkert.org // Allocate to and from queues 776145Snate@binkert.org m_toNetQueues.setSize(m_nodes); 786145Snate@binkert.org m_fromNetQueues.setSize(m_nodes); 796145Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 806145Snate@binkert.org m_toNetQueues[node].setSize(m_virtual_networks); 816145Snate@binkert.org m_fromNetQueues[node].setSize(m_virtual_networks); 826145Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 836145Snate@binkert.org m_toNetQueues[node][j] = new MessageBuffer; 846145Snate@binkert.org m_fromNetQueues[node][j] = new MessageBuffer; 856145Snate@binkert.org } 866145Snate@binkert.org } 876145Snate@binkert.org 886145Snate@binkert.org // Setup the network switches 896145Snate@binkert.org m_topology_ptr = new Topology(this, m_nodes); 906145Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 916145Snate@binkert.org for (int i=0; i<number_of_switches; i++) { 926145Snate@binkert.org m_switch_ptr_vector.insertAtBottom(new Switch(i, this)); 936145Snate@binkert.org } 946145Snate@binkert.org m_topology_ptr->createLinks(false); // false because this isn't a reconfiguration 956145Snate@binkert.org} 966145Snate@binkert.org 976145Snate@binkert.orgvoid SimpleNetwork::reset() 986145Snate@binkert.org{ 996145Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1006145Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1016145Snate@binkert.org m_toNetQueues[node][j]->clear(); 1026145Snate@binkert.org m_fromNetQueues[node][j]->clear(); 1036145Snate@binkert.org } 1046145Snate@binkert.org } 1056145Snate@binkert.org 1066145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++){ 1076145Snate@binkert.org m_switch_ptr_vector[i]->clearBuffers(); 1086145Snate@binkert.org } 1096145Snate@binkert.org} 1106145Snate@binkert.org 1116145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1126145Snate@binkert.org{ 1136145Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1146145Snate@binkert.org m_toNetQueues[i].deletePointers(); 1156145Snate@binkert.org m_fromNetQueues[i].deletePointers(); 1166145Snate@binkert.org } 1176145Snate@binkert.org m_switch_ptr_vector.deletePointers(); 1186145Snate@binkert.org m_buffers_to_free.deletePointers(); 1196145Snate@binkert.org delete m_topology_ptr; 1206145Snate@binkert.org} 1216145Snate@binkert.org 1226145Snate@binkert.org// From a switch to an endpoint node 1236145Snate@binkert.orgvoid SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1246145Snate@binkert.org{ 1256145Snate@binkert.org assert(dest < m_nodes); 1266145Snate@binkert.org assert(src < m_switch_ptr_vector.size()); 1276145Snate@binkert.org assert(m_switch_ptr_vector[src] != NULL); 1286145Snate@binkert.org if(!isReconfiguration){ 1296145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier); 1306145Snate@binkert.org m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 1316145Snate@binkert.org } else { 1326145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1336145Snate@binkert.org } 1346145Snate@binkert.org} 1356145Snate@binkert.org 1366145Snate@binkert.org// From an endpoint node to a switch 1376145Snate@binkert.orgvoid SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration) 1386145Snate@binkert.org{ 1396145Snate@binkert.org assert(src < m_nodes); 1406145Snate@binkert.org if(!isReconfiguration){ 1416145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 1426145Snate@binkert.org } else { 1436145Snate@binkert.org // do nothing 1446145Snate@binkert.org } 1456145Snate@binkert.org} 1466145Snate@binkert.org 1476145Snate@binkert.org// From a switch to a switch 1486145Snate@binkert.orgvoid SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1496145Snate@binkert.org{ 1506145Snate@binkert.org if(!isReconfiguration){ 1516145Snate@binkert.org // Create a set of new MessageBuffers 1526145Snate@binkert.org Vector<MessageBuffer*> queues; 1536145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1546145Snate@binkert.org // allocate a buffer 1556145Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 1566145Snate@binkert.org buffer_ptr->setOrdering(true); 1576145Snate@binkert.org if(FINITE_BUFFERING) { 1586145Snate@binkert.org buffer_ptr->setSize(FINITE_BUFFER_SIZE); 1596145Snate@binkert.org } 1606145Snate@binkert.org queues.insertAtBottom(buffer_ptr); 1616145Snate@binkert.org // remember to deallocate it 1626145Snate@binkert.org m_buffers_to_free.insertAtBottom(buffer_ptr); 1636145Snate@binkert.org } 1646145Snate@binkert.org 1656145Snate@binkert.org // Connect it to the two switches 1666145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(queues); 1676145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier); 1686145Snate@binkert.org } else { 1696145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1706145Snate@binkert.org } 1716145Snate@binkert.org} 1726145Snate@binkert.org 1736145Snate@binkert.orgvoid SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 1746145Snate@binkert.org{ 1756145Snate@binkert.org ASSERT(id < m_nodes); 1766145Snate@binkert.org ASSERT(network_num < m_virtual_networks); 1776145Snate@binkert.org 1786145Snate@binkert.org if (ordered) { 1796145Snate@binkert.org m_ordered[network_num] = true; 1806145Snate@binkert.org } 1816145Snate@binkert.org m_in_use[network_num] = true; 1826145Snate@binkert.org} 1836145Snate@binkert.org 1846145Snate@binkert.orgMessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 1856145Snate@binkert.org{ 1866145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 1876145Snate@binkert.org return m_toNetQueues[id][network_num]; 1886145Snate@binkert.org} 1896145Snate@binkert.org 1906145Snate@binkert.orgMessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 1916145Snate@binkert.org{ 1926145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 1936145Snate@binkert.org return m_fromNetQueues[id][network_num]; 1946145Snate@binkert.org} 1956145Snate@binkert.org 1966145Snate@binkert.orgconst Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const 1976145Snate@binkert.org{ 1986145Snate@binkert.org assert(id >= 0); 1996145Snate@binkert.org assert(id < m_nodes); 2006145Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2016145Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2026145Snate@binkert.org} 2036145Snate@binkert.org 2046145Snate@binkert.orgvoid SimpleNetwork::printStats(ostream& out) const 2056145Snate@binkert.org{ 2066145Snate@binkert.org out << endl; 2076145Snate@binkert.org out << "Network Stats" << endl; 2086145Snate@binkert.org out << "-------------" << endl; 2096145Snate@binkert.org out << endl; 2106145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2116145Snate@binkert.org m_switch_ptr_vector[i]->printStats(out); 2126145Snate@binkert.org } 2136145Snate@binkert.org} 2146145Snate@binkert.org 2156145Snate@binkert.orgvoid SimpleNetwork::clearStats() 2166145Snate@binkert.org{ 2176145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2186145Snate@binkert.org m_switch_ptr_vector[i]->clearStats(); 2196145Snate@binkert.org } 2206145Snate@binkert.org} 2216145Snate@binkert.org 2226145Snate@binkert.orgvoid SimpleNetwork::printConfig(ostream& out) const 2236145Snate@binkert.org{ 2246145Snate@binkert.org out << endl; 2256145Snate@binkert.org out << "Network Configuration" << endl; 2266145Snate@binkert.org out << "---------------------" << endl; 2276145Snate@binkert.org out << "network: SIMPLE_NETWORK" << endl; 2286145Snate@binkert.org out << "topology: " << g_NETWORK_TOPOLOGY << endl; 2296145Snate@binkert.org out << endl; 2306145Snate@binkert.org 2316145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 2326145Snate@binkert.org out << "virtual_net_" << i << ": "; 2336145Snate@binkert.org if (m_in_use[i]) { 2346145Snate@binkert.org out << "active, "; 2356145Snate@binkert.org if (m_ordered[i]) { 2366145Snate@binkert.org out << "ordered" << endl; 2376145Snate@binkert.org } else { 2386145Snate@binkert.org out << "unordered" << endl; 2396145Snate@binkert.org } 2406145Snate@binkert.org } else { 2416145Snate@binkert.org out << "inactive" << endl; 2426145Snate@binkert.org } 2436145Snate@binkert.org } 2446145Snate@binkert.org out << endl; 2456145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2466145Snate@binkert.org m_switch_ptr_vector[i]->printConfig(out); 2476145Snate@binkert.org } 2486145Snate@binkert.org 2496145Snate@binkert.org if (g_PRINT_TOPOLOGY) { 2506145Snate@binkert.org m_topology_ptr->printConfig(out); 2516145Snate@binkert.org } 2526145Snate@binkert.org} 2536145Snate@binkert.org 2546145Snate@binkert.orgvoid SimpleNetwork::print(ostream& out) const 2556145Snate@binkert.org{ 2566145Snate@binkert.org out << "[SimpleNetwork]"; 2576145Snate@binkert.org} 258