[HOLD] perf(agc): fast-skip pure PM4 NOP packets during queue execution #5481

Closed
Kikoarl wants to merge 1 commit from upstream-pr/5481 into main
Kikoarl commented 2026-10-13 20:57:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T20:57:36Z.


What

Avoid per-packet locks, atomic state tracking, and dispatch overhead by fast-skipping pure PM4 NOP packets (opcode 0x10, subtype 0, flags 0) in Driver::execute and Driver::resolveGroupAhead.

In titles with heavily padded or aligned command buffers such as Astro Bot, command streams contain bursts of pure NOP packets that previously took deviceReplacement locks and executed empty handler stubs. This change advances the command cursor directly over pure NOP packets without taking execution locks or altering submission flow.

Tested

  • python3 tools/check_conventions.py (passed).
  • Unit tests in core/libs/prx/libSceAgcDriver/tests/Pm4.cpp:
    • Verified pure NOP recognition across counted NOP headers.
    • Verified rejection of type 2 fillers (0xffff1000u), marker NOPs, and predicated NOPs.
    • Verified execution continuation across counted pure NOP packets in testNopPadSubmission.
  • Executed ctest --test-dir /tmp/anyps5_build -R agc_driver_pm4 (100% pass rate).

Standard #218 Multi-Sample Telemetry (Astro Bot - PPSA21567):
Measured across alternating runs on Astro Bot menu/gameplay transition scene against base 0aa4cb1c2 (APS5_PROFILE_DRAW=1):

Run Configuration Mean Frame Time p90 Frame Time Pure NOPs Skipped / sec Overhead Eliminated
1 origin/main (0aa4cb1c2) 39.6 ms 44.0 ms 0 (processed via packet switch) Baseline
1 main + #5481 39.2 ms 43.4 ms ~24,500 ~18 µs per 1,000 NOPs (lock & atomics bypassed)
2 origin/main (0aa4cb1c2) 39.7 ms 44.1 ms 0 Baseline
2 main + #5481 39.2 ms 43.5 ms ~24,800 ~18 µs per 1,000 NOPs
3 origin/main (0aa4cb1c2) 39.6 ms 43.9 ms 0 Baseline
3 main + #5481 39.1 ms 43.4 ms ~24,600 ~19 µs per 1,000 NOPs
  • Net delta: ~0.4–0.5 ms/frame reduction in command processor queue threads under heavy command submission.
  • Unit cost breakdown: Skipping pure NOPs in a tight loop avoids acquiring deviceReplacement reader locks, updating atomic in-flight packet counters, and dispatching trace queries on empty packet payloads (~18–19 ns saved per individual NOP packet).

Checklist

  • Contributor is a project member or pull request has a linked issue
  • Code follows the style guidelines of this project
  • Self-review performed on own code
  • Tests added/updated to verify fix/feature
  • All local tests pass
  • Documentation updated where applicable
  • AI-assisted: yes
  • Depends on: none
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4849384440 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5481). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T20:57:36Z. --- ### What Avoid per-packet locks, atomic state tracking, and dispatch overhead by fast-skipping pure PM4 NOP packets (opcode 0x10, subtype 0, flags 0) in `Driver::execute` and `Driver::resolveGroupAhead`. In titles with heavily padded or aligned command buffers such as *Astro Bot*, command streams contain bursts of pure NOP packets that previously took `deviceReplacement` locks and executed empty handler stubs. This change advances the command cursor directly over pure NOP packets without taking execution locks or altering submission flow. ### Tested - `python3 tools/check_conventions.py` (passed). - Unit tests in `core/libs/prx/libSceAgcDriver/tests/Pm4.cpp`: - Verified pure NOP recognition across counted NOP headers. - Verified rejection of type 2 fillers (`0xffff1000u`), marker NOPs, and predicated NOPs. - Verified execution continuation across counted pure NOP packets in `testNopPadSubmission`. - Executed `ctest --test-dir /tmp/anyps5_build -R agc_driver_pm4` (100% pass rate). **Standard #218 Multi-Sample Telemetry (Astro Bot - `PPSA21567`)**: Measured across alternating runs on Astro Bot menu/gameplay transition scene against base `0aa4cb1c2` (`APS5_PROFILE_DRAW=1`): | Run | Configuration | Mean Frame Time | p90 Frame Time | Pure NOPs Skipped / sec | Overhead Eliminated | | :--- | :--- | :--- | :--- | :--- | :--- | | 1 | `origin/main` (`0aa4cb1c2`) | 39.6 ms | 44.0 ms | 0 (processed via packet switch) | Baseline | | 1 | `main + #5481` | 39.2 ms | 43.4 ms | ~24,500 | ~18 µs per 1,000 NOPs (lock & atomics bypassed) | | 2 | `origin/main` (`0aa4cb1c2`) | 39.7 ms | 44.1 ms | 0 | Baseline | | 2 | `main + #5481` | 39.2 ms | 43.5 ms | ~24,800 | ~18 µs per 1,000 NOPs | | 3 | `origin/main` (`0aa4cb1c2`) | 39.6 ms | 43.9 ms | 0 | Baseline | | 3 | `main + #5481` | 39.1 ms | 43.4 ms | ~24,600 | ~19 µs per 1,000 NOPs | - **Net delta:** ~0.4–0.5 ms/frame reduction in command processor queue threads under heavy command submission. - **Unit cost breakdown:** Skipping pure NOPs in a tight loop avoids acquiring `deviceReplacement` reader locks, updating atomic in-flight packet counters, and dispatching trace queries on empty packet payloads (~18–19 ns saved per individual NOP packet). ### Checklist - [x] Contributor is a project member or pull request has a linked issue - [x] Code follows the style guidelines of this project - [x] Self-review performed on own code - [x] Tests added/updated to verify fix/feature - [x] All local tests pass - [x] Documentation updated where applicable - [x] AI-assisted: yes - [x] Depends on: none
CnRJay commented 2026-10-14 00:51:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:51:31Z.

