gem5  v22.1.0.0
OutputUnit.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"
39 
40 namespace gem5
41 {
42 
43 namespace ruby
44 {
45 
46 namespace garnet
47 {
48 
49 OutputUnit::OutputUnit(int id, PortDirection direction, Router *router,
50  uint32_t consumerVcs)
51  : Consumer(router), m_router(router), m_id(id), m_direction(direction),
52  m_vc_per_vnet(consumerVcs)
53 {
54  const int m_num_vcs = consumerVcs * m_router->get_num_vnets();
55  outVcState.reserve(m_num_vcs);
56  for (int i = 0; i < m_num_vcs; i++) {
57  outVcState.emplace_back(i, m_router->get_net_ptr(), consumerVcs);
58  }
59 }
60 
61 void
63 {
64  DPRINTF(RubyNetwork, "Router %d OutputUnit %s decrementing credit:%d for "
65  "outvc %d at time: %lld for %s\n", m_router->get_id(),
67  outVcState[out_vc].get_credit_count(),
68  out_vc, m_router->curCycle(), m_credit_link->name());
69 
70  outVcState[out_vc].decrement_credit();
71 }
72 
73 void
75 {
76  DPRINTF(RubyNetwork, "Router %d OutputUnit %s incrementing credit:%d for "
77  "outvc %d at time: %lld from:%s\n", m_router->get_id(),
79  outVcState[out_vc].get_credit_count(),
80  out_vc, m_router->curCycle(), m_credit_link->name());
81 
82  outVcState[out_vc].increment_credit();
83 }
84 
85 // Check if the output VC (i.e., input VC at next router)
86 // has free credits (i..e, buffer slots).
87 // This is tracked by OutVcState
88 bool
90 {
91  assert(outVcState[out_vc].isInState(ACTIVE_, curTick()));
92  return outVcState[out_vc].has_credit();
93 }
94 
95 
96 // Check if the output port (i.e., input port at next router) has free VCs.
97 bool
99 {
100  int vc_base = vnet*m_vc_per_vnet;
101  for (int vc = vc_base; vc < vc_base + m_vc_per_vnet; vc++) {
102  if (is_vc_idle(vc, curTick()))
103  return true;
104  }
105 
106  return false;
107 }
108 
109 // Assign a free output VC to the winner of Switch Allocation
110 int
112 {
113  int vc_base = vnet*m_vc_per_vnet;
114  for (int vc = vc_base; vc < vc_base + m_vc_per_vnet; vc++) {
115  if (is_vc_idle(vc, curTick())) {
116  outVcState[vc].setState(ACTIVE_, curTick());
117  return vc;
118  }
119  }
120 
121  return -1;
122 }
123 
124 /*
125  * The wakeup function of the OutputUnit reads the credit signal from the
126  * downstream router for the output VC (i.e., input VC at downstream router).
127  * It increments the credit count in the appropriate output VC state.
128  * If the credit carries is_free_signal as true,
129  * the output VC is marked IDLE.
130  */
131 
132 void
134 {
135  if (m_credit_link->isReady(curTick())) {
136  Credit *t_credit = (Credit*) m_credit_link->consumeLink();
137  increment_credit(t_credit->get_vc());
138 
139  if (t_credit->is_free_signal())
140  set_vc_state(IDLE_, t_credit->get_vc(), curTick());
141 
142  delete t_credit;
143 
144  if (m_credit_link->isReady(curTick())) {
145  scheduleEvent(Cycles(1));
146  }
147  }
148 }
149 
150 flitBuffer*
152 {
153  return &outBuffer;
154 }
155 
156 void
158 {
159  m_out_link = link;
160 }
161 
162 void
164 {
165  m_credit_link = credit_link;
166 }
167 
168 void
170 {
171  outBuffer.insert(t_flit);
173 }
174 
175 bool
177 {
178  return outBuffer.functionalRead(pkt, mask);
179 }
180 
181 uint32_t
183 {
184  return outBuffer.functionalWrite(pkt);
185 }
186 
187 } // namespace garnet
188 } // namespace ruby
189 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
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...
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
void scheduleEventAbsolute(Tick timeAbs)
Definition: Consumer.cc:63
void scheduleEvent(Cycles timeDelta)
Definition: Consumer.cc:56
void increment_credit(int out_vc)
Definition: OutputUnit.cc:74
void set_out_link(NetworkLink *link)
Definition: OutputUnit.cc:157
void decrement_credit(int out_vc)
Definition: OutputUnit.cc:62
uint32_t functionalWrite(Packet *pkt)
Definition: OutputUnit.cc:182
bool has_credit(int out_vc)
Definition: OutputUnit.cc:89
void set_vc_state(VC_state_type state, int vc, Tick curTime)
Definition: OutputUnit.hh:88
bool functionalRead(Packet *pkt, WriteMask &mask)
Definition: OutputUnit.cc:176
std::vector< OutVcState > outVcState
Definition: OutputUnit.hh:121
void insert_flit(flit *t_flit)
Definition: OutputUnit.cc:169
bool is_vc_idle(int vc, Tick curTime)
Definition: OutputUnit.hh:94
void set_credit_link(CreditLink *credit_link)
Definition: OutputUnit.cc:163
PortDirection get_direction()
Definition: OutputUnit.hh:73
OutputUnit(int id, PortDirection direction, Router *router, uint32_t consumerVcs)
Definition: OutputUnit.cc:49
uint32_t get_num_vnets()
Definition: Router.hh:87
std::string getPortDirectionName(PortDirection direction)
Definition: Router.cc:181
GarnetNetwork * get_net_ptr()
Definition: Router.hh:98
bool functionalRead(Packet *pkt, WriteMask &mask)
Definition: flitBuffer.cc:89
uint32_t functionalWrite(Packet *pkt)
Definition: flitBuffer.cc:102
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 33 > id
Definition: misc_types.hh:257
std::string PortDirection
Definition: TypeDefines.hh:44
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46

Generated on Wed Dec 21 2022 10:22:38 for gem5 by doxygen 1.9.1