gem5  v20.0.0.0
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  assert(src < m_nodes);
153 
154  GarnetExtLink* garnet_link = safe_cast<GarnetExtLink*>(link);
155 
156  // GarnetExtLink is bi-directional
157  NetworkLink* net_link = garnet_link->m_network_links[LinkDirection_In];
158  net_link->setType(EXT_IN_);
159  CreditLink* credit_link = garnet_link->m_credit_links[LinkDirection_In];
160 
161  m_networklinks.push_back(net_link);
162  m_creditlinks.push_back(credit_link);
163 
164  PortDirection dst_inport_dirn = "Local";
165  m_routers[dest]->addInPort(dst_inport_dirn, net_link, credit_link);
166  m_nis[src]->addOutPort(net_link, credit_link, dest);
167 }
168 
169 /*
170  * This function creates a link from the Network to a NI.
171  * It creates a Network Link from a Router to the NI and
172  * a Credit Link from NI to the Router
173 */
174 
175 void
177  const NetDest& routing_table_entry)
178 {
179  assert(dest < m_nodes);
180  assert(src < m_routers.size());
181  assert(m_routers[src] != NULL);
182 
183  GarnetExtLink* garnet_link = safe_cast<GarnetExtLink*>(link);
184 
185  // GarnetExtLink is bi-directional
186  NetworkLink* net_link = garnet_link->m_network_links[LinkDirection_Out];
187  net_link->setType(EXT_OUT_);
188  CreditLink* credit_link = garnet_link->m_credit_links[LinkDirection_Out];
189 
190  m_networklinks.push_back(net_link);
191  m_creditlinks.push_back(credit_link);
192 
193  PortDirection src_outport_dirn = "Local";
194  m_routers[src]->addOutPort(src_outport_dirn, net_link,
195  routing_table_entry,
196  link->m_weight, credit_link);
197  m_nis[dest]->addInPort(net_link, credit_link);
198 }
199 
200 /*
201  * This function creates an internal network link between two routers.
202  * It adds both the network link and an opposite credit link.
203 */
204 
205 void
207  const NetDest& routing_table_entry,
208  PortDirection src_outport_dirn,
209  PortDirection dst_inport_dirn)
210 {
211  GarnetIntLink* garnet_link = safe_cast<GarnetIntLink*>(link);
212 
213  // GarnetIntLink is unidirectional
214  NetworkLink* net_link = garnet_link->m_network_link;
215  net_link->setType(INT_);
216  CreditLink* credit_link = garnet_link->m_credit_link;
217 
218  m_networklinks.push_back(net_link);
219  m_creditlinks.push_back(credit_link);
220 
221  m_routers[dest]->addInPort(dst_inport_dirn, net_link, credit_link);
222  m_routers[src]->addOutPort(src_outport_dirn, net_link,
223  routing_table_entry,
224  link->m_weight, credit_link);
225 }
226 
227 // Total routers in the network
228 int
230 {
231  return m_routers.size();
232 }
233 
234 // Get ID of router connected to a NI.
235 int
237 {
238  return m_nis[ni]->get_router_id();
239 }
240 
241 void
243 {
245 
246  // Packets
249  .name(name() + ".packets_received")
251  ;
252 
255  .name(name() + ".packets_injected")
257  ;
258 
261  .name(name() + ".packet_network_latency")
263  ;
264 
267  .name(name() + ".packet_queueing_latency")
269  ;
270 
271  for (int i = 0; i < m_virtual_networks; i++) {
272  m_packets_received.subname(i, csprintf("vnet-%i", i));
273  m_packets_injected.subname(i, csprintf("vnet-%i", i));
276  }
277 
279  .name(name() + ".average_packet_vnet_latency")
283 
285  .name(name() + ".average_packet_vqueue_latency")
289 
291  .name(name() + ".average_packet_network_latency");
294 
296  .name(name() + ".average_packet_queueing_latency");
299 
301  .name(name() + ".average_packet_latency");
304 
305  // Flits
307  .init(m_virtual_networks)
308  .name(name() + ".flits_received")
310  ;
311 
313  .init(m_virtual_networks)
314  .name(name() + ".flits_injected")
316  ;
317 
319  .init(m_virtual_networks)
320  .name(name() + ".flit_network_latency")
322  ;
323 
325  .init(m_virtual_networks)
326  .name(name() + ".flit_queueing_latency")
328  ;
329 
330  for (int i = 0; i < m_virtual_networks; i++) {
331  m_flits_received.subname(i, csprintf("vnet-%i", i));
332  m_flits_injected.subname(i, csprintf("vnet-%i", i));
333  m_flit_network_latency.subname(i, csprintf("vnet-%i", i));
335  }
336 
338  .name(name() + ".average_flit_vnet_latency")
341 
343  .name(name() + ".average_flit_vqueue_latency")
347 
349  .name(name() + ".average_flit_network_latency");
352 
354  .name(name() + ".average_flit_queueing_latency");
357 
359  .name(name() + ".average_flit_latency");
362 
363 
364  // Hops
365  m_avg_hops.name(name() + ".average_hops");
367 
368  // Links
370  .name(name() + ".ext_in_link_utilization");
372  .name(name() + ".ext_out_link_utilization");
374  .name(name() + ".int_link_utilization");
376  .name(name() + ".avg_link_utilization");
377 
379  .init(m_virtual_networks * m_vcs_per_vnet)
380  .name(name() + ".avg_vc_load")
382  ;
383 }
384 
385 void
387 {
388  RubySystem *rs = params()->ruby_system;
389  double time_delta = double(curCycle() - rs->getStartCycle());
390 
391  for (int i = 0; i < m_networklinks.size(); i++) {
392  link_type type = m_networklinks[i]->getType();
393  int activity = m_networklinks[i]->getLinkUtilization();
394 
395  if (type == EXT_IN_)
397  else if (type == EXT_OUT_)
399  else if (type == INT_)
400  m_total_int_link_utilization += activity;
401 
403  (double(activity) / time_delta);
404 
405  vector<unsigned int> vc_load = m_networklinks[i]->getVcLoad();
406  for (int j = 0; j < vc_load.size(); j++) {
407  m_average_vc_load[j] += ((double)vc_load[j] / time_delta);
408  }
409  }
410 
411  // Ask the routers to collate their statistics
412  for (int i = 0; i < m_routers.size(); i++) {
413  m_routers[i]->collateStats();
414  }
415 }
416 
417 void
418 GarnetNetwork::print(ostream& out) const
419 {
420  out << "[GarnetNetwork]";
421 }
422 
424 GarnetNetworkParams::create()
425 {
426  return new GarnetNetwork(this);
427 }
428 
429 uint32_t
431 {
432  uint32_t num_functional_writes = 0;
433 
434  for (unsigned int i = 0; i < m_routers.size(); i++) {
435  num_functional_writes += m_routers[i]->functionalWrite(pkt);
436  }
437 
438  for (unsigned int i = 0; i < m_nis.size(); ++i) {
439  num_functional_writes += m_nis[i]->functionalWrite(pkt);
440  }
441 
442  for (unsigned int i = 0; i < m_networklinks.size(); ++i) {
443  num_functional_writes += m_networklinks[i]->functionalWrite(pkt);
444  }
445 
446  return num_functional_writes;
447 }
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:156
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:150
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:151
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:129
void printFaultVector(std::ostream &out)
Definition: Router.cc:229
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:126
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:247
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:148
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:149
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:157
Stats::Vector m_flit_queueing_latency
Stats::Formula m_avg_flit_vnet_latency
Stats::Vector m_packet_queueing_latency
bool m_enable_fault_model

Generated on Thu May 28 2020 16:21:34 for gem5 by doxygen 1.8.13