Network.hh revision 11113
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 Network class is the base class for classes that implement the 317054Snate@binkert.org * interconnection network between components (processor/cache 327054Snate@binkert.org * components and memory/directory components). The interconnection 337054Snate@binkert.org * network as described here is not a physical network, but a 347054Snate@binkert.org * programming concept used to implement all communication between 357054Snate@binkert.org * components. Thus parts of this 'network' will model the on-chip 367054Snate@binkert.org * connections between cache controllers and directory controllers as 377054Snate@binkert.org * well as the links between chip and network switches. 387054Snate@binkert.org */ 396145Snate@binkert.org 407054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__ 417054Snate@binkert.org#define __MEM_RUBY_NETWORK_NETWORK_HH__ 426145Snate@binkert.org 437055Snate@binkert.org#include <iostream> 447055Snate@binkert.org#include <string> 457454Snate@binkert.org#include <vector> 467055Snate@binkert.org 478257SBrad.Beckmann@amd.com#include "mem/protocol/LinkDirection.hh" 487054Snate@binkert.org#include "mem/protocol/MessageSizeType.hh" 498645Snilay@cs.wisc.edu#include "mem/ruby/common/TypeDefines.hh" 509594Snilay@cs.wisc.edu#include "mem/ruby/network/Topology.hh" 519594Snilay@cs.wisc.edu#include "mem/packet.hh" 527054Snate@binkert.org#include "params/RubyNetwork.hh" 539465Snilay@cs.wisc.edu#include "sim/clocked_object.hh" 546145Snate@binkert.org 556145Snate@binkert.orgclass NetDest; 566145Snate@binkert.orgclass MessageBuffer; 576145Snate@binkert.org 589465Snilay@cs.wisc.educlass Network : public ClockedObject 597054Snate@binkert.org{ 607054Snate@binkert.org public: 616876Ssteve.reinhardt@amd.com typedef RubyNetworkParams Params; 626876Ssteve.reinhardt@amd.com Network(const Params *p); 639594Snilay@cs.wisc.edu const Params * params() const 6410917Sbrandon.potter@amd.com { return dynamic_cast<const Params *>(_params); } 656145Snate@binkert.org 6610303Snilay@cs.wisc.edu virtual ~Network(); 677054Snate@binkert.org virtual void init(); 686145Snate@binkert.org 699497Snilay@cs.wisc.edu static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; } 7010303Snilay@cs.wisc.edu int getNumNodes() const { return m_nodes; } 7110303Snilay@cs.wisc.edu 729275Snilay@cs.wisc.edu static uint32_t MessageSizeType_to_int(MessageSizeType size_type); 736493STushar.Krishna@amd.com 747054Snate@binkert.org // returns the queue requested for the given component 7511113Sjoe.gross@amd.com void setToNetQueue(NodeID id, bool ordered, int netNumber, 7611113Sjoe.gross@amd.com std::string vnet_type, MessageBuffer *b); 7710311Snilay@cs.wisc.edu virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber, 7811113Sjoe.gross@amd.com std::string vnet_type, MessageBuffer *b); 7911113Sjoe.gross@amd.com 8011113Sjoe.gross@amd.com virtual void checkNetworkAllocation(NodeID id, bool ordered, 8111113Sjoe.gross@amd.com int network_num, std::string vnet_type); 826145Snate@binkert.org 838257SBrad.Beckmann@amd.com virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link, 848257SBrad.Beckmann@amd.com LinkDirection direction, 859799Snilay@cs.wisc.edu const NetDest& routing_table_entry) = 0; 868257SBrad.Beckmann@amd.com virtual void makeInLink(NodeID src, SwitchID dest, BasicLink* link, 878257SBrad.Beckmann@amd.com LinkDirection direction, 889799Snilay@cs.wisc.edu const NetDest& routing_table_entry) = 0; 898257SBrad.Beckmann@amd.com virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 908257SBrad.Beckmann@amd.com LinkDirection direction, 919799Snilay@cs.wisc.edu const NetDest& routing_table_entry) = 0; 926145Snate@binkert.org 939863Snilay@cs.wisc.edu virtual void collateStats() = 0; 947055Snate@binkert.org virtual void print(std::ostream& out) const = 0; 956145Snate@binkert.org 969302Snilay@cs.wisc.edu /* 979302Snilay@cs.wisc.edu * Virtual functions for functionally reading and writing packets in 989302Snilay@cs.wisc.edu * the network. Each network needs to implement these for functional 999302Snilay@cs.wisc.edu * accesses to work correctly. 1009302Snilay@cs.wisc.edu */ 1019302Snilay@cs.wisc.edu virtual bool functionalRead(Packet *pkt) 1029302Snilay@cs.wisc.edu { fatal("Functional read not implemented.\n"); } 1039302Snilay@cs.wisc.edu virtual uint32_t functionalWrite(Packet *pkt) 1049302Snilay@cs.wisc.edu { fatal("Functional write not implemented.\n"); } 1059302Snilay@cs.wisc.edu 1067054Snate@binkert.org protected: 1077054Snate@binkert.org // Private copy constructor and assignment operator 1087054Snate@binkert.org Network(const Network& obj); 1097054Snate@binkert.org Network& operator=(const Network& obj); 1106145Snate@binkert.org 1119863Snilay@cs.wisc.edu uint32_t m_nodes; 1129275Snilay@cs.wisc.edu static uint32_t m_virtual_networks; 11311113Sjoe.gross@amd.com std::vector<std::string> m_vnet_type_names; 1147054Snate@binkert.org Topology* m_topology_ptr; 1159275Snilay@cs.wisc.edu static uint32_t m_control_msg_size; 1169275Snilay@cs.wisc.edu static uint32_t m_data_msg_size; 1179863Snilay@cs.wisc.edu 11810082Snilay@cs.wisc.edu // vector of queues from the components 11910370Snilay@cs.wisc.edu std::vector<std::vector<MessageBuffer*> > m_toNetQueues; 12010370Snilay@cs.wisc.edu std::vector<std::vector<MessageBuffer*> > m_fromNetQueues; 12110082Snilay@cs.wisc.edu std::vector<bool> m_ordered; 12210082Snilay@cs.wisc.edu 1239863Snilay@cs.wisc.edu private: 1249863Snilay@cs.wisc.edu //! Callback class used for collating statistics from all the 1259863Snilay@cs.wisc.edu //! controller of this type. 1269863Snilay@cs.wisc.edu class StatsCallback : public Callback 1279863Snilay@cs.wisc.edu { 1289863Snilay@cs.wisc.edu private: 1299863Snilay@cs.wisc.edu Network *ctr; 1309863Snilay@cs.wisc.edu 1319863Snilay@cs.wisc.edu public: 1329863Snilay@cs.wisc.edu virtual ~StatsCallback() {} 1339863Snilay@cs.wisc.edu 1349863Snilay@cs.wisc.edu StatsCallback(Network *_ctr) 1359863Snilay@cs.wisc.edu : ctr(_ctr) 1369863Snilay@cs.wisc.edu { 1379863Snilay@cs.wisc.edu } 1389863Snilay@cs.wisc.edu 1399863Snilay@cs.wisc.edu void process() {ctr->collateStats();} 1409863Snilay@cs.wisc.edu }; 1416145Snate@binkert.org}; 1426145Snate@binkert.org 1437055Snate@binkert.orginline std::ostream& 1447055Snate@binkert.orgoperator<<(std::ostream& out, const Network& obj) 1456145Snate@binkert.org{ 1467054Snate@binkert.org obj.print(out); 1477055Snate@binkert.org out << std::flush; 1487054Snate@binkert.org return out; 1496145Snate@binkert.org} 1506145Snate@binkert.org 1517054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_NETWORK_HH__ 152