Repository navigation
feat(libSceAmpr): add From*OnCompletion measure helpers - #12061
Conversation
Progress report (d13b3d7 → 0f21aac)📈 System libraries: 48.77% (+0.01%, +3 implemented functions) ✅ 3 implemented
Changed libraries (implemented exports)
|
MarcZX10
left a comment
There was a problem hiding this comment.
I built the exact PR head on Linux (Release) and ran guest_ampr_tests and guest_json_tests under qemu-x86_64 -cpu Haswell; both exited 0. python3 tools/check_conventions.py --base refs/remotes/upstream/main also passes. Native execution is blocked on this host because its Xeon lacks the AVX2/BMI/LZCNT features the test runner requires.
I found a concrete mismatch in the three new AMPR measurement helpers. The PR description says each returns 0x20, matching the Kyty reference, but all three implementations return sizeof(Apr::WriteAddressFromCounterCommand). In this tree that structure is 24 bytes (CommandHeader 8 + address 8 + two 32-bit counters), and I called each built export directly: valid inputs returned 0x18, not 0x20. The cited reference at pinned Kyty commit 0685bffb2f060bf470aa8528a405ebbe17130076 returns the constant 0x20 for all three functions: https://github.com/KytyPS5/KytyPS5/blob/0685bffb2f060bf470aa8528a405ebbe17130076/src/libs/libAmpr.cpp#L1652-L1670
Please resolve the size discrepancy before merge: either implement and test the reported 0x20 result, or provide target-specific evidence that the unversioned helpers should return 0x18 and correct the PR's claim that the behavior matches Kyty. Please add focused assertions for these three new exports; the current AMPR tests cover the _04_00 siblings but not these symbols. I have not approved this head.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Verified —
Focused assertions added in One caveat worth stating: if firmware disasm ever shows the real From* records are 0x20, the fix spans the write paths, the executor and the |
MarcZX10
left a comment
There was a problem hiding this comment.
Follow-up review of exact head 6d7182b3f66b55e5935f58a010a41a421694462f; this resolves my prior measurement-helper concern. The body now distinguishes Kyty’s padded 0x20 slot from this tree’s 24-byte command record: the writer stores sizeof(command) in the record header, the APR executor reads the same WriteAddressFromCounterCommand layout, and the existing _04_00 measurement siblings return that layout size. The new assertions cover all three helpers plus null and odd-pair rejection. Console behavior is still unmeasured, so I am relying on this explicit in-tree contract rather than claiming a PS5 measurement.\n\nI built guest_ampr_tests and guest_json_tests from this exact head and ran both under qemu-x86_64 -cpu Haswell; both exited 0. Exact-head conventions and git diff --check pass. Hosted Windows is still pending; native execution here cannot run on the host Xeon because of its missing AVX2/BMI/LZCNT features.
|
@akkadbakkad89 Thanks. The three Ampr measure helpers read right: their names and NIDs are in aerolib, and their arguments and checks match the |
MarcZX10
left a comment
There was a problem hiding this comment.
The Ampr portion has a coherent in-tree basis: the record is 0x18 bytes, the matching _04_00 helpers return that size, and the reported focused tests cover valid and invalid inputs. The Json2 portion cannot stay in this PR, though. Open #10378 already replaces the same C2/D2 stubs with C1/D1 forwarders and removes the corresponding debt entries. I fetched both exact heads and confirmed the pairwise merge conflicts in Export.cpp, InventoryExports.cpp, and docs/dev/debt/libSceJson2.md; this also combines two unrelated topics. Please drop the Json2 changes and keep the Ampr helpers as the single topic, then rerun the required checks. I am changing my review because this overlap was identified after my earlier approval.
6d7182b to
0f21aac
Compare
|
Done — the branch is now Ampr-only ( For the record on the Ampr overlap the bot also flagged: #11936 declares the same three helpers. Whichever lands first, the other rebases to a no-op — the signatures and NIDs are identical, and both follow the
|
MarcZX10
left a comment
There was a problem hiding this comment.
The AMPR implementation itself now has a clear in-tree contract and focused assertions, and the earlier unrelated Json2 overlap has been removed. One integration issue remains: open #11936 declares the same three exports as throwing placeholders. The exact branches merge textually, but combining them leaves duplicate/conflicting declarations and two definitions for each export; accepting both as-is is not safe. Please coordinate with #11936's author and record which PR supersedes the other, or an explicit landing order/rebase that results in exactly one declaration and one implementation. The current checklist still says Depends on: none and the overlap comment's 'either rebases to a no-op' needs a concrete resolution before merge.
|
|
||
| std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWriteAddressOnCompletion() { return sizeof(Apr::WriteAddressCommand); } | ||
| std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWriteCounterOnCompletion() { return sizeof(Apr::WriteCounterCommand); } | ||
|
|
There was a problem hiding this comment.
#11936 is still open and adds throwing definitions for these exact three exports. A clean textual merge is not enough here: combining it with this implementation leaves duplicate definitions and conflicting declarations. Please coordinate which PR supersedes the other and update/close the duplicate stub work accordingly, or document a safe landing order and rebase so only one definition remains.
|
@MarcZX10 Coordination posted on #11936's thread: #11936 (comment) — proposing this PR lands first since it implements the three helpers (verified Checklist updated to |
|
@MarcZX10 resolved on the coordination front: @kyon-eth closed #11936 today ("closing this redundant stub batch in favor of that implementation"), so the throwing-definition duplicate no longer exists — this PR is now the only carrier of the three |
|
Windows run of this head (
AI-assisted: yes (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The exact-head AMPR implementation follows the existing 0x18-byte command-record contract, its focused tests pass under QEMU, and the former overlap with #11936 is resolved because that PR is closed.
What I ran
PR head 0f21aac195687ffe257906ec021926d789d19f20; current base main b433c40f2f46aa2e59e19806010a839ac8572d64. The merge preview is clean (tree 8893520a96689b4efe3766efd994b38b3bde31e4). Linux x86_64, GCC 12.2.0, Release; native CPU is Intel Xeon E5-1620 v2. QEMU user-mode emulation used the Haswell CPU model for execution.
cmake --build build-review --target guest_ampr_tests guest_ampr_threads_tests guest_ampr_cpp_error_tests --parallel 4
ctest --test-dir build-review -R '^guest_ampr_markers$' -V
qemu-x86_64 -cpu Haswell -L / build-review/tests/guest_ampr_tests
qemu-x86_64 -cpu Haswell,-pcid,-x2apic,-tsc-deadline,-hle,-invpcid,-rtm -L / build-review/tests/guest_ampr_threads_tests
qemu-x86_64 -cpu Haswell -L / build-review/tests/guest_ampr_cpp_error_tests
git diff --check refs/remotes/upstream/main...refs/review/pr-12061
python3 tools/check_conventions.py --base refs/remotes/upstream/main --head refs/review/pr-12061 --title 'feat(libSceAmpr): add From*OnCompletion measure helpers' --body /tmp/pr-12061-body.md
git merge-tree --write-tree refs/remotes/upstream/main refs/review/pr-12061
python3 tools/pr_overlap.py --base main --branch refs/review/pr-12061 --repo boykopovar/AnyPS5 --jobs 8Results
| Check | Result |
|---|---|
| Focused build | Pass; guest_ampr_tests, guest_ampr_threads_tests, and guest_ampr_cpp_error_tests built |
| Native CTest | Could not execute on this host: the project CPU guard requires LZCNT, BMI1/2, MOVBE, AVX2, and FMA, which this Xeon lacks |
| Focused tests under QEMU | All three executables returned exit code 0; the AMPR marker tests exercise the new valid/null/odd-counter cases |
| Diff and conventions | Pass; conventions report All conventions checks passed. |
| Merge preview | Clean against current main |
| Overlap | The full scan found an uncomparable shared Export.cpp in #7081; manual diff shows only three CRT forwarding renames, unrelated to these exports. Search found no other open PR for the three new AMPR exports. #11936 is closed. |
| Hosted checks on exact head | Windows, conventions, labels, eligibility, and report pass; Linux and specialized jobs are skipped |
Raw command output
cmake --build completed with:
[105/197] Building CXX object core/libs/prx/libSceAmpr/CMakeFiles/libSceAmpr.dir/Export.cpp.o
[108/197] Building CXX object core/libs/prx/libSceAmpr/CMakeFiles/guest_ampr_tests.dir/__/__/tests/GuestAmpr.cpp.o
[196/197] Linking CXX shared library core/libs/libs/unpatched/libSceAmpr.prx
[197/197] Linking CXX executable tests/guest_ampr_tests
Native CTest output:
Internal ctest changing into directory: /dev/shm/AnyPS5-review-12149-local/build-review
UpdateCTestConfiguration from :/dev/shm/AnyPS5-review-12149-local/build-review/DartConfiguration.tcl
UpdateCTestConfiguration from :/dev/shm/AnyPS5-review-12149-local/build-review/DartConfiguration.tcl
Test project /dev/shm/AnyPS5-review-12149-local/build-review
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1612
Start 1612: guest_ampr_markers
1612: Test command: /dev/shm/AnyPS5-review-12149-local/build-review/tests/guest_ampr_tests
1612: Working Directory: /dev/shm/AnyPS5-review-12149-local/build-review/core/libs/prx/libSceAmpr
1612: Test timeout computed to be: 10000000
1612: [src/HostCpu.cpp:193 operator()] host CPU Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz: has SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, POPCNT, CMPXCHG16B, LAHF/SAHF, AVX, F16C, AES, PCLMULQDQ, RDRAND, XSAVEOPT, OS AVX state (XCR0); lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA, RDSEED, ADX, SHA, CLFLUSHOPT, CLWB, RDPID, XSAVEC, SSE4A, PREFETCHW, CLZERO
1612: [libc] unhandled exception 'St13runtime_error' thrown from 0x7fb2c629861d
1612: terminate called after throwing an instance of 'std::runtime_error'
1612: what(): The host CPU (Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz) lacks LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA. The PS5's Zen 2 CPU has these extensions and titles run their instructions natively, so this CPU cannot run them.
Errors while running CTest
Output from these tests are in: /dev/shm/AnyPS5-review-12149-local/build-review/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
1/1 Test #1612: guest_ampr_markers ...............Subprocess aborted***Exception: 0.02 sec
0 tests passed, 1 tests failed out of 1
Total Test time (real) = 0.23 sec
The following tests FAILED:
1612 - guest_ampr_markers (Subprocess aborted)
The three QEMU executions returned exit code 0. The guest_ampr_cpp_error_tests output ended with:
guest _Throw_Cpp_error system_error, generic category and range: PASS
Convention output:
All conventions checks passed.
git diff --check produced no output and returned 0. The merge command printed:
8893520a96689b4efe3766efd994b38b3bde31e4
GitHub check runs are all attached to exact head 0f21aac195687ffe257906ec021926d789d19f20:
conventions success
labels success
windows success
eligibility success
report success
linux skipped
register-context skipped
relinker skipped
relinker-asan skipped
write-watch skipped
The overlap scan reported only:
| [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libSceAmpr/Export.cpp` |
Negative control
| Assertion | Change made to code under test | Did the test fail? |
|---|---|---|
| New measurement sizes and invalid-argument cases | No mutation applied | Not exercised |
Findings
Blocking
None found in the reviewed diff.
Non-blocking
The PR explicitly does not claim console measurement. The 0x18 return size is supported by this tree's command header/record layout and matching _04_00 measurement helpers; the current tests establish the in-tree contract, not PS5 behavior.
Sources
- PR head: AMPR implementation
- PR head: public API declarations
- PR head: focused AMPR tests
- PR head: APR command record definitions
- Reviewed base commit
- Closed overlapping stub PR #11936
Not verified
Native execution on a supported CPU and the Windows run in the PR description were not independently reproduced. Linux hosted product CI is skipped. Console behavior remains unmeasured as stated by the author.
To get this to a good state
No change is needed for this review. If the head changes, I will rerun the same build, focused tests, convention, diff, merge-preview, and overlap checks against the new SHA.
|
Checked the three |
What
Cross-checked KytyPS5 (
src/libs/, ~1,554 registered exports) against this tree's export table by resolving every NID against the full aerolib database. Almost every apparent gap was already covered under a different naming form, module grouping, or mangled C++ spelling. This PR takes the residue that is portable 1:1 — no Kyty code is copied; the convention already lives here and only needed three more exports.libSceAmpr — three missing measure helpers.
sceAmprMeasureCommandSizeWriteAddressFromTimeCounterOnCompletion,sceAmprMeasureCommandSizeWriteAddressFromCounterOnCompletionandsceAmprMeasureCommandSizeWriteAddressFromCounterPairOnCompletionare real firmware exports (aerolib) whoseCommandBufferWrite*siblings already exist. They mirror the_04_00measure convention exactly:ValidWriteAddressargument checks andsizeof(Apr::WriteAddressFromCounterCommand)= 0x18 on success,MeasureInvalidon failure — 0x18 becauseAppendCommandstampsheader.bytes = sizeof(command)and the kernel APR executor_reads that exact struct for these opcodes. (Kyty's flat 0x20 is a padded slot size; itsWriteCounterOnCompletionappends a 0x20 no-op, not a record.)GuestAmpr.cppgains focused assertions for all three: valid arguments return the record size, nullptr returnsMeasureInvalid, and the pair helper rejects an odd counter.Tested
Windows 11 (MinGW build, i7-10700):
ctest -R guest_ampr—guest_ampr_markers,guest_ampr_threads,guest_ampr_cpp_errorall pass (3/3). Conventions check clean.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)