fix(libSceAudioOut): return from a blocking AudioOut2 push once the queue has room #12954
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12954"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-29T16:57:34Z.
What
sceAudioOut2ContextPushwithblocking1 waited only before queueing its grain, while the queue was full. The push that fills the queue therefore returned at once, with the queue at its depth.PRAGMATA (PPSA02530) feeds the context its sound engine renders into (queue depth 4) from three threads: a ticker polls
sceAudioOut2ContextGetQueueLevel, callssceAudioOut2ContextAdvanceonce per free slot and signals a semaphore per slot; a feeder thread waits on that semaphore, callssceAudioOut2ContextPush(ctx, 1)and then sets the event flag that wakes the render thread; the render thread waits on that flag with no timeout. With the push returning as soon as the grain was queued, the fourth push left the queue full, the woken render thread found no free slot and slept, and nothing woke it until the title's next frame. Every call traced on one context (local diagnostic, not part of this PR):So the mix advanced four 21.3 ms grains per rendered frame, and at the 1-3 fps the title renders at under AnyPS5 the context took 0.5-6 pushes per second instead of 46.9. The real-time scene after the opening film follows that audio: it crawls and then stops on one frame, on one of the opening credits, for the rest of the run (in every run that got that far, from about 485 s after start on), while rendering continues and the title still takes input.
A blocking push now also waits after queueing until fewer grains than the queue depth wait to be played, with the existing 200 ms limit, so the feeder is paced by playback and wakes the renderer once per grain. A non-blocking push is unchanged. When the console's blocking push returns is not measured; the debt entry says so.
Tested
Linux (Arch, kernel 7.2.11, GCC 16.2.1, Release), on
mainbb04a4f1ea.New
TestBlockingPushWaitsForRoomWithoutADeviceincore/libs/prx/libSceAudioOut/tests/AudioOut2Timing.cpp(run byaudio_out2_timing): a blocking push that fills a context's queue must not return before the queue has room again. With onlyAudioOut2Context.cpprestored frommain,audio_out2_timingfails (Subprocess aborted).Real audio device, before and after with exact builds. Both builds are
mainbb04a4f1ea+ #10935 6076b8591c + #11580fedf3e91a7+ #784489d6a7caf7+ #6565 f2029f9ebe + #12898d2d43310ad+ #1030431f895cb59+ #10497 8a0dcd5af9 + #7446a4a99c3afc+ #67824433a62b3b(0109385f31, the open PRs PRAGMATA needs to reach that scene on currentmain), one with this PR's head1ed07de320merged on top (ea561be1f7); nothing else differs (no local diagnostics; onlylibSceAudioOut.prxchanges). Audio went through SDL's PulseAudio backend into a PipeWire null sink, and both AudioOut2 contexts opened a device (SDL device 2 opened,SDL device 3 opened). Same warmed shader cache, 1400 s each,APS5_TRACE_AUDIOOUT2=1for the per-second summary:primes)vkQueueSubmit recorder: Vulkan result -4; DISPATCH_INDIRECT on queue 0x0)Deterministic blocking/release tests on a test clock (
AudioOut2Timing.cpp): a device-less context can run its queue model onclockForTest, so playback and the 200 ms wait limit only advance when the test moves the clock.TestBlockingPushStaysBlockedUntilPlaybackFreesASlot: with the clock frozen and depth - 1 grains queued, a blocking push from another thread is observed under the context lock with its grain queued (queued == depth) but not yet counted (pushes == depth - 1), its future still pending and the level at depth. Playing one grain on the test clock returns it with 0 and the level at depth - 1.TestBlockingPushOnAFullQueueQueuesOnlyOnceASlotIsFree: with the queue filled by non-blocking pushes, a blocking push never takesqueuedpast the depth, and returns once two grains are played.main'sAudioOut2Context.cpp(bb04a4f1ea) failspushes == depth - 1; the head without the post-queue wait fails the same assertion; the head without the pre-queue wait failsqueued <= depth. On the old code, queueing and counting the push happen in one critical section, so the first assertion fails however the threads are scheduled. The head passes 3 of 3.ctest -R audio_out: 52 of 52 pass, three times in a row.main102c4f95a2merged in (56fd9eac87):AudioOut2Context.cppconflicted wheremainreplaced the handle cast with its context registry (AudioOut2FindContext); the resolution keeps the registry and this PR's test clock.ctest -R audio_out: 56 of 56, three times in a row.PRAGMATA (PPSA02530), 1000 s runs from boot through the menus into the opening film and the real-time scene after it, SDL
dummyaudio, with a local diagnostic that logs the context's pushes per second. Both builds are the same local integration build PRAGMATA needs to get there (maine61a7c7e24plus open PRs, including #6565 and #12898) and differ only in this change toAudioOut2Context.cpp:4.1 pushes/sat 400 s,0.5 pushes/sat 543 s)46.9 pushes/sfor the rest of both runs, no underruns)Under the
dummydriver only one AudioOut2 context gets a device (SDL_OpenAudioDevice failed: Audio device already open), so the engine's context runs on the device-less clock. A run with the SDLdiskdriver, where both contexts got a device, stopped at the same point without this change (6-10 pushes per second).tools/check_conventions.py --base origin/mainpasses andgit diff --checkis clean.Checklist
main; no other open PR implements the same functions (#12698 only documents theblockingvalues titles pass)NotImplemented_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)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T17:08:15Z.
Review: COMMENTED
Reviewed head
7a75ea95b3againstmainbb04a4f1ea. The merge preview is clean,git diff --checkis clean andtools/check_conventions.py --base upstream/mainpasses.What I ran
I built a standalone harness on macOS arm64 (Apple clang, ASan+UBSan). It copies
GrainDuration,Drain, the device-lessQueueLevelbranch,WaitForRoomand the blocking/non-blocking control flow ofsceAudioOut2ContextPushverbatim from this head. SDL, rendering and tracing are left out. The new test's rows run against it unchanged (depth 2, 1024-frame grains).WaitForRoom(equivalent tomain)WaitForRoomOther measurements from the same harness:
mainthey took 0 ms because the fourth push waits for the oldest grain. This is the observable change for titles that prime the queue before they start their clock. The debt line says the console behaviour is unmeasured, which is the right place for it.mainit took 200 ms. The debt line already says "each wait ends after at most 200 ms".Findings
//lines aboveTestBlockingPushWaitsForRoomWithoutADeviceare not technical-debt comments. The CI checker accepts them only because the PR also touchesdocs/dev/debt/. AGENTS.md and CONVENTIONS.md still allow only debt comments,#endifand namespace ends, so please drop these lines and keep the explanation in the PR body.WaitForRoompasses every row. If it is meant to keepmain's "wait before queueing" behaviour after a timeout, a row with a stalled queue would pin it down. Otherwise it could go, which would also bring the worst-case stall back to 200 ms. This is non-blocking.sceAudioOut2ContextPush(ctx, 1)on a fresh depth-N context (when the Nth push returns) would settle it.Not verified
I did not build the real
audio_out2_timingtarget. It needs the SDL2 submodule, which is not initialised here. I did not run the device path (device != 0,DeviceQueueLevel), Windows or a console.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T17:19:29Z.
Review: COMMENTED
Tests run and reviewed — console behavior unverified
The focused host test passes on the current head and the base-source negative control aborts, but the console’s blocking return timing remains unmeasured.
What I ran
Head
bb6d79e52e3d8ec72a604af30d0e4429b193cf66; basebb04a4f1ea0175e9e4f149f0359a764d62ff3296.git merge-treeproduced a clean preview tree (9f11fc6a2c604b83f18d0f53e115185ac6c13a9f); no merge was attempted. Environment: Debian Linux x86_64, kernel6.1.0-54-amd64, GCC 12.2.0, QEMU x86_64 Haswell.Results
audio_out2_timing_testsbuildgit diff --checkBuild output
Focused test output
Convention check output
Negative control
AudioOut2Context.cppfrom basebb04a4f1ea0175e9e4f149f0359a764d62ff3296, keeping the PR test sourceRequiredoes not print which assertion failed.Negative-control output
Findings
Blocking
None found in the focused host implementation/test review.
Non-blocking
Sources
Not verified
audio_outCTest suite; the PR body reports it, but I did not rerun it.To get this to a good state
Please confirm the combined timeout is intended and provide a console timing trace if one becomes available; I will rerun these same commands on the new head.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T17:21:15Z.
Review: COMMENTED
Re-review at
bb6d79e52e. The only change since7a75ea95b3is commitbb6d79e52e, which removes the three//lines aboveTestBlockingPushWaitsForRoomWithoutADevice. That settles my point 1. The production code (42beeaa468) and the debt line (7a75ea95b3) have not changed.What I ran
python3 tools/check_conventions.py --base upstream/main: passgit diff --check upstream/main...HEAD: cleangit merge-tree --write-tree upstream/main HEADagainstbb04a4f1ea: cleangit diff upstream/main...HEAD | grep '^+.*//': no added//linesMy harness results from the first review still apply because the code under test is unchanged: the PR rows pass, dropping the post-queue wait turns 3 rows red, and dropping the pre-queue wait survives.
Still open
WaitForRoom, or drop that wait) and point 3 (a console timing of the Nth blocking push on a fresh depth-N context).main.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T17:24:07Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The elapsed-time regression test can fail with correct code under scheduler delay and can pass with the old code, so its current negative control is not reliable.
What I ran
Head
bb6d79e52e3d8ec72a604af30d0e4429b193cf66; basebb04a4f1ea0175e9e4f149f0359a764d62ff3296. The merge preview is clean; no merge was attempted. Environment: Debian Linux x86_64, kernel6.1.0-54-amd64, GCC 12.2.0, QEMU x86_64 Haswell.Results
audio_out2_timing_testsbuildgit diff --checkFocused test output
Convention output
Negative control
AudioOut2Context.cppfrom basebb04a4f1ea0175e9e4f149f0359a764d62ff3296, leaving the PR test source in placeRequiredoes not print the failing assertion. The timing-sensitive test can still pass under a different scheduling delay.Negative-control output
Findings
Blocking
TestBlockingPushWaitsForRoomWithoutADeviceasserts that each measured push takes at least half a grain and checks queue level after return. If the test thread is descheduled between pushes, playback can drain a slot before a correct call begins, making the elapsed-time assertion fail. If it is descheduled after recordingstartbut before callingPush, that delay can satisfy the threshold on the old implementation; a pause after the old call returns can also let the queue-level check observe a drained slot. Please replace the elapsed-time oracle with a handshake and test-controlled playback clock/advance: establish a full queue, verify the push remains blocked, release one slot, and verify it then returns. Run the same test against the base implementation as a deterministic negative control.Non-blocking
ContextDestroycould race with a waiting push. I could not establish whether the API permits destroy concurrent with push; please ensure the lifetime is safe or document that restriction.Sources
Not verified
audio_outCTest suite; the PR body reports it, but I did not rerun it.To get this to a good state
Replace the timing-based test with a synchronized clock/advance test and confirm the push/context-destroy lifetime contract. I will rerun these same commands on the new head.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T17:49:02Z.
Review: COMMENTED
Re-review at
1ed07de320. The production code (42beeaa468) has not changed. Commit1ed07de320replaces the elapsed-time check inTestBlockingPushWaitsForRoomWithoutADevicewith a queue-level check after each push. It also adds one sentence to the debt line: destroying a context while a push waits on it is not supported.What I ran
python3 tools/check_conventions.py --base upstream/main: passgit diff --check upstream/main...HEAD: cleangit merge-tree --write-tree upstream/main HEADagainstbb04a4f1ea: clean. No added//lines.FULL_WAIT_*,GrainDuration,Drain, the device-lessQueueLevelbranch andWaitForRoom.Pushis reduced to pre-wait /queued++; playHead += grain/ post-wait. The four-round loop andlevel < queueDepth && available > 0match the new test (depth 2, 1024-frame grains).yes× ncpu)main)One run takes 0.07 s.
Why the new check is deterministic
Once a push returns, nothing else adds to the queue before
GetQueueLevel, andDraincan only lower the level. So correct code cannot fail because of a scheduler delay. The only way it could fail is the 200 ms timeout expiring while the queue is still full, and a 21 ms grain always drains well before that. Old code returns at level 2 in rounds 1 to 3. It could only pass if the thread were descheduled for more than one grain between the push and the poll, in all three rounds, and that never happened even with every core busy. The flake that MarcZX10 and oneandonlydean pointed out (point 1) is fixed.Still open
WaitForRoomis still not covered by a test (the mutant survives). A stalled-queue row would cover it, or that wait could be dropped.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T23:49:10Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The elapsed-time threshold is gone, but the new queue-level assertion can still pass the old behavior if the test thread is descheduled after
Pushreturns and before it reads the queue.What I ran
1f905993a3463cc9aa39460b77491bc9eb4405d7; recorded PR base:bb04a4f1ea0175e9e4f149f0359a764d62ff3296.upstream/main:1189ec3003672bb364dd9f3119ead7b3976e3c83; merge preview is clean, tree60a6cfd16dca697446a9d58dc37cc99ca499ae43.Results
git diff --checkUnedited local command output
Negative control
queueDepthWaitForRoomFindings
Blocking
TestBlockingPushWaitsForRoomWithoutADevicechecks the queue after each synchronous push, but does not control playback or observe that the full-queue push is blocked.QueueLeveladvances from the live clock; if the test thread is paused for a grain after the old implementation returns, the queue drains before the assertion and the regression is missed. Please make the playback/clock progression test-controlled (or use an equivalent handshake), assert that the full-queue push remains blocked until a slot is released, and show that the old implementation fails the same test.Non-blocking
The author records context destruction concurrent with a waiting push as unsupported; console return timing remains unmeasured. I did not find a new source-level blocker in those stated limitations.
Sources
Not verified
I did not build or run the focused test locally, run a negative control, or verify console behavior. The test and title results cited above are author-reported.
To get this to a good state
Add a controlled blocking/release test and a red control using the previous push behavior. I will rerun the same source checks and review the exact new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T01:25:39Z.
Review: COMMENTED
Re-checked — new head, test concern addressed
The test-clock changes at head
3fc5485e6c6cc0b25e27d9db9e1b7c3504f56695replace the scheduler-sensitive oracle with controlled blocking and playback checks, addressing the prior test blocker.I inspected the new test and clock-injection diff against the prior reviewed head
1f905993a3463cc9aa39460b77491bc9eb4405d7. The author reports 52/52audio_outtests passing three times and deterministic red controls for the base implementation and for removing either wait; I did not run them locally. The current-main change in the shared implementation file since the PR base is a pad-rumble call and does not touch this wait path. The hosted Windows job was still in progress when refreshed; Linux and specialized jobs are skipped. Console blocking-return timing remains unmeasured, so this is a comment-only recheck, not an approval.