PerfectSwitch.hh revision 8229
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297039Snate@binkert.org/* 307039Snate@binkert.org * Perfect switch, of course it is perfect and no latency or what so 316145Snate@binkert.org * ever. Every cycle it is woke up and perform all the necessary 327002Snate@binkert.org * routings that must be done. Note, this switch also has number of 337002Snate@binkert.org * input ports/output ports and has a routing table as well. 347002Snate@binkert.org */ 356154Snate@binkert.org 366145Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 377039Snate@binkert.org#define __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 387039Snate@binkert.org 397039Snate@binkert.org#include <iostream> 407039Snate@binkert.org#include <string> 417039Snate@binkert.org#include <vector> 427039Snate@binkert.org 437039Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 446145Snate@binkert.org#include "mem/ruby/common/Global.hh" 458090Snilay@cs.wisc.edu#include "mem/ruby/system/NodeID.hh" 466285Snate@binkert.org 477039Snate@binkert.orgclass MessageBuffer; 487039Snate@binkert.orgclass NetDest; 497039Snate@binkert.orgclass SimpleNetwork; 507039Snate@binkert.org 517039Snate@binkert.orgstruct LinkOrder 526145Snate@binkert.org{ 537039Snate@binkert.org int m_link; 546285Snate@binkert.org int m_value; 557039Snate@binkert.org}; 566145Snate@binkert.org 577039Snate@binkert.orgclass PerfectSwitch : public Consumer 587039Snate@binkert.org{ 597039Snate@binkert.org public: 607039Snate@binkert.org PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr); 617039Snate@binkert.org ~PerfectSwitch(); 627039Snate@binkert.org 637039Snate@binkert.org std::string name() 647039Snate@binkert.org { return csprintf("PerfectSwitch-%i", m_switch_id); } 657039Snate@binkert.org 667039Snate@binkert.org void addInPort(const std::vector<MessageBuffer*>& in); 677039Snate@binkert.org void addOutPort(const std::vector<MessageBuffer*>& out, 687039Snate@binkert.org const NetDest& routing_table_entry); 697039Snate@binkert.org void clearRoutingTables(); 706145Snate@binkert.org void clearBuffers(); 716145Snate@binkert.org void reconfigureOutPort(const NetDest& routing_table_entry); 727039Snate@binkert.org int getInLinks() const { return m_in.size(); } 737039Snate@binkert.org int getOutLinks() const { return m_out.size(); } 746285Snate@binkert.org 757039Snate@binkert.org void wakeup(); 767039Snate@binkert.org void storeEventInfo(int info); 777039Snate@binkert.org 787039Snate@binkert.org void printStats(std::ostream& out) const; 797039Snate@binkert.org void clearStats(); 806285Snate@binkert.org void printConfig(std::ostream& out) const; 816285Snate@binkert.org 827039Snate@binkert.org void print(std::ostream& out) const; 837039Snate@binkert.org 846285Snate@binkert.org private: 857039Snate@binkert.org // Private copy constructor and assignment operator 866285Snate@binkert.org PerfectSwitch(const PerfectSwitch& obj); 876285Snate@binkert.org PerfectSwitch& operator=(const PerfectSwitch& obj); 887039Snate@binkert.org 897039Snate@binkert.org SwitchID m_switch_id; 906285Snate@binkert.org 916285Snate@binkert.org // vector of queues from the components 926285Snate@binkert.org std::vector<std::vector<MessageBuffer*> > m_in; 936285Snate@binkert.org std::vector<std::vector<MessageBuffer*> > m_out; 947039Snate@binkert.org std::vector<NetDest> m_routing_table; 957039Snate@binkert.org std::vector<LinkOrder> m_link_order; 966285Snate@binkert.org int m_virtual_networks; 977039Snate@binkert.org int m_round_robin_start; 986285Snate@binkert.org int m_wakeups_wo_switch; 996145Snate@binkert.org SimpleNetwork* m_network_ptr; 1007039Snate@binkert.org std::vector<int> m_pending_message_count; 1017039Snate@binkert.org}; 1026145Snate@binkert.org 1037039Snate@binkert.orginline std::ostream& 1047039Snate@binkert.orgoperator<<(std::ostream& out, const PerfectSwitch& obj) 1057039Snate@binkert.org{ 1066145Snate@binkert.org obj.print(out); 1076145Snate@binkert.org out << std::flush; 1087039Snate@binkert.org return out; 1097039Snate@binkert.org} 1106145Snate@binkert.org 1117039Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 1126145Snate@binkert.org