Network.hh revision 12065
16145Snate@binkert.org/*
212065Snikos.nikoleris@arm.com * Copyright (c) 2017 ARM Limited
312065Snikos.nikoleris@arm.com * All rights reserved.
412065Snikos.nikoleris@arm.com *
512065Snikos.nikoleris@arm.com * The license below extends only to copyright in the software and shall
612065Snikos.nikoleris@arm.com * not be construed as granting a license to any other intellectual
712065Snikos.nikoleris@arm.com * property including but not limited to intellectual property relating
812065Snikos.nikoleris@arm.com * to a hardware implementation of the functionality of the software
912065Snikos.nikoleris@arm.com * licensed hereunder.  You may use the software subject to the license
1012065Snikos.nikoleris@arm.com * terms below provided that you ensure that this notice is replicated
1112065Snikos.nikoleris@arm.com * unmodified and in its entirety in all distributions of the software,
1212065Snikos.nikoleris@arm.com * modified or unmodified, in source code or in binary form.
1312065Snikos.nikoleris@arm.com *
146145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
156145Snate@binkert.org * All rights reserved.
166145Snate@binkert.org *
176145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
186145Snate@binkert.org * modification, are permitted provided that the following conditions are
196145Snate@binkert.org * met: redistributions of source code must retain the above copyright
206145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
216145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
226145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
236145Snate@binkert.org * documentation and/or other materials provided with the distribution;
246145Snate@binkert.org * neither the name of the copyright holders nor the names of its
256145Snate@binkert.org * contributors may be used to endorse or promote products derived from
266145Snate@binkert.org * this software without specific prior written permission.
276145Snate@binkert.org *
286145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396145Snate@binkert.org */
406145Snate@binkert.org
416145Snate@binkert.org/*
427054Snate@binkert.org * The Network class is the base class for classes that implement the
437054Snate@binkert.org * interconnection network between components (processor/cache
447054Snate@binkert.org * components and memory/directory components).  The interconnection
457054Snate@binkert.org * network as described here is not a physical network, but a
467054Snate@binkert.org * programming concept used to implement all communication between
477054Snate@binkert.org * components.  Thus parts of this 'network' will model the on-chip
487054Snate@binkert.org * connections between cache controllers and directory controllers as
497054Snate@binkert.org * well as the links between chip and network switches.
507054Snate@binkert.org */
516145Snate@binkert.org
527054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__
537054Snate@binkert.org#define __MEM_RUBY_NETWORK_NETWORK_HH__
546145Snate@binkert.org
557055Snate@binkert.org#include <iostream>
567055Snate@binkert.org#include <string>
5712065Snikos.nikoleris@arm.com#include <unordered_map>
587454Snate@binkert.org#include <vector>
597055Snate@binkert.org
6012065Snikos.nikoleris@arm.com#include "base/addr_range.hh"
6112065Snikos.nikoleris@arm.com#include "base/types.hh"
6212065Snikos.nikoleris@arm.com#include "mem/packet.hh"
638257SBrad.Beckmann@amd.com#include "mem/protocol/LinkDirection.hh"
647054Snate@binkert.org#include "mem/protocol/MessageSizeType.hh"
6512065Snikos.nikoleris@arm.com#include "mem/ruby/common/MachineID.hh"
668645Snilay@cs.wisc.edu#include "mem/ruby/common/TypeDefines.hh"
679594Snilay@cs.wisc.edu#include "mem/ruby/network/Topology.hh"
687054Snate@binkert.org#include "params/RubyNetwork.hh"
699465Snilay@cs.wisc.edu#include "sim/clocked_object.hh"
706145Snate@binkert.org
716145Snate@binkert.orgclass NetDest;
726145Snate@binkert.orgclass MessageBuffer;
736145Snate@binkert.org
749465Snilay@cs.wisc.educlass Network : public ClockedObject
757054Snate@binkert.org{
767054Snate@binkert.org  public:
776876Ssteve.reinhardt@amd.com    typedef RubyNetworkParams Params;
786876Ssteve.reinhardt@amd.com    Network(const Params *p);
799594Snilay@cs.wisc.edu    const Params * params() const
8010917Sbrandon.potter@amd.com    { return dynamic_cast<const Params *>(_params); }
816145Snate@binkert.org
8210303Snilay@cs.wisc.edu    virtual ~Network();
837054Snate@binkert.org    virtual void init();
846145Snate@binkert.org
859497Snilay@cs.wisc.edu    static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
8610303Snilay@cs.wisc.edu    int getNumNodes() const { return m_nodes; }
8710303Snilay@cs.wisc.edu
889275Snilay@cs.wisc.edu    static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
896493STushar.Krishna@amd.com
907054Snate@binkert.org    // returns the queue requested for the given component
9111113Sjoe.gross@amd.com    void setToNetQueue(NodeID id, bool ordered, int netNumber,
9211113Sjoe.gross@amd.com                               std::string vnet_type, MessageBuffer *b);
9310311Snilay@cs.wisc.edu    virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber,
9411113Sjoe.gross@amd.com                                 std::string vnet_type, MessageBuffer *b);
9511113Sjoe.gross@amd.com
9611113Sjoe.gross@amd.com    virtual void checkNetworkAllocation(NodeID id, bool ordered,
9711113Sjoe.gross@amd.com        int network_num, std::string vnet_type);
986145Snate@binkert.org
9911663Stushar@ece.gatech.edu    virtual void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link,
1009799Snilay@cs.wisc.edu                             const NetDest& routing_table_entry) = 0;
10111663Stushar@ece.gatech.edu    virtual void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link,
1029799Snilay@cs.wisc.edu                            const NetDest& routing_table_entry) = 0;
1038257SBrad.Beckmann@amd.com    virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
10411664Stushar@ece.gatech.edu                                  const NetDest& routing_table_entry,
10511664Stushar@ece.gatech.edu                                  PortDirection src_outport,
10611664Stushar@ece.gatech.edu                                  PortDirection dst_inport) = 0;
1076145Snate@binkert.org
1089863Snilay@cs.wisc.edu    virtual void collateStats() = 0;
1097055Snate@binkert.org    virtual void print(std::ostream& out) const = 0;
1106145Snate@binkert.org
1119302Snilay@cs.wisc.edu    /*
1129302Snilay@cs.wisc.edu     * Virtual functions for functionally reading and writing packets in
1139302Snilay@cs.wisc.edu     * the network. Each network needs to implement these for functional
1149302Snilay@cs.wisc.edu     * accesses to work correctly.
1159302Snilay@cs.wisc.edu     */
1169302Snilay@cs.wisc.edu    virtual bool functionalRead(Packet *pkt)
1179302Snilay@cs.wisc.edu    { fatal("Functional read not implemented.\n"); }
1189302Snilay@cs.wisc.edu    virtual uint32_t functionalWrite(Packet *pkt)
1199302Snilay@cs.wisc.edu    { fatal("Functional write not implemented.\n"); }
1209302Snilay@cs.wisc.edu
12112065Snikos.nikoleris@arm.com    /**
12212065Snikos.nikoleris@arm.com     * Map an address to the correct NodeID
12312065Snikos.nikoleris@arm.com     *
12412065Snikos.nikoleris@arm.com     * This function traverses the global address map to find the
12512065Snikos.nikoleris@arm.com     * NodeID that corresponds to the given address and the type of
12612065Snikos.nikoleris@arm.com     * the destination. For example for a request to a directory this
12712065Snikos.nikoleris@arm.com     * function will return the NodeID of the right directory.
12812065Snikos.nikoleris@arm.com     *
12912065Snikos.nikoleris@arm.com     * @param the destination address
13012065Snikos.nikoleris@arm.com     * @param the type of the destination
13112065Snikos.nikoleris@arm.com     * @return the NodeID of the destination
13212065Snikos.nikoleris@arm.com     */
13312065Snikos.nikoleris@arm.com    NodeID addressToNodeID(Addr addr, MachineType mtype);
13412065Snikos.nikoleris@arm.com
1357054Snate@binkert.org  protected:
1367054Snate@binkert.org    // Private copy constructor and assignment operator
1377054Snate@binkert.org    Network(const Network& obj);
1387054Snate@binkert.org    Network& operator=(const Network& obj);
1396145Snate@binkert.org
1409863Snilay@cs.wisc.edu    uint32_t m_nodes;
1419275Snilay@cs.wisc.edu    static uint32_t m_virtual_networks;
14211113Sjoe.gross@amd.com    std::vector<std::string> m_vnet_type_names;
1437054Snate@binkert.org    Topology* m_topology_ptr;
1449275Snilay@cs.wisc.edu    static uint32_t m_control_msg_size;
1459275Snilay@cs.wisc.edu    static uint32_t m_data_msg_size;
1469863Snilay@cs.wisc.edu
14710082Snilay@cs.wisc.edu    // vector of queues from the components
14810370Snilay@cs.wisc.edu    std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
14910370Snilay@cs.wisc.edu    std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
15010082Snilay@cs.wisc.edu    std::vector<bool> m_ordered;
15110082Snilay@cs.wisc.edu
1529863Snilay@cs.wisc.edu  private:
1539863Snilay@cs.wisc.edu    //! Callback class used for collating statistics from all the
1549863Snilay@cs.wisc.edu    //! controller of this type.
1559863Snilay@cs.wisc.edu    class StatsCallback : public Callback
1569863Snilay@cs.wisc.edu    {
1579863Snilay@cs.wisc.edu      private:
1589863Snilay@cs.wisc.edu        Network *ctr;
1599863Snilay@cs.wisc.edu
1609863Snilay@cs.wisc.edu      public:
1619863Snilay@cs.wisc.edu        virtual ~StatsCallback() {}
1629863Snilay@cs.wisc.edu
1639863Snilay@cs.wisc.edu        StatsCallback(Network *_ctr)
1649863Snilay@cs.wisc.edu            : ctr(_ctr)
1659863Snilay@cs.wisc.edu        {
1669863Snilay@cs.wisc.edu        }
1679863Snilay@cs.wisc.edu
1689863Snilay@cs.wisc.edu        void process() {ctr->collateStats();}
1699863Snilay@cs.wisc.edu    };
17012065Snikos.nikoleris@arm.com
17112065Snikos.nikoleris@arm.com    // Global address map
17212065Snikos.nikoleris@arm.com    struct AddrMapNode {
17312065Snikos.nikoleris@arm.com        NodeID id;
17412065Snikos.nikoleris@arm.com        AddrRangeList ranges;
17512065Snikos.nikoleris@arm.com    };
17612065Snikos.nikoleris@arm.com    std::unordered_multimap<MachineType, AddrMapNode> addrMap;
1776145Snate@binkert.org};
1786145Snate@binkert.org
1797055Snate@binkert.orginline std::ostream&
1807055Snate@binkert.orgoperator<<(std::ostream& out, const Network& obj)
1816145Snate@binkert.org{
1827054Snate@binkert.org    obj.print(out);
1837055Snate@binkert.org    out << std::flush;
1847054Snate@binkert.org    return out;
1856145Snate@binkert.org}
1866145Snate@binkert.org
1877054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_NETWORK_HH__
188