Switch.cc (10918:dd3ab1f109ad) Switch.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 <numeric>
30
31#include "base/cast.hh"
32#include "base/stl_helpers.hh"
33#include "mem/ruby/network/MessageBuffer.hh"
34#include "mem/ruby/network/simple/PerfectSwitch.hh"
35#include "mem/ruby/network/simple/SimpleNetwork.hh"
36#include "mem/ruby/network/simple/Switch.hh"
37#include "mem/ruby/network/simple/Throttle.hh"
38
39using namespace std;
40using m5::stl_helpers::deletePointers;
41using m5::stl_helpers::operator<<;
42
43Switch::Switch(const Params *p) : BasicRouter(p)
44{
45 m_perfect_switch = new PerfectSwitch(m_id, this, p->virt_nets);
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/cast.hh"
32#include "base/stl_helpers.hh"
33#include "mem/ruby/network/MessageBuffer.hh"
34#include "mem/ruby/network/simple/PerfectSwitch.hh"
35#include "mem/ruby/network/simple/SimpleNetwork.hh"
36#include "mem/ruby/network/simple/Switch.hh"
37#include "mem/ruby/network/simple/Throttle.hh"
38
39using namespace std;
40using m5::stl_helpers::deletePointers;
41using m5::stl_helpers::operator<<;
42
43Switch::Switch(const Params *p) : BasicRouter(p)
44{
45 m_perfect_switch = new PerfectSwitch(m_id, this, p->virt_nets);
46 m_port_buffers = p->port_buffers;
47 m_num_connected_buffers = 0;
46}
47
48Switch::~Switch()
49{
50 delete m_perfect_switch;
51
52 // Delete throttles (one per output port)
53 deletePointers(m_throttles);
54
55 // Delete MessageBuffers
48}
49
50Switch::~Switch()
51{
52 delete m_perfect_switch;
53
54 // Delete throttles (one per output port)
55 deletePointers(m_throttles);
56
57 // Delete MessageBuffers
56 deletePointers(m_buffers_to_free);
58 deletePointers(m_port_buffers);
57}
58
59void
60Switch::init()
61{
62 BasicRouter::init();
63 m_perfect_switch->init(m_network_ptr);
64}
65
66void
67Switch::addInPort(const vector<MessageBuffer*>& in)
68{
69 m_perfect_switch->addInPort(in);
70
71 for (auto& it : in) {
72 if (it != nullptr) {
73 it->setReceiver(this);
74 }
75 }
76}
77
78void
79Switch::addOutPort(const vector<MessageBuffer*>& out,
80 const NetDest& routing_table_entry,
81 Cycles link_latency, int bw_multiplier)
82{
83 // Create a throttle
84 RubySystem *rs = m_network_ptr->params()->ruby_system;
85 Throttle* throttle_ptr = new Throttle(m_id, rs, m_throttles.size(),
86 link_latency, bw_multiplier,
87 m_network_ptr->getEndpointBandwidth(),
88 this);
89
90 m_throttles.push_back(throttle_ptr);
91
92 // Create one buffer per vnet (these are intermediaryQueues)
93 vector<MessageBuffer*> intermediateBuffers;
94
95 for (int i = 0; i < out.size(); ++i) {
96 if (out[i] != nullptr) {
97 out[i]->setSender(this);
98 }
99
59}
60
61void
62Switch::init()
63{
64 BasicRouter::init();
65 m_perfect_switch->init(m_network_ptr);
66}
67
68void
69Switch::addInPort(const vector<MessageBuffer*>& in)
70{
71 m_perfect_switch->addInPort(in);
72
73 for (auto& it : in) {
74 if (it != nullptr) {
75 it->setReceiver(this);
76 }
77 }
78}
79
80void
81Switch::addOutPort(const vector<MessageBuffer*>& out,
82 const NetDest& routing_table_entry,
83 Cycles link_latency, int bw_multiplier)
84{
85 // Create a throttle
86 RubySystem *rs = m_network_ptr->params()->ruby_system;
87 Throttle* throttle_ptr = new Throttle(m_id, rs, m_throttles.size(),
88 link_latency, bw_multiplier,
89 m_network_ptr->getEndpointBandwidth(),
90 this);
91
92 m_throttles.push_back(throttle_ptr);
93
94 // Create one buffer per vnet (these are intermediaryQueues)
95 vector<MessageBuffer*> intermediateBuffers;
96
97 for (int i = 0; i < out.size(); ++i) {
98 if (out[i] != nullptr) {
99 out[i]->setSender(this);
100 }
101
100 MessageBuffer* buffer_ptr = new MessageBuffer;
101 // Make these queues ordered
102 buffer_ptr->setOrdering(true);
103 if (m_network_ptr->getBufferSize() > 0) {
104 buffer_ptr->resize(m_network_ptr->getBufferSize());
105 }
106
102 assert(m_num_connected_buffers < m_port_buffers.size());
103 MessageBuffer* buffer_ptr = m_port_buffers[m_num_connected_buffers];
104 m_num_connected_buffers++;
107 intermediateBuffers.push_back(buffer_ptr);
105 intermediateBuffers.push_back(buffer_ptr);
108 m_buffers_to_free.push_back(buffer_ptr);
109
110 buffer_ptr->setSender(this);
111 buffer_ptr->setReceiver(this);
112 }
113
114 // Hook the queues to the PerfectSwitch
115 m_perfect_switch->addOutPort(intermediateBuffers, routing_table_entry);
116
117 // Hook the queues to the Throttle
118 throttle_ptr->addLinks(intermediateBuffers, out);
119}
120
121const Throttle*
122Switch::getThrottle(LinkID link_number) const
123{
124 assert(m_throttles[link_number] != NULL);
125 return m_throttles[link_number];
126}
127
128void
129Switch::regStats()
130{
131 for (int link = 0; link < m_throttles.size(); link++) {
132 m_throttles[link]->regStats(name());
133 }
134
135 m_avg_utilization.name(name() + ".percent_links_utilized");
136 for (unsigned int i = 0; i < m_throttles.size(); i++) {
137 m_avg_utilization += m_throttles[i]->getUtilization();
138 }
139 m_avg_utilization /= Stats::constant(m_throttles.size());
140
141 for (unsigned int type = MessageSizeType_FIRST;
142 type < MessageSizeType_NUM; ++type) {
143 m_msg_counts[type]
144 .name(name() + ".msg_count." +
145 MessageSizeType_to_string(MessageSizeType(type)))
146 .flags(Stats::nozero)
147 ;
148 m_msg_bytes[type]
149 .name(name() + ".msg_bytes." +
150 MessageSizeType_to_string(MessageSizeType(type)))
151 .flags(Stats::nozero)
152 ;
153
154 for (unsigned int i = 0; i < m_throttles.size(); i++) {
155 m_msg_counts[type] += m_throttles[i]->getMsgCount(type);
156 }
157 m_msg_bytes[type] = m_msg_counts[type] * Stats::constant(
158 Network::MessageSizeType_to_int(MessageSizeType(type)));
159 }
160}
161
162void
163Switch::resetStats()
164{
165 m_perfect_switch->clearStats();
166 for (int i = 0; i < m_throttles.size(); i++) {
167 m_throttles[i]->clearStats();
168 }
169}
170
171void
172Switch::collateStats()
173{
174 m_perfect_switch->collateStats();
175 for (int i = 0; i < m_throttles.size(); i++) {
176 m_throttles[i]->collateStats();
177 }
178}
179
180void
181Switch::print(std::ostream& out) const
182{
183 // FIXME printing
184 out << "[Switch]";
185}
186
187bool
188Switch::functionalRead(Packet *pkt)
189{
190 // Access the buffers in the switch for performing a functional read
106
107 buffer_ptr->setSender(this);
108 buffer_ptr->setReceiver(this);
109 }
110
111 // Hook the queues to the PerfectSwitch
112 m_perfect_switch->addOutPort(intermediateBuffers, routing_table_entry);
113
114 // Hook the queues to the Throttle
115 throttle_ptr->addLinks(intermediateBuffers, out);
116}
117
118const Throttle*
119Switch::getThrottle(LinkID link_number) const
120{
121 assert(m_throttles[link_number] != NULL);
122 return m_throttles[link_number];
123}
124
125void
126Switch::regStats()
127{
128 for (int link = 0; link < m_throttles.size(); link++) {
129 m_throttles[link]->regStats(name());
130 }
131
132 m_avg_utilization.name(name() + ".percent_links_utilized");
133 for (unsigned int i = 0; i < m_throttles.size(); i++) {
134 m_avg_utilization += m_throttles[i]->getUtilization();
135 }
136 m_avg_utilization /= Stats::constant(m_throttles.size());
137
138 for (unsigned int type = MessageSizeType_FIRST;
139 type < MessageSizeType_NUM; ++type) {
140 m_msg_counts[type]
141 .name(name() + ".msg_count." +
142 MessageSizeType_to_string(MessageSizeType(type)))
143 .flags(Stats::nozero)
144 ;
145 m_msg_bytes[type]
146 .name(name() + ".msg_bytes." +
147 MessageSizeType_to_string(MessageSizeType(type)))
148 .flags(Stats::nozero)
149 ;
150
151 for (unsigned int i = 0; i < m_throttles.size(); i++) {
152 m_msg_counts[type] += m_throttles[i]->getMsgCount(type);
153 }
154 m_msg_bytes[type] = m_msg_counts[type] * Stats::constant(
155 Network::MessageSizeType_to_int(MessageSizeType(type)));
156 }
157}
158
159void
160Switch::resetStats()
161{
162 m_perfect_switch->clearStats();
163 for (int i = 0; i < m_throttles.size(); i++) {
164 m_throttles[i]->clearStats();
165 }
166}
167
168void
169Switch::collateStats()
170{
171 m_perfect_switch->collateStats();
172 for (int i = 0; i < m_throttles.size(); i++) {
173 m_throttles[i]->collateStats();
174 }
175}
176
177void
178Switch::print(std::ostream& out) const
179{
180 // FIXME printing
181 out << "[Switch]";
182}
183
184bool
185Switch::functionalRead(Packet *pkt)
186{
187 // Access the buffers in the switch for performing a functional read
191 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
192 if (m_buffers_to_free[i]->functionalRead(pkt)) {
188 for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
189 if (m_port_buffers[i]->functionalRead(pkt)) {
193 return true;
194 }
195 }
196 return false;
197}
198
199uint32_t
200Switch::functionalWrite(Packet *pkt)
201{
202 // Access the buffers in the switch for performing a functional write
203 uint32_t num_functional_writes = 0;
190 return true;
191 }
192 }
193 return false;
194}
195
196uint32_t
197Switch::functionalWrite(Packet *pkt)
198{
199 // Access the buffers in the switch for performing a functional write
200 uint32_t num_functional_writes = 0;
204 for (unsigned int i = 0; i < m_buffers_to_free.size(); ++i) {
205 num_functional_writes += m_buffers_to_free[i]->functionalWrite(pkt);
201 for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
202 num_functional_writes += m_port_buffers[i]->functionalWrite(pkt);
206 }
207 return num_functional_writes;
208}
209
210Switch *
211SwitchParams::create()
212{
213 return new Switch(this);
214}
203 }
204 return num_functional_writes;
205}
206
207Switch *
208SwitchParams::create()
209{
210 return new Switch(this);
211}