gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Router.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  * Authors: Niket Agarwal
30  * Tushar Krishna
31  */
32 
33 
35 
36 #include "base/stl_helpers.hh"
37 #include "debug/RubyNetwork.hh"
46 
47 using namespace std;
49 
51  : BasicRouter(p), Consumer(this)
52 {
53  m_latency = p->latency;
54  m_virtual_networks = p->virt_nets;
55  m_vc_per_vnet = p->vcs_per_vnet;
57 
58  m_routing_unit = new RoutingUnit(this);
59  m_sw_alloc = new SwitchAllocator(this);
60  m_switch = new CrossbarSwitch(this);
61 
62  m_input_unit.clear();
63  m_output_unit.clear();
64 }
65 
67 {
70  delete m_routing_unit;
71  delete m_sw_alloc;
72  delete m_switch;
73 }
74 
75 void
77 {
79 
80  m_sw_alloc->init();
81  m_switch->init();
82 }
83 
84 void
86 {
87  DPRINTF(RubyNetwork, "Router %d woke up\n", m_id);
88 
89  // check for incoming flits
90  for (int inport = 0; inport < m_input_unit.size(); inport++) {
91  m_input_unit[inport]->wakeup();
92  }
93 
94  // check for incoming credits
95  // Note: the credit update is happening before SA
96  // buffer turnaround time =
97  // credit traversal (1-cycle) + SA (1-cycle) + Link Traversal (1-cycle)
98  // if we want the credit update to take place after SA, this loop should
99  // be moved after the SA request
100  for (int outport = 0; outport < m_output_unit.size(); outport++) {
101  m_output_unit[outport]->wakeup();
102  }
103 
104  // Switch Allocation
105  m_sw_alloc->wakeup();
106 
107  // Switch Traversal
108  m_switch->wakeup();
109 }
110 
111 void
113  NetworkLink *in_link, CreditLink *credit_link)
114 {
115  int port_num = m_input_unit.size();
116  InputUnit *input_unit = new InputUnit(port_num, inport_dirn, this);
117 
118  input_unit->set_in_link(in_link);
119  input_unit->set_credit_link(credit_link);
120  in_link->setLinkConsumer(this);
121  credit_link->setSourceQueue(input_unit->getCreditQueue());
122 
123  m_input_unit.push_back(input_unit);
124 
125  m_routing_unit->addInDirection(inport_dirn, port_num);
126 }
127 
128 void
130  NetworkLink *out_link,
131  const NetDest& routing_table_entry, int link_weight,
132  CreditLink *credit_link)
133 {
134  int port_num = m_output_unit.size();
135  OutputUnit *output_unit = new OutputUnit(port_num, outport_dirn, this);
136 
137  output_unit->set_out_link(out_link);
138  output_unit->set_credit_link(credit_link);
139  credit_link->setLinkConsumer(this);
140  out_link->setSourceQueue(output_unit->getOutQueue());
141 
142  m_output_unit.push_back(output_unit);
143 
144  m_routing_unit->addRoute(routing_table_entry);
145  m_routing_unit->addWeight(link_weight);
146  m_routing_unit->addOutDirection(outport_dirn, port_num);
147 }
148 
151 {
152  return m_output_unit[outport]->get_direction();
153 }
154 
157 {
158  return m_input_unit[inport]->get_direction();
159 }
160 
161 int
162 Router::route_compute(RouteInfo route, int inport, PortDirection inport_dirn)
163 {
164  return m_routing_unit->outportCompute(route, inport, inport_dirn);
165 }
166 
167 void
168 Router::grant_switch(int inport, flit *t_flit)
169 {
170  m_switch->update_sw_winner(inport, t_flit);
171 }
172 
173 void
175 {
176  // wake up after time cycles
177  scheduleEvent(time);
178 }
179 
180 std::string
182 {
183  // PortDirection is actually a string
184  // If not, then this function should add a switch
185  // statement to convert direction to a string
186  // that can be printed out
187  return direction;
188 }
189 
190 void
192 {
194 
196  .name(name() + ".buffer_reads")
198  ;
199 
201  .name(name() + ".buffer_writes")
203  ;
204 
206  .name(name() + ".crossbar_activity")
208  ;
209 
211  .name(name() + ".sw_input_arbiter_activity")
213  ;
214 
216  .name(name() + ".sw_output_arbiter_activity")
218  ;
219 }
220 
221 void
223 {
224  for (int j = 0; j < m_virtual_networks; j++) {
225  for (int i = 0; i < m_input_unit.size(); i++) {
226  m_buffer_reads += m_input_unit[i]->get_buf_read_activity(j);
227  m_buffer_writes += m_input_unit[i]->get_buf_write_activity(j);
228  }
229  }
230 
234 }
235 
236 void
238 {
239  for (int j = 0; j < m_virtual_networks; j++) {
240  for (int i = 0; i < m_input_unit.size(); i++) {
241  m_input_unit[i]->resetStats();
242  }
243  }
244 }
245 
246 void
248 {
249  int temperature_celcius = BASELINE_TEMPERATURE_CELCIUS;
250  int num_fault_types = m_network_ptr->fault_model->number_of_fault_types;
251  float fault_vector[num_fault_types];
252  get_fault_vector(temperature_celcius, fault_vector);
253  out << "Router-" << m_id << " fault vector: " << endl;
254  for (int fault_type_index = 0; fault_type_index < num_fault_types;
255  fault_type_index++) {
256  out << " - probability of (";
257  out <<
258  m_network_ptr->fault_model->fault_type_to_string(fault_type_index);
259  out << ") = ";
260  out << fault_vector[fault_type_index] << endl;
261  }
262 }
263 
264 void
266 {
267  int temperature_celcius = BASELINE_TEMPERATURE_CELCIUS;
268  float aggregate_fault_prob;
269  get_aggregate_fault_probability(temperature_celcius,
270  &aggregate_fault_prob);
271  out << "Router-" << m_id << " fault probability: ";
272  out << aggregate_fault_prob << endl;
273 }
274 
275 uint32_t
277 {
278  uint32_t num_functional_writes = 0;
279  num_functional_writes += m_switch->functionalWrite(pkt);
280 
281  for (uint32_t i = 0; i < m_input_unit.size(); i++) {
282  num_functional_writes += m_input_unit[i]->functionalWrite(pkt);
283  }
284 
285  for (uint32_t i = 0; i < m_output_unit.size(); i++) {
286  num_functional_writes += m_output_unit[i]->functionalWrite(pkt);
287  }
288 
289  return num_functional_writes;
290 }
291 
292 Router *
293 GarnetRouterParams::create()
294 {
295  return new Router(this);
296 }
#define DPRINTF(x,...)
Definition: trace.hh:212
void set_in_link(NetworkLink *link)
Definition: InputUnit.hh:130
Stats::Scalar m_buffer_reads
Definition: Router.hh:131
BasicRouterParams Params
Definition: BasicRouter.hh:42
GarnetNetwork * m_network_ptr
Definition: Router.hh:122
void set_out_link(NetworkLink *link)
Definition: OutputUnit.cc:153
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
RoutingUnit * m_routing_unit
Definition: Router.hh:126
Bitfield< 7 > i
Definition: miscregs.hh:1378
uint32_t m_id
Definition: BasicRouter.hh:53
PortDirection getOutportDirection(int outport)
Definition: Router.cc:150
int m_vc_per_vnet
Definition: Router.hh:121
std::vector< OutputUnit * > m_output_unit
Definition: Router.hh:125
void scheduleEvent(Cycles timeDelta)
Definition: Consumer.cc:34
int m_num_vcs
Definition: Router.hh:121
void grant_switch(int inport, flit *t_flit)
Definition: Router.cc:168
int route_compute(RouteInfo route, int inport, PortDirection direction)
Definition: Router.cc:162
Cycles m_latency
Definition: Router.hh:120
void resetStats()
Reset statistics associated with this object.
Definition: Router.cc:237
void update_sw_winner(int inport, flit *t_flit)
uint32_t functionalWrite(Packet *pkt)
Stats::Scalar m_buffer_writes
Definition: Router.hh:132
bool get_aggregate_fault_probability(int temperature, float *aggregate_fault_prob)
Definition: Router.hh:111
std::string getPortDirectionName(PortDirection direction)
Definition: Router.cc:181
Stats::Scalar m_sw_output_arbiter_activity
Definition: Router.hh:135
~Router()
Definition: Router.cc:66
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:311
flitBuffer * getOutQueue()
Definition: OutputUnit.cc:147
void set_credit_link(CreditLink *credit_link)
Definition: InputUnit.hh:138
std::string fault_type_to_string(int fault_type_index)
Definition: FaultModel.cc:104
Stats::Scalar m_sw_input_arbiter_activity
Definition: Router.hh:134
void addWeight(int link_weight)
Definition: RoutingUnit.cc:55
uint32_t functionalWrite(Packet *)
Definition: Router.cc:276
double get_output_arbiter_activity()
double get_crossbar_activity()
void collateStats()
Definition: Router.cc:222
void schedule_wakeup(Cycles time)
Definition: Router.cc:174
#define BASELINE_TEMPERATURE_CELCIUS
Definition: FaultModel.hh:46
Definition: flit.hh:44
FaultModel * fault_model
void addInPort(PortDirection inport_dirn, NetworkLink *link, CreditLink *credit_link)
Definition: Router.cc:112
SwitchAllocator * m_sw_alloc
Definition: Router.hh:127
Stats::Scalar m_crossbar_activity
Definition: Router.hh:137
std::string PortDirection
Definition: Topology.hh:55
Router(const Params *p)
Definition: Router.cc:50
void addRoute(const NetDest &routing_table_entry)
Definition: RoutingUnit.cc:49
void deletePointers(C< T, A > &container)
Definition: stl_helpers.hh:77
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: BasicRouter.cc:39
int m_virtual_networks
Definition: Router.hh:121
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
void set_credit_link(CreditLink *credit_link)
Definition: OutputUnit.cc:159
void addInDirection(PortDirection inport_dirn, int inport)
Definition: RoutingUnit.cc:119
Bitfield< 24 > j
Definition: miscregs.hh:1369
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:254
Definition: Router.hh:57
void printFaultVector(std::ostream &out)
Definition: Router.cc:247
std::vector< InputUnit * > m_input_unit
Definition: Router.hh:124
virtual const std::string name() const
Definition: sim_object.hh:117
bool get_fault_vector(int temperature, float fault_vector[])
Definition: Router.hh:107
void addOutPort(PortDirection outport_dirn, NetworkLink *link, const NetDest &routing_table_entry, int link_weight, CreditLink *credit_link)
Definition: Router.cc:129
double get_input_arbiter_activity()
int outportCompute(RouteInfo route, int inport, PortDirection inport_dirn)
Definition: RoutingUnit.cc:139
void addOutDirection(PortDirection outport_dirn, int outport)
Definition: RoutingUnit.cc:126
void printAggregateFaultProbability(std::ostream &out)
Definition: Router.cc:265
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
Bitfield< 0 > p
flitBuffer * getCreditQueue()
Definition: InputUnit.hh:127
void wakeup()
Definition: Router.cc:85
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Router.cc:76
void regStats() override
Register statistics for this object.
void regStats()
Register statistics for this object.
Definition: Router.cc:191
CrossbarSwitch * m_switch
Definition: Router.hh:128
PortDirection getInportDirection(int inport)
Definition: Router.cc:156

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6