perf(libkernel): read a loaded image's unwind tables once in sceKernelGetModuleInfoFromAddr #3514

Merged
gookie-dev merged 1 commit from upstream-pr/3514 into main 2026-10-11 21:29:38 +00:00
gookie-dev commented 2026-10-11 12:06:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gookie-dev on 2026-10-11T12:06:34Z.


What

sceKernelGetModuleInfoFromAddr found the size of the image's .eh_frame on every call by walking all of its CIE/FDE records (EhFrame::FramesSize), checking each against every PT_LOAD header. The guest libc's unwinder calls it for each frame it unwinds, so a title that unwinds often walks its whole .eh_frame hundreds of times per second.

The tables read from a .eh_frame_hdr are now kept per header address and reused while the image stays loaded. The cache is dropped whenever dl_iterate_phdr reports that an object was unloaded (dlpi_subs), so an address reused by another image is read again. Linux path only; Windows reads .ehmeta and is unchanged.

Tested

Ubuntu 24.04, GCC 13.3, Release.

  • guest_module_info now queries a module twice and expects the same tables, then unloads it, loads it again and expects tables of the same size at the same offset in the new image. guest_unwind_module_info and guest_unwind_module_info_failure pass.
  • PPSA16827 (Harmony's Odyssey), relinked with --to-intel, title screen, 10 s CPU sampling: 9269 samples before, 53.7% of them in this walk (FindImage<ModuleInfoEx>); 3306 after, 3.2% in the lookup. Over 500 calls per second, counted under gdb (which slows the title).
  • The title still runs at 27 FPS on this machine; its frame rate is limited elsewhere. It also does not react to controller input on its title screen yet (separate issue, not addressed here).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818924668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3514). Originally posted by [gookie-dev](https://github.com/gookie-dev) on 2026-10-11T12:06:34Z. --- ### What `sceKernelGetModuleInfoFromAddr` found the size of the image's `.eh_frame` on every call by walking all of its CIE/FDE records (`EhFrame::FramesSize`), checking each against every `PT_LOAD` header. The guest libc's unwinder calls it for each frame it unwinds, so a title that unwinds often walks its whole `.eh_frame` hundreds of times per second. The tables read from a `.eh_frame_hdr` are now kept per header address and reused while the image stays loaded. The cache is dropped whenever `dl_iterate_phdr` reports that an object was unloaded (`dlpi_subs`), so an address reused by another image is read again. Linux path only; Windows reads `.ehmeta` and is unchanged. ### Tested Ubuntu 24.04, GCC 13.3, Release. - `guest_module_info` now queries a module twice and expects the same tables, then unloads it, loads it again and expects tables of the same size at the same offset in the new image. `guest_unwind_module_info` and `guest_unwind_module_info_failure` pass. - PPSA16827 (Harmony's Odyssey), relinked with `--to-intel`, title screen, 10 s CPU sampling: 9269 samples before, 53.7% of them in this walk (`FindImage<ModuleInfoEx>`); 3306 after, 3.2% in the lookup. Over 500 calls per second, counted under gdb (which slows the title). - The title still runs at 27 FPS on this machine; its frame rate is limited elsewhere. It also does not react to controller input on its title screen yet (separate issue, not addressed here). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-11 13:16:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:16:25Z.


The current conventions and relinker failures are all from checkout, before the PR code runs: the failed run checked merge commit 2220effbe42c850d7f8df56dbac52e3cdea54009 and reports No url found for submodule path '3rdparty/imgui' in .gitmodules. Current main (a11c8f7f70a0ed4e71504a89de69e8cdae687817) no longer has that orphan gitlink, so this run is stale relative to the fixed base. Please rebase or trigger a fresh run against current main before treating those failures as PR-specific.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109422009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3514#issuecomment-6109422009). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T13:16:25Z. --- The current conventions and relinker failures are all from checkout, before the PR code runs: the failed run checked merge commit `2220effbe42c850d7f8df56dbac52e3cdea54009` and reports `No url found for submodule path '3rdparty/imgui' in .gitmodules`. Current `main` (`a11c8f7f70a0ed4e71504a89de69e8cdae687817`) no longer has that orphan gitlink, so this run is stale relative to the fixed base. Please rebase or trigger a fresh run against current `main` before treating those failures as PR-specific.
github-actions[bot] commented 2026-10-11 19:52:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T19:52:07Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3948 core/libs/prx/libkernel/Module/src/ModuleInfo.cpp L24-25
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113054224 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3514#issuecomment-6113054224). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T19:52:07Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3948 | `core/libs/prx/libkernel/Module/src/ModuleInfo.cpp` [L24-25](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/core/libs/prx/libkernel/Module/src/ModuleInfo.cpp#L24-L25) | | |
adriadam10 commented 2026-10-11 21:29:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:29:35Z.


Checked the diff, built it merged onto current main and ran the libs/libkernel ctest scope (112 tests, guest_module_info included) green. The cache is read and cleared under the loader lock held by dl_iterate_phdr, keyed by header address and dropped on dlpi_subs changes; Windows is untouched. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113982166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3514#issuecomment-6113982166). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:29:35Z. --- Checked the diff, built it merged onto current main and ran the libs/libkernel ctest scope (112 tests, `guest_module_info` included) green. The cache is read and cleared under the loader lock held by `dl_iterate_phdr`, keyed by header address and dropped on `dlpi_subs` changes; Windows is untouched. Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3514
No description provided.