gem5  v21.1.0.2
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 namespace gem5
39 {
40 
41 namespace ruby
42 {
43 
44 namespace garnet
45 {
46 
47 InputUnit::InputUnit(int id, PortDirection direction, Router *router)
48  : Consumer(router), m_router(router), m_id(id), m_direction(direction),
49  m_vc_per_vnet(m_router->get_vc_per_vnet())
50 {
51  const int m_num_vcs = m_router->get_num_vcs();
52  m_num_buffer_reads.resize(m_num_vcs/m_vc_per_vnet);
53  m_num_buffer_writes.resize(m_num_vcs/m_vc_per_vnet);
54  for (int i = 0; i < m_num_buffer_reads.size(); i++) {
55  m_num_buffer_reads[i] = 0;
57  }
58 
59  // Instantiating the virtual channels
60  virtualChannels.reserve(m_num_vcs);
61  for (int i=0; i < m_num_vcs; i++) {
62  virtualChannels.emplace_back();
63  }
64 }
65 
66 /*
67  * The InputUnit wakeup function reads the input flit from its input link.
68  * Each flit arrives with an input VC.
69  * For HEAD/HEAD_TAIL flits, performs route computation,
70  * and updates route in the input VC.
71  * The flit is buffered for (m_latency - 1) cycles in the input VC
72  * and marked as valid for SwitchAllocation starting that cycle.
73  *
74  */
75 
76 void
78 {
79  flit *t_flit;
80  if (m_in_link->isReady(curTick())) {
81 
82  t_flit = m_in_link->consumeLink();
83  DPRINTF(RubyNetwork, "Router[%d] Consuming:%s Width: %d Flit:%s\n",
85  m_router->getBitWidth(), *t_flit);
86  assert(t_flit->m_width == m_router->getBitWidth());
87  int vc = t_flit->get_vc();
88  t_flit->increment_hops(); // for stats
89 
90  if ((t_flit->get_type() == HEAD_) ||
91  (t_flit->get_type() == HEAD_TAIL_)) {
92 
93  assert(virtualChannels[vc].get_state() == IDLE_);
94  set_vc_active(vc, curTick());
95 
96  // Route computation for this vc
97  int outport = m_router->route_compute(t_flit->get_route(),
98  m_id, m_direction);
99 
100  // Update output port in VC
101  // All flits in this packet will use this output port
102  // The output port field in the flit is updated after it wins SA
103  grant_outport(vc, outport);
104 
105  } else {
106  assert(virtualChannels[vc].get_state() == ACTIVE_);
107  }
108 
109 
110  // Buffer the flit
111  virtualChannels[vc].insertFlit(t_flit);
112 
113  int vnet = vc/m_vc_per_vnet;
114  // number of writes same as reads
115  // any flit that is written will be read only once
116  m_num_buffer_writes[vnet]++;
117  m_num_buffer_reads[vnet]++;
118 
119  Cycles pipe_stages = m_router->get_pipe_stages();
120  if (pipe_stages == 1) {
121  // 1-cycle router
122  // Flit goes for SA directly
123  t_flit->advance_stage(SA_, curTick());
124  } else {
125  assert(pipe_stages > 1);
126  // Router delay is modeled by making flit wait in buffer for
127  // (pipe_stages cycles - 1) cycles before going for SA
128 
129  Cycles wait_time = pipe_stages - Cycles(1);
130  t_flit->advance_stage(SA_, m_router->clockEdge(wait_time));
131 
132  // Wakeup the router in that cycle to perform SA
133  m_router->schedule_wakeup(Cycles(wait_time));
134  }
135 
136  if (m_in_link->isReady(curTick())) {
138  }
139  }
140 }
141 
142 // Send a credit back to upstream router for this VC.
143 // Called by SwitchAllocator when the flit in this VC wins the Switch.
144 void
145 InputUnit::increment_credit(int in_vc, bool free_signal, Tick curTime)
146 {
147  DPRINTF(RubyNetwork, "Router[%d]: Sending a credit vc:%d free:%d to %s\n",
148  m_router->get_id(), in_vc, free_signal, m_credit_link->name());
149  Credit *t_credit = new Credit(in_vc, free_signal, curTime);
150  creditQueue.insert(t_credit);
152 }
153 
154 
155 uint32_t
157 {
158  uint32_t num_functional_writes = 0;
159  for (auto& virtual_channel : virtualChannels) {
160  num_functional_writes += virtual_channel.functionalWrite(pkt);
161  }
162 
163  return num_functional_writes;
164 }
165 
166 void
168 {
169  for (int j = 0; j < m_num_buffer_reads.size(); j++) {
170  m_num_buffer_reads[j] = 0;
171  m_num_buffer_writes[j] = 0;
172  }
173 }
174 
175 } // namespace garnet
176 } // namespace ruby
177 } // namespace gem5
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::ruby::garnet::InputUnit::resetStats
void resetStats()
Definition: InputUnit.cc:167
gem5::ruby::garnet::flit
Definition: flit.hh:50
gem5::ruby::garnet::InputUnit::grant_outport
void grant_outport(int vc, int outport)
Definition: InputUnit.hh:79
gem5::ruby::garnet::InputUnit::increment_credit
void increment_credit(int in_vc, bool free_signal, Tick curTime)
Definition: InputUnit.cc:145
gem5::ruby::PortDirection
std::string PortDirection
Definition: Topology.hh:68
gem5::ruby::garnet::HEAD_TAIL_
@ HEAD_TAIL_
Definition: CommonTypes.hh:47
gem5::ruby::garnet::Router::getBitWidth
int getBitWidth()
Definition: Router.hh:114
gem5::ruby::garnet::Credit
Definition: Credit.hh:54
gem5::ruby::garnet::SA_
@ SA_
Definition: CommonTypes.hh:51
gem5::ruby::garnet::flit::increment_hops
void increment_hops()
Definition: flit.hh:81
InputUnit.hh
gem5::ruby::garnet::Router
Definition: Router.hh:66
gem5::ruby::garnet::InputUnit::m_router
Router * m_router
Definition: InputUnit.hh:159
gem5::ruby::Consumer
Definition: Consumer.hh:61
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::ruby::garnet::Router::get_num_vcs
uint32_t get_num_vcs()
Definition: Router.hh:86
gem5::ruby::garnet::InputUnit::m_credit_link
CreditLink * m_credit_link
Definition: InputUnit.hh:164
gem5::ruby::garnet::InputUnit::set_vc_active
void set_vc_active(int vc, Tick curTime)
Definition: InputUnit.hh:73
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::ArmISA::j
Bitfield< 24 > j
Definition: misc_types.hh:57
gem5::ruby::garnet::flit::get_vc
int get_vc()
Definition: flit.hh:66
gem5::ruby::garnet::flit::get_route
RouteInfo get_route()
Definition: flit.hh:67
gem5::ruby::garnet::HEAD_
@ HEAD_
Definition: CommonTypes.hh:47
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::ruby::garnet::InputUnit::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: InputUnit.cc:156
gem5::ruby::garnet::InputUnit::virtualChannels
std::vector< VirtualChannel > virtualChannels
Definition: InputUnit.hh:168
gem5::ruby::garnet::flitBuffer::insert
void insert(flit *flt)
Definition: flitBuffer.hh:78
gem5::ruby::garnet::IDLE_
@ IDLE_
Definition: CommonTypes.hh:49
gem5::ruby::garnet::InputUnit::InputUnit
InputUnit(int id, PortDirection direction, Router *router)
Definition: InputUnit.cc:47
gem5::ruby::garnet::InputUnit::creditQueue
flitBuffer creditQueue
Definition: InputUnit.hh:165
gem5::ruby::garnet::InputUnit::m_num_buffer_reads
std::vector< double > m_num_buffer_reads
Definition: InputUnit.hh:172
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::flit::advance_stage
void advance_stage(flit_stage t_stage, Tick newTime)
Definition: flit.hh:92
gem5::ruby::garnet::InputUnit::m_direction
PortDirection m_direction
Definition: InputUnit.hh:161
Credit.hh
gem5::ruby::garnet::InputUnit::m_in_link
NetworkLink * m_in_link
Definition: InputUnit.hh:163
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:250
gem5::ruby::garnet::Router::schedule_wakeup
void schedule_wakeup(Cycles time)
Definition: Router.cc:174
gem5::ruby::garnet::flit::get_type
flit_type get_type()
Definition: flit.hh:69
gem5::ruby::garnet::ACTIVE_
@ ACTIVE_
Definition: CommonTypes.hh:49
gem5::ruby::garnet::Router::get_id
int get_id()
Definition: Router.hh:91
gem5::ruby::garnet::InputUnit::wakeup
void wakeup()
Definition: InputUnit.cc:77
gem5::ruby::garnet::InputUnit::m_num_buffer_writes
std::vector< double > m_num_buffer_writes
Definition: InputUnit.hh:171
gem5::ruby::garnet::InputUnit::m_vc_per_vnet
int m_vc_per_vnet
Definition: InputUnit.hh:162
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ruby::garnet::flit::m_width
uint32_t m_width
Definition: flit.hh:114
gem5::ruby::garnet::Router::get_pipe_stages
Cycles get_pipe_stages()
Definition: Router.hh:85
gem5::ruby::Consumer::scheduleEventAbsolute
void scheduleEventAbsolute(Tick timeAbs)
Definition: Consumer.cc:63
Router.hh
gem5::ruby::garnet::InputUnit::m_id
int m_id
Definition: InputUnit.hh:160

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