SimpleNetwork.cc (7056:b66b558578bd) SimpleNetwork.cc (7454:3a3e8e8cce1b)
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
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"
29#include "mem/gems_common/Map.hh"
30#include "mem/protocol/MachineType.hh"
31#include "mem/protocol/Protocol.hh"
32#include "mem/protocol/TopologyType.hh"
33#include "mem/ruby/buffers/MessageBuffer.hh"
34#include "mem/ruby/common/NetDest.hh"
35#include "mem/ruby/network/simple/SimpleNetwork.hh"
36#include "mem/ruby/network/simple/Switch.hh"
37#include "mem/ruby/network/simple/Topology.hh"
38#include "mem/ruby/profiler/Profiler.hh"
39#include "mem/ruby/system/System.hh"
40
41using namespace std;
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;
42
43#if 0
44// ***BIG HACK*** - This is actually code that _should_ be in Network.cc
45
46// Note: Moved to Princeton Network
47// calls new to abstract away from the network
48Network*
49Network::createNetwork(int nodes)
50{
51 return new SimpleNetwork(nodes);
52}
53#endif
54
55SimpleNetwork::SimpleNetwork(const Params *p)
56 : Network(p)
57{
58 // Note: the parent Network Object constructor is called before the
59 // SimpleNetwork child constructor. Therefore, the member variables
60 // used below should already be initialized.
61
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
62 m_endpoint_switches.setSize(m_nodes);
64 m_endpoint_switches.resize(m_nodes);
63
65
64 m_in_use.setSize(m_virtual_networks);
65 m_ordered.setSize(m_virtual_networks);
66 m_in_use.resize(m_virtual_networks);
67 m_ordered.resize(m_virtual_networks);
66 for (int i = 0; i < m_virtual_networks; i++) {
67 m_in_use[i] = false;
68 m_ordered[i] = false;
69 }
70
71 // Allocate to and from queues
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
72 m_toNetQueues.setSize(m_nodes);
73 m_fromNetQueues.setSize(m_nodes);
74 m_toNetQueues.resize(m_nodes);
75 m_fromNetQueues.resize(m_nodes);
74 for (int node = 0; node < m_nodes; node++) {
76 for (int node = 0; node < m_nodes; node++) {
75 m_toNetQueues[node].setSize(m_virtual_networks);
76 m_fromNetQueues[node].setSize(m_virtual_networks);
77 m_toNetQueues[node].resize(m_virtual_networks);
78 m_fromNetQueues[node].resize(m_virtual_networks);
77 for (int j = 0; j < m_virtual_networks; j++) {
78 m_toNetQueues[node][j] =
79 new MessageBuffer(csprintf("toNet node %d j %d", node, j));
80 m_fromNetQueues[node][j] =
81 new MessageBuffer(csprintf("fromNet node %d j %d", node, j));
82 }
83 }
84}
85
86void
87SimpleNetwork::init()
88{
89 Network::init();
90
91 // The topology pointer should have already been initialized in
92 // the parent class network constructor.
93 assert(m_topology_ptr != NULL);
94 int number_of_switches = m_topology_ptr->numSwitches();
95 for (int i = 0; i < number_of_switches; i++) {
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++) {
96 m_switch_ptr_vector.insertAtBottom(new Switch(i, this));
98 m_switch_ptr_vector.push_back(new Switch(i, this));
97 }
98
99 // false because this isn't a reconfiguration
100 m_topology_ptr->createLinks(this, false);
101}
102
103void
104SimpleNetwork::reset()
105{
106 for (int node = 0; node < m_nodes; node++) {
107 for (int j = 0; j < m_virtual_networks; j++) {
108 m_toNetQueues[node][j]->clear();
109 m_fromNetQueues[node][j]->clear();
110 }
111 }
112
113 for(int i = 0; i < m_switch_ptr_vector.size(); i++){
114 m_switch_ptr_vector[i]->clearBuffers();
115 }
116}
117
118SimpleNetwork::~SimpleNetwork()
119{
120 for (int i = 0; i < m_nodes; i++) {
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++) {
121 m_toNetQueues[i].deletePointers();
122 m_fromNetQueues[i].deletePointers();
123 deletePointers(m_toNetQueues[i]);
124 deletePointers(m_fromNetQueues[i]);
123 }
125 }
124 m_switch_ptr_vector.deletePointers();
125 m_buffers_to_free.deletePointers();
126 deletePointers(m_switch_ptr_vector);
127 deletePointers(m_buffers_to_free);
126 // delete m_topology_ptr;
127}
128
129// From a switch to an endpoint node
130void
131SimpleNetwork::makeOutLink(SwitchID src, NodeID dest,
132 const NetDest& routing_table_entry, int link_latency, int link_weight,
133 int bw_multiplier, bool isReconfiguration)
134{
135 assert(dest < m_nodes);
136 assert(src < m_switch_ptr_vector.size());
137 assert(m_switch_ptr_vector[src] != NULL);
138
139 if (isReconfiguration) {
140 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
141 return;
142 }
143
144 m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest],
145 routing_table_entry, link_latency, bw_multiplier);
146 m_endpoint_switches[dest] = m_switch_ptr_vector[src];
147}
148
149// From an endpoint node to a switch
150void
151SimpleNetwork::makeInLink(NodeID src, SwitchID dest,
152 const NetDest& routing_table_entry, int link_latency, int bw_multiplier,
153 bool isReconfiguration)
154{
155 assert(src < m_nodes);
156 if (isReconfiguration) {
157 // do nothing
158 return;
159 }
160
161 m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]);
162}
163
164// From a switch to a switch
165void
166SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest,
167 const NetDest& routing_table_entry, int link_latency, int link_weight,
168 int bw_multiplier, bool isReconfiguration)
169{
170 if (isReconfiguration) {
171 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
172 return;
173 }
174
175 // Create a set of new MessageBuffers
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
176 Vector<MessageBuffer*> queues;
178 std::vector<MessageBuffer*> queues;
177 for (int i = 0; i < m_virtual_networks; i++) {
178 // allocate a buffer
179 MessageBuffer* buffer_ptr = new MessageBuffer;
180 buffer_ptr->setOrdering(true);
181 if (m_buffer_size > 0) {
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) {
182 buffer_ptr->setSize(m_buffer_size);
184 buffer_ptr->resize(m_buffer_size);
183 }
185 }
184 queues.insertAtBottom(buffer_ptr);
186 queues.push_back(buffer_ptr);
185 // remember to deallocate it
187 // remember to deallocate it
186 m_buffers_to_free.insertAtBottom(buffer_ptr);
188 m_buffers_to_free.push_back(buffer_ptr);
187 }
188 // Connect it to the two switches
189 m_switch_ptr_vector[dest]->addInPort(queues);
190 m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry,
191 link_latency, bw_multiplier);
192}
193
194void
195SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
196{
197 ASSERT(id < m_nodes);
198 ASSERT(network_num < m_virtual_networks);
199
200 if (ordered) {
201 m_ordered[network_num] = true;
202 }
203 m_in_use[network_num] = true;
204}
205
206MessageBuffer*
207SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num)
208{
209 checkNetworkAllocation(id, ordered, network_num);
210 return m_toNetQueues[id][network_num];
211}
212
213MessageBuffer*
214SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num)
215{
216 checkNetworkAllocation(id, ordered, network_num);
217 return m_fromNetQueues[id][network_num];
218}
219
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
220const Vector<Throttle*>*
222const std::vector<Throttle*>*
221SimpleNetwork::getThrottles(NodeID id) const
222{
223 assert(id >= 0);
224 assert(id < m_nodes);
225 assert(m_endpoint_switches[id] != NULL);
226 return m_endpoint_switches[id]->getThrottles();
227}
228
229void
230SimpleNetwork::printStats(ostream& out) const
231{
232 out << endl;
233 out << "Network Stats" << endl;
234 out << "-------------" << endl;
235 out << endl;
236 for (int i = 0; i < m_switch_ptr_vector.size(); i++) {
237 m_switch_ptr_vector[i]->printStats(out);
238 }
239 m_topology_ptr->printStats(out);
240}
241
242void
243SimpleNetwork::clearStats()
244{
245 for (int i = 0; i < m_switch_ptr_vector.size(); i++) {
246 m_switch_ptr_vector[i]->clearStats();
247 }
248 m_topology_ptr->clearStats();
249}
250
251void
252SimpleNetwork::printConfig(ostream& out) const
253{
254 out << endl;
255 out << "Network Configuration" << endl;
256 out << "---------------------" << endl;
257 out << "network: SIMPLE_NETWORK" << endl;
258 out << "topology: " << m_topology_ptr->getName() << endl;
259 out << endl;
260
261 for (int i = 0; i < m_virtual_networks; i++) {
262 out << "virtual_net_" << i << ": ";
263 if (m_in_use[i]) {
264 out << "active, ";
265 if (m_ordered[i]) {
266 out << "ordered" << endl;
267 } else {
268 out << "unordered" << endl;
269 }
270 } else {
271 out << "inactive" << endl;
272 }
273 }
274 out << endl;
275
276 for(int i = 0; i < m_switch_ptr_vector.size(); i++) {
277 m_switch_ptr_vector[i]->printConfig(out);
278 }
279
280 m_topology_ptr->printConfig(out);
281}
282
283void
284SimpleNetwork::print(ostream& out) const
285{
286 out << "[SimpleNetwork]";
287}
288
289
290SimpleNetwork *
291SimpleNetworkParams::create()
292{
293 return new SimpleNetwork(this);
294}
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}