Deleted Added
sdiff udiff text old ( 8255:73089f793a0a ) new ( 8257:7226aebb77b4 )
full compact
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/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
44const int DEFAULT_BW_MULTIPLIER = 1; // Just to be consistent with above :)
45
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;
67 m_number_of_switches = p->num_int_nodes;
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",
80 m_nodes != params()->ext_links.size());
81 }
82
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();
86 i != params()->ext_links.end(); ++i) {
87 const ExtLinkParams *p = (*i)->params();
88 AbstractController *c = p->ext_node;
89
90 // Store the controller pointers for later
91 m_controller_vector.push_back(c);
92
93 int ext_idx1 =
94 MachineType_base_number(c->getMachineType()) + c->getVersion();
95 int ext_idx2 = ext_idx1 + m_nodes;
96 int int_idx = p->int_node + 2*m_nodes;
97
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);
101 }
102
103 for (vector::const_iterator i = params()->int_links.begin();
104 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;
108
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);
112 }
113}
114
115
116void
117Topology::initNetworkPtr(Network* net_ptr)
118{
119 for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) {
120 m_controller_vector[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;
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]);
132 }
133
134 // Initialize weight vector
135 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);
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);
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);
151 topology_latency[i].resize(num_switches);
152 topology_bw_multis[i].resize(num_switches);
153 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
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
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];
185 }
186
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];
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,
197 topology_weights, dist);
198 assert(latency != -1);
199 makeLink(net, i, j, destination_set, latency, weight,
200 bw_multiplier, isReconfiguration);
201 }
202 }
203 }
204}
205
206SwitchID
207Topology::newSwitchID()
208{
209 m_number_of_switches++;
210 return m_number_of_switches-1+m_nodes+m_nodes;
211}
212
213void
214Topology::addLink(SwitchID src, SwitchID dest, int link_latency)
215{
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);
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);
237}
238
239void
240Topology::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)
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
248 if (src < m_nodes) {
249 net->makeInLink(src, dest-(2*m_nodes), routing_table_entry,
250 link_latency, bw_multiplier, isReconfiguration);
251 } else if (dest < 2*m_nodes) {
252 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);
256 } 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);
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
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}