Switch.hh revision 11021
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 * The actual modelled switch. It use the perfect switch and a 317054Snate@binkert.org * Throttle object to control and bandwidth and timing *only for the 327054Snate@binkert.org * output port*. So here we have un-realistic modelling, since the 337054Snate@binkert.org * order of PerfectSwitch and Throttle objects get woke up affect the 347054Snate@binkert.org * message timing. A more accurate model would be having two set of 357054Snate@binkert.org * system states, one for this cycle, one for next cycle. And on the 367054Snate@binkert.org * cycle boundary swap the two set of states. 376145Snate@binkert.org */ 386145Snate@binkert.org 397054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__ 407054Snate@binkert.org#define __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__ 416145Snate@binkert.org 427002Snate@binkert.org#include <iostream> 437454Snate@binkert.org#include <vector> 447002Snate@binkert.org 459389Sandreas.hansson@arm.com#include "mem/packet.hh" 469866Sjthestness@gmail.com#include "mem/protocol/MessageSizeType.hh" 479389Sandreas.hansson@arm.com#include "mem/ruby/common/TypeDefines.hh" 489274Snilay@cs.wisc.edu#include "mem/ruby/network/BasicRouter.hh" 499274Snilay@cs.wisc.edu#include "params/Switch.hh" 509274Snilay@cs.wisc.edu 516145Snate@binkert.orgclass MessageBuffer; 526145Snate@binkert.orgclass PerfectSwitch; 536145Snate@binkert.orgclass NetDest; 546145Snate@binkert.orgclass SimpleNetwork; 556145Snate@binkert.orgclass Throttle; 566145Snate@binkert.org 579274Snilay@cs.wisc.educlass Switch : public BasicRouter 587054Snate@binkert.org{ 597054Snate@binkert.org public: 609274Snilay@cs.wisc.edu typedef SwitchParams Params; 619274Snilay@cs.wisc.edu Switch(const Params *p); 627054Snate@binkert.org ~Switch(); 6310311Snilay@cs.wisc.edu void init(); 646145Snate@binkert.org 6510370Snilay@cs.wisc.edu void addInPort(const std::vector<MessageBuffer*>& in); 6610370Snilay@cs.wisc.edu void addOutPort(const std::vector<MessageBuffer*>& out, 6710311Snilay@cs.wisc.edu const NetDest& routing_table_entry, 6810311Snilay@cs.wisc.edu Cycles link_latency, int bw_multiplier); 6910311Snilay@cs.wisc.edu 707054Snate@binkert.org const Throttle* getThrottle(LinkID link_number) const; 716145Snate@binkert.org 729863Snilay@cs.wisc.edu void resetStats(); 739863Snilay@cs.wisc.edu void collateStats(); 749863Snilay@cs.wisc.edu void regStats(); 759863Snilay@cs.wisc.edu const Stats::Formula & getMsgCount(unsigned int type) const 769863Snilay@cs.wisc.edu { return m_msg_counts[type]; } 779863Snilay@cs.wisc.edu 787054Snate@binkert.org void print(std::ostream& out) const; 799274Snilay@cs.wisc.edu void init_net_ptr(SimpleNetwork* net_ptr) { m_network_ptr = net_ptr; } 806145Snate@binkert.org 819302Snilay@cs.wisc.edu bool functionalRead(Packet *); 829302Snilay@cs.wisc.edu uint32_t functionalWrite(Packet *); 839302Snilay@cs.wisc.edu 847054Snate@binkert.org private: 857054Snate@binkert.org // Private copy constructor and assignment operator 867054Snate@binkert.org Switch(const Switch& obj); 877054Snate@binkert.org Switch& operator=(const Switch& obj); 886145Snate@binkert.org 899858Snilay@cs.wisc.edu PerfectSwitch* m_perfect_switch; 908259SBrad.Beckmann@amd.com SimpleNetwork* m_network_ptr; 917454Snate@binkert.org std::vector<Throttle*> m_throttles; 9211021Sjthestness@gmail.com std::vector<MessageBuffer*> m_port_buffers; 9311021Sjthestness@gmail.com unsigned m_num_connected_buffers; 949863Snilay@cs.wisc.edu 959863Snilay@cs.wisc.edu // Statistical variables 969863Snilay@cs.wisc.edu Stats::Formula m_avg_utilization; 979866Sjthestness@gmail.com Stats::Formula m_msg_counts[MessageSizeType_NUM]; 989866Sjthestness@gmail.com Stats::Formula m_msg_bytes[MessageSizeType_NUM]; 996145Snate@binkert.org}; 1006145Snate@binkert.org 1017054Snate@binkert.orginline std::ostream& 1027054Snate@binkert.orgoperator<<(std::ostream& out, const Switch& obj) 1036145Snate@binkert.org{ 1047054Snate@binkert.org obj.print(out); 1057054Snate@binkert.org out << std::flush; 1067054Snate@binkert.org return out; 1076145Snate@binkert.org} 1086145Snate@binkert.org 1097054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__ 110