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

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17