SimpleNetwork.cc (11113:5a2e1b1b5c43) SimpleNetwork.cc (11124:5d38dc2f7d66)
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"
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/RubySystem.hh"
42
43using namespace std;
44using m5::stl_helpers::deletePointers;
45
46SimpleNetwork::SimpleNetwork(const Params *p)
41
42using namespace std;
43using m5::stl_helpers::deletePointers;
44
45SimpleNetwork::SimpleNetwork(const Params *p)
47 : Network(p)
46 : Network(p), m_buffer_size(p->buffer_size),
47 m_endpoint_bandwidth(p->endpoint_bandwidth),
48 m_adaptive_routing(p->adaptive_routing)
48{
49{
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;
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);
84 deletePointers(m_int_link_buffers);
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);
50 // record the routers
51 for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
52 i != p->routers.end(); ++i) {
53 Switch* s = safe_cast<Switch*>(*i);
54 m_switches.push_back(s);
55 s->init_net_ptr(this);
56 }
57
58 m_int_link_buffers = p->int_link_buffers;
59 m_num_connected_buffers = 0;
60}
61
62void
63SimpleNetwork::init()
64{
65 Network::init();
66
67 // The topology pointer should have already been initialized in
68 // the parent class network constructor.
69 assert(m_topology_ptr != NULL);
70 m_topology_ptr->createLinks(this);
71}
72
73SimpleNetwork::~SimpleNetwork()
74{
75 deletePointers(m_switches);
76 deletePointers(m_int_link_buffers);
77}
78
79// From a switch to an endpoint node
80void
81SimpleNetwork::makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
82 LinkDirection direction,
83 const NetDest& routing_table_entry)
84{
85 assert(dest < m_nodes);
86 assert(src < m_switches.size());
87 assert(m_switches[src] != NULL);
88
89 SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
90
91 m_switches[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry,
92 simple_link->m_latency,
93 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
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++;
130 queues[i] = buffer_ptr;
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::regStats()
144{
145 for (MessageSizeType type = MessageSizeType_FIRST;
146 type < MessageSizeType_NUM; ++type) {
147 m_msg_counts[(unsigned int) type]
148 .name(name() + ".msg_count." + MessageSizeType_to_string(type))
149 .flags(Stats::nozero)
150 ;
151 m_msg_bytes[(unsigned int) type]
152 .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
153 .flags(Stats::nozero)
154 ;
155
156 // Now state what the formula is.
157 for (int i = 0; i < m_switches.size(); i++) {
158 m_msg_counts[(unsigned int) type] +=
159 sum(m_switches[i]->getMsgCount(type));
160 }
161
162 m_msg_bytes[(unsigned int) type] =
163 m_msg_counts[(unsigned int) type] * Stats::constant(
164 Network::MessageSizeType_to_int(type));
165 }
166}
167
168void
169SimpleNetwork::collateStats()
170{
171 for (int i = 0; i < m_switches.size(); i++) {
172 m_switches[i]->collateStats();
173 }
174}
175
176void
177SimpleNetwork::print(ostream& out) const
178{
179 out << "[SimpleNetwork]";
180}
181
182SimpleNetwork *
183SimpleNetworkParams::create()
184{
185 return new SimpleNetwork(this);
186}
187
188/*
189 * The simple network has an array of switches. These switches have buffers
190 * that need to be accessed for functional reads and writes. Also the links
191 * between different switches have buffers that need to be accessed.
192 */
193bool
194SimpleNetwork::functionalRead(Packet *pkt)
195{
196 for (unsigned int i = 0; i < m_switches.size(); i++) {
197 if (m_switches[i]->functionalRead(pkt)) {
198 return true;
199 }
200 }
201
202 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
203 if (m_int_link_buffers[i]->functionalRead(pkt)) {
204 return true;
205 }
206 }
207
208 return false;
209}
210
211uint32_t
212SimpleNetwork::functionalWrite(Packet *pkt)
213{
214 uint32_t num_functional_writes = 0;
215
216 for (unsigned int i = 0; i < m_switches.size(); i++) {
217 num_functional_writes += m_switches[i]->functionalWrite(pkt);
218 }
219
220 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
221 num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
222 }
223 return num_functional_writes;
224}
94}
95
96// From an endpoint node to a switch
97void
98SimpleNetwork::makeInLink(NodeID src, SwitchID dest, BasicLink* link,
99 LinkDirection direction,
100 const NetDest& routing_table_entry)
101{
102 assert(src < m_nodes);
103 m_switches[dest]->addInPort(m_toNetQueues[src]);
104}
105
106// From a switch to a switch
107void
108SimpleNetwork::makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
109 LinkDirection direction,
110 const NetDest& routing_table_entry)
111{
112 // Create a set of new MessageBuffers
113 std::vector<MessageBuffer*> queues(m_virtual_networks);
114
115 for (int i = 0; i < m_virtual_networks; i++) {
116 // allocate a buffer
117 assert(m_num_connected_buffers < m_int_link_buffers.size());
118 MessageBuffer* buffer_ptr = m_int_link_buffers[m_num_connected_buffers];
119 m_num_connected_buffers++;
120 queues[i] = buffer_ptr;
121 }
122
123 // Connect it to the two switches
124 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
125
126 m_switches[dest]->addInPort(queues);
127 m_switches[src]->addOutPort(queues, routing_table_entry,
128 simple_link->m_latency,
129 simple_link->m_bw_multiplier);
130}
131
132void
133SimpleNetwork::regStats()
134{
135 for (MessageSizeType type = MessageSizeType_FIRST;
136 type < MessageSizeType_NUM; ++type) {
137 m_msg_counts[(unsigned int) type]
138 .name(name() + ".msg_count." + MessageSizeType_to_string(type))
139 .flags(Stats::nozero)
140 ;
141 m_msg_bytes[(unsigned int) type]
142 .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
143 .flags(Stats::nozero)
144 ;
145
146 // Now state what the formula is.
147 for (int i = 0; i < m_switches.size(); i++) {
148 m_msg_counts[(unsigned int) type] +=
149 sum(m_switches[i]->getMsgCount(type));
150 }
151
152 m_msg_bytes[(unsigned int) type] =
153 m_msg_counts[(unsigned int) type] * Stats::constant(
154 Network::MessageSizeType_to_int(type));
155 }
156}
157
158void
159SimpleNetwork::collateStats()
160{
161 for (int i = 0; i < m_switches.size(); i++) {
162 m_switches[i]->collateStats();
163 }
164}
165
166void
167SimpleNetwork::print(ostream& out) const
168{
169 out << "[SimpleNetwork]";
170}
171
172SimpleNetwork *
173SimpleNetworkParams::create()
174{
175 return new SimpleNetwork(this);
176}
177
178/*
179 * The simple network has an array of switches. These switches have buffers
180 * that need to be accessed for functional reads and writes. Also the links
181 * between different switches have buffers that need to be accessed.
182 */
183bool
184SimpleNetwork::functionalRead(Packet *pkt)
185{
186 for (unsigned int i = 0; i < m_switches.size(); i++) {
187 if (m_switches[i]->functionalRead(pkt)) {
188 return true;
189 }
190 }
191
192 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
193 if (m_int_link_buffers[i]->functionalRead(pkt)) {
194 return true;
195 }
196 }
197
198 return false;
199}
200
201uint32_t
202SimpleNetwork::functionalWrite(Packet *pkt)
203{
204 uint32_t num_functional_writes = 0;
205
206 for (unsigned int i = 0; i < m_switches.size(); i++) {
207 num_functional_writes += m_switches[i]->functionalWrite(pkt);
208 }
209
210 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
211 num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
212 }
213 return num_functional_writes;
214}