gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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 <set>
38#include <string>
39#include <vector>
40
42#include "base/statistics.hh"
43#include "mem/port.hh"
44#include "mem/request.hh"
45#include "params/VegaTLBCoalescer.hh"
46#include "sim/clocked_object.hh"
47
48namespace gem5
49{
50
51class Packet;
52class ThreadContext;
53
62{
63 public:
64 VegaTLBCoalescer(const VegaTLBCoalescerParams &p);
66
67 // Number of TLB probes per cycle. Parameterizable - default 2.
69
70 // Consider coalescing across that many ticks.
71 // Paraemterizable - default 1.
73
74 // Each coalesced request consists of multiple packets
75 // that all fall within the same virtual page
77
78 // disables coalescing when true
80
81 /*
82 * This is a hash map with <tick_index> as a key.
83 * It contains a vector of coalescedReqs per <tick_index>.
84 * Requests are buffered here until they can be issued to
85 * the TLB, at which point they are copied to the
86 * issuedTranslationsTable hash map.
87 *
88 * In terms of coalescing, we coalesce requests in a given
89 * window of x cycles by using tick_index = issueTime/x as a
90 * key, where x = coalescingWindow. issueTime is the issueTime
91 * of the pkt from the ComputeUnit's perspective, but another
92 * option is to change it to curTick(), so we coalesce based
93 * on the receive time.
94 *
95 * pair.second represents the assume page size.
96 */
97 typedef std::map<Tick, std::vector<std::pair<coalescedReq, Addr> > >
99
101
102 /*
103 * issuedTranslationsTable: a hash_map indexed by virtual page
104 * address. Each hash_map entry has a vector of PacketPtr associated
105 * with it denoting the different packets that share an outstanding
106 * coalesced translation request for the same virtual page.
107 *
108 * The rules that determine which requests we can coalesce are
109 * specified in the canCoalesce() method.
110 */
111 typedef std::unordered_map<Addr, coalescedReq> CoalescingTable;
112
114
115 // number of packets the coalescer receives
117 // number packets the coalescer send to the TLB
119
120 // Number of cycles the coalesced requests spend waiting in
121 // coalescerFIFO. For each packet the coalescer receives we take into
122 // account the number of all uncoalesced requests this pkt "represents"
124
125 // On average how much time a request from the
126 // uncoalescedAccesses that reaches the TLB
127 // spends waiting?
130 // localqueuingCycles/uncoalescedAccesses
132 // latency of a request to be completed
134
135 bool canCoalesce(PacketPtr pkt1, PacketPtr pkt2, Addr pagebytes);
137 void regStats() override;
138
140 {
141 public:
142 CpuSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer,
143 PortID _index)
144 : ResponsePort(_name), coalescer(tlb_coalescer),
145 index(_index) { }
146
147 protected:
149 int index;
150
151 virtual bool recvTimingReq(PacketPtr pkt);
152 virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
153 virtual void recvFunctional(PacketPtr pkt);
154 virtual void recvRangeChange() { }
155 virtual void recvReqRetry();
156
157 virtual void
159 {
160 fatal("recvRespRetry() is not implemented in the TLB "
161 "coalescer.\n");
162 }
163
164 virtual AddrRangeList getAddrRanges() const;
165 };
166
168 {
169 public:
170 MemSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer,
171 PortID _index)
172 : RequestPort(_name), coalescer(tlb_coalescer),
173 index(_index) { }
174
176
177 protected:
179 int index;
180
181 virtual bool recvTimingResp(PacketPtr pkt);
182 virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
183 virtual void recvFunctional(PacketPtr pkt);
184 virtual void recvRangeChange() { }
185 virtual void recvReqRetry();
186
187 virtual void
189 {
190 fatal("recvRespRetry() not implemented in TLB coalescer");
191 }
192 };
193
194 // Coalescer response ports on the cpu Side
196 // Coalescer request ports on the memory side
198
199 Port &getPort(const std::string &if_name,
200 PortID idx=InvalidPortID) override;
201
205
206 void processCleanupEvent();
210
212
213 Addr default_pgSize = 1ULL << 21;
214 std::set<Addr> potentialPagesize;
215
218 unsigned int numDownstream;
220 std::queue<CpuSidePort *> stalledPortsQueue;
221 // enforce uniqueness in queue
222 std::map<CpuSidePort *, CpuSidePort *> stalledPortsMap;
223
224 unsigned int availDownstreamSlots() {
225 assert(tlb_level == 1);
227 }
228
229 void insertStalledPortIfNotMapped(CpuSidePort *);
230 bool mustStallCUPort(CpuSidePort *);
231
233 assert(tlb_level == 1);
234 return stalledPortsQueue.size() > 0;
235 }
236
238 assert(tlb_level == 1);
239 assert(numDownstream > 0);
241 }
242
244 assert(tlb_level == 1);
245 assert(maxDownstream >= numDownstream);
247 }
248
249 void unstallPorts();
250
251
252 // this FIFO queue keeps track of the virt. page
253 // addresses that are pending cleanup
254 std::queue<Addr> cleanupQueue;
255};
256
257} // namespace gem5
258
259#endif // __ARCH_AMDGPU_VEGA_TLB_COALESCER_HH__
ClockedObject(const ClockedObjectParams &p)
const std::string _name
Definition named.hh:54
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Ports are used to interface objects to each other.
Definition port.hh:62
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:125
ResponsePort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Response port.
Definition port.cc:218
ThreadContext is the external interface to all thread state for anything outside of the CPU.
CpuSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer, PortID _index)
virtual Tick recvAtomic(PacketPtr pkt)
Receive an atomic request packet from the peer.
virtual AddrRangeList getAddrRanges() const
Get a list of the non-overlapping address ranges the owner is responsible for.
virtual void recvFunctional(PacketPtr pkt)
Receive a functional request packet from the peer.
virtual void recvRespRetry()
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
virtual bool recvTimingReq(PacketPtr pkt)
Receive a timing request from the peer.
virtual void recvRangeChange()
Called to receive an address range change from the peer response port.
virtual void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
virtual void recvFunctional(PacketPtr pkt)
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
MemSidePort(const std::string &_name, VegaTLBCoalescer *tlb_coalescer, PortID _index)
virtual Tick recvAtomic(PacketPtr pkt)
statistics::Scalar localqueuingCycles
statistics::Scalar coalescedAccesses
CoalescingTable issuedTranslationsTable
void updatePhysAddresses(PacketPtr pkt)
statistics::Scalar queuingCycles
EventFunctionWrapper cleanupEvent
The cleanupEvent is scheduled after a TLBEvent triggers in order to free memory and do the required c...
std::queue< CpuSidePort * > stalledPortsQueue
bool canCoalesce(PacketPtr pkt1, PacketPtr pkt2, Addr pagebytes)
std::set< Addr > potentialPagesize
statistics::Scalar uncoalescedAccesses
std::vector< PacketPtr > coalescedReq
std::map< Tick, std::vector< std::pair< coalescedReq, Addr > > > CoalescingFIFO
void reissue_pkt_helper(PacketPtr pkt)
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
std::vector< CpuSidePort * > cpuSidePort
std::vector< MemSidePort * > memSidePort
EventFunctionWrapper probeTLBEvent
This event issues the TLB probes.
VegaTLBCoalescer(const VegaTLBCoalescerParams &p)
void insertStalledPortIfNotMapped(CpuSidePort *)
CoalescingFIFO coalescerFIFO
std::unordered_map< Addr, coalescedReq > CoalescingTable
std::map< CpuSidePort *, CpuSidePort * > stalledPortsMap
void regStats() override
Callback to set stat parameters.
statistics::Formula localLatency
unsigned int availDownstreamSlots()
std::queue< Addr > cleanupQueue
bool mustStallCUPort(CpuSidePort *)
statistics::Scalar localCycles
statistics::Formula latency
A formula for statistics that is calculated when printed.
This is a simple scalar statistic, like a counter.
STL deque class.
Definition stl.hh:44
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:232
Port Object Declaration.
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
Packet * PacketPtr
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.

Generated on Mon Oct 27 2025 04:12:54 for gem5 by doxygen 1.14.0