Network.hh revision 10370
14661Sksewell@umich.edu/* 25222Sksewell@umich.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 34661Sksewell@umich.edu * All rights reserved. 44661Sksewell@umich.edu * 54661Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 64661Sksewell@umich.edu * modification, are permitted provided that the following conditions are 74661Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 84661Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 94661Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 104661Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 114661Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 124661Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 134661Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 144661Sksewell@umich.edu * this software without specific prior written permission. 154661Sksewell@umich.edu * 164661Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174661Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184661Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194661Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204661Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214661Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224661Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234661Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244661Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254661Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264661Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274661Sksewell@umich.edu */ 284661Sksewell@umich.edu 294661Sksewell@umich.edu/* 304661Sksewell@umich.edu * The Network class is the base class for classes that implement the 314661Sksewell@umich.edu * interconnection network between components (processor/cache 324661Sksewell@umich.edu * components and memory/directory components). The interconnection 334661Sksewell@umich.edu * network as described here is not a physical network, but a 344661Sksewell@umich.edu * programming concept used to implement all communication between 354661Sksewell@umich.edu * components. Thus parts of this 'network' will model the on-chip 364661Sksewell@umich.edu * connections between cache controllers and directory controllers as 374661Sksewell@umich.edu * well as the links between chip and network switches. 384661Sksewell@umich.edu */ 394661Sksewell@umich.edu 404661Sksewell@umich.edu#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__ 414661Sksewell@umich.edu#define __MEM_RUBY_NETWORK_NETWORK_HH__ 424661Sksewell@umich.edu 435558Snate@binkert.org#include <iostream> 444661Sksewell@umich.edu#include <string> 454661Sksewell@umich.edu#include <vector> 465558Snate@binkert.org 474661Sksewell@umich.edu#include "mem/protocol/LinkDirection.hh" 485558Snate@binkert.org#include "mem/protocol/MessageSizeType.hh" 495558Snate@binkert.org#include "mem/ruby/common/TypeDefines.hh" 504661Sksewell@umich.edu#include "mem/ruby/network/Topology.hh" 515558Snate@binkert.org#include "mem/packet.hh" 525558Snate@binkert.org#include "params/RubyNetwork.hh" 534661Sksewell@umich.edu#include "sim/clocked_object.hh" 545558Snate@binkert.org 554661Sksewell@umich.educlass NetDest; 564661Sksewell@umich.educlass MessageBuffer; 574661Sksewell@umich.edu 584661Sksewell@umich.educlass Network : public ClockedObject 594661Sksewell@umich.edu{ 604661Sksewell@umich.edu public: 615558Snate@binkert.org typedef RubyNetworkParams Params; 625558Snate@binkert.org Network(const Params *p); 634661Sksewell@umich.edu const Params * params() const 645558Snate@binkert.org { return dynamic_cast<const Params *>(_params);} 654661Sksewell@umich.edu 665558Snate@binkert.org virtual ~Network(); 674661Sksewell@umich.edu virtual void init(); 685558Snate@binkert.org 694661Sksewell@umich.edu static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; } 704661Sksewell@umich.edu int getNumNodes() const { return m_nodes; } 715558Snate@binkert.org 724661Sksewell@umich.edu static uint32_t MessageSizeType_to_int(MessageSizeType size_type); 734661Sksewell@umich.edu 744661Sksewell@umich.edu // returns the queue requested for the given component 754661Sksewell@umich.edu virtual void setToNetQueue(NodeID id, bool ordered, int netNumber, 764661Sksewell@umich.edu std::string vnet_type, MessageBuffer *b) = 0; 775558Snate@binkert.org virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber, 784661Sksewell@umich.edu std::string vnet_type, MessageBuffer *b) = 0; 794661Sksewell@umich.edu 805558Snate@binkert.org virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link, 814661Sksewell@umich.edu LinkDirection direction, 824661Sksewell@umich.edu const NetDest& routing_table_entry) = 0; 834661Sksewell@umich.edu virtual void makeInLink(NodeID src, SwitchID dest, BasicLink* link, 844661Sksewell@umich.edu LinkDirection direction, 854661Sksewell@umich.edu const NetDest& routing_table_entry) = 0; 864661Sksewell@umich.edu virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link, 875558Snate@binkert.org LinkDirection direction, 884661Sksewell@umich.edu const NetDest& routing_table_entry) = 0; 894661Sksewell@umich.edu 904661Sksewell@umich.edu virtual void collateStats() = 0; 915558Snate@binkert.org virtual void print(std::ostream& out) const = 0; 925558Snate@binkert.org 934661Sksewell@umich.edu /* 945558Snate@binkert.org * Virtual functions for functionally reading and writing packets in 954661Sksewell@umich.edu * the network. Each network needs to implement these for functional 965558Snate@binkert.org * accesses to work correctly. 974661Sksewell@umich.edu */ 984661Sksewell@umich.edu virtual bool functionalRead(Packet *pkt) 995558Snate@binkert.org { fatal("Functional read not implemented.\n"); } 1005558Snate@binkert.org virtual uint32_t functionalWrite(Packet *pkt) 1014661Sksewell@umich.edu { fatal("Functional write not implemented.\n"); } 1024661Sksewell@umich.edu 1034661Sksewell@umich.edu protected: 1045558Snate@binkert.org // Private copy constructor and assignment operator 1055558Snate@binkert.org Network(const Network& obj); 1064661Sksewell@umich.edu Network& operator=(const Network& obj); 1074661Sksewell@umich.edu 1084661Sksewell@umich.edu uint32_t m_nodes; 1094661Sksewell@umich.edu static uint32_t m_virtual_networks; 1105558Snate@binkert.org Topology* m_topology_ptr; 1114661Sksewell@umich.edu static uint32_t m_control_msg_size; 1124661Sksewell@umich.edu static uint32_t m_data_msg_size; 1134661Sksewell@umich.edu 1145558Snate@binkert.org // vector of queues from the components 1154661Sksewell@umich.edu std::vector<std::vector<MessageBuffer*> > m_toNetQueues; 1164661Sksewell@umich.edu std::vector<std::vector<MessageBuffer*> > m_fromNetQueues; 1175558Snate@binkert.org 1184661Sksewell@umich.edu std::vector<bool> m_in_use; 1194661Sksewell@umich.edu std::vector<bool> m_ordered; 1205558Snate@binkert.org 1214661Sksewell@umich.edu private: 1224661Sksewell@umich.edu //! Callback class used for collating statistics from all the 1234661Sksewell@umich.edu //! controller of this type. 1244661Sksewell@umich.edu class StatsCallback : public Callback 1254661Sksewell@umich.edu { 1264661Sksewell@umich.edu private: 1274661Sksewell@umich.edu Network *ctr; 1284661Sksewell@umich.edu 1295558Snate@binkert.org public: 1304661Sksewell@umich.edu virtual ~StatsCallback() {} 1315558Snate@binkert.org 1324661Sksewell@umich.edu StatsCallback(Network *_ctr) 1334661Sksewell@umich.edu : ctr(_ctr) 1344661Sksewell@umich.edu { 1355558Snate@binkert.org } 1364661Sksewell@umich.edu 1374661Sksewell@umich.edu void process() {ctr->collateStats();} 1384661Sksewell@umich.edu }; 1394661Sksewell@umich.edu}; 1404661Sksewell@umich.edu 1414661Sksewell@umich.eduinline std::ostream& 1424661Sksewell@umich.eduoperator<<(std::ostream& out, const Network& obj) 1435558Snate@binkert.org{ 1444661Sksewell@umich.edu obj.print(out); 1455558Snate@binkert.org out << std::flush; 1464661Sksewell@umich.edu return out; 1474661Sksewell@umich.edu} 1485558Snate@binkert.org 1494661Sksewell@umich.edu#endif // __MEM_RUBY_NETWORK_NETWORK_HH__ 1504661Sksewell@umich.edu