SimpleNetwork.cc revision 7054
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297054Snate@binkert.org#include "mem/gems_common/Map.hh" 307054Snate@binkert.org#include "mem/protocol/MachineType.hh" 317054Snate@binkert.org#include "mem/protocol/Protocol.hh" 327054Snate@binkert.org#include "mem/protocol/TopologyType.hh" 337054Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 347054Snate@binkert.org#include "mem/ruby/common/NetDest.hh" 356154Snate@binkert.org#include "mem/ruby/network/simple/SimpleNetwork.hh" 367054Snate@binkert.org#include "mem/ruby/network/simple/Switch.hh" 377054Snate@binkert.org#include "mem/ruby/network/simple/Topology.hh" 386154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 396154Snate@binkert.org#include "mem/ruby/system/System.hh" 406145Snate@binkert.org 417054Snate@binkert.org#if 0 426284Snate@binkert.org// ***BIG HACK*** - This is actually code that _should_ be in Network.cc 436145Snate@binkert.org 446145Snate@binkert.org// Note: Moved to Princeton Network 456145Snate@binkert.org// calls new to abstract away from the network 467054Snate@binkert.orgNetwork* 477054Snate@binkert.orgNetwork::createNetwork(int nodes) 486145Snate@binkert.org{ 497054Snate@binkert.org return new SimpleNetwork(nodes); 506145Snate@binkert.org} 517054Snate@binkert.org#endif 526145Snate@binkert.org 536876Ssteve.reinhardt@amd.comSimpleNetwork::SimpleNetwork(const Params *p) 546876Ssteve.reinhardt@amd.com : Network(p) 556285Snate@binkert.org{ 567054Snate@binkert.org // Note: the parent Network Object constructor is called before the 577054Snate@binkert.org // SimpleNetwork child constructor. Therefore, the member variables 587054Snate@binkert.org // used below should already be initialized. 596285Snate@binkert.org 607054Snate@binkert.org m_endpoint_switches.setSize(m_nodes); 616285Snate@binkert.org 627054Snate@binkert.org m_in_use.setSize(m_virtual_networks); 637054Snate@binkert.org m_ordered.setSize(m_virtual_networks); 647054Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 657054Snate@binkert.org m_in_use[i] = false; 667054Snate@binkert.org m_ordered[i] = false; 676285Snate@binkert.org } 687054Snate@binkert.org 697054Snate@binkert.org // Allocate to and from queues 707054Snate@binkert.org m_toNetQueues.setSize(m_nodes); 717054Snate@binkert.org m_fromNetQueues.setSize(m_nodes); 727054Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 737054Snate@binkert.org m_toNetQueues[node].setSize(m_virtual_networks); 747054Snate@binkert.org m_fromNetQueues[node].setSize(m_virtual_networks); 757054Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 767054Snate@binkert.org m_toNetQueues[node][j] = new MessageBuffer( 777054Snate@binkert.org "toNet node "+int_to_string(node)+" j "+int_to_string(j)); 787054Snate@binkert.org m_fromNetQueues[node][j] = new MessageBuffer( 797054Snate@binkert.org "fromNet node "+int_to_string(node)+" j "+int_to_string(j)); 807054Snate@binkert.org } 817054Snate@binkert.org } 826881SBrad.Beckmann@amd.com} 836285Snate@binkert.org 847054Snate@binkert.orgvoid 857054Snate@binkert.orgSimpleNetwork::init() 866881SBrad.Beckmann@amd.com{ 877054Snate@binkert.org Network::init(); 886881SBrad.Beckmann@amd.com 897054Snate@binkert.org // The topology pointer should have already been initialized in 907054Snate@binkert.org // the parent class network constructor. 917054Snate@binkert.org assert(m_topology_ptr != NULL); 927054Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 937054Snate@binkert.org for (int i = 0; i < number_of_switches; i++) { 947054Snate@binkert.org m_switch_ptr_vector.insertAtBottom(new Switch(i, this)); 957054Snate@binkert.org } 966881SBrad.Beckmann@amd.com 977054Snate@binkert.org // false because this isn't a reconfiguration 987054Snate@binkert.org m_topology_ptr->createLinks(this, false); 996285Snate@binkert.org} 1006145Snate@binkert.org 1017054Snate@binkert.orgvoid 1027054Snate@binkert.orgSimpleNetwork::reset() 1036145Snate@binkert.org{ 1047054Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1057054Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1067054Snate@binkert.org m_toNetQueues[node][j]->clear(); 1077054Snate@binkert.org m_fromNetQueues[node][j]->clear(); 1087054Snate@binkert.org } 1096145Snate@binkert.org } 1106145Snate@binkert.org 1117054Snate@binkert.org for(int i = 0; i < m_switch_ptr_vector.size(); i++){ 1127054Snate@binkert.org m_switch_ptr_vector[i]->clearBuffers(); 1137054Snate@binkert.org } 1146145Snate@binkert.org} 1156145Snate@binkert.org 1166145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1176145Snate@binkert.org{ 1187054Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1197054Snate@binkert.org m_toNetQueues[i].deletePointers(); 1207054Snate@binkert.org m_fromNetQueues[i].deletePointers(); 1217054Snate@binkert.org } 1227054Snate@binkert.org m_switch_ptr_vector.deletePointers(); 1237054Snate@binkert.org m_buffers_to_free.deletePointers(); 1247054Snate@binkert.org // delete m_topology_ptr; 1256145Snate@binkert.org} 1266145Snate@binkert.org 1276145Snate@binkert.org// From a switch to an endpoint node 1287054Snate@binkert.orgvoid 1297054Snate@binkert.orgSimpleNetwork::makeOutLink(SwitchID src, NodeID dest, 1307054Snate@binkert.org const NetDest& routing_table_entry, int link_latency, int link_weight, 1317054Snate@binkert.org int bw_multiplier, bool isReconfiguration) 1326145Snate@binkert.org{ 1337054Snate@binkert.org assert(dest < m_nodes); 1347054Snate@binkert.org assert(src < m_switch_ptr_vector.size()); 1357054Snate@binkert.org assert(m_switch_ptr_vector[src] != NULL); 1367054Snate@binkert.org 1377054Snate@binkert.org if (isReconfiguration) { 1387054Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1397054Snate@binkert.org return; 1407054Snate@binkert.org } 1417054Snate@binkert.org 1427054Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], 1437054Snate@binkert.org routing_table_entry, link_latency, bw_multiplier); 1446145Snate@binkert.org m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 1456145Snate@binkert.org} 1466145Snate@binkert.org 1476145Snate@binkert.org// From an endpoint node to a switch 1487054Snate@binkert.orgvoid 1497054Snate@binkert.orgSimpleNetwork::makeInLink(NodeID src, SwitchID dest, 1507054Snate@binkert.org const NetDest& routing_table_entry, int link_latency, int bw_multiplier, 1517054Snate@binkert.org bool isReconfiguration) 1526145Snate@binkert.org{ 1537054Snate@binkert.org assert(src < m_nodes); 1547054Snate@binkert.org if (isReconfiguration) { 1557054Snate@binkert.org // do nothing 1567054Snate@binkert.org return; 1577054Snate@binkert.org } 1587054Snate@binkert.org 1596145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 1606145Snate@binkert.org} 1616145Snate@binkert.org 1626145Snate@binkert.org// From a switch to a switch 1637054Snate@binkert.orgvoid 1647054Snate@binkert.orgSimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, 1657054Snate@binkert.org const NetDest& routing_table_entry, int link_latency, int link_weight, 1667054Snate@binkert.org int bw_multiplier, bool isReconfiguration) 1676145Snate@binkert.org{ 1687054Snate@binkert.org if (isReconfiguration) { 1697054Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1707054Snate@binkert.org return; 1717054Snate@binkert.org } 1727054Snate@binkert.org 1736145Snate@binkert.org // Create a set of new MessageBuffers 1746145Snate@binkert.org Vector<MessageBuffer*> queues; 1756145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1767054Snate@binkert.org // allocate a buffer 1777054Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 1787054Snate@binkert.org buffer_ptr->setOrdering(true); 1797054Snate@binkert.org if (m_buffer_size > 0) { 1807054Snate@binkert.org buffer_ptr->setSize(m_buffer_size); 1817054Snate@binkert.org } 1827054Snate@binkert.org queues.insertAtBottom(buffer_ptr); 1837054Snate@binkert.org // remember to deallocate it 1847054Snate@binkert.org m_buffers_to_free.insertAtBottom(buffer_ptr); 1857054Snate@binkert.org } 1867054Snate@binkert.org // Connect it to the two switches 1877054Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(queues); 1887054Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, 1897054Snate@binkert.org link_latency, bw_multiplier); 1907054Snate@binkert.org} 1917054Snate@binkert.org 1927054Snate@binkert.orgvoid 1937054Snate@binkert.orgSimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 1947054Snate@binkert.org{ 1957054Snate@binkert.org ASSERT(id < m_nodes); 1967054Snate@binkert.org ASSERT(network_num < m_virtual_networks); 1977054Snate@binkert.org 1987054Snate@binkert.org if (ordered) { 1997054Snate@binkert.org m_ordered[network_num] = true; 2007054Snate@binkert.org } 2017054Snate@binkert.org m_in_use[network_num] = true; 2027054Snate@binkert.org} 2037054Snate@binkert.org 2047054Snate@binkert.orgMessageBuffer* 2057054Snate@binkert.orgSimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 2067054Snate@binkert.org{ 2077054Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2087054Snate@binkert.org return m_toNetQueues[id][network_num]; 2097054Snate@binkert.org} 2107054Snate@binkert.org 2117054Snate@binkert.orgMessageBuffer* 2127054Snate@binkert.orgSimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 2137054Snate@binkert.org{ 2147054Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2157054Snate@binkert.org return m_fromNetQueues[id][network_num]; 2167054Snate@binkert.org} 2177054Snate@binkert.org 2187054Snate@binkert.orgconst Vector<Throttle*>* 2197054Snate@binkert.orgSimpleNetwork::getThrottles(NodeID id) const 2207054Snate@binkert.org{ 2217054Snate@binkert.org assert(id >= 0); 2227054Snate@binkert.org assert(id < m_nodes); 2237054Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2247054Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2257054Snate@binkert.org} 2267054Snate@binkert.org 2277054Snate@binkert.orgvoid 2287054Snate@binkert.orgSimpleNetwork::printStats(ostream& out) const 2297054Snate@binkert.org{ 2307054Snate@binkert.org out << endl; 2317054Snate@binkert.org out << "Network Stats" << endl; 2327054Snate@binkert.org out << "-------------" << endl; 2337054Snate@binkert.org out << endl; 2347054Snate@binkert.org for (int i = 0; i < m_switch_ptr_vector.size(); i++) { 2357054Snate@binkert.org m_switch_ptr_vector[i]->printStats(out); 2367054Snate@binkert.org } 2377054Snate@binkert.org m_topology_ptr->printStats(out); 2387054Snate@binkert.org} 2397054Snate@binkert.org 2407054Snate@binkert.orgvoid 2417054Snate@binkert.orgSimpleNetwork::clearStats() 2427054Snate@binkert.org{ 2437054Snate@binkert.org for (int i = 0; i < m_switch_ptr_vector.size(); i++) { 2447054Snate@binkert.org m_switch_ptr_vector[i]->clearStats(); 2457054Snate@binkert.org } 2467054Snate@binkert.org m_topology_ptr->clearStats(); 2477054Snate@binkert.org} 2487054Snate@binkert.org 2497054Snate@binkert.orgvoid 2507054Snate@binkert.orgSimpleNetwork::printConfig(ostream& out) const 2517054Snate@binkert.org{ 2527054Snate@binkert.org out << endl; 2537054Snate@binkert.org out << "Network Configuration" << endl; 2547054Snate@binkert.org out << "---------------------" << endl; 2557054Snate@binkert.org out << "network: SIMPLE_NETWORK" << endl; 2567054Snate@binkert.org out << "topology: " << m_topology_ptr->getName() << endl; 2577054Snate@binkert.org out << endl; 2587054Snate@binkert.org 2597054Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 2607054Snate@binkert.org out << "virtual_net_" << i << ": "; 2617054Snate@binkert.org if (m_in_use[i]) { 2627054Snate@binkert.org out << "active, "; 2637054Snate@binkert.org if (m_ordered[i]) { 2647054Snate@binkert.org out << "ordered" << endl; 2657054Snate@binkert.org } else { 2667054Snate@binkert.org out << "unordered" << endl; 2677054Snate@binkert.org } 2687054Snate@binkert.org } else { 2697054Snate@binkert.org out << "inactive" << endl; 2707054Snate@binkert.org } 2717054Snate@binkert.org } 2727054Snate@binkert.org out << endl; 2737054Snate@binkert.org 2747054Snate@binkert.org for(int i = 0; i < m_switch_ptr_vector.size(); i++) { 2757054Snate@binkert.org m_switch_ptr_vector[i]->printConfig(out); 2766145Snate@binkert.org } 2776145Snate@binkert.org 2787054Snate@binkert.org m_topology_ptr->printConfig(out); 2796145Snate@binkert.org} 2806145Snate@binkert.org 2817054Snate@binkert.orgvoid 2827054Snate@binkert.orgSimpleNetwork::print(ostream& out) const 2836145Snate@binkert.org{ 2847054Snate@binkert.org out << "[SimpleNetwork]"; 2856145Snate@binkert.org} 2866876Ssteve.reinhardt@amd.com 2876876Ssteve.reinhardt@amd.com 2886876Ssteve.reinhardt@amd.comSimpleNetwork * 2896876Ssteve.reinhardt@amd.comSimpleNetworkParams::create() 2906876Ssteve.reinhardt@amd.com{ 2916876Ssteve.reinhardt@amd.com return new SimpleNetwork(this); 2926876Ssteve.reinhardt@amd.com} 293