Network.hh revision 13784
18086SBrad.Beckmann@amd.com/*
26657SN/A * Copyright (c) 2017 ARM Limited
36657SN/A * All rights reserved.
46657SN/A *
56657SN/A * The license below extends only to copyright in the software and shall
66657SN/A * not be construed as granting a license to any other intellectual
76657SN/A * property including but not limited to intellectual property relating
86657SN/A * to a hardware implementation of the functionality of the software
96657SN/A * licensed hereunder.  You may use the software subject to the license
106657SN/A * terms below provided that you ensure that this notice is replicated
116657SN/A * unmodified and in its entirety in all distributions of the software,
126657SN/A * modified or unmodified, in source code or in binary form.
136657SN/A *
146657SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
156657SN/A * All rights reserved.
166657SN/A *
176657SN/A * Redistribution and use in source and binary forms, with or without
186657SN/A * modification, are permitted provided that the following conditions are
196657SN/A * met: redistributions of source code must retain the above copyright
206657SN/A * notice, this list of conditions and the following disclaimer;
216657SN/A * redistributions in binary form must reproduce the above copyright
226657SN/A * notice, this list of conditions and the following disclaimer in the
236657SN/A * documentation and/or other materials provided with the distribution;
246657SN/A * neither the name of the copyright holders nor the names of its
256657SN/A * contributors may be used to endorse or promote products derived from
266657SN/A * this software without specific prior written permission.
276657SN/A *
286657SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296657SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
308086SBrad.Beckmann@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
318086SBrad.Beckmann@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
328086SBrad.Beckmann@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336657SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346657SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
358086SBrad.Beckmann@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366657SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376657SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
388086SBrad.Beckmann@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396657SN/A */
406714SN/A
416657SN/A/*
426714SN/A * The Network class is the base class for classes that implement the
436657SN/A * interconnection network between components (processor/cache
446657SN/A * components and memory/directory components).  The interconnection
456657SN/A * network as described here is not a physical network, but a
466657SN/A * programming concept used to implement all communication between
476657SN/A * components.  Thus parts of this 'network' will model the on-chip
486714SN/A * connections between cache controllers and directory controllers as
496714SN/A * well as the links between chip and network switches.
506657SN/A */
516657SN/A
526657SN/A#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__
536657SN/A#define __MEM_RUBY_NETWORK_NETWORK_HH__
546657SN/A
556657SN/A#include <iostream>
566657SN/A#include <string>
576657SN/A#include <unordered_map>
586657SN/A#include <vector>
598086SBrad.Beckmann@amd.com
608086SBrad.Beckmann@amd.com#include "base/addr_range.hh"
618086SBrad.Beckmann@amd.com#include "base/types.hh"
626657SN/A#include "mem/packet.hh"
636657SN/A#include "mem/port.hh"
646657SN/A#include "mem/protocol/LinkDirection.hh"
656657SN/A#include "mem/protocol/MessageSizeType.hh"
666657SN/A#include "mem/ruby/common/MachineID.hh"
6710984SBrad.Beckmann@amd.com#include "mem/ruby/common/TypeDefines.hh"
6810984SBrad.Beckmann@amd.com#include "mem/ruby/network/Topology.hh"
6911049Snilay@cs.wisc.edu#include "mem/ruby/network/dummy_port.hh"
709298Snilay@cs.wisc.edu#include "params/RubyNetwork.hh"
716657SN/A#include "sim/clocked_object.hh"
728086SBrad.Beckmann@amd.com
738086SBrad.Beckmann@amd.comclass NetDest;
748086SBrad.Beckmann@amd.comclass MessageBuffer;
758086SBrad.Beckmann@amd.com
768086SBrad.Beckmann@amd.comclass Network : public ClockedObject
7710984SBrad.Beckmann@amd.com{
7810984SBrad.Beckmann@amd.com  public:
7911049Snilay@cs.wisc.edu    typedef RubyNetworkParams Params;
809298Snilay@cs.wisc.edu    Network(const Params *p);
818086SBrad.Beckmann@amd.com    const Params * params() const
82    { return dynamic_cast<const Params *>(_params); }
83
84    virtual ~Network();
85    virtual void init();
86
87    static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
88    int getNumNodes() const { return m_nodes; }
89
90    static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
91
92    // returns the queue requested for the given component
93    void setToNetQueue(NodeID id, bool ordered, int netNumber,
94                               std::string vnet_type, MessageBuffer *b);
95    virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber,
96                                 std::string vnet_type, MessageBuffer *b);
97
98    virtual void checkNetworkAllocation(NodeID id, bool ordered,
99        int network_num, std::string vnet_type);
100
101    virtual void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link,
102                             const NetDest& routing_table_entry) = 0;
103    virtual void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link,
104                            const NetDest& routing_table_entry) = 0;
105    virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
106                                  const NetDest& routing_table_entry,
107                                  PortDirection src_outport,
108                                  PortDirection dst_inport) = 0;
109
110    virtual void collateStats() = 0;
111    virtual void print(std::ostream& out) const = 0;
112
113    /*
114     * Virtual functions for functionally reading and writing packets in
115     * the network. Each network needs to implement these for functional
116     * accesses to work correctly.
117     */
118    virtual bool functionalRead(Packet *pkt)
119    { fatal("Functional read not implemented.\n"); }
120    virtual uint32_t functionalWrite(Packet *pkt)
121    { fatal("Functional write not implemented.\n"); }
122
123    /**
124     * Map an address to the correct NodeID
125     *
126     * This function traverses the global address map to find the
127     * NodeID that corresponds to the given address and the type of
128     * the destination. For example for a request to a directory this
129     * function will return the NodeID of the right directory.
130     *
131     * @param the destination address
132     * @param the type of the destination
133     * @return the NodeID of the destination
134     */
135    NodeID addressToNodeID(Addr addr, MachineType mtype);
136
137    Port &
138    getPort(const std::string &, PortID idx=InvalidPortID) override
139    {
140        return RubyDummyPort::instance();
141    }
142
143  protected:
144    // Private copy constructor and assignment operator
145    Network(const Network& obj);
146    Network& operator=(const Network& obj);
147
148    uint32_t m_nodes;
149    static uint32_t m_virtual_networks;
150    std::vector<std::string> m_vnet_type_names;
151    Topology* m_topology_ptr;
152    static uint32_t m_control_msg_size;
153    static uint32_t m_data_msg_size;
154
155    // vector of queues from the components
156    std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
157    std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
158    std::vector<bool> m_ordered;
159
160  private:
161    //! Callback class used for collating statistics from all the
162    //! controller of this type.
163    class StatsCallback : public Callback
164    {
165      private:
166        Network *ctr;
167
168      public:
169        virtual ~StatsCallback() {}
170
171        StatsCallback(Network *_ctr)
172            : ctr(_ctr)
173        {
174        }
175
176        void process() {ctr->collateStats();}
177    };
178
179    // Global address map
180    struct AddrMapNode {
181        NodeID id;
182        AddrRangeList ranges;
183    };
184    std::unordered_multimap<MachineType, AddrMapNode> addrMap;
185};
186
187inline std::ostream&
188operator<<(std::ostream& out, const Network& obj)
189{
190    obj.print(out);
191    out << std::flush;
192    return out;
193}
194
195#endif // __MEM_RUBY_NETWORK_NETWORK_HH__
196