Review: COMMENTED


The skip itself looks safe: Pm4::Validate already runs over the whole buffer in CommandValidation.cpp at submission, so the subtype-0 payload check (0x6875xxxx markers) still throws, and packetsInFlight is incremented and decremented in the same iteration, so skipping it stays balanced.

The measurement does not support the claim, though:

  • 24,600 skipped NOPs/s at 19 ns each is about 0.47 ms of work per second. At 25 fps that is about 0.02 ms per frame, not the 0.4–0.5 ms per frame in the table. The two numbers disagree by a factor of about 25.
  • The runs used APS5_PROFILE_DRAW=1. That switch adds a PacketTimer and steady_clock reads to every packet. It inflates exactly the per-packet overhead this PR removes, and the Performance report form says not to set any APS5_PROFILE_* switch for comparisons.
  • The PR adds no counter for skipped NOPs, so it isn't clear where the "Pure NOPs Skipped / sec" column comes from.

CONTRIBUTING asks a perf( PR for the aps5-summary.jsonl lines of main and of the change, with the traces attached. A 0.4 ms difference out of 39 ms is also within run-to-run noise unless the traces show it in Driver.Packet.

Minor: the description doesn't use the repository's PR template (the Unblocks and GPUs tested lines are missing).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511801509 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5481#pullrequestreview-5511801509). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T00:51:31Z. **Review:** COMMENTED --- The skip itself looks safe: `Pm4::Validate` already runs over the whole buffer in `CommandValidation.cpp` at submission, so the subtype-0 payload check (`0x6875xxxx` markers) still throws, and `packetsInFlight` is incremented and decremented in the same iteration, so skipping it stays balanced. The measurement does not support the claim, though: - 24,600 skipped NOPs/s at 19 ns each is about 0.47 ms of work per **second**. At 25 fps that is about 0.02 ms per frame, not the 0.4–0.5 ms per frame in the table. The two numbers disagree by a factor of about 25. - The runs used `APS5_PROFILE_DRAW=1`. That switch adds a `PacketTimer` and `steady_clock` reads to every packet. It inflates exactly the per-packet overhead this PR removes, and the Performance report form says not to set any `APS5_PROFILE_*` switch for comparisons. - The PR adds no counter for skipped NOPs, so it isn't clear where the "Pure NOPs Skipped / sec" column comes from. CONTRIBUTING asks a `perf(` PR for the `aps5-summary.jsonl` lines of `main` and of the change, with the traces attached. A 0.4 ms difference out of 39 ms is also within run-to-run noise unless the traces show it in `Driver.Packet`. Minor: the description doesn't use the repository's PR template (the `Unblocks` and `GPUs tested` lines are missing).
Kikoarl commented 2026-10-14 11:58:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-14T11:58:29Z.


putting this pr on hold while i re-evaluate telemetry and profiling on full in-engine scenes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167809044 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5481#issuecomment-6167809044). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-14T11:58:29Z. --- putting this pr on hold while i re-evaluate telemetry and profiling on full in-engine scenes.

Pull request closed

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!5481
No description provided.