feat(libSceAmpr): answer sceAmprAmmGetUsageStatsData #4207

Merged
xXPBSXx merged 1 commit from upstream-pr/4207 into main 2026-10-12 20:57:05 +00:00
xXPBSXx commented 2026-10-12 01:24:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T01:24:07Z.


What

sceAmprAmmGetUsageStatsData (PPSA30601, Resonance, stops there after #4101; see #4067) currently throws as a stub declared by #3814. This PR implements it: a null pointer, or a size_in_bytes larger than 0x18, returns SCE_KERNEL_ERROR_EINVAL; otherwise the caller-sized prefix of a 24-byte structure is written (size_in_bytes, num_page_table_pool_entries, snapshot allocated entries, high watermark, a reserved u16, ring_idle_flags).

Origin of the layout and values (no console measurement):

  • Layout and the size check: KytyPS5 libAmpr.cpp (AmmUsageStatsData, AmmGetUsageStatsData); the same layout is in iStark/PS5PCEM (likely derived from it, so not independent).
  • The layout therefore comes from KytyPS5 only; iStark/PS5PCEM is probably derived from it. If a reviewer prefers it, throwing (the previous behaviour) is the alternative until a measured source exists.
  • The values 512 pool entries and idle flags 0x7 are KytyPS5's constants; allocated entries and watermark are 0 (nothing is counted). They are not measured anywhere I could find (neither console nor an independent source) and are listed in TechnicalDebt.
  • drakmor/ampr_emu shows that on a console the call passes through to sceKernelMapperGetUsageStatsData (no layout there); this port has no kernel-side counterpart.

Tested

  • Windows, MinGW GCC, Release: guest_ampr_markers and guest_ampr_threads pass with the new TestAmmUsageStats (null, oversize, full structure, partial 8-byte and zero-size writes); the test aborts without the change because the stub throws. tools/check_conventions.py --base upstream/main passes.
  • Not tested on a console. PPSA30601 was last run before this change (it stopped here); it is not re-run with this change.

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: #3814 (declares the stub; the diff here includes its commits until it is merged)
  • AI-assisted: yes (Claude Code)

AI-assisted (Claude Code).
🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823832957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T01:24:07Z. --- ### What `sceAmprAmmGetUsageStatsData` (PPSA30601, Resonance, stops there after #4101; see #4067) currently throws as a stub declared by #3814. This PR implements it: a null pointer, or a `size_in_bytes` larger than 0x18, returns `SCE_KERNEL_ERROR_EINVAL`; otherwise the caller-sized prefix of a 24-byte structure is written (`size_in_bytes`, `num_page_table_pool_entries`, `snapshot allocated entries`, `high watermark`, a reserved `u16`, `ring_idle_flags`). Origin of the layout and values (no console measurement): - Layout and the size check: [KytyPS5 `libAmpr.cpp`](https://github.com/KytyPS5/KytyPS5/blob/main/src/libs/libAmpr.cpp) (`AmmUsageStatsData`, `AmmGetUsageStatsData`); the same layout is in [iStark/PS5PCEM](https://github.com/iStark/PS5PCEM/blob/main/src/hle/libs/bootstrap_services.zig) (likely derived from it, so not independent). - The layout therefore comes from KytyPS5 only; iStark/PS5PCEM is probably derived from it. If a reviewer prefers it, throwing (the previous behaviour) is the alternative until a measured source exists. - The values 512 pool entries and idle flags `0x7` are KytyPS5's constants; allocated entries and watermark are 0 (nothing is counted). They are not measured anywhere I could find (neither console nor an independent source) and are listed in TechnicalDebt. - [drakmor/ampr_emu](https://github.com/drakmor/ampr_emu/blob/main/src/ampr_emu_amm.cpp) shows that on a console the call passes through to `sceKernelMapperGetUsageStatsData` (no layout there); this port has no kernel-side counterpart. ### Tested - Windows, MinGW GCC, Release: `guest_ampr_markers` and `guest_ampr_threads` pass with the new `TestAmmUsageStats` (null, oversize, full structure, partial 8-byte and zero-size writes); the test aborts without the change because the stub throws. `tools/check_conventions.py --base upstream/main` passes. - Not tested on a console. PPSA30601 was last run before this change (it stopped here); it is not re-run with this change. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: #3814 (declares the stub; the diff here includes its commits until it is merged) - [x] AI-assisted: yes (Claude Code) AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-12 01:24:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T01:24:26Z.


Progress report (682ef0c → 4b6f463)

📈 System libraries: 86.39% (+0.03%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceAmpr sceAmprAmmGetUsageStatsData
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116098030 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207#issuecomment-6116098030). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T01:24:26Z. --- <!-- progress-report --> ### Progress report (682ef0c → 4b6f463) 📈 **System libraries**: 86.39% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceAmpr | `sceAmprAmmGetUsageStatsData` | </details>
Dextroid17 commented 2026-10-12 03:24:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T03:24:59Z.


Supporting evidence for this one: a second title needs sceAmprAmmGetUsageStatsData, not just PPSA30601. Trails in the Sky 2nd Chapter (PPSA35169, 01.003.000) imports KqiWXLgCVe0 as well and stops on it once the libkernel pair in #4214 is recorded — measured on the relinked title: #4214 (comment). With the set of imports it is missing answered — this one among them — the title clears that wall and reaches its Vulkan device, swapchain, save data and 16 game threads (same run), so the call sits on a start-up path rather than a rare one.

Disclosure: my #4251 carried a copy of the throwing stub for this export before I saw this PR, #3814 and #4220. I have narrowed #4251 to touqMEt6qXQ = sceAmprAmmSetPageTablePoolOccupancyNotificationThreshold instead, so the implementation here is the only copy of sceAmprAmmGetUsageStatsData outside those two stubs.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117178164 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207#issuecomment-6117178164). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T03:24:59Z. --- Supporting evidence for this one: a second title needs `sceAmprAmmGetUsageStatsData`, not just PPSA30601. Trails in the Sky 2nd Chapter (PPSA35169, 01.003.000) imports `KqiWXLgCVe0` as well and stops on it once the `libkernel` pair in #4214 is recorded — measured on the relinked title: [#4214 (comment)](https://github.com/boykopovar/AnyPS5/issues/4214#issuecomment-6116449486). With the set of imports it is missing answered — this one among them — the title clears that wall and reaches its Vulkan device, swapchain, save data and 16 game threads ([same run](https://github.com/boykopovar/AnyPS5/issues/4214#issuecomment-6116547964)), so the call sits on a start-up path rather than a rare one. Disclosure: my #4251 carried a copy of the throwing stub for this export before I saw this PR, #3814 and #4220. I have narrowed #4251 to `touqMEt6qXQ` = `sceAmprAmmSetPageTablePoolOccupancyNotificationThreshold` instead, so the implementation here is the only copy of `sceAmprAmmGetUsageStatsData` outside those two stubs. Written with AI assistance.
blawesom commented 2026-10-12 15:27:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T15:27:02Z.


Rebase handoff — rebased onto current main, authorship unchanged (staleness only — the rebase applied cleanly).

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 957/957 passed

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4207
git checkout <your branch>
git merge --ff-only FETCH_HEAD
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6127324341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207#issuecomment-6127324341). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T15:27:02Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged (staleness only — the rebase applied cleanly). Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 957/957 passed** **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4207 git checkout <your branch> git merge --ff-only FETCH_HEAD ```
xXPBSXx commented 2026-10-12 17:56:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T17:56:35Z.


Thanks for the rebase and the full-suite run. I had already rebased this branch onto main 2a5eca11c before I saw your handoff (head 83f94758c), so there is nothing to pick up. Your 957/957 on Linux is a useful second platform; on Windows the same state passes guest_ampr_markers and guest_ampr_threads (2/2).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129698361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207#issuecomment-6129698361). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T17:56:35Z. --- Thanks for the rebase and the full-suite run. I had already rebased this branch onto `main` `2a5eca11c` before I saw your handoff (head `83f94758c`), so there is nothing to pick up. Your 957/957 on Linux is a useful second platform; on Windows the same state passes `guest_ampr_markers` and `guest_ampr_threads` (2/2). AI-assisted (Claude Code).
github-actions[bot] commented 2026-10-12 19:27:12 +00:00 (Migrated from github.com)

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


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
#3902 core/libs/tests/GuestAmpr.cpp L1295
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131135606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207#issuecomment-6131135606). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T19:27:12Z. --- <!-- 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 | |---|---|---|---| | #3902 | `core/libs/tests/GuestAmpr.cpp` [L1295](https://github.com/boykopovar/AnyPS5/blob/529f7bfd4aa6d54b082d6c27ccaa0c66b74aad08/core/libs/tests/GuestAmpr.cpp#L1295) | | |
adriadam10 commented 2026-10-12 20:57:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:57:00Z.


Checked the layout, size check and constants against KytyPS5 AmmGetUsageStatsData (identical), built and ran the guest_ampr_* tests on Linux (pass), and confirmed TestAmmUsageStats fails without the change. The TechnicalDebt entry is in the right section and the old stub mention in libSceJson2.md is removed; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132475373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4207#issuecomment-6132475373). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:57:00Z. --- Checked the layout, size check and constants against KytyPS5 `AmmGetUsageStatsData` (identical), built and ran the `guest_ampr_*` tests on Linux (pass), and confirmed `TestAmmUsageStats` fails without the change. The TechnicalDebt entry is in the right section and the old stub mention in `libSceJson2.md` is removed; 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!4207
No description provided.