SimpleNetwork.cc revision 7454
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 297454Snate@binkert.org#include "base/stl_helpers.hh" 307054Snate@binkert.org#include "mem/gems_common/Map.hh" 317054Snate@binkert.org#include "mem/protocol/MachineType.hh" 327054Snate@binkert.org#include "mem/protocol/Protocol.hh" 337054Snate@binkert.org#include "mem/protocol/TopologyType.hh" 347054Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 357054Snate@binkert.org#include "mem/ruby/common/NetDest.hh" 366154Snate@binkert.org#include "mem/ruby/network/simple/SimpleNetwork.hh" 377054Snate@binkert.org#include "mem/ruby/network/simple/Switch.hh" 387054Snate@binkert.org#include "mem/ruby/network/simple/Topology.hh" 396154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 406154Snate@binkert.org#include "mem/ruby/system/System.hh" 416145Snate@binkert.org 427055Snate@binkert.orgusing namespace std; 437454Snate@binkert.orgusing m5::stl_helpers::deletePointers; 447055Snate@binkert.org 457054Snate@binkert.org#if 0 466284Snate@binkert.org// ***BIG HACK*** - This is actually code that _should_ be in Network.cc 476145Snate@binkert.org 486145Snate@binkert.org// Note: Moved to Princeton Network 496145Snate@binkert.org// calls new to abstract away from the network 507054Snate@binkert.orgNetwork* 517054Snate@binkert.orgNetwork::createNetwork(int nodes) 526145Snate@binkert.org{ 537054Snate@binkert.org return new SimpleNetwork(nodes); 546145Snate@binkert.org} 557054Snate@binkert.org#endif 566145Snate@binkert.org 576876Ssteve.reinhardt@amd.comSimpleNetwork::SimpleNetwork(const Params *p) 586876Ssteve.reinhardt@amd.com : Network(p) 596285Snate@binkert.org{ 607054Snate@binkert.org // Note: the parent Network Object constructor is called before the 617054Snate@binkert.org // SimpleNetwork child constructor. Therefore, the member variables 627054Snate@binkert.org // used below should already be initialized. 636285Snate@binkert.org 647454Snate@binkert.org m_endpoint_switches.resize(m_nodes); 656285Snate@binkert.org 667454Snate@binkert.org m_in_use.resize(m_virtual_networks); 677454Snate@binkert.org m_ordered.resize(m_virtual_networks); 687054Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 697054Snate@binkert.org m_in_use[i] = false; 707054Snate@binkert.org m_ordered[i] = false; 716285Snate@binkert.org } 727054Snate@binkert.org 737054Snate@binkert.org // Allocate to and from queues 747454Snate@binkert.org m_toNetQueues.resize(m_nodes); 757454Snate@binkert.org m_fromNetQueues.resize(m_nodes); 767054Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 777454Snate@binkert.org m_toNetQueues[node].resize(m_virtual_networks); 787454Snate@binkert.org m_fromNetQueues[node].resize(m_virtual_networks); 797054Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 807056Snate@binkert.org m_toNetQueues[node][j] = 817056Snate@binkert.org new MessageBuffer(csprintf("toNet node %d j %d", node, j)); 827056Snate@binkert.org m_fromNetQueues[node][j] = 837056Snate@binkert.org new MessageBuffer(csprintf("fromNet node %d j %d", node, j)); 847054Snate@binkert.org } 857054Snate@binkert.org } 866881SBrad.Beckmann@amd.com} 876285Snate@binkert.org 887054Snate@binkert.orgvoid 897054Snate@binkert.orgSimpleNetwork::init() 906881SBrad.Beckmann@amd.com{ 917054Snate@binkert.org Network::init(); 926881SBrad.Beckmann@amd.com 937054Snate@binkert.org // The topology pointer should have already been initialized in 947054Snate@binkert.org // the parent class network constructor. 957054Snate@binkert.org assert(m_topology_ptr != NULL); 967054Snate@binkert.org int number_of_switches = m_topology_ptr->numSwitches(); 977054Snate@binkert.org for (int i = 0; i < number_of_switches; i++) { 987454Snate@binkert.org m_switch_ptr_vector.push_back(new Switch(i, this)); 997054Snate@binkert.org } 1006881SBrad.Beckmann@amd.com 1017054Snate@binkert.org // false because this isn't a reconfiguration 1027054Snate@binkert.org m_topology_ptr->createLinks(this, false); 1036285Snate@binkert.org} 1046145Snate@binkert.org 1057054Snate@binkert.orgvoid 1067054Snate@binkert.orgSimpleNetwork::reset() 1076145Snate@binkert.org{ 1087054Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 1097054Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 1107054Snate@binkert.org m_toNetQueues[node][j]->clear(); 1117054Snate@binkert.org m_fromNetQueues[node][j]->clear(); 1127054Snate@binkert.org } 1136145Snate@binkert.org } 1146145Snate@binkert.org 1157054Snate@binkert.org for(int i = 0; i < m_switch_ptr_vector.size(); i++){ 1167054Snate@binkert.org m_switch_ptr_vector[i]->clearBuffers(); 1177054Snate@binkert.org } 1186145Snate@binkert.org} 1196145Snate@binkert.org 1206145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1216145Snate@binkert.org{ 1227054Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1237454Snate@binkert.org deletePointers(m_toNetQueues[i]); 1247454Snate@binkert.org deletePointers(m_fromNetQueues[i]); 1257054Snate@binkert.org } 1267454Snate@binkert.org deletePointers(m_switch_ptr_vector); 1277454Snate@binkert.org deletePointers(m_buffers_to_free); 1287054Snate@binkert.org // delete m_topology_ptr; 1296145Snate@binkert.org} 1306145Snate@binkert.org 1316145Snate@binkert.org// From a switch to an endpoint node 1327054Snate@binkert.orgvoid 1337054Snate@binkert.orgSimpleNetwork::makeOutLink(SwitchID src, NodeID dest, 1347054Snate@binkert.org const NetDest& routing_table_entry, int link_latency, int link_weight, 1357054Snate@binkert.org int bw_multiplier, bool isReconfiguration) 1366145Snate@binkert.org{ 1377054Snate@binkert.org assert(dest < m_nodes); 1387054Snate@binkert.org assert(src < m_switch_ptr_vector.size()); 1397054Snate@binkert.org assert(m_switch_ptr_vector[src] != NULL); 1407054Snate@binkert.org 1417054Snate@binkert.org if (isReconfiguration) { 1427054Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1437054Snate@binkert.org return; 1447054Snate@binkert.org } 1457054Snate@binkert.org 1467054Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], 1477054Snate@binkert.org routing_table_entry, link_latency, bw_multiplier); 1486145Snate@binkert.org m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 1496145Snate@binkert.org} 1506145Snate@binkert.org 1516145Snate@binkert.org// From an endpoint node to a switch 1527054Snate@binkert.orgvoid 1537054Snate@binkert.orgSimpleNetwork::makeInLink(NodeID src, SwitchID dest, 1547054Snate@binkert.org const NetDest& routing_table_entry, int link_latency, int bw_multiplier, 1557054Snate@binkert.org bool isReconfiguration) 1566145Snate@binkert.org{ 1577054Snate@binkert.org assert(src < m_nodes); 1587054Snate@binkert.org if (isReconfiguration) { 1597054Snate@binkert.org // do nothing 1607054Snate@binkert.org return; 1617054Snate@binkert.org } 1627054Snate@binkert.org 1636145Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 1646145Snate@binkert.org} 1656145Snate@binkert.org 1666145Snate@binkert.org// From a switch to a switch 1677054Snate@binkert.orgvoid 1687054Snate@binkert.orgSimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, 1697054Snate@binkert.org const NetDest& routing_table_entry, int link_latency, int link_weight, 1707054Snate@binkert.org int bw_multiplier, bool isReconfiguration) 1716145Snate@binkert.org{ 1727054Snate@binkert.org if (isReconfiguration) { 1737054Snate@binkert.org m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 1747054Snate@binkert.org return; 1757054Snate@binkert.org } 1767054Snate@binkert.org 1776145Snate@binkert.org // Create a set of new MessageBuffers 1787454Snate@binkert.org std::vector<MessageBuffer*> queues; 1796145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1807054Snate@binkert.org // allocate a buffer 1817054Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 1827054Snate@binkert.org buffer_ptr->setOrdering(true); 1837054Snate@binkert.org if (m_buffer_size > 0) { 1847454Snate@binkert.org buffer_ptr->resize(m_buffer_size); 1857054Snate@binkert.org } 1867454Snate@binkert.org queues.push_back(buffer_ptr); 1877054Snate@binkert.org // remember to deallocate it 1887454Snate@binkert.org m_buffers_to_free.push_back(buffer_ptr); 1897054Snate@binkert.org } 1907054Snate@binkert.org // Connect it to the two switches 1917054Snate@binkert.org m_switch_ptr_vector[dest]->addInPort(queues); 1927054Snate@binkert.org m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, 1937054Snate@binkert.org link_latency, bw_multiplier); 1947054Snate@binkert.org} 1957054Snate@binkert.org 1967054Snate@binkert.orgvoid 1977054Snate@binkert.orgSimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 1987054Snate@binkert.org{ 1997054Snate@binkert.org ASSERT(id < m_nodes); 2007054Snate@binkert.org ASSERT(network_num < m_virtual_networks); 2017054Snate@binkert.org 2027054Snate@binkert.org if (ordered) { 2037054Snate@binkert.org m_ordered[network_num] = true; 2047054Snate@binkert.org } 2057054Snate@binkert.org m_in_use[network_num] = true; 2067054Snate@binkert.org} 2077054Snate@binkert.org 2087054Snate@binkert.orgMessageBuffer* 2097054Snate@binkert.orgSimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 2107054Snate@binkert.org{ 2117054Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2127054Snate@binkert.org return m_toNetQueues[id][network_num]; 2137054Snate@binkert.org} 2147054Snate@binkert.org 2157054Snate@binkert.orgMessageBuffer* 2167054Snate@binkert.orgSimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 2177054Snate@binkert.org{ 2187054Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 2197054Snate@binkert.org return m_fromNetQueues[id][network_num]; 2207054Snate@binkert.org} 2217054Snate@binkert.org 2227454Snate@binkert.orgconst std::vector<Throttle*>* 2237054Snate@binkert.orgSimpleNetwork::getThrottles(NodeID id) const 2247054Snate@binkert.org{ 2257054Snate@binkert.org assert(id >= 0); 2267054Snate@binkert.org assert(id < m_nodes); 2277054Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2287054Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2297054Snate@binkert.org} 2307054Snate@binkert.org 2317054Snate@binkert.orgvoid 2327054Snate@binkert.orgSimpleNetwork::printStats(ostream& out) const 2337054Snate@binkert.org{ 2347054Snate@binkert.org out << endl; 2357054Snate@binkert.org out << "Network Stats" << endl; 2367054Snate@binkert.org out << "-------------" << endl; 2377054Snate@binkert.org out << endl; 2387054Snate@binkert.org for (int i = 0; i < m_switch_ptr_vector.size(); i++) { 2397054Snate@binkert.org m_switch_ptr_vector[i]->printStats(out); 2407054Snate@binkert.org } 2417054Snate@binkert.org m_topology_ptr->printStats(out); 2427054Snate@binkert.org} 2437054Snate@binkert.org 2447054Snate@binkert.orgvoid 2457054Snate@binkert.orgSimpleNetwork::clearStats() 2467054Snate@binkert.org{ 2477054Snate@binkert.org for (int i = 0; i < m_switch_ptr_vector.size(); i++) { 2487054Snate@binkert.org m_switch_ptr_vector[i]->clearStats(); 2497054Snate@binkert.org } 2507054Snate@binkert.org m_topology_ptr->clearStats(); 2517054Snate@binkert.org} 2527054Snate@binkert.org 2537054Snate@binkert.orgvoid 2547054Snate@binkert.orgSimpleNetwork::printConfig(ostream& out) const 2557054Snate@binkert.org{ 2567054Snate@binkert.org out << endl; 2577054Snate@binkert.org out << "Network Configuration" << endl; 2587054Snate@binkert.org out << "---------------------" << endl; 2597054Snate@binkert.org out << "network: SIMPLE_NETWORK" << endl; 2607054Snate@binkert.org out << "topology: " << m_topology_ptr->getName() << endl; 2617054Snate@binkert.org out << endl; 2627054Snate@binkert.org 2637054Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 2647054Snate@binkert.org out << "virtual_net_" << i << ": "; 2657054Snate@binkert.org if (m_in_use[i]) { 2667054Snate@binkert.org out << "active, "; 2677054Snate@binkert.org if (m_ordered[i]) { 2687054Snate@binkert.org out << "ordered" << endl; 2697054Snate@binkert.org } else { 2707054Snate@binkert.org out << "unordered" << endl; 2717054Snate@binkert.org } 2727054Snate@binkert.org } else { 2737054Snate@binkert.org out << "inactive" << endl; 2747054Snate@binkert.org } 2757054Snate@binkert.org } 2767054Snate@binkert.org out << endl; 2777054Snate@binkert.org 2787054Snate@binkert.org for(int i = 0; i < m_switch_ptr_vector.size(); i++) { 2797054Snate@binkert.org m_switch_ptr_vector[i]->printConfig(out); 2806145Snate@binkert.org } 2816145Snate@binkert.org 2827054Snate@binkert.org m_topology_ptr->printConfig(out); 2836145Snate@binkert.org} 2846145Snate@binkert.org 2857054Snate@binkert.orgvoid 2867054Snate@binkert.orgSimpleNetwork::print(ostream& out) const 2876145Snate@binkert.org{ 2887054Snate@binkert.org out << "[SimpleNetwork]"; 2896145Snate@binkert.org} 2906876Ssteve.reinhardt@amd.com 2916876Ssteve.reinhardt@amd.com 2926876Ssteve.reinhardt@amd.comSimpleNetwork * 2936876Ssteve.reinhardt@amd.comSimpleNetworkParams::create() 2946876Ssteve.reinhardt@amd.com{ 2956876Ssteve.reinhardt@amd.com return new SimpleNetwork(this); 2966876Ssteve.reinhardt@amd.com} 297