SimpleNetwork.cc revision 9863
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 297832Snate@binkert.org#include <cassert> 307547SBrad.Beckmann@amd.com#include <numeric> 317547SBrad.Beckmann@amd.com 328645Snilay@cs.wisc.edu#include "base/cast.hh" 337454Snate@binkert.org#include "base/stl_helpers.hh" 347054Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 357054Snate@binkert.org#include "mem/ruby/common/NetDest.hh" 368257SBrad.Beckmann@amd.com#include "mem/ruby/network/BasicLink.hh" 378258SBrad.Beckmann@amd.com#include "mem/ruby/network/simple/SimpleLink.hh" 386154Snate@binkert.org#include "mem/ruby/network/simple/SimpleNetwork.hh" 397054Snate@binkert.org#include "mem/ruby/network/simple/Switch.hh" 407547SBrad.Beckmann@amd.com#include "mem/ruby/network/simple/Throttle.hh" 418255SBrad.Beckmann@amd.com#include "mem/ruby/network/Topology.hh" 426154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 436154Snate@binkert.org#include "mem/ruby/system/System.hh" 446145Snate@binkert.org 457055Snate@binkert.orgusing namespace std; 467454Snate@binkert.orgusing m5::stl_helpers::deletePointers; 477055Snate@binkert.org 486876Ssteve.reinhardt@amd.comSimpleNetwork::SimpleNetwork(const Params *p) 496876Ssteve.reinhardt@amd.com : Network(p) 506285Snate@binkert.org{ 518259SBrad.Beckmann@amd.com m_buffer_size = p->buffer_size; 528259SBrad.Beckmann@amd.com m_endpoint_bandwidth = p->endpoint_bandwidth; 538259SBrad.Beckmann@amd.com m_adaptive_routing = p->adaptive_routing; 548259SBrad.Beckmann@amd.com 557054Snate@binkert.org // Note: the parent Network Object constructor is called before the 567054Snate@binkert.org // SimpleNetwork child constructor. Therefore, the member variables 577054Snate@binkert.org // used below should already be initialized. 586285Snate@binkert.org 597454Snate@binkert.org m_endpoint_switches.resize(m_nodes); 606285Snate@binkert.org 617454Snate@binkert.org m_in_use.resize(m_virtual_networks); 627454Snate@binkert.org m_ordered.resize(m_virtual_networks); 637054Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 647054Snate@binkert.org m_in_use[i] = false; 657054Snate@binkert.org m_ordered[i] = false; 666285Snate@binkert.org } 677054Snate@binkert.org 687054Snate@binkert.org // Allocate to and from queues 697454Snate@binkert.org m_toNetQueues.resize(m_nodes); 707454Snate@binkert.org m_fromNetQueues.resize(m_nodes); 717054Snate@binkert.org for (int node = 0; node < m_nodes; node++) { 727454Snate@binkert.org m_toNetQueues[node].resize(m_virtual_networks); 737454Snate@binkert.org m_fromNetQueues[node].resize(m_virtual_networks); 747054Snate@binkert.org for (int j = 0; j < m_virtual_networks; j++) { 757056Snate@binkert.org m_toNetQueues[node][j] = 767056Snate@binkert.org new MessageBuffer(csprintf("toNet node %d j %d", node, j)); 777056Snate@binkert.org m_fromNetQueues[node][j] = 787056Snate@binkert.org new MessageBuffer(csprintf("fromNet node %d j %d", node, j)); 797054Snate@binkert.org } 807054Snate@binkert.org } 819274Snilay@cs.wisc.edu 829274Snilay@cs.wisc.edu // record the routers 839593Snilay@cs.wisc.edu for (vector<BasicRouter*>::const_iterator i = p->routers.begin(); 849593Snilay@cs.wisc.edu i != p->routers.end(); ++i) { 859274Snilay@cs.wisc.edu Switch* s = safe_cast<Switch*>(*i); 869858Snilay@cs.wisc.edu m_switches.push_back(s); 879274Snilay@cs.wisc.edu s->init_net_ptr(this); 889274Snilay@cs.wisc.edu } 896881SBrad.Beckmann@amd.com} 906285Snate@binkert.org 917054Snate@binkert.orgvoid 927054Snate@binkert.orgSimpleNetwork::init() 936881SBrad.Beckmann@amd.com{ 947054Snate@binkert.org Network::init(); 956881SBrad.Beckmann@amd.com 967054Snate@binkert.org // The topology pointer should have already been initialized in 977054Snate@binkert.org // the parent class network constructor. 987054Snate@binkert.org assert(m_topology_ptr != NULL); 999799Snilay@cs.wisc.edu m_topology_ptr->createLinks(this); 1006285Snate@binkert.org} 1016145Snate@binkert.org 1026145Snate@binkert.orgSimpleNetwork::~SimpleNetwork() 1036145Snate@binkert.org{ 1047054Snate@binkert.org for (int i = 0; i < m_nodes; i++) { 1057454Snate@binkert.org deletePointers(m_toNetQueues[i]); 1067454Snate@binkert.org deletePointers(m_fromNetQueues[i]); 1077054Snate@binkert.org } 1089858Snilay@cs.wisc.edu deletePointers(m_switches); 1097454Snate@binkert.org deletePointers(m_buffers_to_free); 1107054Snate@binkert.org // delete m_topology_ptr; 1116145Snate@binkert.org} 1126145Snate@binkert.org 1136145Snate@binkert.org// From a switch to an endpoint node 1147054Snate@binkert.orgvoid 1158257SBrad.Beckmann@amd.comSimpleNetwork::makeOutLink(SwitchID src, NodeID dest, BasicLink* link, 1168257SBrad.Beckmann@amd.com LinkDirection direction, 1179799Snilay@cs.wisc.edu const NetDest& routing_table_entry) 1186145Snate@binkert.org{ 1197054Snate@binkert.org assert(dest < m_nodes); 1209858Snilay@cs.wisc.edu assert(src < m_switches.size()); 1219858Snilay@cs.wisc.edu assert(m_switches[src] != NULL); 1227054Snate@binkert.org 1238258SBrad.Beckmann@amd.com SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link); 1248258SBrad.Beckmann@amd.com 1259858Snilay@cs.wisc.edu m_switches[src]->addOutPort(m_fromNetQueues[dest], 1268257SBrad.Beckmann@amd.com routing_table_entry, 1278258SBrad.Beckmann@amd.com simple_link->m_latency, 1288258SBrad.Beckmann@amd.com simple_link->m_bw_multiplier); 1298257SBrad.Beckmann@amd.com 1309858Snilay@cs.wisc.edu m_endpoint_switches[dest] = m_switches[src]; 1316145Snate@binkert.org} 1326145Snate@binkert.org 1336145Snate@binkert.org// From an endpoint node to a switch 1347054Snate@binkert.orgvoid 1358257SBrad.Beckmann@amd.comSimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link, 1368257SBrad.Beckmann@amd.com LinkDirection direction, 1379799Snilay@cs.wisc.edu const NetDest& routing_table_entry) 1386145Snate@binkert.org{ 1397054Snate@binkert.org assert(src < m_nodes); 1409858Snilay@cs.wisc.edu m_switches[dest]->addInPort(m_toNetQueues[src]); 1416145Snate@binkert.org} 1426145Snate@binkert.org 1436145Snate@binkert.org// From a switch to a switch 1447054Snate@binkert.orgvoid 1458257SBrad.Beckmann@amd.comSimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 1468257SBrad.Beckmann@amd.com LinkDirection direction, 1479799Snilay@cs.wisc.edu const NetDest& routing_table_entry) 1486145Snate@binkert.org{ 1496145Snate@binkert.org // Create a set of new MessageBuffers 1507454Snate@binkert.org std::vector<MessageBuffer*> queues; 1516145Snate@binkert.org for (int i = 0; i < m_virtual_networks; i++) { 1527054Snate@binkert.org // allocate a buffer 1537054Snate@binkert.org MessageBuffer* buffer_ptr = new MessageBuffer; 1547054Snate@binkert.org buffer_ptr->setOrdering(true); 1557054Snate@binkert.org if (m_buffer_size > 0) { 1567454Snate@binkert.org buffer_ptr->resize(m_buffer_size); 1577054Snate@binkert.org } 1587454Snate@binkert.org queues.push_back(buffer_ptr); 1597054Snate@binkert.org // remember to deallocate it 1607454Snate@binkert.org m_buffers_to_free.push_back(buffer_ptr); 1617054Snate@binkert.org } 1627054Snate@binkert.org // Connect it to the two switches 1638258SBrad.Beckmann@amd.com SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link); 1648258SBrad.Beckmann@amd.com 1659858Snilay@cs.wisc.edu m_switches[dest]->addInPort(queues); 1669858Snilay@cs.wisc.edu m_switches[src]->addOutPort(queues, routing_table_entry, 1678258SBrad.Beckmann@amd.com simple_link->m_latency, 1688258SBrad.Beckmann@amd.com simple_link->m_bw_multiplier); 1697054Snate@binkert.org} 1707054Snate@binkert.org 1717054Snate@binkert.orgvoid 1727054Snate@binkert.orgSimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 1737054Snate@binkert.org{ 1747832Snate@binkert.org assert(id < m_nodes); 1757832Snate@binkert.org assert(network_num < m_virtual_networks); 1767054Snate@binkert.org 1777054Snate@binkert.org if (ordered) { 1787054Snate@binkert.org m_ordered[network_num] = true; 1797054Snate@binkert.org } 1807054Snate@binkert.org m_in_use[network_num] = true; 1817054Snate@binkert.org} 1827054Snate@binkert.org 1837054Snate@binkert.orgMessageBuffer* 1848308Stushar@csail.mit.eduSimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num, 1858308Stushar@csail.mit.edu std::string vnet_type) 1867054Snate@binkert.org{ 1877054Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 1887054Snate@binkert.org return m_toNetQueues[id][network_num]; 1897054Snate@binkert.org} 1907054Snate@binkert.org 1917054Snate@binkert.orgMessageBuffer* 1928308Stushar@csail.mit.eduSimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num, 1938308Stushar@csail.mit.edu std::string vnet_type) 1947054Snate@binkert.org{ 1957054Snate@binkert.org checkNetworkAllocation(id, ordered, network_num); 1967054Snate@binkert.org return m_fromNetQueues[id][network_num]; 1977054Snate@binkert.org} 1987054Snate@binkert.org 1997454Snate@binkert.orgconst std::vector<Throttle*>* 2007054Snate@binkert.orgSimpleNetwork::getThrottles(NodeID id) const 2017054Snate@binkert.org{ 2027054Snate@binkert.org assert(id >= 0); 2037054Snate@binkert.org assert(id < m_nodes); 2047054Snate@binkert.org assert(m_endpoint_switches[id] != NULL); 2057054Snate@binkert.org return m_endpoint_switches[id]->getThrottles(); 2067054Snate@binkert.org} 2077054Snate@binkert.org 2087054Snate@binkert.orgvoid 2099863Snilay@cs.wisc.eduSimpleNetwork::regStats() 2107054Snate@binkert.org{ 2119863Snilay@cs.wisc.edu m_msg_counts.resize(MessageSizeType_NUM); 2129863Snilay@cs.wisc.edu m_msg_bytes.resize(MessageSizeType_NUM); 2137547SBrad.Beckmann@amd.com 2149863Snilay@cs.wisc.edu for (MessageSizeType type = MessageSizeType_FIRST; 2159863Snilay@cs.wisc.edu type < MessageSizeType_NUM; ++type) { 2169863Snilay@cs.wisc.edu m_msg_counts[(unsigned int) type] 2179863Snilay@cs.wisc.edu .name(name() + ".msg_count." + MessageSizeType_to_string(type)) 2189863Snilay@cs.wisc.edu .flags(Stats::nozero) 2199863Snilay@cs.wisc.edu ; 2209863Snilay@cs.wisc.edu m_msg_bytes[(unsigned int) type] 2219863Snilay@cs.wisc.edu .name(name() + ".msg_byte." + MessageSizeType_to_string(type)) 2229863Snilay@cs.wisc.edu .flags(Stats::nozero) 2239863Snilay@cs.wisc.edu ; 2247547SBrad.Beckmann@amd.com 2259863Snilay@cs.wisc.edu // Now state what the formula is. 2269863Snilay@cs.wisc.edu for (int i = 0; i < m_switches.size(); i++) { 2279863Snilay@cs.wisc.edu m_msg_counts[(unsigned int) type] += 2289863Snilay@cs.wisc.edu sum(m_switches[i]->getMsgCount(type)); 2297547SBrad.Beckmann@amd.com } 2309863Snilay@cs.wisc.edu 2319863Snilay@cs.wisc.edu m_msg_bytes[(unsigned int) type] = 2329863Snilay@cs.wisc.edu m_msg_counts[(unsigned int) type] * Stats::constant( 2339863Snilay@cs.wisc.edu Network::MessageSizeType_to_int(type)); 2347054Snate@binkert.org } 2357054Snate@binkert.org} 2367054Snate@binkert.org 2377054Snate@binkert.orgvoid 2389863Snilay@cs.wisc.eduSimpleNetwork::collateStats() 2397054Snate@binkert.org{ 2409858Snilay@cs.wisc.edu for (int i = 0; i < m_switches.size(); i++) { 2419863Snilay@cs.wisc.edu m_switches[i]->collateStats(); 2427054Snate@binkert.org } 2437054Snate@binkert.org} 2447054Snate@binkert.org 2457054Snate@binkert.orgvoid 2467054Snate@binkert.orgSimpleNetwork::print(ostream& out) const 2476145Snate@binkert.org{ 2487054Snate@binkert.org out << "[SimpleNetwork]"; 2496145Snate@binkert.org} 2506876Ssteve.reinhardt@amd.com 2516876Ssteve.reinhardt@amd.comSimpleNetwork * 2526876Ssteve.reinhardt@amd.comSimpleNetworkParams::create() 2536876Ssteve.reinhardt@amd.com{ 2546876Ssteve.reinhardt@amd.com return new SimpleNetwork(this); 2556876Ssteve.reinhardt@amd.com} 2569302Snilay@cs.wisc.edu 2579302Snilay@cs.wisc.edu/* 2589302Snilay@cs.wisc.edu * The simple network has an array of switches. These switches have buffers 2599302Snilay@cs.wisc.edu * that need to be accessed for functional reads and writes. Also the links 2609302Snilay@cs.wisc.edu * between different switches have buffers that need to be accessed. 2619302Snilay@cs.wisc.edu */ 2629302Snilay@cs.wisc.edubool 2639302Snilay@cs.wisc.eduSimpleNetwork::functionalRead(Packet *pkt) 2649302Snilay@cs.wisc.edu{ 2659858Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_switches.size(); i++) { 2669858Snilay@cs.wisc.edu if (m_switches[i]->functionalRead(pkt)) { 2679302Snilay@cs.wisc.edu return true; 2689302Snilay@cs.wisc.edu } 2699302Snilay@cs.wisc.edu } 2709302Snilay@cs.wisc.edu 2719302Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) { 2729302Snilay@cs.wisc.edu if (m_buffers_to_free[i]->functionalRead(pkt)) { 2739302Snilay@cs.wisc.edu return true; 2749302Snilay@cs.wisc.edu } 2759302Snilay@cs.wisc.edu } 2769302Snilay@cs.wisc.edu 2779302Snilay@cs.wisc.edu return false; 2789302Snilay@cs.wisc.edu} 2799302Snilay@cs.wisc.edu 2809302Snilay@cs.wisc.eduuint32_t 2819302Snilay@cs.wisc.eduSimpleNetwork::functionalWrite(Packet *pkt) 2829302Snilay@cs.wisc.edu{ 2839302Snilay@cs.wisc.edu uint32_t num_functional_writes = 0; 2849302Snilay@cs.wisc.edu 2859858Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_switches.size(); i++) { 2869858Snilay@cs.wisc.edu num_functional_writes += m_switches[i]->functionalWrite(pkt); 2879302Snilay@cs.wisc.edu } 2889302Snilay@cs.wisc.edu 2899302Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) { 2909302Snilay@cs.wisc.edu num_functional_writes += m_buffers_to_free[i]->functionalWrite(pkt); 2919302Snilay@cs.wisc.edu } 2929302Snilay@cs.wisc.edu return num_functional_writes; 2939302Snilay@cs.wisc.edu} 294