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