gem5  v20.1.0.0
InputUnit.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Inria
3  * Copyright (c) 2016 Georgia Institute of Technology
4  * Copyright (c) 2008 Princeton University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met: redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer;
11  * redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution;
14  * neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
33 
34 #include "debug/RubyNetwork.hh"
37 
38 using namespace std;
39 
40 InputUnit::InputUnit(int id, PortDirection direction, Router *router)
41  : Consumer(router), m_router(router), m_id(id), m_direction(direction),
42  m_vc_per_vnet(m_router->get_vc_per_vnet())
43 {
44  const int m_num_vcs = m_router->get_num_vcs();
45  m_num_buffer_reads.resize(m_num_vcs/m_vc_per_vnet);
46  m_num_buffer_writes.resize(m_num_vcs/m_vc_per_vnet);
47  for (int i = 0; i < m_num_buffer_reads.size(); i++) {
48  m_num_buffer_reads[i] = 0;
50  }
51 
52  // Instantiating the virtual channels
53  virtualChannels.reserve(m_num_vcs);
54  for (int i=0; i < m_num_vcs; i++) {
55  virtualChannels.emplace_back();
56  }
57 }
58 
59 /*
60  * The InputUnit wakeup function reads the input flit from its input link.
61  * Each flit arrives with an input VC.
62  * For HEAD/HEAD_TAIL flits, performs route computation,
63  * and updates route in the input VC.
64  * The flit is buffered for (m_latency - 1) cycles in the input VC
65  * and marked as valid for SwitchAllocation starting that cycle.
66  *
67  */
68 
69 void
71 {
72  flit *t_flit;
73  if (m_in_link->isReady(curTick())) {
74 
75  t_flit = m_in_link->consumeLink();
76  DPRINTF(RubyNetwork, "Router[%d] Consuming:%s Width: %d Flit:%s\n",
78  m_router->getBitWidth(), *t_flit);
79  assert(t_flit->m_width == m_router->getBitWidth());
80  int vc = t_flit->get_vc();
81  t_flit->increment_hops(); // for stats
82 
83  if ((t_flit->get_type() == HEAD_) ||
84  (t_flit->get_type() == HEAD_TAIL_)) {
85 
86  assert(virtualChannels[vc].get_state() == IDLE_);
87  set_vc_active(vc, curTick());
88 
89  // Route computation for this vc
90  int outport = m_router->route_compute(t_flit->get_route(),
91  m_id, m_direction);
92 
93  // Update output port in VC
94  // All flits in this packet will use this output port
95  // The output port field in the flit is updated after it wins SA
96  grant_outport(vc, outport);
97 
98  } else {
99  assert(virtualChannels[vc].get_state() == ACTIVE_);
100  }
101 
102 
103  // Buffer the flit
104  virtualChannels[vc].insertFlit(t_flit);
105 
106  int vnet = vc/m_vc_per_vnet;
107  // number of writes same as reads
108  // any flit that is written will be read only once
109  m_num_buffer_writes[vnet]++;
110  m_num_buffer_reads[vnet]++;
111 
112  Cycles pipe_stages = m_router->get_pipe_stages();
113  if (pipe_stages == 1) {
114  // 1-cycle router
115  // Flit goes for SA directly
116  t_flit->advance_stage(SA_, curTick());
117  } else {
118  assert(pipe_stages > 1);
119  // Router delay is modeled by making flit wait in buffer for
120  // (pipe_stages cycles - 1) cycles before going for SA
121 
122  Cycles wait_time = pipe_stages - Cycles(1);
123  t_flit->advance_stage(SA_, m_router->clockEdge(wait_time));
124 
125  // Wakeup the router in that cycle to perform SA
126  m_router->schedule_wakeup(Cycles(wait_time));
127  }
128 
129  if (m_in_link->isReady(curTick())) {
131  }
132  }
133 }
134 
135 // Send a credit back to upstream router for this VC.
136 // Called by SwitchAllocator when the flit in this VC wins the Switch.
137 void
138 InputUnit::increment_credit(int in_vc, bool free_signal, Tick curTime)
139 {
140  DPRINTF(RubyNetwork, "Router[%d]: Sending a credit vc:%d free:%d to %s\n",
141  m_router->get_id(), in_vc, free_signal, m_credit_link->name());
142  Credit *t_credit = new Credit(in_vc, free_signal, curTime);
143  creditQueue.insert(t_credit);
145 }
146 
147 
148 uint32_t
150 {
151  uint32_t num_functional_writes = 0;
152  for (auto& virtual_channel : virtualChannels) {
153  num_functional_writes += virtual_channel.functionalWrite(pkt);
154  }
155 
156  return num_functional_writes;
157 }
158 
159 void
161 {
162  for (int j = 0; j < m_num_buffer_reads.size(); j++) {
163  m_num_buffer_reads[j] = 0;
164  m_num_buffer_writes[j] = 0;
165  }
166 }
InputUnit::m_num_buffer_reads
std::vector< double > m_num_buffer_reads
Definition: InputUnit.hh:163
Router::get_id
int get_id()
Definition: Router.hh:81
flit::increment_hops
void increment_hops()
Definition: flit.hh:72
flit
Definition: flit.hh:41
InputUnit::m_id
int m_id
Definition: InputUnit.hh:151
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
InputUnit::set_vc_active
void set_vc_active(int vc, Tick curTime)
Definition: InputUnit.hh:64
flit::advance_stage
void advance_stage(flit_stage t_stage, Tick newTime)
Definition: flit.hh:83
InputUnit.hh
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
InputUnit::m_num_buffer_writes
std::vector< double > m_num_buffer_writes
Definition: InputUnit.hh:162
flit::get_route
RouteInfo get_route()
Definition: flit.hh:58
Router::get_num_vcs
uint32_t get_num_vcs()
Definition: Router.hh:76
IDLE_
@ IDLE_
Definition: CommonTypes.hh:40
Credit
Definition: Credit.hh:45
Router::schedule_wakeup
void schedule_wakeup(Cycles time)
Definition: Router.cc:167
InputUnit::m_router
Router * m_router
Definition: InputUnit.hh:150
InputUnit::InputUnit
InputUnit(int id, PortDirection direction, Router *router)
Definition: InputUnit.cc:40
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
Router
Definition: Router.hh:56
Router::get_pipe_stages
Cycles get_pipe_stages()
Definition: Router.hh:75
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Router::getBitWidth
int getBitWidth()
Definition: Router.hh:104
Consumer
Definition: Consumer.hh:43
HEAD_
@ HEAD_
Definition: CommonTypes.hh:38
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:174
InputUnit::m_credit_link
CreditLink * m_credit_link
Definition: InputUnit.hh:155
flit::get_type
flit_type get_type()
Definition: flit.hh:60
ACTIVE_
@ ACTIVE_
Definition: CommonTypes.hh:40
InputUnit::m_vc_per_vnet
int m_vc_per_vnet
Definition: InputUnit.hh:153
Router::route_compute
int route_compute(RouteInfo route, int inport, PortDirection direction)
Definition: Router.cc:155
InputUnit::grant_outport
void grant_outport(int vc, int outport)
Definition: InputUnit.hh:70
InputUnit::m_direction
PortDirection m_direction
Definition: InputUnit.hh:152
InputUnit::increment_credit
void increment_credit(int in_vc, bool free_signal, Tick curTime)
Definition: InputUnit.cc:138
InputUnit::wakeup
void wakeup()
Definition: InputUnit.cc:70
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
flitBuffer::insert
void insert(flit *flt)
Definition: flitBuffer.hh:70
flit::get_vc
int get_vc()
Definition: flit.hh:57
Consumer::scheduleEventAbsolute
void scheduleEventAbsolute(Tick timeAbs)
Definition: Consumer.cc:40
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
InputUnit::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: InputUnit.cc:149
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Credit.hh
InputUnit::virtualChannels
std::vector< VirtualChannel > virtualChannels
Definition: InputUnit.hh:159
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
PortDirection
std::string PortDirection
Definition: Topology.hh:62
HEAD_TAIL_
@ HEAD_TAIL_
Definition: CommonTypes.hh:38
SA_
@ SA_
Definition: CommonTypes.hh:42
InputUnit::m_in_link
NetworkLink * m_in_link
Definition: InputUnit.hh:154
InputUnit::creditQueue
flitBuffer creditQueue
Definition: InputUnit.hh:156
ArmISA::id
Bitfield< 33 > id
Definition: miscregs_types.hh:247
InputUnit::resetStats
void resetStats()
Definition: InputUnit.cc:160
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
Router.hh
flit::m_width
uint32_t m_width
Definition: flit.hh:105

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17