From e5ce8d29d8ae68afd1fab17dc555f738c0208801 Mon Sep 17 00:00:00 2001 From: Sugar Zhang Date: Wed, 16 May 2018 15:31:40 +0800 Subject: [PATCH] ALSA: pcm_dmaengine: always get stream position from DMA driver This patch fixup that the wrong position when dma desc status is DONE. even if the desc status is DONE, it is still able to get the position from the dma driver. so, just remove the judgement. BACKGROUND In the Multi-Stream audio situation, Some Stream XRUNs unexpected, These stream drived by the synchronous clk, So, it should not be. After enable trace, we find the route cause: CONFIG_FUNCTION_TRACER CONFIG_FUNCTION_GRAPH_TRACER CONFIG_STACK_TRACER CONFIG_DYNAMIC_FTRACE /# cd /sys/kernel/debug/tracing /# echo "snd_pcm:applptr" >> set_event /# echo "snd_pcm:hwptr" >> set_event /# echo "snd_pcm:xrun" >> set_event /# cat trace | head -20 /# echo 1 > tracing_on /# cat trace_pipe > trace.txt 110.291854: applptr: pcmC1D0p/sub0: prev=0, curr=960, avail=2880, period=960, buf=3840 110.292258: applptr: pcmC2D0p/sub0: prev=0, curr=960, avail=2880, period=960, buf=3840 110.292464: applptr: pcmC3D0p/sub0: prev=0, curr=960, avail=2880, period=960, buf=3840 110.292704: applptr: pcmC0D0p/sub0: prev=0, curr=960, avail=2880, period=960, buf=3840 110.293631: applptr: pcmC1D0p/sub0: prev=960, curr=1920, avail=1920, period=960, buf=3840 110.293708: applptr: pcmC2D0p/sub0: prev=960, curr=1920, avail=1920, period=960, buf=3840 110.293750: applptr: pcmC3D0p/sub0: prev=960, curr=1920, avail=1920, period=960, buf=3840 110.293787: applptr: pcmC0D0p/sub0: prev=960, curr=1920, avail=1920, period=960, buf=3840 ... 110.773563: applptr: pcmC2D0p/sub0: prev=25920, curr=26880, avail=8, period=960, buf=3840 110.773564: hwptr: pcmC0D0p/sub0: IRQ: pos=8, old=22088, base=19200, period=960, buf=3840 110.773573: hwptr: pcmC3D0p/sub0: POS: pos=8, old=23048, base=23040, period=960, buf=3840 110.773594: applptr: pcmC3D0p/sub0: prev=25920, curr=26880, avail=8, period=960, buf=3840 110.773624: hwptr: pcmC0D0p/sub0: POS: pos=8, old=23048, base=23040, period=960, buf=3840 110.773648: applptr: pcmC0D0p/sub0: prev=25920, curr=26880, avail=8, period=960, buf=3840 110.773930: hwptr: pcmC1D0p/sub0: POS: pos=32, old=23048, base=23040, period=960, buf=3840 110.775376: hwptr: pcmC1D0p/sub0: POS: pos=104, old=23072, base=23040, period=960, buf=3840 110.775460: applptr: pcmC1D0p/sub0: prev=26880, curr=26984, avail=0, period=960, buf=3840 110.793215: hwptr: pcmC1D0p/sub0: IRQ: pos=960, old=23144, base=23040, period=960, buf=3840 110.793322: applptr: pcmC1D0p/sub0: prev=26984, curr=27840, avail=0, period=960, buf=3840 110.793347: hwptr: pcmC2D0p/sub0: POS: pos=0, old=23048, base=23040, period=960, buf=3840 110.793667: hwptr: pcmC2D0p/sub0: IRQ: pos=976, old=23048, base=23040, period=960, buf=3840 110.794523: applptr: pcmC2D0p/sub0: prev=26880, curr=26888, avail=0, period=960, buf=3840 // applptr was block over one period 110.794703: hwptr: pcmC3D0p/sub0: IRQ: pos=1024, old=23048, base=23040, period=960, buf=3840 110.794804: hwptr: pcmC0D0p/sub0: IRQ: pos=1028, old=23048, base=23040, period=960, buf=3840 110.813277: hwptr: pcmC1D0p/sub0: IRQ: pos=1920, old=24000, base=23040, period=960, buf=3840 110.813330: hwptr: pcmC2D0p/sub0: IRQ: pos=1920, old=23048, base=23040, period=960, buf=3840 110.813714: hwptr: pcmC3D0p/sub0: IRQ: pos=1936, old=24064, base=23040, period=960, buf=3840 110.813759: hwptr: pcmC0D0p/sub0: IRQ: pos=1936, old=24068, base=23040, period=960, buf=3840 110.833221: hwptr: pcmC1D0p/sub0: IRQ: pos=2880, old=24960, base=23040, period=960, buf=3840 110.833336: hwptr: pcmC2D0p/sub0: IRQ: pos=2880, old=23048, base=23040, period=960, buf=3840 110.834086: hwptr: pcmC3D0p/sub0: IRQ: pos=2912, old=24976, base=23040, period=960, buf=3840 110.834216: hwptr: pcmC0D0p/sub0: IRQ: pos=2920, old=24976, base=23040, period=960, buf=3840 110.853208: hwptr: pcmC1D0p/sub0: IRQ: pos=0, old=25920, base=23040, period=960, buf=3840 110.853293: hwptr: pcmC2D0p/sub0: IRQ: pos=0, old=23048, base=23040, period=960, buf=3840 110.853991: hwptr: pcmC3D0p/sub0: IRQ: pos=28, old=25952, base=23040, period=960, buf=3840 110.854001: xrun: pcmC3D0p/sub0: XRUN: old=26908, base=26880, period=960, buf=3840 110.854719: hwptr: pcmC0D0p/sub0: IRQ: pos=64, old=25960, base=23040, period=960, buf=3840 110.854727: xrun: pcmC0D0p/sub0: XRUN: old=26944, base=26880, period=960, buf=3840 110.873221: hwptr: pcmC1D0p/sub0: IRQ: pos=960, old=26880, base=26880, period=960, buf=3840 110.873239: xrun: pcmC1D0p/sub0: XRUN: old=27840, base=26880, period=960, buf=3840 110.874682: applptr: pcmC2D0p/sub0: prev=26888, curr=27840, avail=56, period=960, buf=3840 grep "applptr: pcmC2D0p" trace.txt: applptr was block over 4 periods (80ms) 110.773563: applptr: pcmC2D0p/sub0: prev=25920, curr=26880, avail=8, period=960, buf=3840 110.794523: applptr: pcmC2D0p/sub0: prev=26880, curr=26888, avail=0, period=960, buf=3840 110.874682: applptr: pcmC2D0p/sub0: prev=26888, curr=27840, avail=56, period=960, buf=3840 grep "hwptr: pcmC2D0p/sub0: POS" trace.txt: 110.613370: hwptr: pcmC2D0p/sub0: POS: pos=0, old=15360, base=15360, period=960, buf=3840 110.633389: hwptr: pcmC2D0p/sub0: POS: pos=960, old=16320, base=15360, period=960, buf=3840 110.653371: hwptr: pcmC2D0p/sub0: POS: pos=1920, old=17280, base=15360, period=960, buf=3840 110.673403: hwptr: pcmC2D0p/sub0: POS: pos=2880, old=18240, base=15360, period=960, buf=3840 110.693523: hwptr: pcmC2D0p/sub0: POS: pos=8, old=19200, base=19200, period=960, buf=3840 110.713477: hwptr: pcmC2D0p/sub0: POS: pos=968, old=20168, base=19200, period=960, buf=3840 110.733362: hwptr: pcmC2D0p/sub0: POS: pos=1920, old=21120, base=19200, period=960, buf=3840 110.753459: hwptr: pcmC2D0p/sub0: POS: pos=2888, old=22088, base=19200, period=960, buf=3840 invalid POS rollback (8 -> 0): 110.773536: hwptr: pcmC2D0p/sub0: POS: pos=8, old=23048, base=23040, period=960, buf=3840 110.793347: hwptr: pcmC2D0p/sub0: POS: pos=0, old=23048, base=23040, period=960, buf=3840 Change-Id: I40e92bae09a002f4f5f0b2fab8b0e99fd3ee269d Signed-off-by: Sugar Zhang --- sound/core/pcm_dmaengine.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 1fc2fa077574..c9314c9e87f1 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -244,19 +244,16 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream) struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct dma_tx_state state; - enum dma_status status; unsigned int buf_size; unsigned int pos = 0; - status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); - if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) { - buf_size = snd_pcm_lib_buffer_bytes(substream); - if (state.residue > 0 && state.residue <= buf_size) - pos = buf_size - state.residue; + dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); + buf_size = snd_pcm_lib_buffer_bytes(substream); + if (state.residue > 0 && state.residue <= buf_size) + pos = buf_size - state.residue; - runtime->delay = bytes_to_frames(runtime, - state.in_flight_bytes); - } + runtime->delay = bytes_to_frames(runtime, + state.in_flight_bytes); return bytes_to_frames(runtime, pos); }