Network.hh revision 11664
12SN/A/* 21762SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu/* 302SN/A * The Network class is the base class for classes that implement the 312SN/A * interconnection network between components (processor/cache 322090SN/A * components and memory/directory components). The interconnection 332090SN/A * network as described here is not a physical network, but a 342SN/A * programming concept used to implement all communication between 353614Sgblack@eecs.umich.edu * components. Thus parts of this 'network' will model the on-chip 363614Sgblack@eecs.umich.edu * connections between cache controllers and directory controllers as 373614Sgblack@eecs.umich.edu * well as the links between chip and network switches. 383614Sgblack@eecs.umich.edu */ 392984Sgblack@eecs.umich.edu 403614Sgblack@eecs.umich.edu#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__ 412147SN/A#define __MEM_RUBY_NETWORK_NETWORK_HH__ 422166SN/A 432147SN/A#include <iostream> 442167SN/A#include <string> 452167SN/A#include <vector> 462167SN/A 472147SN/A#include "mem/protocol/LinkDirection.hh" 482090SN/A#include "mem/protocol/MessageSizeType.hh" 492222SN/A#include "mem/ruby/common/TypeDefines.hh" 502090SN/A#include "mem/ruby/network/Topology.hh" 512201SN/A#include "mem/packet.hh" 522201SN/A#include "params/RubyNetwork.hh" 532201SN/A#include "sim/clocked_object.hh" 542112SN/A 552174SN/Aclass NetDest; 562680Sktlim@umich.educlass MessageBuffer; 572174SN/A 582175SN/Aclass Network : public ClockedObject 592222SN/A{ 602SN/A public: 612SN/A typedef RubyNetworkParams Params; 622203SN/A Network(const Params *p); 632166SN/A const Params * params() const 642166SN/A { return dynamic_cast<const Params *>(_params); } 652203SN/A 662166SN/A virtual ~Network(); 672222SN/A virtual void init(); 682166SN/A 692203SN/A static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; } 702166SN/A int getNumNodes() const { return m_nodes; } 712222SN/A 722203SN/A static uint32_t MessageSizeType_to_int(MessageSizeType size_type); 732166SN/A 742166SN/A // returns the queue requested for the given component 752203SN/A void setToNetQueue(NodeID id, bool ordered, int netNumber, 762166SN/A std::string vnet_type, MessageBuffer *b); 772166SN/A virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber, 782203SN/A std::string vnet_type, MessageBuffer *b); 792166SN/A 802222SN/A virtual void checkNetworkAllocation(NodeID id, bool ordered, 812166SN/A int network_num, std::string vnet_type); 822203SN/A 832166SN/A virtual void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link, 842222SN/A const NetDest& routing_table_entry) = 0; 852203SN/A virtual void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link, 862166SN/A const NetDest& routing_table_entry) = 0; 872166SN/A virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 882800Ssaidi@eecs.umich.edu const NetDest& routing_table_entry, 892800Ssaidi@eecs.umich.edu PortDirection src_outport, 902800Ssaidi@eecs.umich.edu PortDirection dst_inport) = 0; 912800Ssaidi@eecs.umich.edu 922800Ssaidi@eecs.umich.edu virtual void collateStats() = 0; 932800Ssaidi@eecs.umich.edu virtual void print(std::ostream& out) const = 0; 942800Ssaidi@eecs.umich.edu 952800Ssaidi@eecs.umich.edu /* 962800Ssaidi@eecs.umich.edu * Virtual functions for functionally reading and writing packets in 972800Ssaidi@eecs.umich.edu * the network. Each network needs to implement these for functional 982800Ssaidi@eecs.umich.edu * accesses to work correctly. 992800Ssaidi@eecs.umich.edu */ 1002800Ssaidi@eecs.umich.edu virtual bool functionalRead(Packet *pkt) 1012800Ssaidi@eecs.umich.edu { fatal("Functional read not implemented.\n"); } 1022800Ssaidi@eecs.umich.edu virtual uint32_t functionalWrite(Packet *pkt) 1032800Ssaidi@eecs.umich.edu { fatal("Functional write not implemented.\n"); } 1042800Ssaidi@eecs.umich.edu 1052800Ssaidi@eecs.umich.edu protected: 1062800Ssaidi@eecs.umich.edu // Private copy constructor and assignment operator 1072800Ssaidi@eecs.umich.edu Network(const Network& obj); 1082800Ssaidi@eecs.umich.edu Network& operator=(const Network& obj); 1092800Ssaidi@eecs.umich.edu 1102800Ssaidi@eecs.umich.edu uint32_t m_nodes; 1112166SN/A static uint32_t m_virtual_networks; 1122166SN/A std::vector<std::string> m_vnet_type_names; 1132203SN/A Topology* m_topology_ptr; 1142166SN/A static uint32_t m_control_msg_size; 1152166SN/A static uint32_t m_data_msg_size; 1162166SN/A 1172166SN/A // vector of queues from the components 1182203SN/A std::vector<std::vector<MessageBuffer*> > m_toNetQueues; 1192166SN/A std::vector<std::vector<MessageBuffer*> > m_fromNetQueues; 1202166SN/A std::vector<bool> m_ordered; 1212147SN/A 1222090SN/A private: 1232147SN/A //! Callback class used for collating statistics from all the 1242147SN/A //! controller of this type. 1252147SN/A class StatsCallback : public Callback 1262222SN/A { 1272112SN/A private: 1282147SN/A Network *ctr; 1292147SN/A 1302222SN/A public: 1312147SN/A virtual ~StatsCallback() {} 1322090SN/A 1332147SN/A StatsCallback(Network *_ctr) 1342090SN/A : ctr(_ctr) 1352201SN/A { 1362201SN/A } 1372147SN/A 1382147SN/A void process() {ctr->collateStats();} 1392147SN/A }; 1402222SN/A}; 1412112SN/A 1422147SN/Ainline std::ostream& 1432147SN/Aoperator<<(std::ostream& out, const Network& obj) 1442222SN/A{ 1452203SN/A obj.print(out); 1462680Sktlim@umich.edu out << std::flush; 1472203SN/A return out; 1482147SN/A} 1492090SN/A 1502147SN/A#endif // __MEM_RUBY_NETWORK_NETWORK_HH__ 1512090SN/A