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