Switch.cc (8229:78bf55f23338) Switch.cc (8259:36987780169e)
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
31#include "base/stl_helpers.hh"
32#include "mem/protocol/MessageSizeType.hh"
33#include "mem/protocol/Protocol.hh"
34#include "mem/ruby/buffers/MessageBuffer.hh"
35#include "mem/ruby/network/simple/PerfectSwitch.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 <numeric>
30
31#include "base/stl_helpers.hh"
32#include "mem/protocol/MessageSizeType.hh"
33#include "mem/protocol/Protocol.hh"
34#include "mem/ruby/buffers/MessageBuffer.hh"
35#include "mem/ruby/network/simple/PerfectSwitch.hh"
36#include "mem/ruby/network/simple/SimpleNetwork.hh"
36#include "mem/ruby/network/simple/Switch.hh"
37#include "mem/ruby/network/simple/Throttle.hh"
37#include "mem/ruby/network/simple/Switch.hh"
38#include "mem/ruby/network/simple/Throttle.hh"
38#include "mem/ruby/network/Network.hh"
39
40using namespace std;
41using m5::stl_helpers::deletePointers;
42using m5::stl_helpers::operator<<;
43
44Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr)
45{
46 m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr);
47 m_switch_id = sid;
48}
49
50Switch::~Switch()
51{
52 delete m_perfect_switch_ptr;
53
54 // Delete throttles (one per output port)
55 deletePointers(m_throttles);
56
57 // Delete MessageBuffers
58 deletePointers(m_buffers_to_free);
59}
60
61void
62Switch::addInPort(const vector<MessageBuffer*>& in)
63{
64 m_perfect_switch_ptr->addInPort(in);
65}
66
67void
68Switch::addOutPort(const vector<MessageBuffer*>& out,
69 const NetDest& routing_table_entry, int link_latency, int bw_multiplier)
70{
71 Throttle* throttle_ptr = NULL;
39
40using namespace std;
41using m5::stl_helpers::deletePointers;
42using m5::stl_helpers::operator<<;
43
44Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr)
45{
46 m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr);
47 m_switch_id = sid;
48}
49
50Switch::~Switch()
51{
52 delete m_perfect_switch_ptr;
53
54 // Delete throttles (one per output port)
55 deletePointers(m_throttles);
56
57 // Delete MessageBuffers
58 deletePointers(m_buffers_to_free);
59}
60
61void
62Switch::addInPort(const vector<MessageBuffer*>& in)
63{
64 m_perfect_switch_ptr->addInPort(in);
65}
66
67void
68Switch::addOutPort(const vector<MessageBuffer*>& out,
69 const NetDest& routing_table_entry, int link_latency, int bw_multiplier)
70{
71 Throttle* throttle_ptr = NULL;
72 SimpleNetwork* net_ptr =
73 safe_cast<SimpleNetwork*>(RubySystem::getNetwork());
72
73 // Create a throttle
74 throttle_ptr = new Throttle(m_switch_id, m_throttles.size(), link_latency,
74
75 // Create a throttle
76 throttle_ptr = new Throttle(m_switch_id, m_throttles.size(), link_latency,
75 bw_multiplier);
77 bw_multiplier, net_ptr->getEndpointBandwidth());
76 m_throttles.push_back(throttle_ptr);
77
78 // Create one buffer per vnet (these are intermediaryQueues)
79 vector<MessageBuffer*> intermediateBuffers;
80 for (int i = 0; i < out.size(); i++) {
81 MessageBuffer* buffer_ptr = new MessageBuffer;
82 // Make these queues ordered
83 buffer_ptr->setOrdering(true);
78 m_throttles.push_back(throttle_ptr);
79
80 // Create one buffer per vnet (these are intermediaryQueues)
81 vector<MessageBuffer*> intermediateBuffers;
82 for (int i = 0; i < out.size(); i++) {
83 MessageBuffer* buffer_ptr = new MessageBuffer;
84 // Make these queues ordered
85 buffer_ptr->setOrdering(true);
84 Network* net_ptr = RubySystem::getNetwork();
85 if (net_ptr->getBufferSize() > 0) {
86 buffer_ptr->resize(net_ptr->getBufferSize());
87 }
88 intermediateBuffers.push_back(buffer_ptr);
89 m_buffers_to_free.push_back(buffer_ptr);
90 }
91
92 // Hook the queues to the PerfectSwitch
93 m_perfect_switch_ptr->addOutPort(intermediateBuffers, routing_table_entry);
94
95 // Hook the queues to the Throttle
96 throttle_ptr->addLinks(intermediateBuffers, out);
97}
98
99void
100Switch::clearRoutingTables()
101{
102 m_perfect_switch_ptr->clearRoutingTables();
103}
104
105void
106Switch::clearBuffers()
107{
108 m_perfect_switch_ptr->clearBuffers();
109 for (int i = 0; i < m_throttles.size(); i++) {
110 if (m_throttles[i] != NULL) {
111 m_throttles[i]->clear();
112 }
113 }
114}
115
116void
117Switch::reconfigureOutPort(const NetDest& routing_table_entry)
118{
119 m_perfect_switch_ptr->reconfigureOutPort(routing_table_entry);
120}
121
122const Throttle*
123Switch::getThrottle(LinkID link_number) const
124{
125 assert(m_throttles[link_number] != NULL);
126 return m_throttles[link_number];
127}
128
129const vector<Throttle*>*
130Switch::getThrottles() const
131{
132 return &m_throttles;
133}
134
135void
136Switch::printStats(std::ostream& out) const
137{
138 ccprintf(out, "switch_%d_inlinks: %d\n", m_switch_id,
139 m_perfect_switch_ptr->getInLinks());
140 ccprintf(out, "switch_%d_outlinks: %d\n", m_switch_id,
141 m_perfect_switch_ptr->getOutLinks());
142
143 // Average link utilizations
144 double average_utilization = 0.0;
145 int throttle_count = 0;
146
147 for (int i = 0; i < m_throttles.size(); i++) {
148 Throttle* throttle_ptr = m_throttles[i];
149 if (throttle_ptr) {
150 average_utilization += throttle_ptr->getUtilization();
151 throttle_count++;
152 }
153 }
154 average_utilization =
155 throttle_count == 0 ? 0 : average_utilization / throttle_count;
156
157 // Individual link utilizations
158 out << "links_utilized_percent_switch_" << m_switch_id << ": "
159 << average_utilization << endl;
160
161 for (int link = 0; link < m_throttles.size(); link++) {
162 Throttle* throttle_ptr = m_throttles[link];
163 if (throttle_ptr != NULL) {
164 out << " links_utilized_percent_switch_" << m_switch_id
165 << "_link_" << link << ": "
166 << throttle_ptr->getUtilization() << " bw: "
167 << throttle_ptr->getLinkBandwidth()
168 << " base_latency: " << throttle_ptr->getLatency() << endl;
169 }
170 }
171 out << endl;
172
173 // Traffic breakdown
174 for (int link = 0; link < m_throttles.size(); link++) {
175 Throttle* throttle_ptr = m_throttles[link];
176 if (!throttle_ptr)
177 continue;
178
179 const vector<vector<int> >& message_counts =
180 throttle_ptr->getCounters();
181 for (int int_type = 0; int_type < MessageSizeType_NUM; int_type++) {
182 MessageSizeType type = MessageSizeType(int_type);
183 const vector<int> &mct = message_counts[type];
184 int sum = accumulate(mct.begin(), mct.end(), 0);
185 if (sum == 0)
186 continue;
187
188 out << " outgoing_messages_switch_" << m_switch_id
189 << "_link_" << link << "_" << type << ": " << sum << " "
190 << sum * RubySystem::getNetwork()->MessageSizeType_to_int(type)
191 << " ";
192 out << mct;
193 out << " base_latency: "
194 << throttle_ptr->getLatency() << endl;
195 }
196 }
197 out << endl;
198}
199
200void
201Switch::clearStats()
202{
203 m_perfect_switch_ptr->clearStats();
204 for (int i = 0; i < m_throttles.size(); i++) {
205 if (m_throttles[i] != NULL)
206 m_throttles[i]->clearStats();
207 }
208}
209
210void
211Switch::printConfig(std::ostream& out) const
212{
213 m_perfect_switch_ptr->printConfig(out);
214 for (int i = 0; i < m_throttles.size(); i++) {
215 if (m_throttles[i] != NULL)
216 m_throttles[i]->printConfig(out);
217 }
218}
219
220void
221Switch::print(std::ostream& out) const
222{
223 // FIXME printing
224 out << "[Switch]";
225}
226
86 if (net_ptr->getBufferSize() > 0) {
87 buffer_ptr->resize(net_ptr->getBufferSize());
88 }
89 intermediateBuffers.push_back(buffer_ptr);
90 m_buffers_to_free.push_back(buffer_ptr);
91 }
92
93 // Hook the queues to the PerfectSwitch
94 m_perfect_switch_ptr->addOutPort(intermediateBuffers, routing_table_entry);
95
96 // Hook the queues to the Throttle
97 throttle_ptr->addLinks(intermediateBuffers, out);
98}
99
100void
101Switch::clearRoutingTables()
102{
103 m_perfect_switch_ptr->clearRoutingTables();
104}
105
106void
107Switch::clearBuffers()
108{
109 m_perfect_switch_ptr->clearBuffers();
110 for (int i = 0; i < m_throttles.size(); i++) {
111 if (m_throttles[i] != NULL) {
112 m_throttles[i]->clear();
113 }
114 }
115}
116
117void
118Switch::reconfigureOutPort(const NetDest& routing_table_entry)
119{
120 m_perfect_switch_ptr->reconfigureOutPort(routing_table_entry);
121}
122
123const Throttle*
124Switch::getThrottle(LinkID link_number) const
125{
126 assert(m_throttles[link_number] != NULL);
127 return m_throttles[link_number];
128}
129
130const vector<Throttle*>*
131Switch::getThrottles() const
132{
133 return &m_throttles;
134}
135
136void
137Switch::printStats(std::ostream& out) const
138{
139 ccprintf(out, "switch_%d_inlinks: %d\n", m_switch_id,
140 m_perfect_switch_ptr->getInLinks());
141 ccprintf(out, "switch_%d_outlinks: %d\n", m_switch_id,
142 m_perfect_switch_ptr->getOutLinks());
143
144 // Average link utilizations
145 double average_utilization = 0.0;
146 int throttle_count = 0;
147
148 for (int i = 0; i < m_throttles.size(); i++) {
149 Throttle* throttle_ptr = m_throttles[i];
150 if (throttle_ptr) {
151 average_utilization += throttle_ptr->getUtilization();
152 throttle_count++;
153 }
154 }
155 average_utilization =
156 throttle_count == 0 ? 0 : average_utilization / throttle_count;
157
158 // Individual link utilizations
159 out << "links_utilized_percent_switch_" << m_switch_id << ": "
160 << average_utilization << endl;
161
162 for (int link = 0; link < m_throttles.size(); link++) {
163 Throttle* throttle_ptr = m_throttles[link];
164 if (throttle_ptr != NULL) {
165 out << " links_utilized_percent_switch_" << m_switch_id
166 << "_link_" << link << ": "
167 << throttle_ptr->getUtilization() << " bw: "
168 << throttle_ptr->getLinkBandwidth()
169 << " base_latency: " << throttle_ptr->getLatency() << endl;
170 }
171 }
172 out << endl;
173
174 // Traffic breakdown
175 for (int link = 0; link < m_throttles.size(); link++) {
176 Throttle* throttle_ptr = m_throttles[link];
177 if (!throttle_ptr)
178 continue;
179
180 const vector<vector<int> >& message_counts =
181 throttle_ptr->getCounters();
182 for (int int_type = 0; int_type < MessageSizeType_NUM; int_type++) {
183 MessageSizeType type = MessageSizeType(int_type);
184 const vector<int> &mct = message_counts[type];
185 int sum = accumulate(mct.begin(), mct.end(), 0);
186 if (sum == 0)
187 continue;
188
189 out << " outgoing_messages_switch_" << m_switch_id
190 << "_link_" << link << "_" << type << ": " << sum << " "
191 << sum * RubySystem::getNetwork()->MessageSizeType_to_int(type)
192 << " ";
193 out << mct;
194 out << " base_latency: "
195 << throttle_ptr->getLatency() << endl;
196 }
197 }
198 out << endl;
199}
200
201void
202Switch::clearStats()
203{
204 m_perfect_switch_ptr->clearStats();
205 for (int i = 0; i < m_throttles.size(); i++) {
206 if (m_throttles[i] != NULL)
207 m_throttles[i]->clearStats();
208 }
209}
210
211void
212Switch::printConfig(std::ostream& out) const
213{
214 m_perfect_switch_ptr->printConfig(out);
215 for (int i = 0; i < m_throttles.size(); i++) {
216 if (m_throttles[i] != NULL)
217 m_throttles[i]->printConfig(out);
218 }
219}
220
221void
222Switch::print(std::ostream& out) const
223{
224 // FIXME printing
225 out << "[Switch]";
226}
227