apple-bce: fix scheduling while atomic and playback timestamp#50
Open
Vakarux12 wants to merge 2 commits into
Open
apple-bce: fix scheduling while atomic and playback timestamp#50Vakarux12 wants to merge 2 commits into
Vakarux12 wants to merge 2 commits into
Conversation
Two fixes to the bundled apple-bce driver, syncing with upstream t2linux/apple-bce-drv: 1. audio/pcm: skip period_elapsed for streams that are not started The T2 chip sends timestamp events for all devices continuously. Calling snd_pcm_period_elapsed() on a stopped stream causes the ALSA state machine to call aaudio_pcm_trigger(STOP), which blocks on wait_for_completion_timeout(). On PREEMPT(full) kernels the BCE DMA IRQ handler runs with BHs disabled, so this triggers: BUG: scheduling while atomic Fix: return early when stream->started == 0. 2. audio/pcm: use os_timestamp for PLAYBACK in aaudio_handle_timestamp PLAYBACK was using dev_timestamp (T2 clock domain) while CAPTURE correctly used os_timestamp. After module re-probe the T2 clock can drift, causing wild PCM positions and XRUNs. Use os_timestamp for both streams.
aaudio_cmd_stop_io blocks waiting for a T2 reply. When called from PCM trigger(STOP) it can block PipeWire's main thread while the RT data thread holds a PI mutex the main thread needs, causing a deadlock. It can also be called from atomic context (BCE DMA BH handler) causing scheduling-while-atomic. Always defer via schedule_work. In trigger(START) use cancel_work_sync to cancel any pending stop before starting without blocking callers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Syncs the bundled apple-bce driver with fixes from t2linux/apple-bce-drv#31.
Fix 1: skip period_elapsed for streams that are not started
Symptom: Connecting speakers or headphones to the 3.5mm jack causes
BUG: scheduling while atomicinirq/bce_dma, followed by a flood ofaaudio_pcm_pointer while not startedmessages. System becomes unresponsive for audio.Cause: The T2 chip sends timestamp events for all registered audio devices continuously, even when no ALSA stream is open.
aaudio_handle_stream_timestamp()was unconditionally callingsnd_pcm_period_elapsed(), which on a stopped stream chains intosnd_pcm_do_stop→aaudio_pcm_trigger(STOP)→wait_for_completion_timeout(). The BCE DMA IRQ handler runs with BHs disabled, so any attempt to sleep triggers the bug.Fix: Return early when
stream->started == 0, matching the guard already inaaudio_pcm_pointer().Fix 2: use os_timestamp for PLAYBACK
Cause:
aaudio_handle_timestamp()was passingdev_timestamp(T2 clock domain) to the PLAYBACK substream while CAPTURE correctly usedos_timestamp. After suspend/resume or module re-probe the T2 clock drifts, causing wild PCM positions and XRUNs.Fix: Use
os_timestampfor both PLAYBACK and CAPTURE.Tested
MacBookPro16,1, kernel 7.0.12-arch1-Watanare-T2-1-t2, PREEMPT(full). Before: connecting speakers crashed audio. After: clean kernel log, audio works on both speakers and headphones.