PerfectSwitch.hh revision 10312
14107SN/A/* 23294SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 33294SN/A * All rights reserved. 43294SN/A * 53294SN/A * Redistribution and use in source and binary forms, with or without 63294SN/A * modification, are permitted provided that the following conditions are 73294SN/A * met: redistributions of source code must retain the above copyright 83294SN/A * notice, this list of conditions and the following disclaimer; 93294SN/A * redistributions in binary form must reproduce the above copyright 103294SN/A * notice, this list of conditions and the following disclaimer in the 113294SN/A * documentation and/or other materials provided with the distribution; 123294SN/A * neither the name of the copyright holders nor the names of its 133294SN/A * contributors may be used to endorse or promote products derived from 143294SN/A * this software without specific prior written permission. 153294SN/A * 163294SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173294SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183294SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193294SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203294SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213294SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223294SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233294SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243294SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253294SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263294SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273294SN/A */ 283294SN/A 296654SN/A/* 303671SN/A * Perfect switch, of course it is perfect and no latency or what so 314107SN/A * ever. Every cycle it is woke up and perform all the necessary 323671SN/A * routings that must be done. Note, this switch also has number of 334227SN/A * input ports/output ports and has a routing table as well. 349792Sandreas.hansson@arm.com */ 359792Sandreas.hansson@arm.com 364107SN/A#ifndef __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 374107SN/A#define __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 384107SN/A 394107SN/A#include <iostream> 404199SN/A#include <string> 414199SN/A#include <vector> 424199SN/A 434199SN/A#include "mem/ruby/common/Consumer.hh" 444199SN/A 454199SN/Aclass MessageBuffer; 464199SN/Aclass NetDest; 474199SN/Aclass SimpleNetwork; 48class Switch; 49 50struct LinkOrder 51{ 52 int m_link; 53 int m_value; 54}; 55 56bool operator<(const LinkOrder& l1, const LinkOrder& l2); 57 58class PerfectSwitch : public Consumer 59{ 60 public: 61 PerfectSwitch(SwitchID sid, Switch *, uint32_t); 62 ~PerfectSwitch(); 63 64 std::string name() 65 { return csprintf("PerfectSwitch-%i", m_switch_id); } 66 67 void init(SimpleNetwork *); 68 void addInPort(const std::map<int, MessageBuffer*>& in); 69 void addOutPort(const std::map<int, MessageBuffer*>& out, 70 const NetDest& routing_table_entry); 71 72 int getInLinks() const { return m_in.size(); } 73 int getOutLinks() const { return m_out.size(); } 74 75 void wakeup(); 76 void storeEventInfo(int info); 77 78 void clearStats(); 79 void collateStats(); 80 void print(std::ostream& out) const; 81 82 private: 83 // Private copy constructor and assignment operator 84 PerfectSwitch(const PerfectSwitch& obj); 85 PerfectSwitch& operator=(const PerfectSwitch& obj); 86 87 void operateVnet(int vnet); 88 89 SwitchID m_switch_id; 90 91 // vector of queues from the components 92 std::vector<std::map<int, MessageBuffer*> > m_in; 93 std::vector<std::map<int, MessageBuffer*> > m_out; 94 95 std::vector<NetDest> m_routing_table; 96 std::vector<LinkOrder> m_link_order; 97 98 uint32_t m_virtual_networks; 99 int m_round_robin_start; 100 int m_wakeups_wo_switch; 101 102 SimpleNetwork* m_network_ptr; 103 std::vector<int> m_pending_message_count; 104}; 105 106inline std::ostream& 107operator<<(std::ostream& out, const PerfectSwitch& obj) 108{ 109 obj.print(out); 110 out << std::flush; 111 return out; 112} 113 114#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 115