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 <cassert> 30#include <numeric> 31 32#include "base/stl_helpers.hh" 33#include "mem/protocol/MachineType.hh" 34#include "mem/protocol/Protocol.hh" 35#include "mem/protocol/TopologyType.hh" 36#include "mem/ruby/buffers/MessageBuffer.hh" 37#include "mem/ruby/common/NetDest.hh" 38#include "mem/ruby/network/BasicLink.hh" 39#include "mem/ruby/network/simple/SimpleLink.hh" 40#include "mem/ruby/network/simple/SimpleNetwork.hh" 41#include "mem/ruby/network/simple/Switch.hh" 42#include "mem/ruby/network/simple/Throttle.hh" 43#include "mem/ruby/network/Topology.hh" 44#include "mem/ruby/profiler/Profiler.hh" 45#include "mem/ruby/system/System.hh" 46 47using namespace std; 48using m5::stl_helpers::deletePointers; 49 50#if 0 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 55Network* 56Network::createNetwork(int nodes) 57{ 58 return new SimpleNetwork(nodes); 59} 60#endif 61 62SimpleNetwork::SimpleNetwork(const Params *p) 63 : Network(p) 64{ 65 m_buffer_size = p->buffer_size; 66 m_endpoint_bandwidth = p->endpoint_bandwidth; 67 m_adaptive_routing = p->adaptive_routing; 68 69 // Note: the parent Network Object constructor is called before the 70 // SimpleNetwork child constructor. Therefore, the member variables 71 // used below should already be initialized. 72 73 m_endpoint_switches.resize(m_nodes); 74 75 m_in_use.resize(m_virtual_networks); 76 m_ordered.resize(m_virtual_networks); 77 for (int i = 0; i < m_virtual_networks; i++) { 78 m_in_use[i] = false; 79 m_ordered[i] = false; 80 } 81 82 // Allocate to and from queues 83 m_toNetQueues.resize(m_nodes); 84 m_fromNetQueues.resize(m_nodes); 85 for (int node = 0; node < m_nodes; node++) { 86 m_toNetQueues[node].resize(m_virtual_networks); 87 m_fromNetQueues[node].resize(m_virtual_networks); 88 for (int j = 0; j < m_virtual_networks; j++) { 89 m_toNetQueues[node][j] = 90 new MessageBuffer(csprintf("toNet node %d j %d", node, j)); 91 m_fromNetQueues[node][j] = 92 new MessageBuffer(csprintf("fromNet node %d j %d", node, j)); 93 } 94 } 95} 96 97void 98SimpleNetwork::init() 99{ 100 Network::init(); 101 102 // The topology pointer should have already been initialized in 103 // the parent class network constructor. 104 assert(m_topology_ptr != NULL); 105 int number_of_switches = m_topology_ptr->numSwitches(); 106 for (int i = 0; i < number_of_switches; i++) { 107 m_switch_ptr_vector.push_back(new Switch(i, this)); 108 } 109 110 // false because this isn't a reconfiguration 111 m_topology_ptr->createLinks(this, false); 112} 113 114void 115SimpleNetwork::reset() 116{ 117 for (int node = 0; node < m_nodes; node++) { 118 for (int j = 0; j < m_virtual_networks; j++) { 119 m_toNetQueues[node][j]->clear(); 120 m_fromNetQueues[node][j]->clear(); 121 } 122 } 123 124 for(int i = 0; i < m_switch_ptr_vector.size(); i++){ 125 m_switch_ptr_vector[i]->clearBuffers(); 126 } 127} 128 129SimpleNetwork::~SimpleNetwork() 130{ 131 for (int i = 0; i < m_nodes; i++) { 132 deletePointers(m_toNetQueues[i]); 133 deletePointers(m_fromNetQueues[i]); 134 } 135 deletePointers(m_switch_ptr_vector); 136 deletePointers(m_buffers_to_free); 137 // delete m_topology_ptr; 138} 139 140// From a switch to an endpoint node 141void 142SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, BasicLink* link, 143 LinkDirection direction, 144 const NetDest& routing_table_entry, 145 bool isReconfiguration) 146{ 147 assert(dest < m_nodes); 148 assert(src < m_switch_ptr_vector.size()); 149 assert(m_switch_ptr_vector[src] != NULL); 150 151 if (isReconfiguration) { 152 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 153 return; 154 } 155 156 SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link); 157 158 m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], 159 routing_table_entry, 160 simple_link->m_latency, 161 simple_link->m_bw_multiplier); 162 163 m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 164} 165 166// From an endpoint node to a switch 167void 168SimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link, 169 LinkDirection direction, 170 const NetDest& routing_table_entry, 171 bool isReconfiguration) 172{ 173 assert(src < m_nodes); 174 if (isReconfiguration) { 175 // do nothing 176 return; 177 } 178 179 m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 180} 181 182// From a switch to a switch 183void 184SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 185 LinkDirection direction, 186 const NetDest& routing_table_entry, 187 bool isReconfiguration) 188{ 189 if (isReconfiguration) { 190 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 191 return; 192 } 193 194 // Create a set of new MessageBuffers 195 std::vector<MessageBuffer*> queues; 196 for (int i = 0; i < m_virtual_networks; i++) { 197 // allocate a buffer 198 MessageBuffer* buffer_ptr = new MessageBuffer; 199 buffer_ptr->setOrdering(true); 200 if (m_buffer_size > 0) { 201 buffer_ptr->resize(m_buffer_size); 202 } 203 queues.push_back(buffer_ptr); 204 // remember to deallocate it 205 m_buffers_to_free.push_back(buffer_ptr); 206 } 207 // Connect it to the two switches 208 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link); 209 210 m_switch_ptr_vector[dest]->addInPort(queues); 211 m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, 212 simple_link->m_latency, 213 simple_link->m_bw_multiplier); 214} 215 216void 217SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 218{ 219 assert(id < m_nodes); 220 assert(network_num < m_virtual_networks); 221 222 if (ordered) { 223 m_ordered[network_num] = true; 224 } 225 m_in_use[network_num] = true; 226} 227 228MessageBuffer*
| 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 <cassert> 30#include <numeric> 31 32#include "base/stl_helpers.hh" 33#include "mem/protocol/MachineType.hh" 34#include "mem/protocol/Protocol.hh" 35#include "mem/protocol/TopologyType.hh" 36#include "mem/ruby/buffers/MessageBuffer.hh" 37#include "mem/ruby/common/NetDest.hh" 38#include "mem/ruby/network/BasicLink.hh" 39#include "mem/ruby/network/simple/SimpleLink.hh" 40#include "mem/ruby/network/simple/SimpleNetwork.hh" 41#include "mem/ruby/network/simple/Switch.hh" 42#include "mem/ruby/network/simple/Throttle.hh" 43#include "mem/ruby/network/Topology.hh" 44#include "mem/ruby/profiler/Profiler.hh" 45#include "mem/ruby/system/System.hh" 46 47using namespace std; 48using m5::stl_helpers::deletePointers; 49 50#if 0 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 55Network* 56Network::createNetwork(int nodes) 57{ 58 return new SimpleNetwork(nodes); 59} 60#endif 61 62SimpleNetwork::SimpleNetwork(const Params *p) 63 : Network(p) 64{ 65 m_buffer_size = p->buffer_size; 66 m_endpoint_bandwidth = p->endpoint_bandwidth; 67 m_adaptive_routing = p->adaptive_routing; 68 69 // Note: the parent Network Object constructor is called before the 70 // SimpleNetwork child constructor. Therefore, the member variables 71 // used below should already be initialized. 72 73 m_endpoint_switches.resize(m_nodes); 74 75 m_in_use.resize(m_virtual_networks); 76 m_ordered.resize(m_virtual_networks); 77 for (int i = 0; i < m_virtual_networks; i++) { 78 m_in_use[i] = false; 79 m_ordered[i] = false; 80 } 81 82 // Allocate to and from queues 83 m_toNetQueues.resize(m_nodes); 84 m_fromNetQueues.resize(m_nodes); 85 for (int node = 0; node < m_nodes; node++) { 86 m_toNetQueues[node].resize(m_virtual_networks); 87 m_fromNetQueues[node].resize(m_virtual_networks); 88 for (int j = 0; j < m_virtual_networks; j++) { 89 m_toNetQueues[node][j] = 90 new MessageBuffer(csprintf("toNet node %d j %d", node, j)); 91 m_fromNetQueues[node][j] = 92 new MessageBuffer(csprintf("fromNet node %d j %d", node, j)); 93 } 94 } 95} 96 97void 98SimpleNetwork::init() 99{ 100 Network::init(); 101 102 // The topology pointer should have already been initialized in 103 // the parent class network constructor. 104 assert(m_topology_ptr != NULL); 105 int number_of_switches = m_topology_ptr->numSwitches(); 106 for (int i = 0; i < number_of_switches; i++) { 107 m_switch_ptr_vector.push_back(new Switch(i, this)); 108 } 109 110 // false because this isn't a reconfiguration 111 m_topology_ptr->createLinks(this, false); 112} 113 114void 115SimpleNetwork::reset() 116{ 117 for (int node = 0; node < m_nodes; node++) { 118 for (int j = 0; j < m_virtual_networks; j++) { 119 m_toNetQueues[node][j]->clear(); 120 m_fromNetQueues[node][j]->clear(); 121 } 122 } 123 124 for(int i = 0; i < m_switch_ptr_vector.size(); i++){ 125 m_switch_ptr_vector[i]->clearBuffers(); 126 } 127} 128 129SimpleNetwork::~SimpleNetwork() 130{ 131 for (int i = 0; i < m_nodes; i++) { 132 deletePointers(m_toNetQueues[i]); 133 deletePointers(m_fromNetQueues[i]); 134 } 135 deletePointers(m_switch_ptr_vector); 136 deletePointers(m_buffers_to_free); 137 // delete m_topology_ptr; 138} 139 140// From a switch to an endpoint node 141void 142SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, BasicLink* link, 143 LinkDirection direction, 144 const NetDest& routing_table_entry, 145 bool isReconfiguration) 146{ 147 assert(dest < m_nodes); 148 assert(src < m_switch_ptr_vector.size()); 149 assert(m_switch_ptr_vector[src] != NULL); 150 151 if (isReconfiguration) { 152 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 153 return; 154 } 155 156 SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link); 157 158 m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], 159 routing_table_entry, 160 simple_link->m_latency, 161 simple_link->m_bw_multiplier); 162 163 m_endpoint_switches[dest] = m_switch_ptr_vector[src]; 164} 165 166// From an endpoint node to a switch 167void 168SimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link, 169 LinkDirection direction, 170 const NetDest& routing_table_entry, 171 bool isReconfiguration) 172{ 173 assert(src < m_nodes); 174 if (isReconfiguration) { 175 // do nothing 176 return; 177 } 178 179 m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]); 180} 181 182// From a switch to a switch 183void 184SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 185 LinkDirection direction, 186 const NetDest& routing_table_entry, 187 bool isReconfiguration) 188{ 189 if (isReconfiguration) { 190 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry); 191 return; 192 } 193 194 // Create a set of new MessageBuffers 195 std::vector<MessageBuffer*> queues; 196 for (int i = 0; i < m_virtual_networks; i++) { 197 // allocate a buffer 198 MessageBuffer* buffer_ptr = new MessageBuffer; 199 buffer_ptr->setOrdering(true); 200 if (m_buffer_size > 0) { 201 buffer_ptr->resize(m_buffer_size); 202 } 203 queues.push_back(buffer_ptr); 204 // remember to deallocate it 205 m_buffers_to_free.push_back(buffer_ptr); 206 } 207 // Connect it to the two switches 208 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link); 209 210 m_switch_ptr_vector[dest]->addInPort(queues); 211 m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, 212 simple_link->m_latency, 213 simple_link->m_bw_multiplier); 214} 215 216void 217SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num) 218{ 219 assert(id < m_nodes); 220 assert(network_num < m_virtual_networks); 221 222 if (ordered) { 223 m_ordered[network_num] = true; 224 } 225 m_in_use[network_num] = true; 226} 227 228MessageBuffer*
|