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