gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tlb_coalescer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __ARCH_AMDGPU_VEGA_TLB_COALESCER_HH__
33 #define __ARCH_AMDGPU_VEGA_TLB_COALESCER_HH__
34 
35 #include <list>
36 #include <queue>
37 #include <string>
38 #include <vector>
39 
40 #include "arch/amdgpu/vega/tlb.hh"
41 #include "base/statistics.hh"
42 #include "mem/port.hh"
43 #include "mem/request.hh"
44 #include "params/VegaTLBCoalescer.hh"
45 #include "sim/clocked_object.hh"
46 
47 namespace gem5
48 {
49 
50 class Packet;
51 class ThreadContext;
52 
61 {
62  public:
63  VegaTLBCoalescer(const VegaTLBCoalescerParams &p);
65 
66  // Number of TLB probes per cycle. Parameterizable - default 2.
68 
69  // Consider coalescing across that many ticks.
70  // Paraemterizable - default 1.
72 
73  // Each coalesced request consists of multiple packets
74  // that all fall within the same virtual page
76 
77  // disables coalescing when true
79 
80  /*
81  * This is a hash map with <tick_index> as a key.
82  * It contains a vector of coalescedReqs per <tick_index>.
83  * Requests are buffered here until they can be issued to
84  * the TLB, at which point they are copied to the
85  * issuedTranslationsTable hash map.
86  *
87  * In terms of coalescing, we coalesce requests in a given
88  * window of x cycles by using tick_index = issueTime/x as a
89  * key, where x = coalescingWindow. issueTime is the issueTime
90  * of the pkt from the ComputeUnit's perspective, but another
91  * option is to change it to curTick(), so we coalesce based
92  * on the receive time.
93  */
94  typedef std::map<Tick, std::vector<coalescedReq>> CoalescingFIFO;
95 
97 
98  /*
99  * issuedTranslationsTable: a hash_map indexed by virtual page
100  * address. Each hash_map entry has a vector of PacketPtr associated
101  * with it denoting the different packets that share an outstanding
102  * coalesced translation request for the same virtual page.
103  *
104  * The rules that determine which requests we can coalesce are
105  * specified in the canCoalesce() method.
106  */
107  typedef std::unordered_map<Addr, coalescedReq> CoalescingTable;
108 
110 
111  // number of packets the coalescer receives
113  // number packets the coalescer send to the TLB
115 
116  // Number of cycles the coalesced requests spend waiting in
117  // coalescerFIFO. For each packet the coalescer receives we take into
118  // account the number of all uncoalesced requests this pkt "represents"
120 
121  // On average how much time a request from the
122  // uncoalescedAccesses that reaches the TLB
123  // spends waiting?
126  // localqueuingCycles/uncoalescedAccesses
128  // latency of a request to be completed
130 
131  bool canCoalesce(PacketPtr pkt1, PacketPtr pkt2);
132  void updatePhysAddresses(PacketPtr pkt);
133  void regStats() override;
134 
135  class CpuSidePort : public ResponsePort
136  {
137  public:
138  CpuSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer,
139  PortID _index)
140  : ResponsePort(_name), coalescer(tlb_coalescer),
141  index(_index) { }
142 
143  protected:
145  int index;
146 
147  virtual bool recvTimingReq(PacketPtr pkt);
148  virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
149  virtual void recvFunctional(PacketPtr pkt);
150  virtual void recvRangeChange() { }
151  virtual void recvReqRetry();
152 
153  virtual void
155  {
156  fatal("recvRespRetry() is not implemented in the TLB "
157  "coalescer.\n");
158  }
159 
160  virtual AddrRangeList getAddrRanges() const;
161  };
162 
163  class MemSidePort : public RequestPort
164  {
165  public:
166  MemSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer,
167  PortID _index)
168  : RequestPort(_name), coalescer(tlb_coalescer),
169  index(_index) { }
170 
172 
173  protected:
175  int index;
176 
177  virtual bool recvTimingResp(PacketPtr pkt);
178  virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
179  virtual void recvFunctional(PacketPtr pkt);
180  virtual void recvRangeChange() { }
181  virtual void recvReqRetry();
182 
183  virtual void
185  {
186  fatal("recvRespRetry() not implemented in TLB coalescer");
187  }
188  };
189 
190  // Coalescer response ports on the cpu Side
192  // Coalescer request ports on the memory side
194 
195  Port &getPort(const std::string &if_name,
196  PortID idx=InvalidPortID) override;
197 
198  void processProbeTLBEvent();
201 
202  void processCleanupEvent();
206 
209  unsigned int numDownstream;
211  std::queue<CpuSidePort *> stalledPortsQueue;
212  // enforce uniqueness in queue
213  std::map<CpuSidePort *, CpuSidePort *> stalledPortsMap;
214 
215  unsigned int availDownstreamSlots() {
216  assert(tlb_level == 1);
217  return maxDownstream - numDownstream;
218  }
219 
220  void insertStalledPortIfNotMapped(CpuSidePort *);
221  bool mustStallCUPort(CpuSidePort *);
222 
223  bool stalledPorts() {
224  assert(tlb_level == 1);
225  return stalledPortsQueue.size() > 0;
226  }
227 
229  assert(tlb_level == 1);
230  assert(numDownstream > 0);
231  numDownstream--;
232  }
233 
235  assert(tlb_level == 1);
236  assert(maxDownstream >= numDownstream);
237  numDownstream++;
238  }
239 
240  void unstallPorts();
241 
242 
243  // this FIFO queue keeps track of the virt. page
244  // addresses that are pending cleanup
245  std::queue<Addr> cleanupQueue;
246 };
247 
248 } // namespace gem5
249 
250 #endif // __ARCH_AMDGPU_VEGA_TLB_COALESCER_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1929
gem5::VegaTLBCoalescer::mustStallCUPort
bool mustStallCUPort(CpuSidePort *)
Definition: tlb_coalescer.cc:635
gem5::VegaTLBCoalescer::regStats
void regStats() override
Callback to set stat parameters.
Definition: tlb_coalescer.cc:577
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::VegaTLBCoalescer::queuingCycles
statistics::Scalar queuingCycles
Definition: tlb_coalescer.hh:119
gem5::VegaTLBCoalescer::stalledPortsMap
std::map< CpuSidePort *, CpuSidePort * > stalledPortsMap
Definition: tlb_coalescer.hh:213
gem5::VegaTLBCoalescer::stalledPort
CpuSidePort * stalledPort
Definition: tlb_coalescer.hh:210
gem5::VegaTLBCoalescer::CpuSidePort::CpuSidePort
CpuSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer, PortID _index)
Definition: tlb_coalescer.hh:138
gem5::VegaTLBCoalescer::decrementNumDownstream
void decrementNumDownstream()
Definition: tlb_coalescer.hh:228
gem5::VegaTLBCoalescer::coalescedReq
std::vector< PacketPtr > coalescedReq
Definition: tlb_coalescer.hh:75
gem5::VegaTLBCoalescer::CoalescingFIFO
std::map< Tick, std::vector< coalescedReq > > CoalescingFIFO
Definition: tlb_coalescer.hh:94
gem5::VegaTLBCoalescer::tlb_level
int tlb_level
Definition: tlb_coalescer.hh:207
gem5::VegaTLBCoalescer::VegaTLBCoalescer
VegaTLBCoalescer(const VegaTLBCoalescerParams &p)
Definition: tlb_coalescer.cc:46
gem5::VegaTLBCoalescer::processCleanupEvent
void processCleanupEvent()
Definition: tlb_coalescer.cc:564
gem5::VegaTLBCoalescer::coalescedAccesses
statistics::Scalar coalescedAccesses
Definition: tlb_coalescer.hh:114
gem5::VegaTLBCoalescer::MemSidePort
Definition: tlb_coalescer.hh:163
gem5::VegaTLBCoalescer::issuedTranslationsTable
CoalescingTable issuedTranslationsTable
Definition: tlb_coalescer.hh:109
gem5::VegaTLBCoalescer::stalledPorts
bool stalledPorts()
Definition: tlb_coalescer.hh:223
gem5::VegaTLBCoalescer::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: tlb_coalescer.cc:75
gem5::VegaTLBCoalescer::stalledPortsQueue
std::queue< CpuSidePort * > stalledPortsQueue
Definition: tlb_coalescer.hh:211
gem5::VegaTLBCoalescer::localqueuingCycles
statistics::Scalar localqueuingCycles
Definition: tlb_coalescer.hh:124
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2538
std::vector
STL vector class.
Definition: stl.hh:37
gem5::VegaTLBCoalescer::TLBProbesPerCycle
int TLBProbesPerCycle
Definition: tlb_coalescer.hh:67
gem5::VegaTLBCoalescer::MemSidePort::index
int index
Definition: tlb_coalescer.hh:175
gem5::VegaTLBCoalescer::MemSidePort::coalescer
VegaTLBCoalescer * coalescer
Definition: tlb_coalescer.hh:174
gem5::VegaTLBCoalescer::CpuSidePort::recvRespRetry
virtual void recvRespRetry()
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
Definition: tlb_coalescer.hh:154
gem5::InvalidPortID
const PortID InvalidPortID
Definition: types.hh:246
tlb.hh
request.hh
gem5::VegaTLBCoalescer::CpuSidePort::recvRangeChange
virtual void recvRangeChange()
Definition: tlb_coalescer.hh:150
gem5::VegaTLBCoalescer::CpuSidePort::coalescer
VegaTLBCoalescer * coalescer
Definition: tlb_coalescer.hh:144
gem5::RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:118
gem5::VegaTLBCoalescer::incrementNumDownstream
void incrementNumDownstream()
Definition: tlb_coalescer.hh:234
gem5::VegaTLBCoalescer::availDownstreamSlots
unsigned int availDownstreamSlots()
Definition: tlb_coalescer.hh:215
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::VegaTLBCoalescer::disableCoalescing
bool disableCoalescing
Definition: tlb_coalescer.hh:78
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::VegaTLBCoalescer
The VegaTLBCoalescer is a ClockedObject sitting on the front side (CPUSide) of each TLB.
Definition: tlb_coalescer.hh:60
gem5::VegaTLBCoalescer::CpuSidePort::getAddrRanges
virtual AddrRangeList getAddrRanges() const
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: tlb_coalescer.cc:370
gem5::probing::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:108
statistics.hh
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::VegaTLBCoalescer::MemSidePort::MemSidePort
MemSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer, PortID _index)
Definition: tlb_coalescer.hh:166
gem5::VegaTLBCoalescer::insertStalledPortIfNotMapped
void insertStalledPortIfNotMapped(CpuSidePort *)
Definition: tlb_coalescer.cc:621
gem5::VegaTLBCoalescer::CpuSidePort::recvAtomic
virtual Tick recvAtomic(PacketPtr pkt)
Receive an atomic request packet from the peer.
Definition: tlb_coalescer.hh:148
port.hh
gem5::VegaTLBCoalescer::MemSidePort::recvFunctional
virtual void recvFunctional(PacketPtr pkt)
Definition: tlb_coalescer.cc:410
gem5::VegaTLBCoalescer::probeTLBEvent
EventFunctionWrapper probeTLBEvent
This event issues the TLB probes.
Definition: tlb_coalescer.hh:200
gem5::VegaTLBCoalescer::coalescerFIFO
CoalescingFIFO coalescerFIFO
Definition: tlb_coalescer.hh:96
gem5::VegaTLBCoalescer::CpuSidePort::recvReqRetry
virtual void recvReqRetry()
Definition: tlb_coalescer.cc:341
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::VegaTLBCoalescer::MemSidePort::retries
std::deque< PacketPtr > retries
Definition: tlb_coalescer.hh:171
gem5::VegaTLBCoalescer::MemSidePort::recvAtomic
virtual Tick recvAtomic(PacketPtr pkt)
Definition: tlb_coalescer.hh:178
gem5::VegaTLBCoalescer::canCoalesce
bool canCoalesce(PacketPtr pkt1, PacketPtr pkt2)
Definition: tlb_coalescer.cc:101
gem5::EventFunctionWrapper
Definition: eventq.hh:1136
gem5::VegaTLBCoalescer::unstallPorts
void unstallPorts()
Definition: tlb_coalescer.cc:652
gem5::ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:331
gem5::VegaTLBCoalescer::uncoalescedAccesses
statistics::Scalar uncoalescedAccesses
Definition: tlb_coalescer.hh:112
gem5::VegaTLBCoalescer::MemSidePort::recvReqRetry
virtual void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: tlb_coalescer.cc:401
gem5::VegaTLBCoalescer::MemSidePort::recvRespRetry
virtual void recvRespRetry()
Definition: tlb_coalescer.hh:184
gem5::VegaTLBCoalescer::localCycles
statistics::Scalar localCycles
Definition: tlb_coalescer.hh:125
gem5::VegaTLBCoalescer::numDownstream
unsigned int numDownstream
Definition: tlb_coalescer.hh:209
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
clocked_object.hh
std::deque
STL deque class.
Definition: stl.hh:44
gem5::VegaTLBCoalescer::cleanupQueue
std::queue< Addr > cleanupQueue
Definition: tlb_coalescer.hh:245
gem5::VegaTLBCoalescer::maxDownstream
int maxDownstream
Definition: tlb_coalescer.hh:208
gem5::VegaTLBCoalescer::~VegaTLBCoalescer
~VegaTLBCoalescer()
Definition: tlb_coalescer.hh:64
gem5::VegaTLBCoalescer::cleanupEvent
EventFunctionWrapper cleanupEvent
The cleanupEvent is scheduled after a TLBEvent triggers in order to free memory and do the required c...
Definition: tlb_coalescer.hh:205
gem5::VegaTLBCoalescer::CpuSidePort::recvFunctional
virtual void recvFunctional(PacketPtr pkt)
Receive a functional request packet from the peer.
Definition: tlb_coalescer.cc:347
gem5::VegaTLBCoalescer::CpuSidePort::index
int index
Definition: tlb_coalescer.hh:145
gem5::VegaTLBCoalescer::CpuSidePort
Definition: tlb_coalescer.hh:135
gem5::VegaTLBCoalescer::CoalescingTable
std::unordered_map< Addr, coalescedReq > CoalescingTable
Definition: tlb_coalescer.hh:107
std::list< AddrRange >
gem5::VegaTLBCoalescer::localLatency
statistics::Formula localLatency
Definition: tlb_coalescer.hh:127
gem5::VegaTLBCoalescer::latency
statistics::Formula latency
Definition: tlb_coalescer.hh:129
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::VegaTLBCoalescer::MemSidePort::recvRangeChange
virtual void recvRangeChange()
Called to receive an address range change from the peer response port.
Definition: tlb_coalescer.hh:180
gem5::VegaTLBCoalescer::cpuSidePort
std::vector< CpuSidePort * > cpuSidePort
Definition: tlb_coalescer.hh:191
gem5::VegaTLBCoalescer::MemSidePort::recvTimingResp
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Definition: tlb_coalescer.cc:382
gem5::VegaTLBCoalescer::processProbeTLBEvent
void processProbeTLBEvent()
Definition: tlb_coalescer.cc:428
gem5::Named::_name
const std::string _name
Definition: named.hh:41
gem5::VegaTLBCoalescer::coalescingWindow
int coalescingWindow
Definition: tlb_coalescer.hh:71
gem5::VegaTLBCoalescer::CpuSidePort::recvTimingReq
virtual bool recvTimingReq(PacketPtr pkt)
Receive a timing request from the peer.
Definition: tlb_coalescer.cc:242
gem5::VegaTLBCoalescer::updatePhysAddresses
void updatePhysAddresses(PacketPtr pkt)
Definition: tlb_coalescer.cc:146
gem5::VegaTLBCoalescer::memSidePort
std::vector< MemSidePort * > memSidePort
Definition: tlb_coalescer.hh:193

Generated on Sun Jul 30 2023 01:56:33 for gem5 by doxygen 1.8.17