SimpleNetwork.cc (10303:71e0934af9f1) SimpleNetwork.cc (10311:ad9c042dce54)
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
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);
81 deletePointers(m_buffers_to_free);
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
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
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);
81 deletePointers(m_buffers_to_free);
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],
97 routing_table_entry,
98 simple_link->m_latency,
99 simple_link->m_bw_multiplier);
96 m_switches[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry,
97 simple_link->m_latency,
98 simple_link->m_bw_multiplier);
100
101 m_endpoint_switches[dest] = m_switches[src];
102}
103
104// From an endpoint node to a switch
105void
106SimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link,
107 LinkDirection direction,
108 const NetDest& routing_table_entry)
109{
110 assert(src < m_nodes);
111 m_switches[dest]->addInPort(m_toNetQueues[src]);
112}
113
114// From a switch to a switch
115void
116SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
117 LinkDirection direction,
118 const NetDest& routing_table_entry)
119{
120 // Create a set of new MessageBuffers
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
121 std::vector<MessageBuffer*> queues;
120 std::map<int, MessageBuffer*> queues;
122 for (int i = 0; i < m_virtual_networks; i++) {
123 // allocate a buffer
124 MessageBuffer* buffer_ptr = new MessageBuffer;
125 buffer_ptr->setOrdering(true);
121 for (int i = 0; i < m_virtual_networks; i++) {
122 // allocate a buffer
123 MessageBuffer* buffer_ptr = new MessageBuffer;
124 buffer_ptr->setOrdering(true);
125
126 if (m_buffer_size > 0) {
127 buffer_ptr->resize(m_buffer_size);
128 }
126 if (m_buffer_size > 0) {
127 buffer_ptr->resize(m_buffer_size);
128 }
129 queues.push_back(buffer_ptr);
129
130 queues[i] = buffer_ptr;
130 // remember to deallocate it
131 m_buffers_to_free.push_back(buffer_ptr);
132 }
131 // remember to deallocate it
132 m_buffers_to_free.push_back(buffer_ptr);
133 }
134
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,
135 // Connect it to the two switches
136 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
137
138 m_switches[dest]->addInPort(queues);
139 m_switches[src]->addOutPort(queues, routing_table_entry,
138 simple_link->m_latency,
139 simple_link->m_bw_multiplier);
140 simple_link->m_latency,
141 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
142}
143
144void
145SimpleNetwork::checkNetworkAllocation(NodeID id, bool ordered, int network_num)
146{
147 assert(id < m_nodes);
148 assert(network_num < m_virtual_networks);
149
150 if (ordered) {
151 m_ordered[network_num] = true;
152 }
153 m_in_use[network_num] = true;
154}
155
154MessageBuffer*
155SimpleNetwork::getToNetQueue(NodeID id, bool ordered, int network_num,
156 std::string vnet_type)
156void
157SimpleNetwork::setToNetQueue(NodeID id, bool ordered, int network_num,
158 std::string vnet_type, MessageBuffer *b)
157{
158 checkNetworkAllocation(id, ordered, network_num);
159{
160 checkNetworkAllocation(id, ordered, network_num);
159 return m_toNetQueues[id][network_num];
161 m_toNetQueues[id][network_num] = b;
160}
161
162}
163
162MessageBuffer*
163SimpleNetwork::getFromNetQueue(NodeID id, bool ordered, int network_num,
164 std::string vnet_type)
164void
165SimpleNetwork::setFromNetQueue(NodeID id, bool ordered, int network_num,
166 std::string vnet_type, MessageBuffer *b)
165{
166 checkNetworkAllocation(id, ordered, network_num);
167{
168 checkNetworkAllocation(id, ordered, network_num);
167 return m_fromNetQueues[id][network_num];
169 m_fromNetQueues[id][network_num] = b;
168}
169
170void
171SimpleNetwork::regStats()
172{
173 for (MessageSizeType type = MessageSizeType_FIRST;
174 type < MessageSizeType_NUM; ++type) {
175 m_msg_counts[(unsigned int) type]
176 .name(name() + ".msg_count." + MessageSizeType_to_string(type))
177 .flags(Stats::nozero)
178 ;
179 m_msg_bytes[(unsigned int) type]
180 .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
181 .flags(Stats::nozero)
182 ;
183
184 // Now state what the formula is.
185 for (int i = 0; i < m_switches.size(); i++) {
186 m_msg_counts[(unsigned int) type] +=
187 sum(m_switches[i]->getMsgCount(type));
188 }
189
190 m_msg_bytes[(unsigned int) type] =
191 m_msg_counts[(unsigned int) type] * Stats::constant(
192 Network::MessageSizeType_to_int(type));
193 }
194}
195
196void
197SimpleNetwork::collateStats()
198{
199 for (int i = 0; i < m_switches.size(); i++) {
200 m_switches[i]->collateStats();
201 }
202}
203
204void
205SimpleNetwork::print(ostream& out) const
206{
207 out << "[SimpleNetwork]";
208}
209
210SimpleNetwork *
211SimpleNetworkParams::create()
212{
213 return new SimpleNetwork(this);
214}
215
216/*
217 * The simple network has an array of switches. These switches have buffers
218 * that need to be accessed for functional reads and writes. Also the links
219 * between different switches have buffers that need to be accessed.
220 */
221bool
222SimpleNetwork::functionalRead(Packet *pkt)
223{
224 for (unsigned int i = 0; i < m_switches.size(); i++) {
225 if (m_switches[i]->functionalRead(pkt)) {
226 return true;
227 }
228 }
229
230 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
231 if (m_buffers_to_free[i]->functionalRead(pkt)) {
232 return true;
233 }
234 }
235
236 return false;
237}
238
239uint32_t
240SimpleNetwork::functionalWrite(Packet *pkt)
241{
242 uint32_t num_functional_writes = 0;
243
244 for (unsigned int i = 0; i < m_switches.size(); i++) {
245 num_functional_writes += m_switches[i]->functionalWrite(pkt);
246 }
247
248 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
249 num_functional_writes += m_buffers_to_free[i]->functionalWrite(pkt);
250 }
251 return num_functional_writes;
252}
170}
171
172void
173SimpleNetwork::regStats()
174{
175 for (MessageSizeType type = MessageSizeType_FIRST;
176 type < MessageSizeType_NUM; ++type) {
177 m_msg_counts[(unsigned int) type]
178 .name(name() + ".msg_count." + MessageSizeType_to_string(type))
179 .flags(Stats::nozero)
180 ;
181 m_msg_bytes[(unsigned int) type]
182 .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
183 .flags(Stats::nozero)
184 ;
185
186 // Now state what the formula is.
187 for (int i = 0; i < m_switches.size(); i++) {
188 m_msg_counts[(unsigned int) type] +=
189 sum(m_switches[i]->getMsgCount(type));
190 }
191
192 m_msg_bytes[(unsigned int) type] =
193 m_msg_counts[(unsigned int) type] * Stats::constant(
194 Network::MessageSizeType_to_int(type));
195 }
196}
197
198void
199SimpleNetwork::collateStats()
200{
201 for (int i = 0; i < m_switches.size(); i++) {
202 m_switches[i]->collateStats();
203 }
204}
205
206void
207SimpleNetwork::print(ostream& out) const
208{
209 out << "[SimpleNetwork]";
210}
211
212SimpleNetwork *
213SimpleNetworkParams::create()
214{
215 return new SimpleNetwork(this);
216}
217
218/*
219 * The simple network has an array of switches. These switches have buffers
220 * that need to be accessed for functional reads and writes. Also the links
221 * between different switches have buffers that need to be accessed.
222 */
223bool
224SimpleNetwork::functionalRead(Packet *pkt)
225{
226 for (unsigned int i = 0; i < m_switches.size(); i++) {
227 if (m_switches[i]->functionalRead(pkt)) {
228 return true;
229 }
230 }
231
232 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
233 if (m_buffers_to_free[i]->functionalRead(pkt)) {
234 return true;
235 }
236 }
237
238 return false;
239}
240
241uint32_t
242SimpleNetwork::functionalWrite(Packet *pkt)
243{
244 uint32_t num_functional_writes = 0;
245
246 for (unsigned int i = 0; i < m_switches.size(); i++) {
247 num_functional_writes += m_switches[i]->functionalWrite(pkt);
248 }
249
250 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
251 num_functional_writes += m_buffers_to_free[i]->functionalWrite(pkt);
252 }
253 return num_functional_writes;
254}