gem5  v21.1.0.2
Router.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Advanced Micro Devices, Inc.
3  * Copyright (c) 2020 Inria
4  * Copyright (c) 2016 Georgia Institute of Technology
5  * Copyright (c) 2008 Princeton University
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met: redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer;
12  * redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution;
15  * neither the name of the copyright holders nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 
34 
35 #include "debug/RubyNetwork.hh"
41 
42 namespace gem5
43 {
44 
45 namespace ruby
46 {
47 
48 namespace garnet
49 {
50 
52  : BasicRouter(p), Consumer(this), m_latency(p.latency),
53  m_virtual_networks(p.virt_nets), m_vc_per_vnet(p.vcs_per_vnet),
54  m_num_vcs(m_virtual_networks * m_vc_per_vnet), m_bit_width(p.width),
55  m_network_ptr(nullptr), routingUnit(this), switchAllocator(this),
56  crossbarSwitch(this)
57 {
58  m_input_unit.clear();
59  m_output_unit.clear();
60 }
61 
62 void
64 {
66 
69 }
70 
71 void
73 {
74  DPRINTF(RubyNetwork, "Router %d woke up\n", m_id);
75  assert(clockEdge() == curTick());
76 
77  // check for incoming flits
78  for (int inport = 0; inport < m_input_unit.size(); inport++) {
79  m_input_unit[inport]->wakeup();
80  }
81 
82  // check for incoming credits
83  // Note: the credit update is happening before SA
84  // buffer turnaround time =
85  // credit traversal (1-cycle) + SA (1-cycle) + Link Traversal (1-cycle)
86  // if we want the credit update to take place after SA, this loop should
87  // be moved after the SA request
88  for (int outport = 0; outport < m_output_unit.size(); outport++) {
89  m_output_unit[outport]->wakeup();
90  }
91 
92  // Switch Allocation
94 
95  // Switch Traversal
97 }
98 
99 void
101  NetworkLink *in_link, CreditLink *credit_link)
102 {
103  fatal_if(in_link->bitWidth != m_bit_width, "Widths of link %s(%d)does"
104  " not match that of Router%d(%d). Consider inserting SerDes "
105  "Units.", in_link->name(), in_link->bitWidth, m_id, m_bit_width);
106 
107  int port_num = m_input_unit.size();
108  InputUnit *input_unit = new InputUnit(port_num, inport_dirn, this);
109 
110  input_unit->set_in_link(in_link);
111  input_unit->set_credit_link(credit_link);
112  in_link->setLinkConsumer(this);
113  in_link->setVcsPerVnet(get_vc_per_vnet());
114  credit_link->setSourceQueue(input_unit->getCreditQueue(), this);
115  credit_link->setVcsPerVnet(get_vc_per_vnet());
116 
117  m_input_unit.push_back(std::shared_ptr<InputUnit>(input_unit));
118 
119  routingUnit.addInDirection(inport_dirn, port_num);
120 }
121 
122 void
124  NetworkLink *out_link,
125  std::vector<NetDest>& routing_table_entry, int link_weight,
126  CreditLink *credit_link, uint32_t consumerVcs)
127 {
128  fatal_if(out_link->bitWidth != m_bit_width, "Widths of units do not match."
129  " Consider inserting SerDes Units");
130 
131  int port_num = m_output_unit.size();
132  OutputUnit *output_unit = new OutputUnit(port_num, outport_dirn, this,
133  consumerVcs);
134 
135  output_unit->set_out_link(out_link);
136  output_unit->set_credit_link(credit_link);
137  credit_link->setLinkConsumer(this);
138  credit_link->setVcsPerVnet(consumerVcs);
139  out_link->setSourceQueue(output_unit->getOutQueue(), this);
140  out_link->setVcsPerVnet(consumerVcs);
141 
142  m_output_unit.push_back(std::shared_ptr<OutputUnit>(output_unit));
143 
144  routingUnit.addRoute(routing_table_entry);
145  routingUnit.addWeight(link_weight);
146  routingUnit.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 routingUnit.outportCompute(route, inport, inport_dirn);
165 }
166 
167 void
168 Router::grant_switch(int inport, flit *t_flit)
169 {
170  crossbarSwitch.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 
235 }
236 
237 void
239 {
240  for (int i = 0; i < m_input_unit.size(); i++) {
241  m_input_unit[i]->resetStats();
242  }
243 
246 }
247 
248 void
249 Router::printFaultVector(std::ostream& out)
250 {
251  int temperature_celcius = BASELINE_TEMPERATURE_CELCIUS;
252  int num_fault_types = m_network_ptr->fault_model->number_of_fault_types;
253  float fault_vector[num_fault_types];
254  get_fault_vector(temperature_celcius, fault_vector);
255  out << "Router-" << m_id << " fault vector: " << std::endl;
256  for (int fault_type_index = 0; fault_type_index < num_fault_types;
257  fault_type_index++) {
258  out << " - probability of (";
259  out <<
260  m_network_ptr->fault_model->fault_type_to_string(fault_type_index);
261  out << ") = ";
262  out << fault_vector[fault_type_index] << std::endl;
263  }
264 }
265 
266 void
268 {
269  int temperature_celcius = BASELINE_TEMPERATURE_CELCIUS;
270  float aggregate_fault_prob;
271  get_aggregate_fault_probability(temperature_celcius,
272  &aggregate_fault_prob);
273  out << "Router-" << m_id << " fault probability: ";
274  out << aggregate_fault_prob << std::endl;
275 }
276 
277 uint32_t
279 {
280  uint32_t num_functional_writes = 0;
281  num_functional_writes += crossbarSwitch.functionalWrite(pkt);
282 
283  for (uint32_t i = 0; i < m_input_unit.size(); i++) {
284  num_functional_writes += m_input_unit[i]->functionalWrite(pkt);
285  }
286 
287  for (uint32_t i = 0; i < m_output_unit.size(); i++) {
288  num_functional_writes += m_output_unit[i]->functionalWrite(pkt);
289  }
290 
291  return num_functional_writes;
292 }
293 
294 } // namespace garnet
295 } // namespace ruby
296 } // namespace gem5
gem5::ruby::garnet::Router::crossbarSwitch
CrossbarSwitch crossbarSwitch
Definition: Router.hh:152
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::ruby::garnet::Router::m_network_ptr
GarnetNetwork * m_network_ptr
Definition: Router.hh:148
gem5::ruby::garnet::flit
Definition: flit.hh:50
gem5::ruby::garnet::OutputUnit
Definition: OutputUnit.hh:56
gem5::ruby::garnet::Router::addOutPort
void addOutPort(PortDirection outport_dirn, NetworkLink *link, std::vector< NetDest > &routing_table_entry, int link_weight, CreditLink *credit_link, uint32_t consumerVcs)
Definition: Router.cc:123
gem5::ruby::garnet::Router::get_fault_vector
bool get_fault_vector(int temperature, float fault_vector[])
Definition: Router.hh:132
gem5::ruby::garnet::GarnetNetwork::fault_model
FaultModel * fault_model
Definition: GarnetNetwork.hh:84
gem5::ruby::garnet::Router::addInPort
void addInPort(PortDirection inport_dirn, NetworkLink *link, CreditLink *credit_link)
Definition: Router.cc:100
gem5::ruby::garnet::InputUnit::set_credit_link
void set_credit_link(CreditLink *credit_link)
Definition: InputUnit.hh:145
gem5::ruby::PortDirection
std::string PortDirection
Definition: Topology.hh:68
gem5::ruby::garnet::Router::get_aggregate_fault_probability
bool get_aggregate_fault_probability(int temperature, float *aggregate_fault_prob)
Definition: Router.hh:136
gem5::ruby::FaultModel::fault_type_to_string
std::string fault_type_to_string(int fault_type_index)
Definition: FaultModel.cc:105
gem5::ruby::BasicRouter
Definition: BasicRouter.hh:45
gem5::ruby::garnet::Router::m_crossbar_activity
statistics::Scalar m_crossbar_activity
Definition: Router.hh:164
gem5::ruby::garnet::Router::m_sw_input_arbiter_activity
statistics::Scalar m_sw_input_arbiter_activity
Definition: Router.hh:161
gem5::ruby::garnet::Router::wakeup
void wakeup()
Definition: Router.cc:72
gem5::statistics::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:68
gem5::ruby::BasicRouter::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: BasicRouter.cc:45
InputUnit.hh
gem5::ruby::garnet::RouteInfo
Definition: CommonTypes.hh:56
gem5::ruby::BasicRouter::m_id
uint32_t m_id
Definition: BasicRouter.hh:58
gem5::ruby::garnet::Router::resetStats
void resetStats()
Callback to reset stats.
Definition: Router.cc:238
std::vector
STL vector class.
Definition: stl.hh:37
gem5::ruby::garnet::SwitchAllocator::resetStats
void resetStats()
Definition: SwitchAllocator.cc:393
GarnetNetwork.hh
gem5::ruby::Consumer
Definition: Consumer.hh:61
gem5::ruby::garnet::RoutingUnit::outportCompute
int outportCompute(RouteInfo route, int inport, PortDirection inport_dirn)
Definition: RoutingUnit.cc:169
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::ruby::garnet::InputUnit::getCreditQueue
flitBuffer * getCreditQueue()
Definition: InputUnit.hh:134
gem5::ruby::garnet::Router::m_virtual_networks
uint32_t m_virtual_networks
Definition: Router.hh:146
gem5::ruby::garnet::Router::m_buffer_writes
statistics::Scalar m_buffer_writes
Definition: Router.hh:159
gem5::ruby::garnet::Router::route_compute
int route_compute(RouteInfo route, int inport, PortDirection direction)
Definition: Router.cc:162
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::ruby::garnet::SwitchAllocator::get_output_arbiter_activity
double get_output_arbiter_activity()
Definition: SwitchAllocator.hh:75
gem5::ArmISA::j
Bitfield< 24 > j
Definition: misc_types.hh:57
gem5::ruby::garnet::InputUnit::set_in_link
void set_in_link(NetworkLink *link)
Definition: InputUnit.hh:137
gem5::statistics::DataWrap::name
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:286
gem5::ruby::garnet::CrossbarSwitch::get_crossbar_activity
double get_crossbar_activity()
Definition: CrossbarSwitch.hh:68
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::ArmISA::width
Bitfield< 4 > width
Definition: misc_types.hh:71
gem5::ruby::Consumer::scheduleEvent
void scheduleEvent(Cycles timeDelta)
Definition: Consumer.cc:56
gem5::ruby::garnet::RoutingUnit::addWeight
void addWeight(int link_weight)
Definition: RoutingUnit.cc:68
gem5::ruby::garnet::RoutingUnit::addInDirection
void addInDirection(PortDirection inport_dirn, int inport)
Definition: RoutingUnit.cc:149
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::ruby::garnet::Router::m_buffer_reads
statistics::Scalar m_buffer_reads
Definition: Router.hh:158
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::ruby::garnet::Router::regStats
void regStats()
Callback to set stat parameters.
Definition: Router.cc:191
gem5::ruby::garnet::Router::m_sw_output_arbiter_activity
statistics::Scalar m_sw_output_arbiter_activity
Definition: Router.hh:162
gem5::ruby::garnet::OutputUnit::set_out_link
void set_out_link(NetworkLink *link)
Definition: OutputUnit.cc:157
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ruby::garnet::OutputUnit::getOutQueue
flitBuffer * getOutQueue()
Definition: OutputUnit.cc:151
gem5::ruby::garnet::Router::getOutportDirection
PortDirection getOutportDirection(int outport)
Definition: Router.cc:150
gem5::ruby::garnet::OutputUnit::set_credit_link
void set_credit_link(CreditLink *credit_link)
Definition: OutputUnit.cc:163
gem5::ruby::garnet::Router::grant_switch
void grant_switch(int inport, flit *t_flit)
Definition: Router.cc:168
gem5::ruby::garnet::Router::printFaultVector
void printFaultVector(std::ostream &out)
Definition: Router.cc:249
gem5::ruby::garnet::SwitchAllocator::get_input_arbiter_activity
double get_input_arbiter_activity()
Definition: SwitchAllocator.hh:70
gem5::ruby::garnet::CrossbarSwitch::wakeup
void wakeup()
Definition: CrossbarSwitch.cc:66
gem5::ruby::garnet::CrossbarSwitch::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: CrossbarSwitch.cc:95
gem5::ruby::garnet::RoutingUnit::addOutDirection
void addOutDirection(PortDirection outport_dirn, int outport)
Definition: RoutingUnit.cc:156
gem5::ruby::FaultModel::number_of_fault_types
@ number_of_fault_types
Definition: FaultModel.hh:81
BASELINE_TEMPERATURE_CELCIUS
#define BASELINE_TEMPERATURE_CELCIUS
Definition: FaultModel.hh:44
gem5::ruby::garnet::InputUnit
Definition: InputUnit.hh:55
gem5::ruby::garnet::CrossbarSwitch::resetStats
void resetStats()
Definition: CrossbarSwitch.cc:107
gem5::statistics::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:69
gem5::Clocked::clockEdge
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Definition: clocked_object.hh:177
gem5::ruby::garnet::Router::collateStats
void collateStats()
Definition: Router.cc:222
gem5::ruby::garnet::CrossbarSwitch::init
void init()
Definition: CrossbarSwitch.cc:54
OutputUnit.hh
gem5::ruby::garnet::Router::Params
GarnetRouterParams Params
Definition: Router.hh:69
gem5::ruby::garnet::Router::getInportDirection
PortDirection getInportDirection(int inport)
Definition: Router.cc:156
gem5::ruby::garnet::SwitchAllocator::init
void init()
Definition: SwitchAllocator.cc:61
gem5::ruby::garnet::RoutingUnit::addRoute
void addRoute(std::vector< NetDest > &routing_table_entry)
Definition: RoutingUnit.cc:57
gem5::ruby::garnet::Router::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Router.cc:63
gem5::ruby::garnet::Router::get_vc_per_vnet
uint32_t get_vc_per_vnet()
Definition: Router.hh:88
gem5::ruby::garnet::Router::m_output_unit
std::vector< std::shared_ptr< OutputUnit > > m_output_unit
Definition: Router.hh:155
gem5::ruby::garnet::Router::m_input_unit
std::vector< std::shared_ptr< InputUnit > > m_input_unit
Definition: Router.hh:154
gem5::ruby::garnet::Router::routingUnit
RoutingUnit routingUnit
Definition: Router.hh:150
gem5::ruby::garnet::Router::getPortDirectionName
std::string getPortDirectionName(PortDirection direction)
Definition: Router.cc:181
gem5::ruby::garnet::Router::schedule_wakeup
void schedule_wakeup(Cycles time)
Definition: Router.cc:174
gem5::ruby::garnet::Router::m_bit_width
uint32_t m_bit_width
Definition: Router.hh:147
gem5::ruby::garnet::Router::printAggregateFaultProbability
void printAggregateFaultProbability(std::ostream &out)
Definition: Router.cc:267
gem5::statistics::DataWrap::flags
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:355
gem5::ruby::garnet::SwitchAllocator::wakeup
void wakeup()
Definition: SwitchAllocator.cc:91
gem5::ruby::garnet::Router::Router
Router(const Params &p)
Definition: Router.cc:51
gem5::ruby::garnet::CrossbarSwitch::update_sw_winner
void update_sw_winner(int inport, flit *t_flit)
Definition: CrossbarSwitch.hh:63
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::garnet::Router::functionalWrite
uint32_t functionalWrite(Packet *)
Definition: Router.cc:278
gem5::ruby::garnet::Router::switchAllocator
SwitchAllocator switchAllocator
Definition: Router.hh:151
Router.hh

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