PerfectSwitch.hh revision 7454
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 296145Snate@binkert.org/* 307054Snate@binkert.org * Perfect switch, of course it is perfect and no latency or what so 317054Snate@binkert.org * ever. Every cycle it is woke up and perform all the necessary 327054Snate@binkert.org * routings that must be done. Note, this switch also has number of 337054Snate@binkert.org * input ports/output ports and has a routing table as well. 346145Snate@binkert.org */ 356145Snate@binkert.org 367054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 377054Snate@binkert.org#define __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 386145Snate@binkert.org 397002Snate@binkert.org#include <iostream> 407454Snate@binkert.org#include <vector> 417002Snate@binkert.org 426154Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 437054Snate@binkert.org#include "mem/ruby/common/Global.hh" 446154Snate@binkert.org#include "mem/ruby/system/NodeID.hh" 456145Snate@binkert.org 466145Snate@binkert.orgclass MessageBuffer; 476145Snate@binkert.orgclass NetDest; 486145Snate@binkert.orgclass SimpleNetwork; 496145Snate@binkert.org 507054Snate@binkert.orgstruct LinkOrder 517054Snate@binkert.org{ 527054Snate@binkert.org int m_link; 537054Snate@binkert.org int m_value; 546145Snate@binkert.org}; 556145Snate@binkert.org 567054Snate@binkert.orgclass PerfectSwitch : public Consumer 577054Snate@binkert.org{ 587054Snate@binkert.org public: 597054Snate@binkert.org PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr); 607054Snate@binkert.org ~PerfectSwitch(); 616145Snate@binkert.org 627454Snate@binkert.org void addInPort(const std::vector<MessageBuffer*>& in); 637454Snate@binkert.org void addOutPort(const std::vector<MessageBuffer*>& out, 647054Snate@binkert.org const NetDest& routing_table_entry); 657054Snate@binkert.org void clearRoutingTables(); 667054Snate@binkert.org void clearBuffers(); 677054Snate@binkert.org void reconfigureOutPort(const NetDest& routing_table_entry); 687054Snate@binkert.org int getInLinks() const { return m_in.size(); } 697054Snate@binkert.org int getOutLinks() const { return m_out.size(); } 706145Snate@binkert.org 717054Snate@binkert.org void wakeup(); 726145Snate@binkert.org 737054Snate@binkert.org void printStats(std::ostream& out) const; 747054Snate@binkert.org void clearStats(); 757054Snate@binkert.org void printConfig(std::ostream& out) const; 766145Snate@binkert.org 777054Snate@binkert.org void print(std::ostream& out) const; 786145Snate@binkert.org 797054Snate@binkert.org private: 807054Snate@binkert.org // Private copy constructor and assignment operator 817054Snate@binkert.org PerfectSwitch(const PerfectSwitch& obj); 827054Snate@binkert.org PerfectSwitch& operator=(const PerfectSwitch& obj); 836145Snate@binkert.org 847054Snate@binkert.org SwitchID m_switch_id; 856145Snate@binkert.org 867054Snate@binkert.org // vector of queues from the components 877454Snate@binkert.org std::vector<std::vector<MessageBuffer*> > m_in; 887454Snate@binkert.org std::vector<std::vector<MessageBuffer*> > m_out; 897454Snate@binkert.org std::vector<NetDest> m_routing_table; 907454Snate@binkert.org std::vector<LinkOrder> m_link_order; 917054Snate@binkert.org int m_virtual_networks; 927054Snate@binkert.org int m_round_robin_start; 937054Snate@binkert.org int m_wakeups_wo_switch; 947054Snate@binkert.org SimpleNetwork* m_network_ptr; 956145Snate@binkert.org}; 966145Snate@binkert.org 977054Snate@binkert.orginline std::ostream& 987054Snate@binkert.orgoperator<<(std::ostream& out, const PerfectSwitch& obj) 996145Snate@binkert.org{ 1007054Snate@binkert.org obj.print(out); 1017054Snate@binkert.org out << std::flush; 1027054Snate@binkert.org return out; 1036145Snate@binkert.org} 1046145Snate@binkert.org 1057054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 106