Conversation
69d448f to
152067f
Compare
Extend the Vega page-table walker with a second page-walk cache for valid neighbouring final-level PTEs fetched in the same memory block. Keep the existing PWC for non-final walk levels and defer insertions until the walker knows whether an entry terminates the walk. Add pwc_fetch_bytes to control aligned page-table memory requests, propagate it to GPU, command-processor, and SDMA walkers, and validate that the width is a supported power-of-two multiple of a PTE. Track accesses, hits, misses, insertions, invalidations, and rejected invalid neighbours separately for the two caches.
Track Vega TLB lookup outcomes by page size and extend lookups to the large page sizes the walker can install. Probe additional page sizes during a walk and clamp page sizes used as coalescer keys so a giant mapping cannot serialize an unbounded address region. Add adaptive predictors for page size and coalescing distance, together with statistics for their decisions and outcomes. Preserve request completion and retry ordering while allowing coalescing granularity to follow observed TLB behavior.
152067f to
f319f1c
Compare
|
@Basemism : at least from the tests we've been running, we've been seemingly seeing that there is no L3 TLB in Vega20 or MI300X GPUs. Are you seeing something different? Does this patch fundamentally rely on there being an L3 TLB? I suspect the same changes work regardless of if there is an L3 TLB or not? @TomXia it would be good to get your feedback on this patch too, given that it will need to go on top of your changes. |
mattsinc
left a comment
There was a problem hiding this comment.
I started going through this @Basemism , but either my browser is totally messed up, or the spacing is not correct in your PR. If you haven't, can you please run the checkin script that fixes spacing, etc.? This is really hard to read as is...
| system.%s_tlb[%d].cpu_side_ports[0]" | ||
| % (name, index, name, index) | ||
| ) | ||
| # Give each Vega coalescer a handle to the TLB it feeds so the |
There was a problem hiding this comment.
before we integrate this into the mainline of gem5, Jason will almost definitely ask for a stblib version of this. It's fine to not worry about for today since we aren't using stdlib for the paper, but just an FYI
| system.%s_tlb[%d].cpu_side_ports[0]" | ||
| % (name, index, name, index) | ||
| ) | ||
| # Give each Vega coalescer a handle to the TLB it feeds so the |
There was a problem hiding this comment.
per my comment on the PR itself, if there is no L3 TLB we probably want to move this to the L2 TLB?
There was a problem hiding this comment.
I've already updated it for tlb l2, there may be some stale comments referencing l3. Will check
| assert(devmem); | ||
| devmem->access(read); | ||
|
|
||
| // Extract the requested 8B entry from the fetched block. |
There was a problem hiding this comment.
I'm not sure if it's just my computer, but the spacing seems off on this whole file. Did you run this through the checkin scripts to ensure the gem5 coding style was followed?
| pendingLineAddr = read->getAddr(); | ||
| pendingLineIndex = lineIndex; | ||
| for (unsigned i = 0; i < walker->pwcFetchEntries; i++) | ||
| pendingLineEntries[i] = letoh(lineData[i]); |
There was a problem hiding this comment.
especially here -- either something is wrong with GitHub showing on my browser, or the spacing inside this for loop is wrong -- it looks like there is no indentation?
There was a problem hiding this comment.
also what is letoh? Google says it's not in the C++ standard library, but I also don't see it anywhere in your patch ...
There was a problem hiding this comment.
letoh is defined in src/sim/byteswap.hh it converts little-endian PTE words to host order.
| pendingLineEntries[i] = letoh(lineData[i]); | ||
| pendingLineValid = true; | ||
|
|
||
| // Rewrite word 0 so stepWalk()'s getLE<uint64_t>() sees the |
There was a problem hiding this comment.
I'm not sure why rewriting word 0 is needed? Why does this affect the correct entry -- is this an LRU thing?
There was a problem hiding this comment.
stepWalk() expects the PTE it is processing at the start of the packet data. For a wider aligned fetch, the PTE can be anywhere within that returned block.
We save the complete block for neighbour-PWC insertion. The requested PTE is placed at the packet’s expected position.
|
|
||
| // Populate pending PWC metadata for deferred insertion in stepWalk() | ||
| Addr originalEntryAddr = | ||
| read->getAddr() + lineIndex * sizeof(uint64_t); |
There was a problem hiding this comment.
spacing definitely seems off here too
| assert(idx < walker->pwcFetchEntries); | ||
| lineIndex = idx; | ||
| DPRINTF(GPUPTWalker, "Aligned PDE2 %#lx -> %#lx lineIndex %u\n", | ||
| pde2Addr, alignedAddr, lineIndex); |
I've already update the pr to align with Vishnus changes with 2 level tlb. It now activates line coalescing at tlb_level== 2. However, it is hard-coded to level 2 and would require a rebuild for if the tlb levels changes for future and historical GPU configs. |
|
I will recheck stale comments and spacing artefacts shortly |
TomXia
left a comment
There was a problem hiding this comment.
Thanks @Basemism, I like this implementation, it is far more complete than mine. I would probably have done much the same given more time and a second shot at it.
Apart from the comments below, do you happen to have any memory performance numbers from before and after the patch? Happy to run the comparison on my side if you don't, so no worries.
TomXia
left a comment
There was a problem hiding this comment.
Thanks Basemism, I think these are functionally good to me.
Sounds good, let me know when you are done with that and I'll reapprove |
@mattsinc I think I'm done |
Thanks for the feedback, I really appreciate it. I do have some isolated performance stats, but they are fairly out of date and the workloads were not especially representative, so I’m not entirely happy with them. It would be useful to compare pre-PWC, the current PWC impl. , and this improved version. I assume you already have numbers for the first two; if you could run the same suite for this version as well, that would be great. |
(Apologies for the incoming word vomit.)
This PR improves AMD GPU page-table walking and TLB request coalescing in two related parts:
PWC changes
The page-table walker now maintains two caches:
The existing PWC continues to cache intermediate page-table entries, but does not cache final-level PTEs. Final translations are already cached by the TLB, so storing them in the original PWC would duplicate entries and consume capacity intended for intermediate walk levels.
The neighbour PWC caches valid final-level PTEs returned in the same aligned memory fetch as the requested PTE. For example, a 128-byte page-table fetch contains sixteen 8-byte PTEs. The walker consumes the requested PTE immediately and inserts the other valid leaf PTEs into the neighbour PWC for later translations.
This makes use of data already returned by the page-table memory request. Translations for nearby pages may subsequently complete from the neighbour PWC without another memory access.
The page-table fetch width is configurable through
pwc_fetch_bytes. Requests are aligned to that width, and the requested PTE is selected from the returned block. The configuration is validated to ensure that the width is a supported power-of-two multiple of the 8-byte PTE size.Insertion is deferred until the walker determines whether an entry is intermediate or final-level:
Page-table invalidations apply to both PWCs. The block-fetch and extraction behavior is implemented for both timing and functional page-table walks.
Separate statistics are provided for accesses, hits, misses, insertions, and invalidations in each PWC, along with the number of invalid neighbouring PTEs skipped.
TLB lookup changes
The TLB lookup path now checks every page size that the Vega page-table walker can install: 4 KiB, 2 MiB, 1 GiB (, and 512 though I haven't tested this path)
For each candidate page size, the virtual address is aligned to that page-size boundary before the TLB key is constructed. This allows any address within a large mapping to find the entry installed for the mapping’s base address.
Page-size prediction
Before translation completes, the coalescer must choose the address range over which requests may share a TLB lookup.
Previously, requests were initially grouped using a fixed assumed page size. If the completed translation returned a different size, the requests had to be removed and re-coalesced using the actual size. A workload that repeatedly used the other page size therefore repeated the same incorrect initial grouping for each lookup.
This PR adds a saturating predictor that chooses between 4 KiB and 2 MiB when constructing the initial coalescing group. The predictor is trained using the page size returned by completed translations.
If the prediction is incorrect, the affected requests are removed from the speculative group and re-coalesced using the actual page size. This preserves the previous fallback behavior while avoiding repeated re-coalescing when a workload exhibits stable page-size behavior.
Page sizes larger than the maximum supported coalescing granule are clamped to that granule. A 1 GiB or 512 GiB mapping therefore cannot serialize requests from the entire mapping behind a single coalescer entry.
Adaptive neighbour-PTE coalescing
Fetching adjacent leaf PTEs is most useful when nearby translation requests can share the resulting neighbour-PWC entry block.
The L3 TLB coalescer can widen a request group to cover the virtual pages represented by one pwc_fetch_bytes block. A second saturating predictor decides whether to apply this wider coalescing based on previous translation outcomes:
This is important because both a PWC hit and a page-table memory access pass through the walker, but only the memory access retrieves new neighbouring PTEs.
When speculation is incorrect, the implementation preserves request completion, retry handling, and coalescer FIFO accounting while requests are regrouped.