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