gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GarnetNetwork.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Princeton University
3  * Copyright (c) 2016 Georgia Institute of Technology
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 
32 
33 #include <cassert>
34 
35 #include "base/cast.hh"
45 
46 using namespace std;
47 
48 /*
49  * GarnetNetwork sets up the routers and links and collects stats.
50  * Default parameters (GarnetNetwork.py) can be overwritten from command line
51  * (see configs/network/Network.py)
52  */
53 
55  : Network(p)
56 {
57  m_num_rows = p->num_rows;
58  m_ni_flit_size = p->ni_flit_size;
59  m_vcs_per_vnet = p->vcs_per_vnet;
60  m_buffers_per_data_vc = p->buffers_per_data_vc;
61  m_buffers_per_ctrl_vc = p->buffers_per_ctrl_vc;
62  m_routing_algorithm = p->routing_algorithm;
63 
64  m_enable_fault_model = p->enable_fault_model;
66  fault_model = p->fault_model;
67 
69 
70  for (int i = 0 ; i < m_virtual_networks ; i++) {
71  if (m_vnet_type_names[i] == "response")
72  m_vnet_type[i] = DATA_VNET_; // carries data (and ctrl) packets
73  else
74  m_vnet_type[i] = CTRL_VNET_; // carries only ctrl packets
75  }
76 
77  // record the routers
78  for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
79  i != p->routers.end(); ++i) {
80  Router* router = safe_cast<Router*>(*i);
81  m_routers.push_back(router);
82 
83  // initialize the router's network pointers
84  router->init_net_ptr(this);
85  }
86 
87  // record the network interfaces
88  for (vector<ClockedObject*>::const_iterator i = p->netifs.begin();
89  i != p->netifs.end(); ++i) {
91  m_nis.push_back(ni);
92  ni->init_net_ptr(this);
93  }
94 }
95 
96 void
98 {
99  Network::init();
100 
101  for (int i=0; i < m_nodes; i++) {
102  m_nis[i]->addNode(m_toNetQueues[i], m_fromNetQueues[i]);
103  }
104 
105  // The topology pointer should have already been initialized in the
106  // parent network constructor
107  assert(m_topology_ptr != NULL);
109 
110  // Initialize topology specific parameters
111  if (getNumRows() > 0) {
112  // Only for Mesh topology
113  // m_num_rows and m_num_cols are only used for
114  // implementing XY or custom routing in RoutingUnit.cc
116  m_num_cols = m_routers.size() / m_num_rows;
117  assert(m_num_rows * m_num_cols == m_routers.size());
118  } else {
119  m_num_rows = -1;
120  m_num_cols = -1;
121  }
122 
123  // FaultModel: declare each router to the fault model
124  if (isFaultModelEnabled()) {
126  i != m_routers.end(); ++i) {
127  Router* router = safe_cast<Router*>(*i);
128  int router_id M5_VAR_USED =
130  router->get_num_outports(),
131  router->get_vc_per_vnet(),
134  assert(router_id == router->get_id());
135  router->printAggregateFaultProbability(cout);
136  router->printFaultVector(cout);
137  }
138  }
139 }
140 
141 /*
142  * This function creates a link from the Network Interface (NI)
143  * into the Network.
144  * It creates a Network Link from the NI to a Router and a Credit Link from
145  * the Router to the NI
146 */
147 
148 void
150  const NetDest& routing_table_entry)
151 {
152  NodeID local_src = getLocalNodeID(global_src);
153  assert(local_src < m_nodes);
154 
155  GarnetExtLink* garnet_link = safe_cast<GarnetExtLink*>(link);
156 
157  // GarnetExtLink is bi-directional
158  NetworkLink* net_link = garnet_link->m_network_links[LinkDirection_In];
159  net_link->setType(EXT_IN_);
160  CreditLink* credit_link = garnet_link->m_credit_links[LinkDirection_In];
161 
162  m_networklinks.push_back(net_link);
163  m_creditlinks.push_back(credit_link);
164 
165  PortDirection dst_inport_dirn = "Local";
166  m_routers[dest]->addInPort(dst_inport_dirn, net_link, credit_link);
167  m_nis[local_src]->addOutPort(net_link, credit_link, dest);
168 }
169 
170 /*
171  * This function creates a link from the Network to a NI.
172  * It creates a Network Link from a Router to the NI and
173  * a Credit Link from NI to the Router
174 */
175 
176 void
178  BasicLink* link,
179  const NetDest& routing_table_entry)
180 {
181  NodeID local_dest = getLocalNodeID(global_dest);
182  assert(local_dest < m_nodes);
183  assert(src < m_routers.size());
184  assert(m_routers[src] != NULL);
185 
186  GarnetExtLink* garnet_link = safe_cast<GarnetExtLink*>(link);
187 
188  // GarnetExtLink is bi-directional
189  NetworkLink* net_link = garnet_link->m_network_links[LinkDirection_Out];
190  net_link->setType(EXT_OUT_);
191  CreditLink* credit_link = garnet_link->m_credit_links[LinkDirection_Out];
192 
193  m_networklinks.push_back(net_link);
194  m_creditlinks.push_back(credit_link);
195 
196  PortDirection src_outport_dirn = "Local";
197  m_routers[src]->addOutPort(src_outport_dirn, net_link,
198  routing_table_entry,
199  link->m_weight, credit_link);
200  m_nis[local_dest]->addInPort(net_link, credit_link);
201 }
202 
203 /*
204  * This function creates an internal network link between two routers.
205  * It adds both the network link and an opposite credit link.
206 */
207 
208 void
210  const NetDest& routing_table_entry,
211  PortDirection src_outport_dirn,
212  PortDirection dst_inport_dirn)
213 {
214  GarnetIntLink* garnet_link = safe_cast<GarnetIntLink*>(link);
215 
216  // GarnetIntLink is unidirectional
217  NetworkLink* net_link = garnet_link->m_network_link;
218  net_link->setType(INT_);
219  CreditLink* credit_link = garnet_link->m_credit_link;
220 
221  m_networklinks.push_back(net_link);
222  m_creditlinks.push_back(credit_link);
223 
224  m_routers[dest]->addInPort(dst_inport_dirn, net_link, credit_link);
225  m_routers[src]->addOutPort(src_outport_dirn, net_link,
226  routing_table_entry,
227  link->m_weight, credit_link);
228 }
229 
230 // Total routers in the network
231 int
233 {
234  return m_routers.size();
235 }
236 
237 // Get ID of router connected to a NI.
238 int
240 {
241  NodeID local_ni = getLocalNodeID(global_ni);
242 
243  return m_nis[local_ni]->get_router_id();
244 }
245 
246 void
248 {
250 
251  // Packets
254  .name(name() + ".packets_received")
256  ;
257 
260  .name(name() + ".packets_injected")
262  ;
263 
266  .name(name() + ".packet_network_latency")
268  ;
269 
272  .name(name() + ".packet_queueing_latency")
274  ;
275 
276  for (int i = 0; i < m_virtual_networks; i++) {
277  m_packets_received.subname(i, csprintf("vnet-%i", i));
278  m_packets_injected.subname(i, csprintf("vnet-%i", i));
281  }
282 
284  .name(name() + ".average_packet_vnet_latency")
288 
290  .name(name() + ".average_packet_vqueue_latency")
294 
296  .name(name() + ".average_packet_network_latency");
299 
301  .name(name() + ".average_packet_queueing_latency");
304 
306  .name(name() + ".average_packet_latency");
309 
310  // Flits
312  .init(m_virtual_networks)
313  .name(name() + ".flits_received")
315  ;
316 
318  .init(m_virtual_networks)
319  .name(name() + ".flits_injected")
321  ;
322 
324  .init(m_virtual_networks)
325  .name(name() + ".flit_network_latency")
327  ;
328 
330  .init(m_virtual_networks)
331  .name(name() + ".flit_queueing_latency")
333  ;
334 
335  for (int i = 0; i < m_virtual_networks; i++) {
336  m_flits_received.subname(i, csprintf("vnet-%i", i));
337  m_flits_injected.subname(i, csprintf("vnet-%i", i));
338  m_flit_network_latency.subname(i, csprintf("vnet-%i", i));
340  }
341 
343  .name(name() + ".average_flit_vnet_latency")
346 
348  .name(name() + ".average_flit_vqueue_latency")
352 
354  .name(name() + ".average_flit_network_latency");
357 
359  .name(name() + ".average_flit_queueing_latency");
362 
364  .name(name() + ".average_flit_latency");
367 
368 
369  // Hops
370  m_avg_hops.name(name() + ".average_hops");
372 
373  // Links
375  .name(name() + ".ext_in_link_utilization");
377  .name(name() + ".ext_out_link_utilization");
379  .name(name() + ".int_link_utilization");
381  .name(name() + ".avg_link_utilization");
382 
384  .init(m_virtual_networks * m_vcs_per_vnet)
385  .name(name() + ".avg_vc_load")
387  ;
388 }
389 
390 void
392 {
393  RubySystem *rs = params()->ruby_system;
394  double time_delta = double(curCycle() - rs->getStartCycle());
395 
396  for (int i = 0; i < m_networklinks.size(); i++) {
397  link_type type = m_networklinks[i]->getType();
398  int activity = m_networklinks[i]->getLinkUtilization();
399 
400  if (type == EXT_IN_)
402  else if (type == EXT_OUT_)
404  else if (type == INT_)
405  m_total_int_link_utilization += activity;
406 
408  (double(activity) / time_delta);
409 
410  vector<unsigned int> vc_load = m_networklinks[i]->getVcLoad();
411  for (int j = 0; j < vc_load.size(); j++) {
412  m_average_vc_load[j] += ((double)vc_load[j] / time_delta);
413  }
414  }
415 
416  // Ask the routers to collate their statistics
417  for (int i = 0; i < m_routers.size(); i++) {
418  m_routers[i]->collateStats();
419  }
420 }
421 
422 void
424 {
425  for (int i = 0; i < m_routers.size(); i++) {
426  m_routers[i]->resetStats();
427  }
428  for (int i = 0; i < m_networklinks.size(); i++) {
429  m_networklinks[i]->resetStats();
430  }
431  for (int i = 0; i < m_creditlinks.size(); i++) {
432  m_creditlinks[i]->resetStats();
433  }
434 }
435 
436 void
437 GarnetNetwork::print(ostream& out) const
438 {
439  out << "[GarnetNetwork]";
440 }
441 
443 GarnetNetworkParams::create()
444 {
445  return new GarnetNetwork(this);
446 }
447 
448 uint32_t
450 {
451  uint32_t num_functional_writes = 0;
452 
453  for (unsigned int i = 0; i < m_routers.size(); i++) {
454  num_functional_writes += m_routers[i]->functionalWrite(pkt);
455  }
456 
457  for (unsigned int i = 0; i < m_nis.size(); ++i) {
458  num_functional_writes += m_nis[i]->functionalWrite(pkt);
459  }
460 
461  for (unsigned int i = 0; i < m_networklinks.size(); ++i) {
462  num_functional_writes += m_networklinks[i]->functionalWrite(pkt);
463  }
464 
465  return num_functional_writes;
466 }
Stats::Formula m_avg_flit_queueing_latency
GarnetNetworkParams Params
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition: info.hh:51
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
bool isFaultModelEnabled() const
std::vector< CreditLink * > m_creditlinks
Stats::Vector m_packets_injected
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation...
Definition: statistics.hh:376
Stats::Vector m_flits_injected
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:158
Bitfield< 7 > i
void init_net_ptr(GarnetNetwork *net_ptr)
Definition: Router.hh:82
Stats::Formula m_avg_packet_latency
int declare_router(int number_of_inputs, int number_of_outputs, int number_of_vcs_per_vnet, int number_of_buff_per_data_vc, int number_of_buff_per_ctrl_vc)
Definition: FaultModel.cc:133
Stats::Formula m_avg_packet_network_latency
Stats::Vector m_flits_received
uint32_t m_buffers_per_ctrl_vc
Stats::Vector m_average_vc_load
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Stats::Scalar m_total_int_link_utilization
void regStats()
Callback to set stat parameters.
std::vector< std::string > m_vnet_type_names
Definition: Network.hh:152
Stats::Scalar m_total_ext_out_link_utilization
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:333
link_type
Definition: CommonTypes.hh:42
Stats::Formula m_avg_packet_queueing_latency
STL vector class.
Definition: stl.hh:37
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1149
uint32_t m_vcs_per_vnet
const Params * params() const
Definition: Network.hh:81
Topology * m_topology_ptr
Definition: Network.hh:153
int get_id()
Definition: Router.hh:80
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, const NetDest &routing_table_entry)
std::vector< Router * > m_routers
unsigned int NodeID
Definition: TypeDefines.hh:34
Stats::Vector m_packet_network_latency
uint8_t type
Definition: inet.hh:328
unsigned int SwitchID
Definition: TypeDefines.hh:35
Cycles getStartCycle()
Definition: RubySystem.hh:66
uint32_t getBuffersPerCtrlVC()
Bitfield< 18 > sum
Definition: registers.hh:610
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
GarnetNetwork(const Params *p)
FaultModel * fault_model
int get_num_outports()
Definition: Router.hh:79
int getNumRows() const
std::vector< VNET_type > m_vnet_type
const FlagsType oneline
Print all values on a single line.
Definition: info.hh:61
std::string PortDirection
Definition: Topology.hh:55
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
int get_vc_per_vnet()
Definition: Router.hh:77
std::vector< NetworkInterface * > m_nis
T safe_cast(U ptr)
Definition: cast.hh:59
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
int get_router_id(int ni)
const FlagsType total
Print the total.
Definition: info.hh:49
Bitfield< 24 > j
Bitfield< 3 > ni
Definition: miscregs.hh:92
Stats::Formula m_avg_hops
Stats::Scalar m_average_link_utilization
Stats::Vector m_packets_received
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:276
Definition: Router.hh:56
uint32_t getBuffersPerDataVC()
Stats::Formula m_avg_packet_vqueue_latency
void makeInternalLink(SwitchID src, SwitchID dest, BasicLink *link, const NetDest &routing_table_entry, PortDirection src_outport_dirn, PortDirection dest_inport_dirn)
virtual const std::string name() const
Definition: sim_object.hh:128
void printFaultVector(std::ostream &out)
Definition: Router.cc:227
NodeID getLocalNodeID(NodeID global_id) const
Definition: Network.cc:247
Stats::Scalar m_total_hops
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Network.cc:152
Stats::Vector m_flit_network_latency
Stats::Formula m_avg_flit_vqueue_latency
Stats::Formula m_avg_flit_network_latency
std::vector< NetworkLink * > m_networklinks
int get_num_inports()
Definition: Router.hh:78
void printAggregateFaultProbability(std::ostream &out)
Definition: Router.cc:245
uint32_t functionalWrite(Packet *pkt)
Function for performing a functional write.
void init_net_ptr(GarnetNetwork *net_ptr)
uint32_t m_ni_flit_size
uint32_t m_nodes
Definition: Network.hh:150
Stats::Formula m_avg_flit_latency
Stats::Formula m_avg_packet_vnet_latency
uint32_t m_buffers_per_data_vc
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
Stats::Scalar m_total_ext_in_link_utilization
void makeExtOutLink(SwitchID src, NodeID dest, BasicLink *link, const NetDest &routing_table_entry)
static uint32_t m_virtual_networks
Definition: Network.hh:151
const FlagsType nozero
Don&#39;t print if this is zero.
Definition: info.hh:57
void createLinks(Network *net)
Definition: Topology.cc:109
void print(std::ostream &out) const
Bitfield< 0 > p
Bitfield< 9, 8 > rs
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:159
Stats::Vector m_flit_queueing_latency
Stats::Formula m_avg_flit_vnet_latency
Stats::Vector m_packet_queueing_latency
void resetStats()
Callback to reset stats.
bool m_enable_fault_model

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