SimpleNetwork.cc revision 6881
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{ 656881SBrad.Beckmann@amd.com // 666881SBrad.Beckmann@amd.com // Note: the parent Network Object constructor is called before the 676881SBrad.Beckmann@amd.com // SimpleNetwork child constructor. Therefore, the member variables 686881SBrad.Beckmann@amd.com // used below should already be initialized. 696881SBrad.Beckmann@amd.com // 706881SBrad.Beckmann@amd.com 716285Snate@binkert.org m_endpoint_switches.setSize(m_nodes); 726285Snate@binkert.org 736285Snate@binkert.org m_in_use.setSize(m_virtual_networks); 746285Snate@binkert.org m_ordered.setSize(m_virtual_networks); 756285Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 766285Snate@binkert.org m_in_use[i] = false; 776285Snate@binkert.org m_ordered[i] = false; 786285Snate@binkert.org } 796285Snate@binkert.org 806285Snate@binkert.org // Allocate to and from queues 816285Snate@binkert.org m_toNetQueues.setSize(m_nodes); 826285Snate@binkert.org m_fromNetQueues.setSize(m_nodes); 836285Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 846285Snate@binkert.org m_toNetQueues[node].setSize(m_virtual_networks); 856285Snate@binkert.org m_fromNetQueues[node].setSize(m_virtual_networks); 866285Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 876795SBrad.Beckmann@amd.com m_toNetQueues[node][j] = new MessageBuffer( 886781SBrad.Beckmann@amd.com "toNet node "+int_to_string(node)+" j "+int_to_string(j)); 896795SBrad.Beckmann@amd.com m_fromNetQueues[node][j] = new MessageBuffer( 906781SBrad.Beckmann@amd.com "fromNet node "+int_to_string(node)+" j "+int_to_string(j)); 916285Snate@binkert.org } 926285Snate@binkert.org } 936881SBrad.Beckmann@amd.com} 946285Snate@binkert.org 956881SBrad.Beckmann@amd.comvoid SimpleNetwork::init() 966881SBrad.Beckmann@amd.com{ 976881SBrad.Beckmann@amd.com 986881SBrad.Beckmann@amd.com Network::init(); 996881SBrad.Beckmann@amd.com 1006881SBrad.Beckmann@amd.com // 1016881SBrad.Beckmann@amd.com // The topology pointer should have already been initialized in the parent 1026881SBrad.Beckmann@amd.com // class network constructor. 1036881SBrad.Beckmann@amd.com // 1046881SBrad.Beckmann@amd.com assert(m_topology_ptr != NULL); 1056285Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 1066285Snate@binkert.org for (int i=0; i<number_of_switches; i++) { 1076285Snate@binkert.org m_switch_ptr_vector.insertAtBottom(new Switch(i, this)); 1086285Snate@binkert.org } 1096879Ssteve.reinhardt@amd.com m_topology_ptr->createLinks(this, false); // false because this isn't a reconfiguration 1106285Snate@binkert.org} 1116145Snate@binkert.org 1126145Snate@binkert.orgvoid SimpleNetwork::reset() 1136145Snate@binkert.org{ 1146145Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1156145Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1166145Snate@binkert.org m_toNetQueues[node][j]->clear(); 1176145Snate@binkert.org m_fromNetQueues[node][j]->clear(); 1186145Snate@binkert.org } 1196145Snate@binkert.org } 1206145Snate@binkert.org 1216145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++){ 1226145Snate@binkert.org m_switch_ptr_vector[i]->clearBuffers(); 1236145Snate@binkert.org } 1246145Snate@binkert.org} 1256145Snate@binkert.org 1266145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1276145Snate@binkert.org{ 1286145Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1296145Snate@binkert.org m_toNetQueues[i].deletePointers(); 1306145Snate@binkert.org m_fromNetQueues[i].deletePointers(); 1316145Snate@binkert.org } 1326145Snate@binkert.org m_switch_ptr_vector.deletePointers(); 1336145Snate@binkert.org m_buffers_to_free.deletePointers(); 1346762SBrad.Beckmann@amd.com // delete m_topology_ptr; 1356145Snate@binkert.org} 1366145Snate@binkert.org 1376145Snate@binkert.org// From a switch to an endpoint node 1386145Snate@binkert.orgvoid SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1396145Snate@binkert.org{ 1406145Snate@binkert.org assert(dest < m_nodes); 1416145Snate@binkert.org assert(src < m_switch_ptr_vector.size()); 1426145Snate@binkert.org assert(m_switch_ptr_vector[src] != NULL); 1436145Snate@binkert.org if(!isReconfiguration){ 1446145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier); 1456145Snate@binkert.org m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 1466145Snate@binkert.org } else { 1476145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1486145Snate@binkert.org } 1496145Snate@binkert.org} 1506145Snate@binkert.org 1516145Snate@binkert.org// From an endpoint node to a switch 1526145Snate@binkert.orgvoid SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration) 1536145Snate@binkert.org{ 1546145Snate@binkert.org assert(src < m_nodes); 1556145Snate@binkert.org if(!isReconfiguration){ 1566145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 1576145Snate@binkert.org } else { 1586145Snate@binkert.org // do nothing 1596145Snate@binkert.org } 1606145Snate@binkert.org} 1616145Snate@binkert.org 1626145Snate@binkert.org// From a switch to a switch 1636145Snate@binkert.orgvoid SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) 1646145Snate@binkert.org{ 1656145Snate@binkert.org if(!isReconfiguration){ 1666145Snate@binkert.org // Create a set of new MessageBuffers 1676145Snate@binkert.org Vector<MessageBuffer*> queues; 1686145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1696145Snate@binkert.org // allocate a buffer 1706145Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 1716145Snate@binkert.org buffer_ptr->setOrdering(true); 1726285Snate@binkert.org if (m_buffer_size > 0) { 1736285Snate@binkert.org buffer_ptr->setSize(m_buffer_size); 1746145Snate@binkert.org } 1756145Snate@binkert.org queues.insertAtBottom(buffer_ptr); 1766145Snate@binkert.org // remember to deallocate it 1776145Snate@binkert.org m_buffers_to_free.insertAtBottom(buffer_ptr); 1786145Snate@binkert.org } 1796145Snate@binkert.org 1806145Snate@binkert.org // Connect it to the two switches 1816145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(queues); 1826145Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier); 1836145Snate@binkert.org } else { 1846145Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1856145Snate@binkert.org } 1866145Snate@binkert.org} 1876145Snate@binkert.org 1886145Snate@binkert.orgvoid SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 1896145Snate@binkert.org{ 1906145Snate@binkert.org ASSERT(id < m_nodes); 1916145Snate@binkert.org ASSERT(network_num < m_virtual_networks); 1926145Snate@binkert.org 1936145Snate@binkert.org if (ordered) { 1946145Snate@binkert.org m_ordered[network_num] = true; 1956145Snate@binkert.org } 1966145Snate@binkert.org m_in_use[network_num] = true; 1976145Snate@binkert.org} 1986145Snate@binkert.org 1996145Snate@binkert.orgMessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 2006145Snate@binkert.org{ 2016145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2026145Snate@binkert.org return m_toNetQueues[id][network_num]; 2036145Snate@binkert.org} 2046145Snate@binkert.org 2056145Snate@binkert.orgMessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 2066145Snate@binkert.org{ 2076145Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2086145Snate@binkert.org return m_fromNetQueues[id][network_num]; 2096145Snate@binkert.org} 2106145Snate@binkert.org 2116145Snate@binkert.orgconst Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const 2126145Snate@binkert.org{ 2136145Snate@binkert.org assert(id >= 0); 2146145Snate@binkert.org assert(id < m_nodes); 2156145Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2166145Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2176145Snate@binkert.org} 2186145Snate@binkert.org 2196145Snate@binkert.orgvoid SimpleNetwork::printStats(ostream& out) const 2206145Snate@binkert.org{ 2216145Snate@binkert.org out << endl; 2226145Snate@binkert.org out << "Network Stats" << endl; 2236145Snate@binkert.org out << "-------------" << endl; 2246145Snate@binkert.org out << endl; 2256145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2266145Snate@binkert.org m_switch_ptr_vector[i]->printStats(out); 2276145Snate@binkert.org } 2286145Snate@binkert.org} 2296145Snate@binkert.org 2306145Snate@binkert.orgvoid SimpleNetwork::clearStats() 2316145Snate@binkert.org{ 2326145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2336145Snate@binkert.org m_switch_ptr_vector[i]->clearStats(); 2346145Snate@binkert.org } 2356145Snate@binkert.org} 2366145Snate@binkert.org 2376145Snate@binkert.orgvoid SimpleNetwork::printConfig(ostream& out) const 2386145Snate@binkert.org{ 2396145Snate@binkert.org out << endl; 2406145Snate@binkert.org out << "Network Configuration" << endl; 2416145Snate@binkert.org out << "---------------------" << endl; 2426145Snate@binkert.org out << "network: SIMPLE_NETWORK" << endl; 2436285Snate@binkert.org out << "topology: " << m_topology_ptr->getName() << endl; 2446145Snate@binkert.org out << endl; 2456145Snate@binkert.org 2466145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 2476145Snate@binkert.org out << "virtual_net_" << i << ": "; 2486145Snate@binkert.org if (m_in_use[i]) { 2496145Snate@binkert.org out << "active, "; 2506145Snate@binkert.org if (m_ordered[i]) { 2516145Snate@binkert.org out << "ordered" << endl; 2526145Snate@binkert.org } else { 2536145Snate@binkert.org out << "unordered" << endl; 2546145Snate@binkert.org } 2556145Snate@binkert.org } else { 2566145Snate@binkert.org out << "inactive" << endl; 2576145Snate@binkert.org } 2586145Snate@binkert.org } 2596145Snate@binkert.org out << endl; 2606145Snate@binkert.org for(int i=0; i<m_switch_ptr_vector.size(); i++) { 2616145Snate@binkert.org m_switch_ptr_vector[i]->printConfig(out); 2626145Snate@binkert.org } 2636145Snate@binkert.org 2646285Snate@binkert.org m_topology_ptr->printConfig(out); 2656145Snate@binkert.org} 2666145Snate@binkert.org 2676145Snate@binkert.orgvoid SimpleNetwork::print(ostream& out) const 2686145Snate@binkert.org{ 2696145Snate@binkert.org out << "[SimpleNetwork]"; 2706145Snate@binkert.org} 2716876Ssteve.reinhardt@amd.com 2726876Ssteve.reinhardt@amd.com 2736876Ssteve.reinhardt@amd.comSimpleNetwork * 2746876Ssteve.reinhardt@amd.comSimpleNetworkParams::create() 2756876Ssteve.reinhardt@amd.com{ 2766876Ssteve.reinhardt@amd.com return new SimpleNetwork(this); 2776876Ssteve.reinhardt@amd.com} 278