Network.hh (11664:2365e9e396f7) Network.hh (12065:e3e51756dfef)
1/*
1/*
2 * Copyright (c) 2017 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * The Network class is the base class for classes that implement the
31 * interconnection network between components (processor/cache
32 * components and memory/directory components). The interconnection
33 * network as described here is not a physical network, but a
34 * programming concept used to implement all communication between
35 * components. Thus parts of this 'network' will model the on-chip
36 * connections between cache controllers and directory controllers as
37 * well as the links between chip and network switches.
38 */
39
40#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__
41#define __MEM_RUBY_NETWORK_NETWORK_HH__
42
43#include <iostream>
44#include <string>
14 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41/*
42 * The Network class is the base class for classes that implement the
43 * interconnection network between components (processor/cache
44 * components and memory/directory components). The interconnection
45 * network as described here is not a physical network, but a
46 * programming concept used to implement all communication between
47 * components. Thus parts of this 'network' will model the on-chip
48 * connections between cache controllers and directory controllers as
49 * well as the links between chip and network switches.
50 */
51
52#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__
53#define __MEM_RUBY_NETWORK_NETWORK_HH__
54
55#include <iostream>
56#include <string>
57#include <unordered_map>
45#include <vector>
46
58#include <vector>
59
60#include "base/addr_range.hh"
61#include "base/types.hh"
62#include "mem/packet.hh"
47#include "mem/protocol/LinkDirection.hh"
48#include "mem/protocol/MessageSizeType.hh"
63#include "mem/protocol/LinkDirection.hh"
64#include "mem/protocol/MessageSizeType.hh"
65#include "mem/ruby/common/MachineID.hh"
49#include "mem/ruby/common/TypeDefines.hh"
50#include "mem/ruby/network/Topology.hh"
66#include "mem/ruby/common/TypeDefines.hh"
67#include "mem/ruby/network/Topology.hh"
51#include "mem/packet.hh"
52#include "params/RubyNetwork.hh"
53#include "sim/clocked_object.hh"
54
55class NetDest;
56class MessageBuffer;
57
58class Network : public ClockedObject
59{
60 public:
61 typedef RubyNetworkParams Params;
62 Network(const Params *p);
63 const Params * params() const
64 { return dynamic_cast<const Params *>(_params); }
65
66 virtual ~Network();
67 virtual void init();
68
69 static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
70 int getNumNodes() const { return m_nodes; }
71
72 static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
73
74 // returns the queue requested for the given component
75 void setToNetQueue(NodeID id, bool ordered, int netNumber,
76 std::string vnet_type, MessageBuffer *b);
77 virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber,
78 std::string vnet_type, MessageBuffer *b);
79
80 virtual void checkNetworkAllocation(NodeID id, bool ordered,
81 int network_num, std::string vnet_type);
82
83 virtual void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link,
84 const NetDest& routing_table_entry) = 0;
85 virtual void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link,
86 const NetDest& routing_table_entry) = 0;
87 virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
88 const NetDest& routing_table_entry,
89 PortDirection src_outport,
90 PortDirection dst_inport) = 0;
91
92 virtual void collateStats() = 0;
93 virtual void print(std::ostream& out) const = 0;
94
95 /*
96 * Virtual functions for functionally reading and writing packets in
97 * the network. Each network needs to implement these for functional
98 * accesses to work correctly.
99 */
100 virtual bool functionalRead(Packet *pkt)
101 { fatal("Functional read not implemented.\n"); }
102 virtual uint32_t functionalWrite(Packet *pkt)
103 { fatal("Functional write not implemented.\n"); }
104
68#include "params/RubyNetwork.hh"
69#include "sim/clocked_object.hh"
70
71class NetDest;
72class MessageBuffer;
73
74class Network : public ClockedObject
75{
76 public:
77 typedef RubyNetworkParams Params;
78 Network(const Params *p);
79 const Params * params() const
80 { return dynamic_cast<const Params *>(_params); }
81
82 virtual ~Network();
83 virtual void init();
84
85 static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
86 int getNumNodes() const { return m_nodes; }
87
88 static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
89
90 // returns the queue requested for the given component
91 void setToNetQueue(NodeID id, bool ordered, int netNumber,
92 std::string vnet_type, MessageBuffer *b);
93 virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber,
94 std::string vnet_type, MessageBuffer *b);
95
96 virtual void checkNetworkAllocation(NodeID id, bool ordered,
97 int network_num, std::string vnet_type);
98
99 virtual void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link,
100 const NetDest& routing_table_entry) = 0;
101 virtual void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link,
102 const NetDest& routing_table_entry) = 0;
103 virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
104 const NetDest& routing_table_entry,
105 PortDirection src_outport,
106 PortDirection dst_inport) = 0;
107
108 virtual void collateStats() = 0;
109 virtual void print(std::ostream& out) const = 0;
110
111 /*
112 * Virtual functions for functionally reading and writing packets in
113 * the network. Each network needs to implement these for functional
114 * accesses to work correctly.
115 */
116 virtual bool functionalRead(Packet *pkt)
117 { fatal("Functional read not implemented.\n"); }
118 virtual uint32_t functionalWrite(Packet *pkt)
119 { fatal("Functional write not implemented.\n"); }
120
121 /**
122 * Map an address to the correct NodeID
123 *
124 * This function traverses the global address map to find the
125 * NodeID that corresponds to the given address and the type of
126 * the destination. For example for a request to a directory this
127 * function will return the NodeID of the right directory.
128 *
129 * @param the destination address
130 * @param the type of the destination
131 * @return the NodeID of the destination
132 */
133 NodeID addressToNodeID(Addr addr, MachineType mtype);
134
105 protected:
106 // Private copy constructor and assignment operator
107 Network(const Network& obj);
108 Network& operator=(const Network& obj);
109
110 uint32_t m_nodes;
111 static uint32_t m_virtual_networks;
112 std::vector<std::string> m_vnet_type_names;
113 Topology* m_topology_ptr;
114 static uint32_t m_control_msg_size;
115 static uint32_t m_data_msg_size;
116
117 // vector of queues from the components
118 std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
119 std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
120 std::vector<bool> m_ordered;
121
122 private:
123 //! Callback class used for collating statistics from all the
124 //! controller of this type.
125 class StatsCallback : public Callback
126 {
127 private:
128 Network *ctr;
129
130 public:
131 virtual ~StatsCallback() {}
132
133 StatsCallback(Network *_ctr)
134 : ctr(_ctr)
135 {
136 }
137
138 void process() {ctr->collateStats();}
139 };
135 protected:
136 // Private copy constructor and assignment operator
137 Network(const Network& obj);
138 Network& operator=(const Network& obj);
139
140 uint32_t m_nodes;
141 static uint32_t m_virtual_networks;
142 std::vector<std::string> m_vnet_type_names;
143 Topology* m_topology_ptr;
144 static uint32_t m_control_msg_size;
145 static uint32_t m_data_msg_size;
146
147 // vector of queues from the components
148 std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
149 std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
150 std::vector<bool> m_ordered;
151
152 private:
153 //! Callback class used for collating statistics from all the
154 //! controller of this type.
155 class StatsCallback : public Callback
156 {
157 private:
158 Network *ctr;
159
160 public:
161 virtual ~StatsCallback() {}
162
163 StatsCallback(Network *_ctr)
164 : ctr(_ctr)
165 {
166 }
167
168 void process() {ctr->collateStats();}
169 };
170
171 // Global address map
172 struct AddrMapNode {
173 NodeID id;
174 AddrRangeList ranges;
175 };
176 std::unordered_multimap<MachineType, AddrMapNode> addrMap;
140};
141
142inline std::ostream&
143operator<<(std::ostream& out, const Network& obj)
144{
145 obj.print(out);
146 out << std::flush;
147 return out;
148}
149
150#endif // __MEM_RUBY_NETWORK_NETWORK_HH__
177};
178
179inline std::ostream&
180operator<<(std::ostream& out, const Network& obj)
181{
182 obj.print(out);
183 out << std::flush;
184 return out;
185}
186
187#endif // __MEM_RUBY_NETWORK_NETWORK_HH__