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" 4411793Sbrandon.potter@amd.com#include "mem/ruby/common/TypeDefines.hh" 456145Snate@binkert.org 466145Snate@binkert.orgclass MessageBuffer; 476145Snate@binkert.orgclass NetDest; 486145Snate@binkert.orgclass SimpleNetwork; 499274Snilay@cs.wisc.educlass Switch; 506145Snate@binkert.org 517054Snate@binkert.orgstruct LinkOrder 527054Snate@binkert.org{ 537054Snate@binkert.org int m_link; 547054Snate@binkert.org int m_value; 556145Snate@binkert.org}; 566145Snate@binkert.org 579554Sandreas.hansson@arm.combool operator<(const LinkOrder& l1, const LinkOrder& l2); 589554Sandreas.hansson@arm.com 597054Snate@binkert.orgclass PerfectSwitch : public Consumer 607054Snate@binkert.org{ 617054Snate@binkert.org public: 629274Snilay@cs.wisc.edu PerfectSwitch(SwitchID sid, Switch *, uint32_t); 637054Snate@binkert.org ~PerfectSwitch(); 646145Snate@binkert.org 658054Sksewell@umich.edu std::string name() 668054Sksewell@umich.edu { return csprintf("PerfectSwitch-%i", m_switch_id); } 678054Sksewell@umich.edu 689274Snilay@cs.wisc.edu void init(SimpleNetwork *); 6910370Snilay@cs.wisc.edu void addInPort(const std::vector<MessageBuffer*>& in); 7010370Snilay@cs.wisc.edu void addOutPort(const std::vector<MessageBuffer*>& out, 719863Snilay@cs.wisc.edu const NetDest& routing_table_entry); 7210311Snilay@cs.wisc.edu 737054Snate@binkert.org int getInLinks() const { return m_in.size(); } 747054Snate@binkert.org int getOutLinks() const { return m_out.size(); } 756145Snate@binkert.org 767054Snate@binkert.org void wakeup(); 777973Snilay@cs.wisc.edu void storeEventInfo(int info); 786145Snate@binkert.org 797054Snate@binkert.org void clearStats(); 809863Snilay@cs.wisc.edu void collateStats(); 817054Snate@binkert.org void print(std::ostream& out) const; 826145Snate@binkert.org 837054Snate@binkert.org private: 847054Snate@binkert.org // Private copy constructor and assignment operator 857054Snate@binkert.org PerfectSwitch(const PerfectSwitch& obj); 867054Snate@binkert.org PerfectSwitch& operator=(const PerfectSwitch& obj); 876145Snate@binkert.org 8810312Snilay@cs.wisc.edu void operateVnet(int vnet); 8911093Snilay@cs.wisc.edu void operateMessageBuffer(MessageBuffer *b, int incoming, int vnet); 9010312Snilay@cs.wisc.edu 9111092Snilay@cs.wisc.edu const SwitchID m_switch_id; 9211092Snilay@cs.wisc.edu Switch * const m_switch; 936145Snate@binkert.org 947054Snate@binkert.org // vector of queues from the components 9510370Snilay@cs.wisc.edu std::vector<std::vector<MessageBuffer*> > m_in; 9610370Snilay@cs.wisc.edu std::vector<std::vector<MessageBuffer*> > m_out; 9710311Snilay@cs.wisc.edu 987454Snate@binkert.org std::vector<NetDest> m_routing_table; 997454Snate@binkert.org std::vector<LinkOrder> m_link_order; 1009274Snilay@cs.wisc.edu 1019274Snilay@cs.wisc.edu uint32_t m_virtual_networks; 1027054Snate@binkert.org int m_round_robin_start; 1037054Snate@binkert.org int m_wakeups_wo_switch; 1049274Snilay@cs.wisc.edu 1057054Snate@binkert.org SimpleNetwork* m_network_ptr; 1067973Snilay@cs.wisc.edu std::vector<int> m_pending_message_count; 1076145Snate@binkert.org}; 1086145Snate@binkert.org 1097054Snate@binkert.orginline std::ostream& 1107054Snate@binkert.orgoperator<<(std::ostream& out, const PerfectSwitch& obj) 1116145Snate@binkert.org{ 1127054Snate@binkert.org obj.print(out); 1137054Snate@binkert.org out << std::flush; 1147054Snate@binkert.org return out; 1156145Snate@binkert.org} 1166145Snate@binkert.org 1177054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__ 118