SimpleNetwork.cc (6795:394bc95d417b) SimpleNetwork.cc (6876:a658c315512c)
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * SimpleNetwork.cc
32 *
33 * Description: See SimpleNetwork.hh
34 *
35 * $Id$
36 *
37 */
38
39#include "mem/ruby/network/simple/SimpleNetwork.hh"
40#include "mem/ruby/profiler/Profiler.hh"
41#include "mem/ruby/system/System.hh"
42#include "mem/ruby/network/simple/Switch.hh"
43#include "mem/ruby/common/NetDest.hh"
44#include "mem/ruby/network/simple/Topology.hh"
45#include "mem/protocol/TopologyType.hh"
46#include "mem/protocol/MachineType.hh"
47#include "mem/ruby/buffers/MessageBuffer.hh"
48#include "mem/protocol/Protocol.hh"
49#include "mem/gems_common/Map.hh"
50
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
55/*
56Network* Network::createNetwork(int nodes)
57{
58 return new SimpleNetwork(nodes);
59}
60*/
61
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * SimpleNetwork.cc
32 *
33 * Description: See SimpleNetwork.hh
34 *
35 * $Id$
36 *
37 */
38
39#include "mem/ruby/network/simple/SimpleNetwork.hh"
40#include "mem/ruby/profiler/Profiler.hh"
41#include "mem/ruby/system/System.hh"
42#include "mem/ruby/network/simple/Switch.hh"
43#include "mem/ruby/common/NetDest.hh"
44#include "mem/ruby/network/simple/Topology.hh"
45#include "mem/protocol/TopologyType.hh"
46#include "mem/protocol/MachineType.hh"
47#include "mem/ruby/buffers/MessageBuffer.hh"
48#include "mem/protocol/Protocol.hh"
49#include "mem/gems_common/Map.hh"
50
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
55/*
56Network* Network::createNetwork(int nodes)
57{
58 return new SimpleNetwork(nodes);
59}
60*/
61
62SimpleNetwork::SimpleNetwork(const string & name)
63 : Network(name)
62SimpleNetwork::SimpleNetwork(const Params *p)
63 : Network(p)
64{
65 m_virtual_networks = 0;
66 m_topology_ptr = NULL;
67}
68
64{
65 m_virtual_networks = 0;
66 m_topology_ptr = NULL;
67}
68
69void SimpleNetwork::init(const vector<string> & argv)
69void SimpleNetwork::init()
70{
71
70{
71
72 Network::init(argv);
72 Network::init();
73
74 m_endpoint_switches.setSize(m_nodes);
75
76 m_in_use.setSize(m_virtual_networks);
77 m_ordered.setSize(m_virtual_networks);
78 for (int i = 0; i < m_virtual_networks; i++) {
79 m_in_use[i] = false;
80 m_ordered[i] = false;
81 }
82
83 // Allocate to and from queues
84 m_toNetQueues.setSize(m_nodes);
85 m_fromNetQueues.setSize(m_nodes);
86 for (int node = 0; node < m_nodes; node++) {
87 m_toNetQueues[node].setSize(m_virtual_networks);
88 m_fromNetQueues[node].setSize(m_virtual_networks);
89 for (int j = 0; j < m_virtual_networks; j++) {
90 m_toNetQueues[node][j] = new MessageBuffer(
91 "toNet node "+int_to_string(node)+" j "+int_to_string(j));
92 m_fromNetQueues[node][j] = new MessageBuffer(
93 "fromNet node "+int_to_string(node)+" j "+int_to_string(j));
94 }
95 }
96
97 // Setup the network switches
98 // m_topology_ptr = new Topology(this, m_nodes);
99 m_topology_ptr->makeTopology();
100 int number_of_switches = m_topology_ptr->numSwitches();
101 for (int i=0; i<number_of_switches; i++) {
102 m_switch_ptr_vector.insertAtBottom(new Switch(i, this));
103 }
104 m_topology_ptr->createLinks(false); // false because this isn't a reconfiguration
105}
106
107void SimpleNetwork::reset()
108{
109 for (int node = 0; node < m_nodes; node++) {
110 for (int j = 0; j < m_virtual_networks; j++) {
111 m_toNetQueues[node][j]->clear();
112 m_fromNetQueues[node][j]->clear();
113 }
114 }
115
116 for(int i=0; i<m_switch_ptr_vector.size(); i++){
117 m_switch_ptr_vector[i]->clearBuffers();
118 }
119}
120
121SimpleNetwork::~SimpleNetwork()
122{
123 for (int i = 0; i < m_nodes; i++) {
124 m_toNetQueues[i].deletePointers();
125 m_fromNetQueues[i].deletePointers();
126 }
127 m_switch_ptr_vector.deletePointers();
128 m_buffers_to_free.deletePointers();
129 // delete m_topology_ptr;
130}
131
132// From a switch to an endpoint node
133void SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, 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 if(!isReconfiguration){
139 m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier);
140 m_endpoint_switches[dest] = m_switch_ptr_vector[src];
141 } else {
142 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
143 }
144}
145
146// From an endpoint node to a switch
147void SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration)
148{
149 assert(src < m_nodes);
150 if(!isReconfiguration){
151 m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]);
152 } else {
153 // do nothing
154 }
155}
156
157// From a switch to a switch
158void SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration)
159{
160 if(!isReconfiguration){
161 // Create a set of new MessageBuffers
162 Vector<MessageBuffer*> queues;
163 for (int i = 0; i < m_virtual_networks; i++) {
164 // allocate a buffer
165 MessageBuffer* buffer_ptr = new MessageBuffer;
166 buffer_ptr->setOrdering(true);
167 if (m_buffer_size > 0) {
168 buffer_ptr->setSize(m_buffer_size);
169 }
170 queues.insertAtBottom(buffer_ptr);
171 // remember to deallocate it
172 m_buffers_to_free.insertAtBottom(buffer_ptr);
173 }
174
175 // Connect it to the two switches
176 m_switch_ptr_vector[dest]->addInPort(queues);
177 m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier);
178 } else {
179 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
180 }
181}
182
183void SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
184{
185 ASSERT(id < m_nodes);
186 ASSERT(network_num < m_virtual_networks);
187
188 if (ordered) {
189 m_ordered[network_num] = true;
190 }
191 m_in_use[network_num] = true;
192}
193
194MessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num)
195{
196 checkNetworkAllocation(id, ordered, network_num);
197 return m_toNetQueues[id][network_num];
198}
199
200MessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num)
201{
202 checkNetworkAllocation(id, ordered, network_num);
203 return m_fromNetQueues[id][network_num];
204}
205
206const Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const
207{
208 assert(id >= 0);
209 assert(id < m_nodes);
210 assert(m_endpoint_switches[id] != NULL);
211 return m_endpoint_switches[id]->getThrottles();
212}
213
214void SimpleNetwork::printStats(ostream& out) const
215{
216 out << endl;
217 out << "Network Stats" << endl;
218 out << "-------------" << endl;
219 out << endl;
220 for(int i=0; i<m_switch_ptr_vector.size(); i++) {
221 m_switch_ptr_vector[i]->printStats(out);
222 }
223}
224
225void SimpleNetwork::clearStats()
226{
227 for(int i=0; i<m_switch_ptr_vector.size(); i++) {
228 m_switch_ptr_vector[i]->clearStats();
229 }
230}
231
232void SimpleNetwork::printConfig(ostream& out) const
233{
234 out << endl;
235 out << "Network Configuration" << endl;
236 out << "---------------------" << endl;
237 out << "network: SIMPLE_NETWORK" << endl;
238 out << "topology: " << m_topology_ptr->getName() << endl;
239 out << endl;
240
241 for (int i = 0; i < m_virtual_networks; i++) {
242 out << "virtual_net_" << i << ": ";
243 if (m_in_use[i]) {
244 out << "active, ";
245 if (m_ordered[i]) {
246 out << "ordered" << endl;
247 } else {
248 out << "unordered" << endl;
249 }
250 } else {
251 out << "inactive" << endl;
252 }
253 }
254 out << endl;
255 for(int i=0; i<m_switch_ptr_vector.size(); i++) {
256 m_switch_ptr_vector[i]->printConfig(out);
257 }
258
259 m_topology_ptr->printConfig(out);
260}
261
262void SimpleNetwork::print(ostream& out) const
263{
264 out << "[SimpleNetwork]";
265}
73
74 m_endpoint_switches.setSize(m_nodes);
75
76 m_in_use.setSize(m_virtual_networks);
77 m_ordered.setSize(m_virtual_networks);
78 for (int i = 0; i < m_virtual_networks; i++) {
79 m_in_use[i] = false;
80 m_ordered[i] = false;
81 }
82
83 // Allocate to and from queues
84 m_toNetQueues.setSize(m_nodes);
85 m_fromNetQueues.setSize(m_nodes);
86 for (int node = 0; node < m_nodes; node++) {
87 m_toNetQueues[node].setSize(m_virtual_networks);
88 m_fromNetQueues[node].setSize(m_virtual_networks);
89 for (int j = 0; j < m_virtual_networks; j++) {
90 m_toNetQueues[node][j] = new MessageBuffer(
91 "toNet node "+int_to_string(node)+" j "+int_to_string(j));
92 m_fromNetQueues[node][j] = new MessageBuffer(
93 "fromNet node "+int_to_string(node)+" j "+int_to_string(j));
94 }
95 }
96
97 // Setup the network switches
98 // m_topology_ptr = new Topology(this, m_nodes);
99 m_topology_ptr->makeTopology();
100 int number_of_switches = m_topology_ptr->numSwitches();
101 for (int i=0; i<number_of_switches; i++) {
102 m_switch_ptr_vector.insertAtBottom(new Switch(i, this));
103 }
104 m_topology_ptr->createLinks(false); // false because this isn't a reconfiguration
105}
106
107void SimpleNetwork::reset()
108{
109 for (int node = 0; node < m_nodes; node++) {
110 for (int j = 0; j < m_virtual_networks; j++) {
111 m_toNetQueues[node][j]->clear();
112 m_fromNetQueues[node][j]->clear();
113 }
114 }
115
116 for(int i=0; i<m_switch_ptr_vector.size(); i++){
117 m_switch_ptr_vector[i]->clearBuffers();
118 }
119}
120
121SimpleNetwork::~SimpleNetwork()
122{
123 for (int i = 0; i < m_nodes; i++) {
124 m_toNetQueues[i].deletePointers();
125 m_fromNetQueues[i].deletePointers();
126 }
127 m_switch_ptr_vector.deletePointers();
128 m_buffers_to_free.deletePointers();
129 // delete m_topology_ptr;
130}
131
132// From a switch to an endpoint node
133void SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, 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 if(!isReconfiguration){
139 m_switch_ptr_vector[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry, link_latency, bw_multiplier);
140 m_endpoint_switches[dest] = m_switch_ptr_vector[src];
141 } else {
142 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
143 }
144}
145
146// From an endpoint node to a switch
147void SimpleNetwork::makeInLink(NodeID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration)
148{
149 assert(src < m_nodes);
150 if(!isReconfiguration){
151 m_switch_ptr_vector[dest]->addInPort(m_toNetQueues[src]);
152 } else {
153 // do nothing
154 }
155}
156
157// From a switch to a switch
158void SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration)
159{
160 if(!isReconfiguration){
161 // Create a set of new MessageBuffers
162 Vector<MessageBuffer*> queues;
163 for (int i = 0; i < m_virtual_networks; i++) {
164 // allocate a buffer
165 MessageBuffer* buffer_ptr = new MessageBuffer;
166 buffer_ptr->setOrdering(true);
167 if (m_buffer_size > 0) {
168 buffer_ptr->setSize(m_buffer_size);
169 }
170 queues.insertAtBottom(buffer_ptr);
171 // remember to deallocate it
172 m_buffers_to_free.insertAtBottom(buffer_ptr);
173 }
174
175 // Connect it to the two switches
176 m_switch_ptr_vector[dest]->addInPort(queues);
177 m_switch_ptr_vector[src]->addOutPort(queues, routing_table_entry, link_latency, bw_multiplier);
178 } else {
179 m_switch_ptr_vector[src]->reconfigureOutPort(routing_table_entry);
180 }
181}
182
183void SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
184{
185 ASSERT(id < m_nodes);
186 ASSERT(network_num < m_virtual_networks);
187
188 if (ordered) {
189 m_ordered[network_num] = true;
190 }
191 m_in_use[network_num] = true;
192}
193
194MessageBuffer* SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num)
195{
196 checkNetworkAllocation(id, ordered, network_num);
197 return m_toNetQueues[id][network_num];
198}
199
200MessageBuffer* SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num)
201{
202 checkNetworkAllocation(id, ordered, network_num);
203 return m_fromNetQueues[id][network_num];
204}
205
206const Vector<Throttle*>* SimpleNetwork::getThrottles(NodeID id) const
207{
208 assert(id >= 0);
209 assert(id < m_nodes);
210 assert(m_endpoint_switches[id] != NULL);
211 return m_endpoint_switches[id]->getThrottles();
212}
213
214void SimpleNetwork::printStats(ostream& out) const
215{
216 out << endl;
217 out << "Network Stats" << endl;
218 out << "-------------" << endl;
219 out << endl;
220 for(int i=0; i<m_switch_ptr_vector.size(); i++) {
221 m_switch_ptr_vector[i]->printStats(out);
222 }
223}
224
225void SimpleNetwork::clearStats()
226{
227 for(int i=0; i<m_switch_ptr_vector.size(); i++) {
228 m_switch_ptr_vector[i]->clearStats();
229 }
230}
231
232void SimpleNetwork::printConfig(ostream& out) const
233{
234 out << endl;
235 out << "Network Configuration" << endl;
236 out << "---------------------" << endl;
237 out << "network: SIMPLE_NETWORK" << endl;
238 out << "topology: " << m_topology_ptr->getName() << endl;
239 out << endl;
240
241 for (int i = 0; i < m_virtual_networks; i++) {
242 out << "virtual_net_" << i << ": ";
243 if (m_in_use[i]) {
244 out << "active, ";
245 if (m_ordered[i]) {
246 out << "ordered" << endl;
247 } else {
248 out << "unordered" << endl;
249 }
250 } else {
251 out << "inactive" << endl;
252 }
253 }
254 out << endl;
255 for(int i=0; i<m_switch_ptr_vector.size(); i++) {
256 m_switch_ptr_vector[i]->printConfig(out);
257 }
258
259 m_topology_ptr->printConfig(out);
260}
261
262void SimpleNetwork::print(ostream& out) const
263{
264 out << "[SimpleNetwork]";
265}
266
267
268SimpleNetwork *
269SimpleNetworkParams::create()
270{
271 return new SimpleNetwork(this);
272}