Network.hh revision 11113:5a2e1b1b5c43
111507SCurtis.Dunham@arm.com/* 211507SCurtis.Dunham@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 311960Sgabeblack@google.com * All rights reserved. 411960Sgabeblack@google.com * 511960Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 611960Sgabeblack@google.com * modification, are permitted provided that the following conditions are 711960Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 811960Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 911960Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1011960Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1111960Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1211960Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1311960Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1411960Sgabeblack@google.com * this software without specific prior written permission. 1511960Sgabeblack@google.com * 1611960Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711960Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811960Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911960Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011960Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111960Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211960Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311960Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411960Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511960Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611960Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711960Sgabeblack@google.com */ 2811960Sgabeblack@google.com 2911960Sgabeblack@google.com/* 3011960Sgabeblack@google.com * The Network class is the base class for classes that implement the 3111960Sgabeblack@google.com * interconnection network between components (processor/cache 3211960Sgabeblack@google.com * components and memory/directory components). The interconnection 3311960Sgabeblack@google.com * network as described here is not a physical network, but a 3411960Sgabeblack@google.com * programming concept used to implement all communication between 3511960Sgabeblack@google.com * components. Thus parts of this 'network' will model the on-chip 3611960Sgabeblack@google.com * connections between cache controllers and directory controllers as 3711960Sgabeblack@google.com * well as the links between chip and network switches. 3811960Sgabeblack@google.com */ 3911960Sgabeblack@google.com 4011960Sgabeblack@google.com#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__ 4111960Sgabeblack@google.com#define __MEM_RUBY_NETWORK_NETWORK_HH__ 4211960Sgabeblack@google.com 4311960Sgabeblack@google.com#include <iostream> 4411960Sgabeblack@google.com#include <string> 4511960Sgabeblack@google.com#include <vector> 4611960Sgabeblack@google.com 4711960Sgabeblack@google.com#include "mem/protocol/LinkDirection.hh" 4811960Sgabeblack@google.com#include "mem/protocol/MessageSizeType.hh" 4911960Sgabeblack@google.com#include "mem/ruby/common/TypeDefines.hh" 5011960Sgabeblack@google.com#include "mem/ruby/network/Topology.hh" 5111960Sgabeblack@google.com#include "mem/packet.hh" 5211960Sgabeblack@google.com#include "params/RubyNetwork.hh" 5311960Sgabeblack@google.com#include "sim/clocked_object.hh" 5411960Sgabeblack@google.com 5511960Sgabeblack@google.comclass NetDest; 5611960Sgabeblack@google.comclass MessageBuffer; 5711960Sgabeblack@google.com 5811960Sgabeblack@google.comclass Network : public ClockedObject 5911960Sgabeblack@google.com{ 6011960Sgabeblack@google.com public: 6111960Sgabeblack@google.com typedef RubyNetworkParams Params; 6211960Sgabeblack@google.com Network(const Params *p); 6311960Sgabeblack@google.com const Params * params() const 6411960Sgabeblack@google.com { return dynamic_cast<const Params *>(_params); } 6511960Sgabeblack@google.com 6611960Sgabeblack@google.com virtual ~Network(); 6711960Sgabeblack@google.com virtual void init(); 6811960Sgabeblack@google.com 6911960Sgabeblack@google.com static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; } 7011960Sgabeblack@google.com int getNumNodes() const { return m_nodes; } 7111960Sgabeblack@google.com 7211960Sgabeblack@google.com static uint32_t MessageSizeType_to_int(MessageSizeType size_type); 7311960Sgabeblack@google.com 7411960Sgabeblack@google.com // returns the queue requested for the given component 7511960Sgabeblack@google.com void setToNetQueue(NodeID id, bool ordered, int netNumber, 7611960Sgabeblack@google.com std::string vnet_type, MessageBuffer *b); 7711960Sgabeblack@google.com virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber, 7811960Sgabeblack@google.com std::string vnet_type, MessageBuffer *b); 7911960Sgabeblack@google.com 8011960Sgabeblack@google.com virtual void checkNetworkAllocation(NodeID id, bool ordered, 8111960Sgabeblack@google.com int network_num, std::string vnet_type); 8211960Sgabeblack@google.com 8311960Sgabeblack@google.com virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link, 8411960Sgabeblack@google.com LinkDirection direction, 8511960Sgabeblack@google.com const NetDest& routing_table_entry) = 0; 8611960Sgabeblack@google.com virtual void makeInLink(NodeID src, SwitchID dest, BasicLink* link, 8711960Sgabeblack@google.com LinkDirection direction, 8811960Sgabeblack@google.com const NetDest& routing_table_entry) = 0; 8911960Sgabeblack@google.com virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 9011960Sgabeblack@google.com LinkDirection direction, 9111960Sgabeblack@google.com const NetDest& routing_table_entry) = 0; 9211960Sgabeblack@google.com 9311960Sgabeblack@google.com virtual void collateStats() = 0; 9411960Sgabeblack@google.com virtual void print(std::ostream& out) const = 0; 9511960Sgabeblack@google.com 9611960Sgabeblack@google.com /* 9711960Sgabeblack@google.com * Virtual functions for functionally reading and writing packets in 9811960Sgabeblack@google.com * the network. Each network needs to implement these for functional 9911960Sgabeblack@google.com * accesses to work correctly. 10011960Sgabeblack@google.com */ 10111960Sgabeblack@google.com virtual bool functionalRead(Packet *pkt) 10211960Sgabeblack@google.com { fatal("Functional read not implemented.\n"); } 10311960Sgabeblack@google.com virtual uint32_t functionalWrite(Packet *pkt) 10411960Sgabeblack@google.com { fatal("Functional write not implemented.\n"); } 10511960Sgabeblack@google.com 10611960Sgabeblack@google.com protected: 10711960Sgabeblack@google.com // Private copy constructor and assignment operator 10811960Sgabeblack@google.com Network(const Network& obj); 10911960Sgabeblack@google.com Network& operator=(const Network& obj); 11011960Sgabeblack@google.com 11111960Sgabeblack@google.com uint32_t m_nodes; 11211960Sgabeblack@google.com static uint32_t m_virtual_networks; 11311960Sgabeblack@google.com std::vector<std::string> m_vnet_type_names; 11411960Sgabeblack@google.com Topology* m_topology_ptr; 11511960Sgabeblack@google.com static uint32_t m_control_msg_size; 11611960Sgabeblack@google.com static uint32_t m_data_msg_size; 11711960Sgabeblack@google.com 11811960Sgabeblack@google.com // vector of queues from the components 11911960Sgabeblack@google.com std::vector<std::vector<MessageBuffer*> > m_toNetQueues; 12011960Sgabeblack@google.com std::vector<std::vector<MessageBuffer*> > m_fromNetQueues; 12111960Sgabeblack@google.com std::vector<bool> m_ordered; 12211960Sgabeblack@google.com 12311960Sgabeblack@google.com private: 12411960Sgabeblack@google.com //! Callback class used for collating statistics from all the 12511960Sgabeblack@google.com //! controller of this type. 12611960Sgabeblack@google.com class StatsCallback : public Callback 12711960Sgabeblack@google.com { 12811960Sgabeblack@google.com private: 12911960Sgabeblack@google.com Network *ctr; 13011960Sgabeblack@google.com 13111960Sgabeblack@google.com public: 13211960Sgabeblack@google.com virtual ~StatsCallback() {} 13311960Sgabeblack@google.com 13411960Sgabeblack@google.com StatsCallback(Network *_ctr) 13511960Sgabeblack@google.com : ctr(_ctr) 13611960Sgabeblack@google.com { 13711960Sgabeblack@google.com } 13811507SCurtis.Dunham@arm.com 13911507SCurtis.Dunham@arm.com void process() {ctr->collateStats();} 140 }; 141}; 142 143inline std::ostream& 144operator<<(std::ostream& out, const Network& obj) 145{ 146 obj.print(out); 147 out << std::flush; 148 return out; 149} 150 151#endif // __MEM_RUBY_NETWORK_NETWORK_HH__ 152