PerfectSwitch.hh revision 9554
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> 408229Snate@binkert.org#include <string> 417454Snate@binkert.org#include <vector> 427002Snate@binkert.org 436154Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 446145Snate@binkert.org 456145Snate@binkert.orgclass MessageBuffer; 466145Snate@binkert.orgclass NetDest; 476145Snate@binkert.orgclass SimpleNetwork; 489274Snilay@cs.wisc.educlass Switch; 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 569554Sandreas.hansson@arm.combool operator<(const LinkOrder& l1, const LinkOrder& l2); 579554Sandreas.hansson@arm.com 587054Snate@binkert.orgclass PerfectSwitch : public Consumer 597054Snate@binkert.org{ 607054Snate@binkert.org public: 619274Snilay@cs.wisc.edu PerfectSwitch(SwitchID sid, Switch *, uint32_t); 627054Snate@binkert.org ~PerfectSwitch(); 636145Snate@binkert.org 648054Sksewell@umich.edu std::string name() 658054Sksewell@umich.edu { return csprintf("PerfectSwitch-%i", m_switch_id); } 668054Sksewell@umich.edu 679274Snilay@cs.wisc.edu void init(SimpleNetwork *); 689508Snilay@cs.wisc.edu void addInPort(const std::vector<MessageBuffer*>& in); 697454Snate@binkert.org void addOutPort(const std::vector<MessageBuffer*>& out, 707054Snate@binkert.org const NetDest& routing_table_entry); 717054Snate@binkert.org void clearRoutingTables(); 727054Snate@binkert.org void clearBuffers(); 737054Snate@binkert.org void reconfigureOutPort(const NetDest& routing_table_entry); 747054Snate@binkert.org int getInLinks() const { return m_in.size(); } 757054Snate@binkert.org int getOutLinks() const { return m_out.size(); } 766145Snate@binkert.org 777054Snate@binkert.org void wakeup(); 787973Snilay@cs.wisc.edu void storeEventInfo(int info); 796145Snate@binkert.org 807054Snate@binkert.org void printStats(std::ostream& out) const; 817054Snate@binkert.org void clearStats(); 827054Snate@binkert.org void print(std::ostream& out) const; 836145Snate@binkert.org 847054Snate@binkert.org private: 857054Snate@binkert.org // Private copy constructor and assignment operator 867054Snate@binkert.org PerfectSwitch(const PerfectSwitch& obj); 877054Snate@binkert.org PerfectSwitch& operator=(const PerfectSwitch& obj); 886145Snate@binkert.org 897054Snate@binkert.org SwitchID m_switch_id; 906145Snate@binkert.org 917054Snate@binkert.org // vector of queues from the components 927454Snate@binkert.org std::vector<std::vector<MessageBuffer*> > m_in; 937454Snate@binkert.org std::vector<std::vector<MessageBuffer*> > m_out; 947454Snate@binkert.org std::vector<NetDest> m_routing_table; 957454Snate@binkert.org std::vector<LinkOrder> m_link_order; 969274Snilay@cs.wisc.edu 979274Snilay@cs.wisc.edu uint32_t m_virtual_networks; 987054Snate@binkert.org int m_round_robin_start; 997054Snate@binkert.org int m_wakeups_wo_switch; 1009274Snilay@cs.wisc.edu 1017054Snate@binkert.org SimpleNetwork* m_network_ptr; 1027973Snilay@cs.wisc.edu std::vector<int> m_pending_message_count; 1036145Snate@binkert.org}; 1046145Snate@binkert.org 1057054Snate@binkert.orginline std::ostream& 1067054Snate@binkert.orgoperator<<(std::ostream& out, const PerfectSwitch& obj) 1076145Snate@binkert.org{ 1087054Snate@binkert.org obj.print(out); 1097054Snate@binkert.org out << std::flush; 1107054Snate@binkert.org return out; 1116145Snate@binkert.org} 1126145Snate@binkert.org 1137054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 114