You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
garbled audio after XRUN/RESTART done with FREE_PCM+PCM_PARAMS pair #1063
stream has been previously running and then restarted (1) S3 suspend+resume, 2) application stopped with SIGSUSPEND, 3) XRUN, or 4) applications which start/stop the stream with snd_pcm_drop() + snd_pcm_prepare() + snd_pcm_start()))
With these conditions met, with PR1049 merged, streaming can be resumed, but occasionally the audio output is corrupt and the corruption persists as long as audio is played out.
To Reproduce
To simplify testing, I figured out following way to reproduce this with aplay (but this will impact a wide range of other ALSA applications):
Expected behavior
Playback should resume succesfully.
Impact
Marked is as P2 as severe artifacts can be heard. Not marking as P1 as this only happens with PR1049 merged (which again affects only uses of custom start_threshold value).
Debugged today whether the garbled audio is caused by FW processing. I made the following experiment today.
played test tones during test sequence (e.g. a sine tone and a slow 1Hz square wave)
added debug code to dai.c to calculate basic statistics out of sample data as seen by the DAI (last component in topology)
When I compare traces between success case (audio ok after start) and failures (garbled audio), the debug dumps look identical. So it would seem the audio content FW is sending to the HDA codec is fine.
Both the HDA controller and FW PCM params are completely reset in the sequence, so running out of options in this direction. Next step is to check our actions towards the codec.
@kv2019i What does exactly setting start threshold mean for FW? What is the default value?
Also do you have FW logs from the above scenario? ctrl-Z + fg is pause/release or stop/start?
changed the title [-]garbled audio after XRUN/RESTART w/ aplay and low start threshold[/-][+]garbled audio after XRUN/RESTART done with FREE_PCM+PCM_PARAMS pair[/+]on Jun 28, 2019
@kv2019i What does exactly setting start threshold mean for FW? What is the default value?
I actually updated the bug description just now. The start-threshold setting affects #1062 , but not this bug. So once I fix #1062 by reseting DMA at stream restart (PR1049), then I start getting garbled audio and this affects more use-cases.
Start_threshold is an ALSA parameter to control when the PCM DMA trigger start is sent and HW should start consuming samples from DDR. By default it is set to be equal to buffer size. So with typical applications, they fill the whole DDR DMA buffer with audio data and only when buffer is completely filled, DMA trigger start will be sent. This is ok for simple playback (like aplay), but of course creates quite a long latency to playback. Alternative way to trigger playback is to set "start_threshold" to a low value (so that DMA is triggered when X% of the buffer is filled), or by an explicit start command from the application. Many applications that need precise control over output latency will choose to explicitly start the PCM stream (prefil few tens of milleseconds of audio and then start).
Also do you have FW logs from the above scenario? ctrl-Z + fg is pause/release or stop/start?
Attached is one log with the aplay sequence. Audio is fine on first run but gets garbled after stream is restarted. I can see nothing wrong in the long, but yet audio is bad on ~4/10 of cases. The main problem seems to be going through PCM_PARAMS->START->STOP->FREE_PCM->PCM_PARAMS cycle of IPC commands without power-cycling the DSP in between. Without PR1049, the driver only did this when system was suspended to S3, but then power was cycled anyways, so we did not hit this problem.
@kv2019i I've quickly looked at PR1049 and I haven't noticed the piece of code, which actually resets DMA stream on the host and link side (SRST bit). What is the sequence for the STOP? I assume you first send STOP ipc to the FW and after that set RUN = 0?
@kv2019i Also try to reset the whole HDA controller (not only stream) after freeing PCM. This experiment should show us if the problem is with the second stream configuration on host side.
@kv2019i I've quickly looked at PR1049 and I haven't noticed the piece of code, which actually resets DMA stream on the host and link side (SRST bit). What is the sequence for the STOP? I assume you first send STOP ipc to the FW and after that set RUN = 0?
It's indeed a bit hidden, but it is there in hda-stream.c:hda_dsp_stream_hw_params(). The logic to stop DMA and SRST sequence seems correct. The order is indeed like you say, first STOP ipc is sent, and only after that comples, stream is stopped and reset.
@kv2019i Also try to reset the whole HDA controller (not only stream) after freeing PCM. This
experiment should show us if the problem is with the second stream configuration on host side.
Thanks for the good pointers! I tried this, but results very inconclusive. When I reset the controller, then DMA doesn't restart properly anymore (instead of garbled audio I get no audio). But I believe this is because of other side-effects... the codec, link DMA and DSP controls are in separate places in the driver and doing the host reset in middle of the DSP/PCM path probably misses some state.
I continued to do following experiments:
A high number (many thousands) of PCM_PARAMS -> FREE_PCM IPC messages at stream start
-> no issues found (so no resource leaks in driver or FW that could cause subsequence PCM_PARAMS->FREE_PCM transactions to fail)
A forced START-STOP-FREEPCM->PCM_PARAMS->START sequence (but link DMA not running)
-> no issues, audio is still good -- doing this forced IPC sequence did still work. HDA DMA showed position to have progressed to "192" (so the preload phase had completed).
Same as (2) but now also stopping and starting the link DMA in the extra START-STOP-START flow
-> original issue hit again!
So problem points to link DMA configuration. I will continue tomorrow and dig deeper into the link DMA configuration sequences.
So problem points to link DMA configuration. I will continue tomorrow and dig deeper into the link DMA configuration sequences.
And this indeed was the problem. By reprogramming all the link DMA parameters, the garbled audio problem disappears. Patch to fix this now added to PR1049.
Activity
kv2019i commentedon Jun 28, 2019
Debugged today whether the garbled audio is caused by FW processing. I made the following experiment today.
When I compare traces between success case (audio ok after start) and failures (garbled audio), the debug dumps look identical. So it would seem the audio content FW is sending to the HDA codec is fine.
Both the HDA controller and FW PCM params are completely reset in the sequence, so running out of options in this direction. Next step is to check our actions towards the codec.
kv2019i commentedon Jun 28, 2019
Additional test today:
tlauda commentedon Jun 28, 2019
@kv2019i What does exactly setting start threshold mean for FW? What is the default value?
Also do you have FW logs from the above scenario? ctrl-Z + fg is pause/release or stop/start?
[-]garbled audio after XRUN/RESTART w/ aplay and low start threshold[/-][+]garbled audio after XRUN/RESTART done with FREE_PCM+PCM_PARAMS pair[/+]kv2019i commentedon Jun 28, 2019
@tlauda wrote:
I actually updated the bug description just now. The start-threshold setting affects #1062 , but not this bug. So once I fix #1062 by reseting DMA at stream restart (PR1049), then I start getting garbled audio and this affects more use-cases.
Start_threshold is an ALSA parameter to control when the PCM DMA trigger start is sent and HW should start consuming samples from DDR. By default it is set to be equal to buffer size. So with typical applications, they fill the whole DDR DMA buffer with audio data and only when buffer is completely filled, DMA trigger start will be sent. This is ok for simple playback (like aplay), but of course creates quite a long latency to playback. Alternative way to trigger playback is to set "start_threshold" to a low value (so that DMA is triggered when X% of the buffer is filled), or by an explicit start command from the application. Many applications that need precise control over output latency will choose to explicitly start the PCM stream (prefil few tens of milleseconds of audio and then start).
Attached is one log with the aplay sequence. Audio is fine on first run but gets garbled after stream is restarted. I can see nothing wrong in the long, but yet audio is bad on ~4/10 of cases. The main problem seems to be going through PCM_PARAMS->START->STOP->FREE_PCM->PCM_PARAMS cycle of IPC commands without power-cycling the DSP in between. Without PR1049, the driver only did this when system was suspended to S3, but then power was cycled anyways, so we did not hit this problem.
20190628-soflog-start-stop-3.txt
Thanks for looking at this!
tlauda commentedon Jun 28, 2019
@kv2019i I've quickly looked at PR1049 and I haven't noticed the piece of code, which actually resets DMA stream on the host and link side (SRST bit). What is the sequence for the STOP? I assume you first send STOP ipc to the FW and after that set RUN = 0?
tlauda commentedon Jun 29, 2019
@kv2019i Also try to reset the whole HDA controller (not only stream) after freeing PCM. This experiment should show us if the problem is with the second stream configuration on host side.
kv2019i commentedon Jul 1, 2019
@tlauda wrote:
It's indeed a bit hidden, but it is there in hda-stream.c:hda_dsp_stream_hw_params(). The logic to stop DMA and SRST sequence seems correct. The order is indeed like you say, first STOP ipc is sent, and only after that comples, stream is stopped and reset.
Thanks for the good pointers! I tried this, but results very inconclusive. When I reset the controller, then DMA doesn't restart properly anymore (instead of garbled audio I get no audio). But I believe this is because of other side-effects... the codec, link DMA and DSP controls are in separate places in the driver and doing the host reset in middle of the DSP/PCM path probably misses some state.
I continued to do following experiments:
-> no issues found (so no resource leaks in driver or FW that could cause subsequence PCM_PARAMS->FREE_PCM transactions to fail)
-> no issues, audio is still good -- doing this forced IPC sequence did still work. HDA DMA showed position to have progressed to "192" (so the preload phase had completed).
-> original issue hit again!
So problem points to link DMA configuration. I will continue tomorrow and dig deeper into the link DMA configuration sequences.
kv2019i commentedon Jul 2, 2019
@kv2019i wrote:
And this indeed was the problem. By reprogramming all the link DMA parameters, the garbled audio problem disappears. Patch to fix this now added to PR1049.
kv2019i commentedon Jul 12, 2019
#1049 merged, closing this bug
bpf, selftests: Add test cases for pointer alu from multiple paths