1 2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 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" 44#include "mem/protocol/MessageSizeType.hh" 45#include "mem/ruby/network/Network.hh" 46#include "mem/protocol/Protocol.hh" 47 48Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr) 49{ 50 m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr); 51 m_switch_id = sid; 52 m_throttles.setSize(0); 53} 54 55Switch::~Switch() 56{ 57 delete m_perfect_switch_ptr; 58 59 // Delete throttles (one per output port) 60 m_throttles.deletePointers(); 61 62 // Delete MessageBuffers 63 m_buffers_to_free.deletePointers(); 64} 65 66void Switch::addInPort(const Vector<MessageBuffer*>& in) 67{ 68 m_perfect_switch_ptr->addInPort(in); 69} 70 71void Switch::addOutPort(const Vector<MessageBuffer*>& out, const NetDest& routing_table_entry, int link_latency, int bw_multiplier) 72{ 73 Throttle* throttle_ptr = NULL; 74 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); 78 79 // Create one buffer per vnet (these are intermediaryQueues) 80 Vector<MessageBuffer*> 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); 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} 100 101void Switch::clearRoutingTables() 102{ 103 m_perfect_switch_ptr->clearRoutingTables(); 104} 105 106void Switch::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 Switch::reconfigureOutPort(const NetDest& routing_table_entry) 117{ 118 m_perfect_switch_ptr->reconfigureOutPort(routing_table_entry); 119} 120 121const Throttle* Switch::getThrottle(LinkID link_number) const 122{ 123 assert(m_throttles[link_number] != NULL); 124 return m_throttles[link_number]; 125} 126 127const Vector<Throttle*>* Switch::getThrottles() const 128{ 129 return &m_throttles; 130} 131
| 1 2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 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" 44#include "mem/protocol/MessageSizeType.hh" 45#include "mem/ruby/network/Network.hh" 46#include "mem/protocol/Protocol.hh" 47 48Switch::Switch(SwitchID sid, SimpleNetwork* network_ptr) 49{ 50 m_perfect_switch_ptr = new PerfectSwitch(sid, network_ptr); 51 m_switch_id = sid; 52 m_throttles.setSize(0); 53} 54 55Switch::~Switch() 56{ 57 delete m_perfect_switch_ptr; 58 59 // Delete throttles (one per output port) 60 m_throttles.deletePointers(); 61 62 // Delete MessageBuffers 63 m_buffers_to_free.deletePointers(); 64} 65 66void Switch::addInPort(const Vector<MessageBuffer*>& in) 67{ 68 m_perfect_switch_ptr->addInPort(in); 69} 70 71void Switch::addOutPort(const Vector<MessageBuffer*>& out, const NetDest& routing_table_entry, int link_latency, int bw_multiplier) 72{ 73 Throttle* throttle_ptr = NULL; 74 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); 78 79 // Create one buffer per vnet (these are intermediaryQueues) 80 Vector<MessageBuffer*> 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); 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} 100 101void Switch::clearRoutingTables() 102{ 103 m_perfect_switch_ptr->clearRoutingTables(); 104} 105 106void Switch::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 Switch::reconfigureOutPort(const NetDest& routing_table_entry) 117{ 118 m_perfect_switch_ptr->reconfigureOutPort(routing_table_entry); 119} 120 121const Throttle* Switch::getThrottle(LinkID link_number) const 122{ 123 assert(m_throttles[link_number] != NULL); 124 return m_throttles[link_number]; 125} 126 127const Vector<Throttle*>* Switch::getThrottles() const 128{ 129 return &m_throttles; 130} 131
|