gem5  v22.1.0.0
tlb.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_HH__
33 #define __ARCH_AMDGPU_VEGA_TLB_HH__
34 
35 #include <list>
36 #include <queue>
37 #include <string>
38 #include <vector>
39 
41 #include "arch/generic/mmu.hh"
42 #include "base/statistics.hh"
43 #include "base/trace.hh"
44 #include "mem/packet.hh"
45 #include "mem/port.hh"
46 #include "params/VegaGPUTLB.hh"
47 #include "sim/clocked_object.hh"
48 
49 namespace gem5
50 {
51 
52 class BaseMMU;
53 class Packet;
54 class AMDGPUDevice;
55 class ThreadContext;
56 
57 namespace VegaISA
58 {
59 
60 class Walker;
61 
62 class GpuTLB : public ClockedObject
63 {
64  public:
65  GpuTLB(const VegaGPUTLBParams &p);
67 
68  typedef enum BaseMMU::Mode Mode;
69 
71  {
72  public:
73  virtual ~Translation() { }
74 
79  virtual void markDelayed() = 0;
80 
86  virtual void finish(Fault fault, const RequestPtr &req,
87  Mode mode) = 0;
88 
95  virtual bool squashed() const { return false; }
96  };
97 
99  void dumpAll();
100  VegaTlbEntry *lookup(Addr va, bool update_lru=true);
101 
102  Walker *getWalker();
103  void invalidateAll();
104  void demapPage(Addr va, uint64_t asn);
105 
106  protected:
108  EntryList::iterator lookupIt(Addr va, bool update_lru=true);
111 
112  int size;
113  int assoc;
114  int numSets;
115 
119  bool FA;
121 
127 
132 
134 
135  /*
136  * It's a per-set list. As long as we have not reached
137  * the full capacity of the given set, grab an entry from
138  * the freeList.
139  */
141 
150 
151  public:
152  // latencies for a TLB hit, miss and page fault
156 
158  {
160 
163 
164  // local_stats are as seen from the TLB
165  // without taking into account coalescing
170 
171  // global_stats are as seen from the
172  // CU's perspective taking into account
173  // all coalesced requests.
178 
179  // from the CU perspective (global)
182 
183  // from the perspective of this TLB
186  } stats;
187 
188 
189  VegaTlbEntry *insert(Addr vpn, VegaTlbEntry &entry);
190 
191  // Checkpointing
192  virtual void serialize(CheckpointOut& cp) const override;
193  virtual void unserialize(CheckpointIn& cp) override;
196  VegaTlbEntry *tlbLookup(const RequestPtr &req, bool update_stats);
197 
198  void walkerResponse(VegaTlbEntry& entry, PacketPtr pkt);
200  PacketPtr pkt);
201 
203 
205  VegaTlbEntry *tlb_entry, Mode mode);
206 
207  void updatePhysAddresses(Addr virt_page_addr, VegaTlbEntry *tlb_entry,
208  Addr phys_page_addr);
209 
210  void issueTLBLookup(PacketPtr pkt);
211 
212  // CpuSidePort is the TLB Port closer to the CPU/CU side
213  class CpuSidePort : public ResponsePort
214  {
215  public:
216  CpuSidePort(const std::string &_name, GpuTLB * gpu_TLB,
217  PortID _index)
218  : ResponsePort(_name, gpu_TLB), tlb(gpu_TLB), index(_index) { }
219 
220  protected:
222  int index;
223 
224  virtual bool recvTimingReq(PacketPtr pkt);
225  virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
226  virtual void recvFunctional(PacketPtr pkt);
227  virtual void recvRangeChange() { }
228  virtual void recvReqRetry();
229  virtual void recvRespRetry() { panic("recvRespRetry called"); }
230  virtual AddrRangeList getAddrRanges() const;
231  };
232 
240  class MemSidePort : public RequestPort
241  {
242  public:
243  MemSidePort(const std::string &_name, GpuTLB * gpu_TLB,
244  PortID _index)
245  : RequestPort(_name, gpu_TLB), tlb(gpu_TLB), index(_index) { }
246 
248 
249  protected:
251  int index;
252 
253  virtual bool recvTimingResp(PacketPtr pkt);
254  virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
255  virtual void recvFunctional(PacketPtr pkt) { }
256  virtual void recvRangeChange() { }
257  virtual void recvReqRetry();
258  };
259 
260  // TLB ports on the cpu Side
262  // TLB ports on the memory side
264 
265  Port &getPort(const std::string &if_name,
266  PortID idx=InvalidPortID) override;
267 
269 
270  // maximum number of permitted coalesced requests per cycle
272 
273  // Current number of outstandings coalesced requests.
274  // Should be <= maxCoalescedReqs
276 
284  void translationReturn(Addr virtPageAddr, tlbOutcome outcome,
285  PacketPtr pkt);
286 
287  class TLBEvent : public Event
288  {
289  private:
297 
298  public:
299  TLBEvent(GpuTLB *_tlb, Addr _addr, tlbOutcome outcome,
300  PacketPtr _pkt);
301 
302  void process();
303  const char *description() const;
304 
305  // updateOutcome updates the tlbOutcome of a TLBEvent
306  void updateOutcome(tlbOutcome _outcome);
308  };
309 
310  std::unordered_map<Addr, TLBEvent*> translationReturnEvent;
311 
312  // this FIFO queue keeps track of the virt. page addresses
313  // that are pending cleanup
314  std::queue<Addr> cleanupQueue;
315 
316  // the cleanupEvent is scheduled after a TLBEvent triggers in order to
317  // free memory and do the required clean-up
318  void cleanup();
319 
321 };
322 
323 } // namespace VegaISA
324 
325 } // namespace gem5
326 
327 #endif // __ARCH_AMDGPU_VEGA_TLB_HH__
Device model for an AMD GPU.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
const std::string _name
Definition: named.hh:41
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Ports are used to interface objects to each other.
Definition: port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:79
A ResponsePort is a specialization of a port.
Definition: port.hh:270
virtual void recvRangeChange()
Definition: tlb.hh:227
virtual void recvReqRetry()
Definition: tlb.cc:884
virtual bool recvTimingReq(PacketPtr pkt)
recvTiming receives a coalesced timing request from a TLBCoalescer and it calls issueTLBLookup() It o...
Definition: tlb.cc:660
virtual void recvRespRetry()
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
Definition: tlb.hh:229
virtual AddrRangeList getAddrRanges() const
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: tlb.cc:892
CpuSidePort(const std::string &_name, GpuTLB *gpu_TLB, PortID _index)
Definition: tlb.hh:216
virtual void recvFunctional(PacketPtr pkt)
Receive a functional request packet from the peer.
Definition: tlb.cc:766
virtual Tick recvAtomic(PacketPtr pkt)
Receive an atomic request packet from the peer.
Definition: tlb.hh:225
MemSidePort is the TLB Port closer to the memory side If this is a last level TLB then this port will...
Definition: tlb.hh:241
virtual void recvFunctional(PacketPtr pkt)
Definition: tlb.hh:255
std::deque< PacketPtr > retries
Definition: tlb.hh:247
virtual Tick recvAtomic(PacketPtr pkt)
Definition: tlb.hh:254
MemSidePort(const std::string &_name, GpuTLB *gpu_TLB, PortID _index)
Definition: tlb.hh:243
virtual bool recvTimingResp(PacketPtr pkt)
MemSidePort receives the packet back.
Definition: tlb.cc:906
virtual void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: tlb.cc:925
virtual void recvRangeChange()
Called to receive an address range change from the peer response port.
Definition: tlb.hh:256
const char * description() const
Return a C string describing the event.
Definition: tlb.cc:636
void updateOutcome(tlbOutcome _outcome)
Definition: tlb.cc:642
tlbOutcome outcome
outcome can be TLB_HIT, TLB_MISS, or PAGE_WALK
Definition: tlb.hh:295
TLBEvent(GpuTLB *_tlb, Addr _addr, tlbOutcome outcome, PacketPtr _pkt)
Definition: tlb.cc:397
virtual bool squashed() const
This function is used by the page table walker to determine if it should translate the a pending requ...
Definition: tlb.hh:95
virtual void markDelayed()=0
Signal that the translation has been delayed due to a hw page table walk.
virtual void finish(Fault fault, const RequestPtr &req, Mode mode)=0
The memory for this object may be dynamically allocated, and it may be responsible for cleaning itsle...
VegaTlbEntry * lookup(Addr va, bool update_lru=true)
Definition: tlb.cc:211
EntryList::iterator lookupIt(Addr va, bool update_lru=true)
Definition: tlb.cc:181
void walkerResponse(VegaTlbEntry &entry, PacketPtr pkt)
Definition: tlb.cc:425
std::vector< CpuSidePort * > cpuSidePort
Definition: tlb.hh:261
virtual void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:295
virtual void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:300
void issueTLBLookup(PacketPtr pkt)
Do the TLB lookup for this coalesced request and schedule another event <TLB access latency> cycles l...
Definition: tlb.cc:310
VegaTlbEntry * insert(Addr vpn, VegaTlbEntry &entry)
Definition: tlb.cc:157
void translationReturn(Addr virtPageAddr, tlbOutcome outcome, PacketPtr pkt)
A TLBEvent is scheduled after the TLB lookup and helps us take the appropriate actions: (e....
Definition: tlb.cc:548
void pagingProtectionChecks(PacketPtr pkt, VegaTlbEntry *tlb_entry, Mode mode)
Do Paging protection checks.
Definition: tlb.cc:409
void handleFuncTranslationReturn(PacketPtr pkt, tlbOutcome outcome)
handleFuncTranslationReturn is called on a TLB hit, when a TLB miss returns or when a page fault retu...
Definition: tlb.cc:695
enum BaseMMU::Mode Mode
Definition: tlb.hh:68
std::unordered_map< Addr, TLBEvent * > translationReturnEvent
Definition: tlb.hh:310
std::list< VegaTlbEntry * > EntryList
Definition: tlb.hh:107
std::vector< MemSidePort * > memSidePort
Definition: tlb.hh:263
Walker * getWalker()
Definition: tlb.cc:288
std::vector< EntryList > freeList
Definition: tlb.hh:140
void invalidateAll()
Definition: tlb.cc:224
Walker * walker
Definition: tlb.hh:109
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: tlb.cc:114
AMDGPUDevice * gpuDevice
Definition: tlb.hh:110
Addr pageAlign(Addr vaddr)
Definition: tlb.cc:150
void handleTranslationReturn(Addr addr, tlbOutcome outcome, PacketPtr pkt)
handleTranslationReturn is called on a TLB hit, when a TLB miss returns or when a page fault returns.
Definition: tlb.cc:451
std::queue< Addr > cleanupQueue
Definition: tlb.hh:314
bool FA
true if this is a fully-associative TLB
Definition: tlb.hh:119
bool allocationPolicy
Allocation Policy: true if we always allocate on a hit, false otherwise.
Definition: tlb.hh:126
EventFunctionWrapper cleanupEvent
Definition: tlb.hh:320
gem5::VegaISA::GpuTLB::VegaTLBStats stats
VegaTlbEntry * tlbLookup(const RequestPtr &req, bool update_stats)
TLB_lookup will only perform a TLB lookup returning the TLB entry on a TLB hit and nullptr on a TLB m...
Definition: tlb.cc:260
std::vector< EntryList > entryList
An entryList per set is the equivalent of an LRU stack; it's used to guide replacement decisions.
Definition: tlb.hh:149
void demapPage(Addr va, uint64_t asn)
Definition: tlb.cc:238
GpuTLB(const VegaGPUTLBParams &p)
Definition: tlb.cc:52
std::vector< VegaTlbEntry > tlb
Definition: tlb.hh:133
Fault createPagefault(Addr vaddr, Mode mode)
Definition: tlb.cc:136
void updatePhysAddresses(Addr virt_page_addr, VegaTlbEntry *tlb_entry, Addr phys_page_addr)
bool hasMemSidePort
if true, then this is not the last level TLB
Definition: tlb.hh:131
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
STL deque class.
Definition: stl.hh:44
STL list class.
Definition: stl.hh:51
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Port Object Declaration.
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
Bitfield< 8 > va
Definition: misc_types.hh:282
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:109
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
const PortID InvalidPortID
Definition: types.hh:246
std::ostream CheckpointOut
Definition: serialize.hh:66
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
Declaration of the Packet class.
Declaration of Statistics objects.
statistics::Scalar outstandingReqsMax
Definition: tlb.hh:162
statistics::Scalar localNumTLBMisses
Definition: tlb.hh:168
statistics::Formula localLatency
Definition: tlb.hh:185
statistics::Formula localTLBMissRate
Definition: tlb.hh:169
statistics::Scalar localCycles
Definition: tlb.hh:184
statistics::Scalar globalNumTLBAccesses
Definition: tlb.hh:174
statistics::Scalar accessCycles
Definition: tlb.hh:180
statistics::Scalar localNumTLBAccesses
Definition: tlb.hh:166
VegaTLBStats(statistics::Group *parent)
Definition: tlb.cc:958
statistics::Formula globalTLBMissRate
Definition: tlb.hh:177
statistics::Scalar globalNumTLBMisses
Definition: tlb.hh:176
statistics::Scalar localNumTLBHits
Definition: tlb.hh:167
statistics::Scalar pageTableCycles
Definition: tlb.hh:181
statistics::Scalar globalNumTLBHits
Definition: tlb.hh:175
statistics::Scalar maxDownstreamReached
Definition: tlb.hh:161

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