Topology.cc (8255:73089f793a0a) | Topology.cc (8257:7226aebb77b4) |
---|---|
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; --- 19 unchanged lines hidden (view full) --- 28 29#include <cassert> 30 31#include "debug/RubyNetwork.hh" 32#include "mem/protocol/MachineType.hh" 33#include "mem/protocol/Protocol.hh" 34#include "mem/protocol/TopologyType.hh" 35#include "mem/ruby/common/NetDest.hh" | 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; --- 19 unchanged lines hidden (view full) --- 28 29#include <cassert> 30 31#include "debug/RubyNetwork.hh" 32#include "mem/protocol/MachineType.hh" 33#include "mem/protocol/Protocol.hh" 34#include "mem/protocol/TopologyType.hh" 35#include "mem/ruby/common/NetDest.hh" |
36#include "mem/ruby/network/BasicLink.hh" 37#include "mem/ruby/network/BasicRouter.hh" |
|
36#include "mem/ruby/network/Network.hh" 37#include "mem/ruby/network/Topology.hh" 38#include "mem/ruby/slicc_interface/AbstractController.hh" 39#include "mem/ruby/system/System.hh" 40 41using namespace std; 42 43const int INFINITE_LATENCY = 10000; // Yes, this is a big hack | 38#include "mem/ruby/network/Network.hh" 39#include "mem/ruby/network/Topology.hh" 40#include "mem/ruby/slicc_interface/AbstractController.hh" 41#include "mem/ruby/system/System.hh" 42 43using namespace std; 44 45const int INFINITE_LATENCY = 10000; // Yes, this is a big hack |
44const int DEFAULT_BW_MULTIPLIER = 1; // Just to be consistent with above :) | |
45 | 46 |
47class BasicRouter; 48 |
|
46// Note: In this file, we use the first 2*m_nodes SwitchIDs to 47// represent the input and output endpoint links. These really are 48// not 'switches', as they will not have a Switch object allocated for 49// them. The first m_nodes SwitchIDs are the links into the network, 50// the second m_nodes set of SwitchIDs represent the the output queues 51// of the network. 52 53// Helper functions based on chapter 29 of Cormen et al. --- 5 unchanged lines hidden (view full) --- 59 SwitchID final, const Matrix& weights, const Matrix& dist); 60NetDest shortest_path_to_node(SwitchID src, SwitchID next, 61 const Matrix& weights, const Matrix& dist); 62 63Topology::Topology(const Params *p) 64 : SimObject(p) 65{ 66 m_print_config = p->print_config; | 49// Note: In this file, we use the first 2*m_nodes SwitchIDs to 50// represent the input and output endpoint links. These really are 51// not 'switches', as they will not have a Switch object allocated for 52// them. The first m_nodes SwitchIDs are the links into the network, 53// the second m_nodes set of SwitchIDs represent the the output queues 54// of the network. 55 56// Helper functions based on chapter 29 of Cormen et al. --- 5 unchanged lines hidden (view full) --- 62 SwitchID final, const Matrix& weights, const Matrix& dist); 63NetDest shortest_path_to_node(SwitchID src, SwitchID next, 64 const Matrix& weights, const Matrix& dist); 65 66Topology::Topology(const Params *p) 67 : SimObject(p) 68{ 69 m_print_config = p->print_config; |
67 m_number_of_switches = p->num_int_nodes; | 70 m_number_of_switches = p->routers.size(); 71 |
68 // initialize component latencies record 69 m_component_latencies.resize(0); 70 m_component_inter_switches.resize(0); 71 72 // Total nodes/controllers in network 73 // Must make sure this is called after the State Machine constructors 74 m_nodes = MachineType_base_number(MachineType_NUM); 75 assert(m_nodes > 1); 76 77 if (m_nodes != params()->ext_links.size() && 78 m_nodes != params()->ext_links.size()) { 79 fatal("m_nodes (%d) != ext_links vector length (%d)\n", | 72 // initialize component latencies record 73 m_component_latencies.resize(0); 74 m_component_inter_switches.resize(0); 75 76 // Total nodes/controllers in network 77 // Must make sure this is called after the State Machine constructors 78 m_nodes = MachineType_base_number(MachineType_NUM); 79 assert(m_nodes > 1); 80 81 if (m_nodes != params()->ext_links.size() && 82 m_nodes != params()->ext_links.size()) { 83 fatal("m_nodes (%d) != ext_links vector length (%d)\n", |
80 m_nodes != params()->ext_links.size()); | 84 m_nodes != params()->ext_links.size()); |
81 } 82 | 85 } 86 |
83 // First create the links between the endpoints (i.e. controllers) 84 // and the network. 85 for (vector<ExtLink*>::const_iterator i = params()->ext_links.begin(); | 87 // analyze both the internal and external links, create data structures 88 // Note that the python created links are bi-directional, but that the 89 // topology and networks utilize uni-directional links. Thus each 90 // BasicLink is converted to two calls to add link, on for each direction 91 for (vector<BasicExtLink*>::const_iterator i = params()->ext_links.begin(); |
86 i != params()->ext_links.end(); ++i) { | 92 i != params()->ext_links.end(); ++i) { |
87 const ExtLinkParams *p = (*i)->params(); 88 AbstractController *c = p->ext_node; | 93 BasicExtLink *ext_link = (*i); 94 AbstractController *abs_cntrl = ext_link->params()->ext_node; 95 BasicRouter *router = ext_link->params()->int_node; |
89 | 96 |
90 // Store the controller pointers for later 91 m_controller_vector.push_back(c); | 97 // Store the controller and ExtLink pointers for later 98 m_controller_vector.push_back(abs_cntrl); 99 m_ext_link_vector.push_back(ext_link); |
92 | 100 |
93 int ext_idx1 = 94 MachineType_base_number(c->getMachineType()) + c->getVersion(); | 101 int ext_idx1 = abs_cntrl->params()->cntrl_id; |
95 int ext_idx2 = ext_idx1 + m_nodes; | 102 int ext_idx2 = ext_idx1 + m_nodes; |
96 int int_idx = p->int_node + 2*m_nodes; | 103 int int_idx = router->params()->router_id + 2*m_nodes; |
97 | 104 |
98 // create the links in both directions 99 addLink(ext_idx1, int_idx, p->latency, p->bw_multiplier, p->weight); 100 addLink(int_idx, ext_idx2, p->latency, p->bw_multiplier, p->weight); | 105 // create the internal uni-directional links in both directions 106 // the first direction is marked: In 107 addLink(ext_idx1, int_idx, ext_link, LinkDirection_In); 108 // the first direction is marked: Out 109 addLink(int_idx, ext_idx2, ext_link, LinkDirection_Out); |
101 } 102 | 110 } 111 |
103 for (vector | 112 for (vector<BasicIntLink*>::const_iterator i = params()->int_links.begin(); |
104 i != params()->int_links.end(); ++i) { | 113 i != params()->int_links.end(); ++i) { |
105 const IntLinkParams *p = (*i)->params(); 106 int a = p->node_a + 2*m_nodes; 107 int b = p->node_b + 2*m_nodes; | 114 BasicIntLink *int_link = (*i); 115 BasicRouter *router_a = int_link->params()->node_a; 116 BasicRouter *router_b = int_link->params()->node_b; |
108 | 117 |
109 // create the links in both directions 110 addLink(a, b, p->latency, p->bw_multiplier, p->weight); 111 addLink(b, a, p->latency, p->bw_multiplier, p->weight); | 118 // Store the IntLink pointers for later 119 m_int_link_vector.push_back(int_link); 120 121 int a = router_a->params()->router_id + 2*m_nodes; 122 int b = router_b->params()->router_id + 2*m_nodes; 123 124 // create the internal uni-directional links in both directions 125 // the first direction is marked: In 126 addLink(a, b, int_link, LinkDirection_In); 127 // the second direction is marked: Out 128 addLink(b, a, int_link, LinkDirection_Out); |
112 } 113} 114 | 129 } 130} 131 |
132void 133Topology::init() 134{ 135} |
|
115 | 136 |
137 |
|
116void 117Topology::initNetworkPtr(Network* net_ptr) 118{ | 138void 139Topology::initNetworkPtr(Network* net_ptr) 140{ |
119 for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) { 120 m_controller_vector[cntrl]->initNetworkPtr(net_ptr); | 141 for (vector<BasicExtLink*>::const_iterator i = params()->ext_links.begin(); 142 i != params()->ext_links.end(); ++i) { 143 BasicExtLink *ext_link = (*i); 144 AbstractController *abs_cntrl = ext_link->params()->ext_node; 145 abs_cntrl->initNetworkPtr(net_ptr); |
121 } 122} 123 124void 125Topology::createLinks(Network *net, bool isReconfiguration) 126{ 127 // Find maximum switchID 128 SwitchID max_switch_id = 0; | 146 } 147} 148 149void 150Topology::createLinks(Network *net, bool isReconfiguration) 151{ 152 // Find maximum switchID 153 SwitchID max_switch_id = 0; |
129 for (int i = 0; i < m_links_src_vector.size(); i++) { 130 max_switch_id = max(max_switch_id, m_links_src_vector[i]); 131 max_switch_id = max(max_switch_id, m_links_dest_vector[i]); | 154 for (LinkMap::const_iterator i = m_link_map.begin(); 155 i != m_link_map.end(); ++i) { 156 std::pair<int, int> src_dest = (*i).first; 157 max_switch_id = max(max_switch_id, src_dest.first); 158 max_switch_id = max(max_switch_id, src_dest.second); |
132 } 133 | 159 } 160 |
134 // Initialize weight vector | 161 // Initialize weight, latency, and inter switched vectors |
135 Matrix topology_weights; | 162 Matrix topology_weights; |
136 Matrix topology_latency; 137 Matrix topology_bw_multis; | |
138 int num_switches = max_switch_id+1; 139 topology_weights.resize(num_switches); | 163 int num_switches = max_switch_id+1; 164 topology_weights.resize(num_switches); |
140 topology_latency.resize(num_switches); 141 topology_bw_multis.resize(num_switches); 142 143 // FIXME setting the size of a member variable here is a HACK! | |
144 m_component_latencies.resize(num_switches); | 165 m_component_latencies.resize(num_switches); |
145 146 // FIXME setting the size of a member variable here is a HACK! | |
147 m_component_inter_switches.resize(num_switches); 148 149 for (int i = 0; i < topology_weights.size(); i++) { 150 topology_weights[i].resize(num_switches); | 166 m_component_inter_switches.resize(num_switches); 167 168 for (int i = 0; i < topology_weights.size(); i++) { 169 topology_weights[i].resize(num_switches); |
151 topology_latency[i].resize(num_switches); 152 topology_bw_multis[i].resize(num_switches); | |
153 m_component_latencies[i].resize(num_switches); | 170 m_component_latencies[i].resize(num_switches); |
154 155 // FIXME setting the size of a member variable here is a HACK! | |
156 m_component_inter_switches[i].resize(num_switches); 157 158 for (int j = 0; j < topology_weights[i].size(); j++) { 159 topology_weights[i][j] = INFINITE_LATENCY; 160 161 // initialize to invalid values | 171 m_component_inter_switches[i].resize(num_switches); 172 173 for (int j = 0; j < topology_weights[i].size(); j++) { 174 topology_weights[i][j] = INFINITE_LATENCY; 175 176 // initialize to invalid values |
162 topology_latency[i][j] = -1; 163 topology_bw_multis[i][j] = -1; | |
164 m_component_latencies[i][j] = -1; 165 166 // initially assume direct connections / no intermediate 167 // switches between components 168 m_component_inter_switches[i][j] = 0; 169 } 170 } 171 172 // Set identity weights to zero 173 for (int i = 0; i < topology_weights.size(); i++) { 174 topology_weights[i][i] = 0; 175 } 176 177 // Fill in the topology weights and bandwidth multipliers | 177 m_component_latencies[i][j] = -1; 178 179 // initially assume direct connections / no intermediate 180 // switches between components 181 m_component_inter_switches[i][j] = 0; 182 } 183 } 184 185 // Set identity weights to zero 186 for (int i = 0; i < topology_weights.size(); i++) { 187 topology_weights[i][i] = 0; 188 } 189 190 // Fill in the topology weights and bandwidth multipliers |
178 for (int i = 0; i < m_links_src_vector.size(); i++) { 179 int src = m_links_src_vector[i]; 180 int dst = m_links_dest_vector[i]; 181 topology_weights[src][dst] = m_links_weight_vector[i]; 182 topology_latency[src][dst] = m_links_latency_vector[i]; 183 m_component_latencies[src][dst] = m_links_latency_vector[i]; 184 topology_bw_multis[src][dst] = m_bw_multiplier_vector[i]; | 191 for (LinkMap::const_iterator i = m_link_map.begin(); 192 i != m_link_map.end(); ++i) { 193 std::pair<int, int> src_dest = (*i).first; 194 BasicLink* link = (*i).second.link; 195 int src = src_dest.first; 196 int dst = src_dest.second; 197 m_component_latencies[src][dst] = link->m_latency; 198 topology_weights[src][dst] = link->m_weight; |
185 } | 199 } |
186 | 200 |
187 // Walk topology and hookup the links 188 Matrix dist = shortest_path(topology_weights, m_component_latencies, 189 m_component_inter_switches); 190 for (int i = 0; i < topology_weights.size(); i++) { 191 for (int j = 0; j < topology_weights[i].size(); j++) { 192 int weight = topology_weights[i][j]; | 201 // Walk topology and hookup the links 202 Matrix dist = shortest_path(topology_weights, m_component_latencies, 203 m_component_inter_switches); 204 for (int i = 0; i < topology_weights.size(); i++) { 205 for (int j = 0; j < topology_weights[i].size(); j++) { 206 int weight = topology_weights[i][j]; |
193 int bw_multiplier = topology_bw_multis[i][j]; 194 int latency = topology_latency[i][j]; | |
195 if (weight > 0 && weight != INFINITE_LATENCY) { 196 NetDest destination_set = shortest_path_to_node(i, j, | 207 if (weight > 0 && weight != INFINITE_LATENCY) { 208 NetDest destination_set = shortest_path_to_node(i, j, |
197 topology_weights, dist); 198 assert(latency != -1); 199 makeLink(net, i, j, destination_set, latency, weight, 200 bw_multiplier, isReconfiguration); | 209 topology_weights, dist); 210 makeLink(net, i, j, destination_set, isReconfiguration); |
201 } 202 } 203 } 204} 205 | 211 } 212 } 213 } 214} 215 |
206SwitchID 207Topology::newSwitchID() 208{ 209 m_number_of_switches++; 210 return m_number_of_switches-1+m_nodes+m_nodes; 211} 212 | |
213void | 216void |
214Topology::addLink(SwitchID src, SwitchID dest, int link_latency) | 217Topology::addLink(SwitchID src, SwitchID dest, BasicLink* link, 218 LinkDirection dir) |
215{ | 219{ |
216 addLink(src, dest, link_latency, DEFAULT_BW_MULTIPLIER, link_latency); 217} 218 219void 220Topology::addLink(SwitchID src, SwitchID dest, int link_latency, 221 int bw_multiplier) 222{ 223 addLink(src, dest, link_latency, bw_multiplier, link_latency); 224} 225 226void 227Topology::addLink(SwitchID src, SwitchID dest, int link_latency, 228 int bw_multiplier, int link_weight) 229{ | |
230 assert(src <= m_number_of_switches+m_nodes+m_nodes); 231 assert(dest <= m_number_of_switches+m_nodes+m_nodes); | 220 assert(src <= m_number_of_switches+m_nodes+m_nodes); 221 assert(dest <= m_number_of_switches+m_nodes+m_nodes); |
232 m_links_src_vector.push_back(src); 233 m_links_dest_vector.push_back(dest); 234 m_links_latency_vector.push_back(link_latency); 235 m_links_weight_vector.push_back(link_weight); 236 m_bw_multiplier_vector.push_back(bw_multiplier); | 222 223 std::pair<int, int> src_dest_pair; 224 LinkEntry link_entry; 225 226 src_dest_pair.first = src; 227 src_dest_pair.second = dest; 228 link_entry.direction = dir; 229 link_entry.link = link; 230 m_link_map[src_dest_pair] = link_entry; |
237} 238 239void 240Topology::makeLink(Network *net, SwitchID src, SwitchID dest, | 231} 232 233void 234Topology::makeLink(Network *net, SwitchID src, SwitchID dest, |
241 const NetDest& routing_table_entry, int link_latency, int link_weight, 242 int bw_multiplier, bool isReconfiguration) | 235 const NetDest& routing_table_entry, bool isReconfiguration) |
243{ 244 // Make sure we're not trying to connect two end-point nodes 245 // directly together 246 assert(src >= 2 * m_nodes || dest >= 2 * m_nodes); 247 | 236{ 237 // Make sure we're not trying to connect two end-point nodes 238 // directly together 239 assert(src >= 2 * m_nodes || dest >= 2 * m_nodes); 240 |
241 std::pair<int, int> src_dest; 242 LinkEntry link_entry; 243 |
|
248 if (src < m_nodes) { | 244 if (src < m_nodes) { |
249 net->makeInLink(src, dest-(2*m_nodes), routing_table_entry, 250 link_latency, bw_multiplier, isReconfiguration); | 245 src_dest.first = src; 246 src_dest.second = dest; 247 link_entry = m_link_map[src_dest]; 248 net->makeInLink(src, dest - (2 * m_nodes), link_entry.link, 249 link_entry.direction, 250 routing_table_entry, 251 isReconfiguration); |
251 } else if (dest < 2*m_nodes) { 252 assert(dest >= m_nodes); | 252 } else if (dest < 2*m_nodes) { 253 assert(dest >= m_nodes); |
253 NodeID node = dest-m_nodes; 254 net->makeOutLink(src-(2*m_nodes), node, routing_table_entry, 255 link_latency, link_weight, bw_multiplier, isReconfiguration); | 254 NodeID node = dest - m_nodes; 255 src_dest.first = src; 256 src_dest.second = dest; 257 link_entry = m_link_map[src_dest]; 258 net->makeOutLink(src - (2 * m_nodes), node, link_entry.link, 259 link_entry.direction, 260 routing_table_entry, 261 isReconfiguration); |
256 } else { | 262 } else { |
257 assert((src >= 2*m_nodes) && (dest >= 2*m_nodes)); 258 net->makeInternalLink(src-(2*m_nodes), dest-(2*m_nodes), 259 routing_table_entry, link_latency, link_weight, bw_multiplier, 260 isReconfiguration); | 263 assert((src >= 2 * m_nodes) && (dest >= 2 * m_nodes)); 264 src_dest.first = src; 265 src_dest.second = dest; 266 link_entry = m_link_map[src_dest]; 267 net->makeInternalLink(src - (2 * m_nodes), dest - (2 * m_nodes), 268 link_entry.link, link_entry.direction, 269 routing_table_entry, isReconfiguration); |
261 } 262} 263 264void 265Topology::printStats(std::ostream& out) const 266{ 267 for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) { 268 m_controller_vector[cntrl]->printStats(out); --- 149 unchanged lines hidden (view full) --- 418} 419 420Topology * 421TopologyParams::create() 422{ 423 return new Topology(this); 424} 425 | 270 } 271} 272 273void 274Topology::printStats(std::ostream& out) const 275{ 276 for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) { 277 m_controller_vector[cntrl]->printStats(out); --- 149 unchanged lines hidden (view full) --- 427} 428 429Topology * 430TopologyParams::create() 431{ 432 return new Topology(this); 433} 434 |
426Link * 427LinkParams::create() 428{ 429 return new Link(this); 430} 431 432ExtLink * 433ExtLinkParams::create() 434{ 435 return new ExtLink(this); 436} 437 438IntLink * 439IntLinkParams::create() 440{ 441 return new IntLink(this); 442} | |