Repository navigation
perf(agc): answer verifications of the caller's own live stack without a page query - #459
Merged
oneandonlydean merged 1 commit intoOct 3, 2026
Conversation
…t a page query Driver::Submit checks the title's submission packet, which the title passes on its own thread stack. Host thread stacks are neither registry mappings nor write-watched, so no page-state cache covers them and on Linux every check scans /proc/self/maps line by line: about 1.5 ms per submission on the render thread of PPSA21564 (66% of that thread's samples in perf at the title). A range between the calling thread's current frame and its stack's top holds the frames of every caller, so it is mapped readable and writable for as long as the call lasts; verify() now accepts it without a query. A thread on another stack (a fiber's, a signal stack) has its frame outside the thread's bounds and still gets the page query, as does any range that runs past the stack's top or starts below the frame. GetCurrentThreadStackLimits needs _WIN32_WINNT 0x0602 on MinGW, as libkernel already sets; GuestMemory.cpp is compiled by several targets, so the definition is a property of the source file.
oneandonlydean
force-pushed
the
perf/agc-own-stack-verify
branch
from
October 3, 2026 14:02
43f31ce to
5a81652
Compare
9 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Driver::Submitchecks the title's submission packet withGuestMemory::CheckRange, and titles pass that packet on their own thread stack. Host thread stacks are neither registry mappings nor write-watched, so no cached page table covers them, and on Linux every such check scans/proc/self/mapsline by line. In PPSA21564 that was about 1.5 ms per submission on the render thread, 66% of that thread's samples inperfat the title screen.A range between the calling thread's current frame and the top of its stack holds the frames of every caller, so it is mapped readable and writable for as long as the call lasts.
verify()now accepts such a range without a page query:pthread_getattr_np(Linux) orGetCurrentThreadStackLimits(Windows), once per thread;GetCurrentThreadStackLimitsneeds_WIN32_WINNT0x0602 on MinGW, as libkernel already sets. Several targets compileGuestMemory.cpp, so the definition is a property of that source file.#157 caches the parsed maps for these queries; if it lands, this saves less, and I will measure it again then. #157 already conflicts with
maininGuestMemory.cpp.Tested
BUILD_TESTING=ONandctestpass (145/145).RunLiveStackAccessTestsinagc_driver_graphics_tests(tests/LiveStack.cpp): a packet on the test's own stack is accessible and passesCheckRange; a thread on a stack of its own with an inaccessible page above and one at the bottom sees its stack top accessible, a range past the top and the page above it rejected (AccessibleandCheckRange), and the inaccessible page below its frames rejected. After the thread ends, that memory is reported as the page query says. The checks bound the new path: dropping the past-the-top bound fails with "a range past the stack's top counts as accessible", and starting the accepted range at the stack's bottom instead of the frame fails with "an inaccessible page of the stack below the live frames counts as accessible". Without the change the test passes too, since the answers are the same; only the cost differs.CheckRangeon the stack, in the test process (a short maps file): 12.3 us before, 0.01 us after. The title's maps file has thousands of lines (mostly driver mappings), hence the 1.5 ms above.GuestMemory.cpp,BdaTests.hppandtests/Graphics.cpp; the two merge cleanly in either order.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)