SimpleNetwork.cc (10917:c38f28fad4c3) SimpleNetwork.cc (11021:e8a6637afa4c)
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 <cassert>
30#include <numeric>
31
32#include "base/cast.hh"
33#include "base/stl_helpers.hh"
34#include "mem/ruby/common/NetDest.hh"
35#include "mem/ruby/network/MessageBuffer.hh"
36#include "mem/ruby/network/simple/SimpleLink.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"
40#include "mem/ruby/profiler/Profiler.hh"
41#include "mem/ruby/system/System.hh"
42
43using namespace std;
44using m5::stl_helpers::deletePointers;
45
46SimpleNetwork::SimpleNetwork(const Params *p)
47 : Network(p)
48{
49 m_buffer_size = p->buffer_size;
50 m_endpoint_bandwidth = p->endpoint_bandwidth;
51 m_adaptive_routing = p->adaptive_routing;
52
53 // Note: the parent Network Object constructor is called before the
54 // SimpleNetwork child constructor. Therefore, the member variables
55 // used below should already be initialized.
56 m_endpoint_switches.resize(m_nodes);
57
58 // record the routers
59 for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
60 i != p->routers.end(); ++i) {
61 Switch* s = safe_cast<Switch*>(*i);
62 m_switches.push_back(s);
63 s->init_net_ptr(this);
64 }
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 <cassert>
30#include <numeric>
31
32#include "base/cast.hh"
33#include "base/stl_helpers.hh"
34#include "mem/ruby/common/NetDest.hh"
35#include "mem/ruby/network/MessageBuffer.hh"
36#include "mem/ruby/network/simple/SimpleLink.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"
40#include "mem/ruby/profiler/Profiler.hh"
41#include "mem/ruby/system/System.hh"
42
43using namespace std;
44using m5::stl_helpers::deletePointers;
45
46SimpleNetwork::SimpleNetwork(const Params *p)
47 : Network(p)
48{
49 m_buffer_size = p->buffer_size;
50 m_endpoint_bandwidth = p->endpoint_bandwidth;
51 m_adaptive_routing = p->adaptive_routing;
52
53 // Note: the parent Network Object constructor is called before the
54 // SimpleNetwork child constructor. Therefore, the member variables
55 // used below should already be initialized.
56 m_endpoint_switches.resize(m_nodes);
57
58 // record the routers
59 for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
60 i != p->routers.end(); ++i) {
61 Switch* s = safe_cast<Switch*>(*i);
62 m_switches.push_back(s);
63 s->init_net_ptr(this);
64 }
65
66 m_int_link_buffers = p->int_link_buffers;
67 m_num_connected_buffers = 0;
65}
66
67void
68SimpleNetwork::init()
69{
70 Network::init();
71
72 // The topology pointer should have already been initialized in
73 // the parent class network constructor.
74 assert(m_topology_ptr != NULL);
75 m_topology_ptr->createLinks(this);
76}
77
78SimpleNetwork::~SimpleNetwork()
79{
80 deletePointers(m_switches);
68}
69
70void
71SimpleNetwork::init()
72{
73 Network::init();
74
75 // The topology pointer should have already been initialized in
76 // the parent class network constructor.
77 assert(m_topology_ptr != NULL);
78 m_topology_ptr->createLinks(this);
79}
80
81SimpleNetwork::~SimpleNetwork()
82{
83 deletePointers(m_switches);
81 deletePointers(m_buffers_to_free);
84 deletePointers(m_int_link_buffers);
82}
83
84// From a switch to an endpoint node
85void
86SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
87 LinkDirection direction,
88 const NetDest& routing_table_entry)
89{
90 assert(dest < m_nodes);
91 assert(src < m_switches.size());
92 assert(m_switches[src] != NULL);
93
94 SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
95
96 m_switches[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry,
97 simple_link->m_latency,
98 simple_link->m_bw_multiplier);
99
100 m_endpoint_switches[dest] = m_switches[src];
101}
102
103// From an endpoint node to a switch
104void
105SimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link,
106 LinkDirection direction,
107 const NetDest& routing_table_entry)
108{
109 assert(src < m_nodes);
110 m_switches[dest]->addInPort(m_toNetQueues[src]);
111}
112
113// From a switch to a switch
114void
115SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
116 LinkDirection direction,
117 const NetDest& routing_table_entry)
118{
119 // Create a set of new MessageBuffers
120 std::vector<MessageBuffer*> queues(m_virtual_networks);
121
122 for (int i = 0; i < m_virtual_networks; i++) {
123 // allocate a buffer
85}
86
87// From a switch to an endpoint node
88void
89SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
90 LinkDirection direction,
91 const NetDest& routing_table_entry)
92{
93 assert(dest < m_nodes);
94 assert(src < m_switches.size());
95 assert(m_switches[src] != NULL);
96
97 SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
98
99 m_switches[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry,
100 simple_link->m_latency,
101 simple_link->m_bw_multiplier);
102
103 m_endpoint_switches[dest] = m_switches[src];
104}
105
106// From an endpoint node to a switch
107void
108SimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link,
109 LinkDirection direction,
110 const NetDest& routing_table_entry)
111{
112 assert(src < m_nodes);
113 m_switches[dest]->addInPort(m_toNetQueues[src]);
114}
115
116// From a switch to a switch
117void
118SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
119 LinkDirection direction,
120 const NetDest& routing_table_entry)
121{
122 // Create a set of new MessageBuffers
123 std::vector<MessageBuffer*> queues(m_virtual_networks);
124
125 for (int i = 0; i < m_virtual_networks; i++) {
126 // allocate a buffer
124 MessageBuffer* buffer_ptr = new MessageBuffer;
125 buffer_ptr->setOrdering(true);
126
127 if (m_buffer_size > 0) {
128 buffer_ptr->resize(m_buffer_size);
129 }
130
127 assert(m_num_connected_buffers < m_int_link_buffers.size());
128 MessageBuffer* buffer_ptr = m_int_link_buffers[m_num_connected_buffers];
129 m_num_connected_buffers++;
131 queues[i] = buffer_ptr;
130 queues[i] = buffer_ptr;
132 // remember to deallocate it
133 m_buffers_to_free.push_back(buffer_ptr);
134 }
135
136 // Connect it to the two switches
137 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
138
139 m_switches[dest]->addInPort(queues);
140 m_switches[src]->addOutPort(queues, routing_table_entry,
141 simple_link->m_latency,
142 simple_link->m_bw_multiplier);
143}
144
145void
146SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
147{
148 assert(id < m_nodes);
149 assert(network_num < m_virtual_networks);
150
151 if (ordered) {
152 m_ordered[network_num] = true;
153 }
154 m_in_use[network_num] = true;
155}
156
157void
158SimpleNetwork::setToNetQueue(NodeID id, bool ordered, int network_num,
159 std::string vnet_type, MessageBuffer *b)
160{
161 checkNetworkAllocation(id, ordered, network_num);
162 while (m_toNetQueues[id].size() <= network_num) {
163 m_toNetQueues[id].push_back(nullptr);
164 }
165 m_toNetQueues[id][network_num] = b;
166}
167
168void
169SimpleNetwork::setFromNetQueue(NodeID id, bool ordered, int network_num,
170 std::string vnet_type, MessageBuffer *b)
171{
172 checkNetworkAllocation(id, ordered, network_num);
173 while (m_fromNetQueues[id].size() <= network_num) {
174 m_fromNetQueues[id].push_back(nullptr);
175 }
176 m_fromNetQueues[id][network_num] = b;
177}
178
179void
180SimpleNetwork::regStats()
181{
182 for (MessageSizeType type = MessageSizeType_FIRST;
183 type < MessageSizeType_NUM; ++type) {
184 m_msg_counts[(unsigned int) type]
185 .name(name() + ".msg_count." + MessageSizeType_to_string(type))
186 .flags(Stats::nozero)
187 ;
188 m_msg_bytes[(unsigned int) type]
189 .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
190 .flags(Stats::nozero)
191 ;
192
193 // Now state what the formula is.
194 for (int i = 0; i < m_switches.size(); i++) {
195 m_msg_counts[(unsigned int) type] +=
196 sum(m_switches[i]->getMsgCount(type));
197 }
198
199 m_msg_bytes[(unsigned int) type] =
200 m_msg_counts[(unsigned int) type] * Stats::constant(
201 Network::MessageSizeType_to_int(type));
202 }
203}
204
205void
206SimpleNetwork::collateStats()
207{
208 for (int i = 0; i < m_switches.size(); i++) {
209 m_switches[i]->collateStats();
210 }
211}
212
213void
214SimpleNetwork::print(ostream& out) const
215{
216 out << "[SimpleNetwork]";
217}
218
219SimpleNetwork *
220SimpleNetworkParams::create()
221{
222 return new SimpleNetwork(this);
223}
224
225/*
226 * The simple network has an array of switches. These switches have buffers
227 * that need to be accessed for functional reads and writes. Also the links
228 * between different switches have buffers that need to be accessed.
229 */
230bool
231SimpleNetwork::functionalRead(Packet *pkt)
232{
233 for (unsigned int i = 0; i < m_switches.size(); i++) {
234 if (m_switches[i]->functionalRead(pkt)) {
235 return true;
236 }
237 }
238
131 }
132
133 // Connect it to the two switches
134 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
135
136 m_switches[dest]->addInPort(queues);
137 m_switches[src]->addOutPort(queues, routing_table_entry,
138 simple_link->m_latency,
139 simple_link->m_bw_multiplier);
140}
141
142void
143SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
144{
145 assert(id < m_nodes);
146 assert(network_num < m_virtual_networks);
147
148 if (ordered) {
149 m_ordered[network_num] = true;
150 }
151 m_in_use[network_num] = true;
152}
153
154void
155SimpleNetwork::setToNetQueue(NodeID id, bool ordered, int network_num,
156 std::string vnet_type, MessageBuffer *b)
157{
158 checkNetworkAllocation(id, ordered, network_num);
159 while (m_toNetQueues[id].size() <= network_num) {
160 m_toNetQueues[id].push_back(nullptr);
161 }
162 m_toNetQueues[id][network_num] = b;
163}
164
165void
166SimpleNetwork::setFromNetQueue(NodeID id, bool ordered, int network_num,
167 std::string vnet_type, MessageBuffer *b)
168{
169 checkNetworkAllocation(id, ordered, network_num);
170 while (m_fromNetQueues[id].size() <= network_num) {
171 m_fromNetQueues[id].push_back(nullptr);
172 }
173 m_fromNetQueues[id][network_num] = b;
174}
175
176void
177SimpleNetwork::regStats()
178{
179 for (MessageSizeType type = MessageSizeType_FIRST;
180 type < MessageSizeType_NUM; ++type) {
181 m_msg_counts[(unsigned int) type]
182 .name(name() + ".msg_count." + MessageSizeType_to_string(type))
183 .flags(Stats::nozero)
184 ;
185 m_msg_bytes[(unsigned int) type]
186 .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
187 .flags(Stats::nozero)
188 ;
189
190 // Now state what the formula is.
191 for (int i = 0; i < m_switches.size(); i++) {
192 m_msg_counts[(unsigned int) type] +=
193 sum(m_switches[i]->getMsgCount(type));
194 }
195
196 m_msg_bytes[(unsigned int) type] =
197 m_msg_counts[(unsigned int) type] * Stats::constant(
198 Network::MessageSizeType_to_int(type));
199 }
200}
201
202void
203SimpleNetwork::collateStats()
204{
205 for (int i = 0; i < m_switches.size(); i++) {
206 m_switches[i]->collateStats();
207 }
208}
209
210void
211SimpleNetwork::print(ostream& out) const
212{
213 out << "[SimpleNetwork]";
214}
215
216SimpleNetwork *
217SimpleNetworkParams::create()
218{
219 return new SimpleNetwork(this);
220}
221
222/*
223 * The simple network has an array of switches. These switches have buffers
224 * that need to be accessed for functional reads and writes. Also the links
225 * between different switches have buffers that need to be accessed.
226 */
227bool
228SimpleNetwork::functionalRead(Packet *pkt)
229{
230 for (unsigned int i = 0; i < m_switches.size(); i++) {
231 if (m_switches[i]->functionalRead(pkt)) {
232 return true;
233 }
234 }
235
239 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
240 if (m_buffers_to_free[i]->functionalRead(pkt)) {
236 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
237 if (m_int_link_buffers[i]->functionalRead(pkt)) {
241 return true;
242 }
243 }
244
245 return false;
246}
247
248uint32_t
249SimpleNetwork::functionalWrite(Packet *pkt)
250{
251 uint32_t num_functional_writes = 0;
252
253 for (unsigned int i = 0; i < m_switches.size(); i++) {
254 num_functional_writes += m_switches[i]->functionalWrite(pkt);
255 }
256
238 return true;
239 }
240 }
241
242 return false;
243}
244
245uint32_t
246SimpleNetwork::functionalWrite(Packet *pkt)
247{
248 uint32_t num_functional_writes = 0;
249
250 for (unsigned int i = 0; i < m_switches.size(); i++) {
251 num_functional_writes += m_switches[i]->functionalWrite(pkt);
252 }
253
257 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
258 num_functional_writes += m_buffers_to_free[i]->functionalWrite(pkt);
254 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
255 num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
259 }
260 return num_functional_writes;
261}
256 }
257 return num_functional_writes;
258}