gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 InputUnit::InputUnit(int id, PortDirection direction, Router *router)
39  : Consumer(router), m_router(router), m_id(id), m_direction(direction),
40  m_vc_per_vnet(m_router->get_vc_per_vnet())
41 {
42  const int m_num_vcs = m_router->get_num_vcs();
43  m_num_buffer_reads.resize(m_num_vcs/m_vc_per_vnet);
44  m_num_buffer_writes.resize(m_num_vcs/m_vc_per_vnet);
45  for (int i = 0; i < m_num_buffer_reads.size(); i++) {
46  m_num_buffer_reads[i] = 0;
48  }
49 
50  // Instantiating the virtual channels
51  virtualChannels.reserve(m_num_vcs);
52  for (int i=0; i < m_num_vcs; i++) {
53  virtualChannels.emplace_back();
54  }
55 }
56 
57 /*
58  * The InputUnit wakeup function reads the input flit from its input link.
59  * Each flit arrives with an input VC.
60  * For HEAD/HEAD_TAIL flits, performs route computation,
61  * and updates route in the input VC.
62  * The flit is buffered for (m_latency - 1) cycles in the input VC
63  * and marked as valid for SwitchAllocation starting that cycle.
64  *
65  */
66 
67 void
69 {
70  flit *t_flit;
71  if (m_in_link->isReady(curTick())) {
72 
73  t_flit = m_in_link->consumeLink();
74  DPRINTF(RubyNetwork, "Router[%d] Consuming:%s Width: %d Flit:%s\n",
76  m_router->getBitWidth(), *t_flit);
77  assert(t_flit->m_width == m_router->getBitWidth());
78  int vc = t_flit->get_vc();
79  t_flit->increment_hops(); // for stats
80 
81  if ((t_flit->get_type() == HEAD_) ||
82  (t_flit->get_type() == HEAD_TAIL_)) {
83 
84  assert(virtualChannels[vc].get_state() == IDLE_);
85  set_vc_active(vc, curTick());
86 
87  // Route computation for this vc
88  int outport = m_router->route_compute(t_flit->get_route(),
89  m_id, m_direction);
90 
91  // Update output port in VC
92  // All flits in this packet will use this output port
93  // The output port field in the flit is updated after it wins SA
94  grant_outport(vc, outport);
95 
96  } else {
97  assert(virtualChannels[vc].get_state() == ACTIVE_);
98  }
99 
100 
101  // Buffer the flit
102  virtualChannels[vc].insertFlit(t_flit);
103 
104  int vnet = vc/m_vc_per_vnet;
105  // number of writes same as reads
106  // any flit that is written will be read only once
107  m_num_buffer_writes[vnet]++;
108  m_num_buffer_reads[vnet]++;
109 
110  Cycles pipe_stages = m_router->get_pipe_stages();
111  if (pipe_stages == 1) {
112  // 1-cycle router
113  // Flit goes for SA directly
114  t_flit->advance_stage(SA_, curTick());
115  } else {
116  assert(pipe_stages > 1);
117  // Router delay is modeled by making flit wait in buffer for
118  // (pipe_stages cycles - 1) cycles before going for SA
119 
120  Cycles wait_time = pipe_stages - Cycles(1);
121  t_flit->advance_stage(SA_, m_router->clockEdge(wait_time));
122 
123  // Wakeup the router in that cycle to perform SA
124  m_router->schedule_wakeup(Cycles(wait_time));
125  }
126 
127  if (m_in_link->isReady(curTick())) {
129  }
130  }
131 }
132 
133 // Send a credit back to upstream router for this VC.
134 // Called by SwitchAllocator when the flit in this VC wins the Switch.
135 void
136 InputUnit::increment_credit(int in_vc, bool free_signal, Tick curTime)
137 {
138  DPRINTF(RubyNetwork, "Router[%d]: Sending a credit vc:%d free:%d to %s\n",
139  m_router->get_id(), in_vc, free_signal, m_credit_link->name());
140  Credit *t_credit = new Credit(in_vc, free_signal, curTime);
141  creditQueue.insert(t_credit);
143 }
144 
145 
146 uint32_t
148 {
149  uint32_t num_functional_writes = 0;
150  for (auto& virtual_channel : virtualChannels) {
151  num_functional_writes += virtual_channel.functionalWrite(pkt);
152  }
153 
154  return num_functional_writes;
155 }
156 
157 void
159 {
160  for (int j = 0; j < m_num_buffer_reads.size(); j++) {
161  m_num_buffer_reads[j] = 0;
162  m_num_buffer_writes[j] = 0;
163  }
164 }
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:59
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:165
InputUnit::m_router
Router * m_router
Definition: InputUnit.hh:150
InputUnit::InputUnit
InputUnit(int id, PortDirection direction, Router *router)
Definition: InputUnit.cc:38
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:237
Router::getBitWidth
int getBitWidth()
Definition: Router.hh:104
Consumer
Definition: Consumer.hh:55
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:153
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:136
InputUnit::wakeup
void wakeup()
Definition: InputUnit.cc:68
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
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:57
InputUnit::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: InputUnit.cc:147
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
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:79
PortDirection
std::string PortDirection
Definition: Topology.hh:62
HEAD_TAIL_
@ HEAD_TAIL_
Definition: CommonTypes.hh:38
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
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:158
Router.hh
flit::m_width
uint32_t m_width
Definition: flit.hh:105

Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17