gem5 v24.0.0.0
Loading...
Searching...
No Matches
Network.cc
Go to the documentation of this file.
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 *
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
42
43#include "base/logging.hh"
47
48namespace gem5
49{
50
51namespace ruby
52{
53
57
60{
61 m_virtual_networks = p.number_of_virtual_networks;
62 m_control_msg_size = p.control_msg_size;
63
64 fatal_if(p.data_msg_size > p.ruby_system->getBlockSizeBytes(),
65 "%s: data message size > cache line size", name());
66 m_data_msg_size = p.data_msg_size + m_control_msg_size;
67
68 params().ruby_system->registerNetwork(this);
69
70 // Populate localNodeVersions with the version of each MachineType in
71 // this network. This will be used to compute a global to local ID.
72 // Do this by looking at the ext_node for each ext_link. There is one
73 // ext_node per ext_link and it points to an AbstractController.
74 // For RubySystems with one network global and local ID are the same.
75 std::unordered_map<MachineType, std::vector<NodeID>> localNodeVersions;
76 for (auto &it : params().ext_links) {
77 AbstractController *cntrl = it->params().ext_node;
78 localNodeVersions[cntrl->getType()].push_back(cntrl->getVersion());
79 params().ruby_system->registerMachineID(cntrl->getMachineID(), this);
80 }
81
82 // Compute a local ID for each MachineType using the same order as SLICC
83 NodeID local_node_id = 0;
84 for (int i = 0; i < MachineType_base_level(MachineType_NUM); ++i) {
85 MachineType mach = static_cast<MachineType>(i);
86 if (localNodeVersions.count(mach)) {
87 for (auto &ver : localNodeVersions.at(mach)) {
88 // Get the global ID Ruby will pass around
89 NodeID global_node_id = MachineType_base_number(mach) + ver;
90 globalToLocalMap.emplace(global_node_id, local_node_id);
91 ++local_node_id;
92 }
93 }
94 }
95
96 // Total nodes/controllers in network is equal to the local node count
97 // Must make sure this is called after the State Machine constructors
98 m_nodes = local_node_id;
99
100 assert(m_nodes != 0);
101 assert(m_virtual_networks != 0);
102
103 m_topology_ptr = new Topology(m_nodes, p.routers.size(),
105 p.ext_links, p.int_links);
106
107 // Allocate to and from queues
108 // Queues that are getting messages from protocol
109 m_toNetQueues.resize(m_nodes);
110
111 // Queues that are feeding the protocol
112 m_fromNetQueues.resize(m_nodes);
113
116
117 for (int i = 0; i < m_virtual_networks; i++) {
118 m_ordered[i] = false;
119 }
120
121 // Initialize the controller's network pointers
122 for (std::vector<BasicExtLink*>::const_iterator i = p.ext_links.begin();
123 i != p.ext_links.end(); ++i) {
124 BasicExtLink *ext_link = (*i);
125 AbstractController *abs_cntrl = ext_link->params().ext_node;
126 abs_cntrl->initNetworkPtr(this);
127 const AddrRangeList &ranges = abs_cntrl->getAddrRanges();
128 if (!ranges.empty()) {
129 MachineID mid = abs_cntrl->getMachineID();
130 AddrMapNode addr_map_node = {
131 .id = mid.getNum(),
132 .ranges = ranges
133 };
134 addrMap.emplace(mid.getType(), addr_map_node);
135 }
136 }
137
138 // Register a callback function for combining the statistics
140
141 for (auto &it : dynamic_cast<Network *>(this)->params().ext_links) {
142 it->params().ext_node->initNetQueues();
143 }
144}
145
147{
148 for (int node = 0; node < m_nodes; node++) {
149
150 // Delete the Message Buffers
151 for (auto& it : m_toNetQueues[node]) {
152 delete it;
153 }
154
155 for (auto& it : m_fromNetQueues[node]) {
156 delete it;
157 }
158 }
159
160 delete m_topology_ptr;
161}
162
163uint32_t
165{
166 switch(size_type) {
167 case MessageSizeType_Control:
168 case MessageSizeType_Request_Control:
169 case MessageSizeType_Reissue_Control:
170 case MessageSizeType_Response_Control:
171 case MessageSizeType_Writeback_Control:
172 case MessageSizeType_Broadcast_Control:
173 case MessageSizeType_Multicast_Control:
174 case MessageSizeType_Forwarded_Control:
175 case MessageSizeType_Invalidate_Control:
176 case MessageSizeType_Unblock_Control:
177 case MessageSizeType_Persistent_Control:
178 case MessageSizeType_Completion_Control:
179 return m_control_msg_size;
180 case MessageSizeType_Data:
181 case MessageSizeType_Response_Data:
182 case MessageSizeType_ResponseLocal_Data:
183 case MessageSizeType_ResponseL2hit_Data:
184 case MessageSizeType_Writeback_Data:
185 return m_data_msg_size;
186 default:
187 panic("Invalid range for type MessageSizeType");
188 break;
189 }
190}
191
192void
194 int network_num,
195 std::string vnet_type)
196{
197 fatal_if(local_id >= m_nodes, "Node ID is out of range");
198 fatal_if(network_num >= m_virtual_networks, "Network id is out of range");
199
200 if (ordered) {
201 m_ordered[network_num] = true;
202 }
203
204 m_vnet_type_names[network_num] = vnet_type;
205}
206
207
208void
209Network::setToNetQueue(NodeID global_id, bool ordered, int network_num,
210 std::string vnet_type, MessageBuffer *b)
211{
212 NodeID local_id = getLocalNodeID(global_id);
213 checkNetworkAllocation(local_id, ordered, network_num, vnet_type);
214
215 while (m_toNetQueues[local_id].size() <= network_num) {
216 m_toNetQueues[local_id].push_back(nullptr);
217 }
218 m_toNetQueues[local_id][network_num] = b;
219}
220
221void
222Network::setFromNetQueue(NodeID global_id, bool ordered, int network_num,
223 std::string vnet_type, MessageBuffer *b)
224{
225 NodeID local_id = getLocalNodeID(global_id);
226 checkNetworkAllocation(local_id, ordered, network_num, vnet_type);
227
228 while (m_fromNetQueues[local_id].size() <= network_num) {
229 m_fromNetQueues[local_id].push_back(nullptr);
230 }
231 m_fromNetQueues[local_id][network_num] = b;
232}
233
234NodeID
236{
237 // Look through the address maps for entries with matching machine
238 // type to get the responsible node for this address.
239 const auto &matching_ranges = addrMap.equal_range(mtype);
240 for (auto it = matching_ranges.first; it != matching_ranges.second; it++) {
241 AddrMapNode &node = it->second;
242 auto &ranges = node.ranges;
243 for (AddrRange &range: ranges) {
244 if (range.contains(addr)) {
245 return node.id;
246 }
247 }
248 }
249 return MachineType_base_count(mtype);
250}
251
252NodeID
254{
255 assert(globalToLocalMap.count(global_id));
256 return globalToLocalMap.at(global_id);
257}
258
259} // namespace ruby
260} // namespace gem5
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ClockedObjectParams Params
Parameters of ClockedObject.
virtual std::string name() const
Definition named.hh:47
void initNetworkPtr(Network *net_ptr)
const AddrRangeList & getAddrRanges() const
void setToNetQueue(NodeID global_id, bool ordered, int netNumber, std::string vnet_type, MessageBuffer *b)
Definition Network.cc:209
virtual ~Network()
Definition Network.cc:146
virtual void setFromNetQueue(NodeID global_id, bool ordered, int netNumber, std::string vnet_type, MessageBuffer *b)
Definition Network.cc:222
std::unordered_multimap< MachineType, AddrMapNode > addrMap
Definition Network.hh:174
std::vector< bool > m_ordered
Definition Network.hh:165
static uint32_t m_data_msg_size
Definition Network.hh:160
static uint32_t m_control_msg_size
Definition Network.hh:159
Topology * m_topology_ptr
Definition Network.hh:158
virtual void checkNetworkAllocation(NodeID local_id, bool ordered, int network_num, std::string vnet_type)
Definition Network.cc:193
static uint32_t m_virtual_networks
Definition Network.hh:156
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition Network.cc:164
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition Network.hh:164
std::unordered_map< NodeID, NodeID > globalToLocalMap
Definition Network.hh:178
NodeID getLocalNodeID(NodeID global_id) const
Definition Network.cc:253
virtual void collateStats()=0
NodeID addressToNodeID(Addr addr, MachineType mtype)
Map an address to the correct NodeID.
Definition Network.cc:235
Network(const Params &p)
Definition Network.cc:58
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition Network.hh:163
std::vector< std::string > m_vnet_type_names
Definition Network.hh:157
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
const Params & params() const
Bitfield< 7 > b
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
unsigned int NodeID
unsigned int size_type
Definition types.hh:59
void registerDumpCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are about to be dumped.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
MachineType getType() const
Definition MachineID.hh:66
NodeID getNum() const
Definition MachineID.hh:67

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0