SimpleNetwork.cc revision 7454
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "base/stl_helpers.hh" 30#include "mem/gems_common/Map.hh" 31#include "mem/protocol/MachineType.hh" 32#include "mem/protocol/Protocol.hh" 33#include "mem/protocol/TopologyType.hh" 34#include "mem/ruby/buffers/MessageBuffer.hh" 35#include "mem/ruby/common/NetDest.hh" 36#include "mem/ruby/network/simple/SimpleNetwork.hh" 37#include "mem/ruby/network/simple/Switch.hh" 38#include "mem/ruby/network/simple/Topology.hh" 39#include "mem/ruby/profiler/Profiler.hh" 40#include "mem/ruby/system/System.hh" 41 42using namespace std; 43using m5::stl_helpers::deletePointers; 44 45#if 0 46// ***BIG HACK*** - This is actually code that _should_ be in Network.cc 47 48// Note: Moved to Princeton Network 49// calls new to abstract away from the network 50Network* 51Network::createNetwork(int nodes) 52{ 53 return new SimpleNetwork(nodes); 54} 55#endif 56 57SimpleNetwork::SimpleNetwork(const Params *p) 58 : Network(p) 59{ 60 // Note: the parent Network Object constructor is called before the 61 // SimpleNetwork child constructor. Therefore, the member variables 62 // used below should already be initialized. 63 64 m_endpoint_switches.resize(m_nodes); 65 66 m_in_use.resize(m_virtual_networks); 67 m_ordered.resize(m_virtual_networks); 68 for (int i = 0; i < m_virtual_networks; i++) { 69 m_in_use[i] = false; 70 m_ordered[i] = false; 71 } 72 73 // Allocate to and from queues 74 m_toNetQueues.resize(m_nodes); 75 m_fromNetQueues.resize(m_nodes); 76 for (int node = 0; node < m_nodes; node++) { 77 m_toNetQueues[node].resize(m_virtual_networks); 78 m_fromNetQueues[node].resize(m_virtual_networks); 79 for (int j = 0; j < m_virtual_networks; j++) { 80 m_toNetQueues[node][j] = 81 new MessageBuffer(csprintf("toNet node %d j %d", node, j)); 82 m_fromNetQueues[node][j] = 83 new MessageBuffer(csprintf("fromNet node %d j %d", node, j)); 84 } 85 } 86} 87 88void 89SimpleNetwork::init() 90{ 91 Network::init(); 92 93 // The topology pointer should have already been initialized in 94 // the parent class network constructor. 95 assert(m_topology_ptr != NULL); 96 int number_of_switches = m_topology_ptr->numSwitches(); 97 for (int i = 0; i < number_of_switches; i++) { 98 m_switch_ptr_vector.push_back(new Switch(i, this)); 99 } 100 101 // false because this isn't a reconfiguration 102 m_topology_ptr->createLinks(this, false); 103} 104 105void 106SimpleNetwork::reset() 107{ 108 for (int node = 0; node < m_nodes; node++) { 109 for (int j = 0; j < m_virtual_networks; j++) { 110 m_toNetQueues[node][j]->clear(); 111 m_fromNetQueues[node][j]->clear(); 112 } 113 } 114 115 for(int i = 0; i < m_switch_ptr_vector.size(); i++){ 116 m_switch_ptr_vector[i]->clearBuffers(); 117 } 118} 119 120SimpleNetwork::~SimpleNetwork() 121{ 122 for (int i = 0; i < m_nodes; i++) { 123 deletePointers(m_toNetQueues[i]); 124 deletePointers(m_fromNetQueues[i]); 125 } 126 deletePointers(m_switch_ptr_vector); 127 deletePointers(m_buffers_to_free); 128 // delete m_topology_ptr; 129} 130 131// From a switch to an endpoint node 132void 133SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, 134 const NetDest& routing_table_entry, int link_latency, int link_weight, 135 int bw_multiplier, bool isReconfiguration) 136{ 137 assert(dest < m_nodes); 138 assert(src < m_switch_ptr_vector.size()); 139 assert(m_switch_ptr_vector[src] != NULL); 140 141 if (isReconfiguration) { 142 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 143 return; 144 } 145 146 m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], 147 routing_table_entry, link_latency, bw_multiplier); 148 m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 149} 150 151// From an endpoint node to a switch 152void 153SimpleNetwork::makeInLink(NodeID src, SwitchID dest, 154 const NetDest& routing_table_entry, int link_latency, int bw_multiplier, 155 bool isReconfiguration) 156{ 157 assert(src < m_nodes); 158 if (isReconfiguration) { 159 // do nothing 160 return; 161 } 162 163 m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 164} 165 166// From a switch to a switch 167void 168SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, 169 const NetDest& routing_table_entry, int link_latency, int link_weight, 170 int bw_multiplier, bool isReconfiguration) 171{ 172 if (isReconfiguration) { 173 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 174 return; 175 } 176 177 // Create a set of new MessageBuffers 178 std::vector<MessageBuffer*> queues; 179 for (int i = 0; i < m_virtual_networks; i++) { 180 // allocate a buffer 181 MessageBuffer* buffer_ptr = new MessageBuffer; 182 buffer_ptr->setOrdering(true); 183 if (m_buffer_size > 0) { 184 buffer_ptr->resize(m_buffer_size); 185 } 186 queues.push_back(buffer_ptr); 187 // remember to deallocate it 188 m_buffers_to_free.push_back(buffer_ptr); 189 } 190 // Connect it to the two switches 191 m_switch_ptr_vector[dest]->addInPort(queues); 192 m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, 193 link_latency, bw_multiplier); 194} 195 196void 197SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 198{ 199 ASSERT(id < m_nodes); 200 ASSERT(network_num < m_virtual_networks); 201 202 if (ordered) { 203 m_ordered[network_num] = true; 204 } 205 m_in_use[network_num] = true; 206} 207 208MessageBuffer* 209SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num) 210{ 211 checkNetworkAllocation(id, ordered, network_num); 212 return m_toNetQueues[id][network_num]; 213} 214 215MessageBuffer* 216SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num) 217{ 218 checkNetworkAllocation(id, ordered, network_num); 219 return m_fromNetQueues[id][network_num]; 220} 221 222const std::vector<Throttle*>* 223SimpleNetwork::getThrottles(NodeID id) const 224{ 225 assert(id >= 0); 226 assert(id < m_nodes); 227 assert(m_endpoint_switches[id] != NULL); 228 return m_endpoint_switches[id]->getThrottles(); 229} 230 231void 232SimpleNetwork::printStats(ostream& out) const 233{ 234 out << endl; 235 out << "Network Stats" << endl; 236 out << "-------------" << endl; 237 out << endl; 238 for (int i = 0; i < m_switch_ptr_vector.size(); i++) { 239 m_switch_ptr_vector[i]->printStats(out); 240 } 241 m_topology_ptr->printStats(out); 242} 243 244void 245SimpleNetwork::clearStats() 246{ 247 for (int i = 0; i < m_switch_ptr_vector.size(); i++) { 248 m_switch_ptr_vector[i]->clearStats(); 249 } 250 m_topology_ptr->clearStats(); 251} 252 253void 254SimpleNetwork::printConfig(ostream& out) const 255{ 256 out << endl; 257 out << "Network Configuration" << endl; 258 out << "---------------------" << endl; 259 out << "network: SIMPLE_NETWORK" << endl; 260 out << "topology: " << m_topology_ptr->getName() << endl; 261 out << endl; 262 263 for (int i = 0; i < m_virtual_networks; i++) { 264 out << "virtual_net_" << i << ": "; 265 if (m_in_use[i]) { 266 out << "active, "; 267 if (m_ordered[i]) { 268 out << "ordered" << endl; 269 } else { 270 out << "unordered" << endl; 271 } 272 } else { 273 out << "inactive" << endl; 274 } 275 } 276 out << endl; 277 278 for(int i = 0; i < m_switch_ptr_vector.size(); i++) { 279 m_switch_ptr_vector[i]->printConfig(out); 280 } 281 282 m_topology_ptr->printConfig(out); 283} 284 285void 286SimpleNetwork::print(ostream& out) const 287{ 288 out << "[SimpleNetwork]"; 289} 290 291 292SimpleNetwork * 293SimpleNetworkParams::create() 294{ 295 return new SimpleNetwork(this); 296} 297