Switch.cc (7055:4e24742201d7) | Switch.cc (7454:3a3e8e8cce1b) |
---|---|
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; --- 12 unchanged lines hidden (view full) --- 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 | 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; --- 12 unchanged lines hidden (view full) --- 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" |
|
29#include "mem/protocol/MessageSizeType.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 37using namespace std; | 32#include "mem/protocol/MessageSizeType.hh" 33#include "mem/protocol/Protocol.hh" 34#include "mem/ruby/buffers/MessageBuffer.hh" 35#include "mem/ruby/network/Network.hh" 36#include "mem/ruby/network/simple/PerfectSwitch.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<<; |
|
38 39Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr) 40{ 41 m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr); 42 m_switch_id = sid; | 43 44Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr) 45{ 46 m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr); 47 m_switch_id = sid; |
43 m_throttles.setSize(0); | |
44} 45 46Switch::~Switch() 47{ 48 delete m_perfect_switch_ptr; 49 50 // Delete throttles (one per output port) | 48} 49 50Switch::~Switch() 51{ 52 delete m_perfect_switch_ptr; 53 54 // Delete throttles (one per output port) |
51 m_throttles.deletePointers(); | 55 deletePointers(m_throttles); |
52 53 // Delete MessageBuffers | 56 57 // Delete MessageBuffers |
54 m_buffers_to_free.deletePointers(); | 58 deletePointers(m_buffers_to_free); |
55} 56 57void | 59} 60 61void |
58Switch::addInPort(const Vector<MessageBuffer*>& in) | 62Switch::addInPort(const vector<MessageBuffer*>& in) |
59{ 60 m_perfect_switch_ptr->addInPort(in); 61} 62 63void | 63{ 64 m_perfect_switch_ptr->addInPort(in); 65} 66 67void |
64Switch::addOutPort(const Vector<MessageBuffer*>& out, | 68Switch::addOutPort(const vector<MessageBuffer*>& out, |
65 const NetDest& routing_table_entry, int link_latency, int bw_multiplier) 66{ 67 Throttle* throttle_ptr = NULL; 68 69 // Create a throttle 70 throttle_ptr = new Throttle(m_switch_id, m_throttles.size(), link_latency, 71 bw_multiplier); | 69 const NetDest& routing_table_entry, int link_latency, int bw_multiplier) 70{ 71 Throttle* throttle_ptr = NULL; 72 73 // Create a throttle 74 throttle_ptr = new Throttle(m_switch_id, m_throttles.size(), link_latency, 75 bw_multiplier); |
72 m_throttles.insertAtBottom(throttle_ptr); | 76 m_throttles.push_back(throttle_ptr); |
73 74 // Create one buffer per vnet (these are intermediaryQueues) | 77 78 // Create one buffer per vnet (these are intermediaryQueues) |
75 Vector<MessageBuffer*> intermediateBuffers; | 79 vector<MessageBuffer*> intermediateBuffers; |
76 for (int i = 0; i < out.size(); i++) { 77 MessageBuffer* buffer_ptr = new MessageBuffer; 78 // Make these queues ordered 79 buffer_ptr->setOrdering(true); 80 Network* net_ptr = RubySystem::getNetwork(); 81 if (net_ptr->getBufferSize() > 0) { | 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); 84 Network* net_ptr = RubySystem::getNetwork(); 85 if (net_ptr->getBufferSize() > 0) { |
82 buffer_ptr->setSize(net_ptr->getBufferSize()); | 86 buffer_ptr->resize(net_ptr->getBufferSize()); |
83 } | 87 } |
84 intermediateBuffers.insertAtBottom(buffer_ptr); 85 m_buffers_to_free.insertAtBottom(buffer_ptr); | 88 intermediateBuffers.push_back(buffer_ptr); 89 m_buffers_to_free.push_back(buffer_ptr); |
86 } 87 88 // Hook the queues to the PerfectSwitch 89 m_perfect_switch_ptr->addOutPort(intermediateBuffers, routing_table_entry); 90 91 // Hook the queues to the Throttle 92 throttle_ptr->addLinks(intermediateBuffers, out); 93} --- 23 unchanged lines hidden (view full) --- 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 | 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} --- 23 unchanged lines hidden (view full) --- 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 |
125const Vector<Throttle*>* | 129const vector<Throttle*>* |
126Switch::getThrottles() const 127{ 128 return &m_throttles; 129} 130 131void 132Switch::printStats(std::ostream& out) const 133{ --- 33 unchanged lines hidden (view full) --- 167 out << endl; 168 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 | 130Switch::getThrottles() const 131{ 132 return &m_throttles; 133} 134 135void 136Switch::printStats(std::ostream& out) const 137{ --- 33 unchanged lines hidden (view full) --- 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 |
175 const Vector<Vector<int> >& message_counts = | 179 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); | 180 throttle_ptr->getCounters(); 181 for (int int_type = 0; int_type < MessageSizeType_NUM; int_type++) { 182 MessageSizeType type = MessageSizeType(int_type); |
179 int sum = message_counts[type].sum(); | 183 const vector<int> &mct = message_counts[type]; 184 int sum = accumulate(mct.begin(), mct.end(), 0); |
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) | 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) |
186 << " " << message_counts[type] << " base_latency: " | 191 << " "; 192 out << mct; 193 out << " base_latency: " |
187 << throttle_ptr->getLatency() << endl; 188 } 189 } 190 out << endl; 191} 192 193void 194Switch::clearStats() --- 25 unchanged lines hidden --- | 194 << throttle_ptr->getLatency() << endl; 195 } 196 } 197 out << endl; 198} 199 200void 201Switch::clearStats() --- 25 unchanged lines hidden --- |