gem5  v21.1.0.2
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 
48 namespace gem5
49 {
50 
51 namespace ruby
52 {
53 
57 
59  : ClockedObject(p)
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 
163 uint32_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 
192 void
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 
208 void
209 Network::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 
221 void
222 Network::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 
234 NodeID
235 Network::addressToNodeID(Addr addr, MachineType mtype)
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 
252 NodeID
254 {
255  assert(globalToLocalMap.count(global_id));
256  return globalToLocalMap.at(global_id);
257 }
258 
259 } // namespace ruby
260 } // namespace gem5
MachineID.hh
gem5::ruby::MachineID::getType
MachineType getType() const
Definition: MachineID.hh:66
gem5::ruby::Network::m_virtual_networks
static uint32_t m_virtual_networks
Definition: Network.hh:156
gem5::ruby::AbstractController::getVersion
NodeID getVersion() const
Definition: AbstractController.hh:89
gem5::ruby::Network::m_ordered
std::vector< bool > m_ordered
Definition: Network.hh:165
gem5::ruby::Network::AddrMapNode
Definition: Network.hh:169
gem5::ruby::Network::MessageSizeType_to_int
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:164
gem5::ruby::Topology
Definition: Topology.hh:80
gem5::ruby::AbstractController::getType
MachineType getType() const
Definition: AbstractController.hh:90
gem5::ruby::AbstractController::getMachineID
MachineID getMachineID() const
Definition: AbstractController.hh:174
gem5::ruby::Network
Definition: Network.hh:82
gem5::ruby::Network::addrMap
std::unordered_multimap< MachineType, AddrMapNode > addrMap
Definition: Network.hh:174
std::vector
STL vector class.
Definition: stl.hh:37
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::ruby::AbstractController
Definition: AbstractController.hh:82
gem5::statistics::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:324
gem5::ruby::Network::Network
Network(const Params &p)
Definition: Network.cc:58
gem5::ruby::AbstractController::getAddrRanges
const AddrRangeList & getAddrRanges() const
Definition: AbstractController.hh:171
gem5::ArmISA::b
Bitfield< 7 > b
Definition: misc_types.hh:381
gem5::ruby::Network::m_data_msg_size
static uint32_t m_data_msg_size
Definition: Network.hh:160
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::ruby::AbstractController::initNetworkPtr
void initNetworkPtr(Network *net_ptr)
Definition: AbstractController.hh:92
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::ruby::Network::m_nodes
uint32_t m_nodes
Definition: Network.hh:155
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ruby::Network::checkNetworkAllocation
virtual void checkNetworkAllocation(NodeID local_id, bool ordered, int network_num, std::string vnet_type)
Definition: Network.cc:193
gem5::ruby::Network::setFromNetQueue
virtual void setFromNetQueue(NodeID global_id, bool ordered, int netNumber, std::string vnet_type, MessageBuffer *b)
Definition: Network.cc:222
gem5::ruby::Network::getLocalNodeID
NodeID getLocalNodeID(NodeID global_id) const
Definition: Network.cc:253
gem5::ruby::Network::m_fromNetQueues
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:164
gem5::ruby::MachineID::getNum
NodeID getNum() const
Definition: MachineID.hh:67
RubySystem.hh
gem5::statistics::size_type
unsigned int size_type
Definition: types.hh:60
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ruby::Network::collateStats
virtual void collateStats()=0
gem5::ruby::Network::~Network
virtual ~Network()
Definition: Network.cc:146
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::ruby::Network::m_toNetQueues
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:163
gem5::ruby::Network::m_vnet_type_names
std::vector< std::string > m_vnet_type_names
Definition: Network.hh:157
Network.hh
gem5::ruby::Network::m_topology_ptr
Topology * m_topology_ptr
Definition: Network.hh:158
gem5::ruby::Network::addressToNodeID
NodeID addressToNodeID(Addr addr, MachineType mtype)
Map an address to the correct NodeID.
Definition: Network.cc:235
gem5::ruby::Network::globalToLocalMap
std::unordered_map< NodeID, NodeID > globalToLocalMap
Definition: Network.hh:178
logging.hh
gem5::ruby::NodeID
unsigned int NodeID
Definition: TypeDefines.hh:40
gem5::ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:240
gem5::ruby::Network::m_control_msg_size
static uint32_t m_control_msg_size
Definition: Network.hh:159
gem5::ruby::MessageBuffer
Definition: MessageBuffer.hh:74
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:71
std::list< AddrRange >
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:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ruby::Network::AddrMapNode::ranges
AddrRangeList ranges
Definition: Network.hh:172
gem5::ruby::MachineID
Definition: MachineID.hh:56
gem5::ruby::Network::setToNetQueue
void setToNetQueue(NodeID global_id, bool ordered, int netNumber, std::string vnet_type, MessageBuffer *b)
Definition: Network.cc:209
gem5::ruby::Network::AddrMapNode::id
NodeID id
Definition: Network.hh:171
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:41 for gem5 by doxygen 1.8.17