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

Generated on Mon Jun 8 2020 15:45:12 for gem5 by doxygen 1.8.13