Skip to content

IPC fixes -- for snd_pcm_period_elapse() invoking - #849

Merged
plbossart merged 3 commits into
thesofproject:topic/sof-devfrom
keyonjie:ipc_elapse_fix
Apr 25, 2019
Merged

plbossart merged 3 commits into
thesofproject:topic/sof-devfrom
keyonjie:ipc_elapse_fix

Conversation

@keyonjie

Copy link
Copy Markdown
Our IPC implementation in SOF requires sending IPCs serially, that is,
we should not send a new IPC before we get ack(or time out) from FW.

OTOH, snd_pcm_period_elapsed() will do trigger stop(IPC Tx to Firmware)
at PCM draining done, that means, we should not invoke the function
before IRQ_HANDLED is returned.

Unfortunately, We invoke snd_pcm_period_elapsed() in interrupt thread
before IRQ_HANDLED is returned, this fact leads to possible ipc time out
at stopping PCMs, especially when the draining done happens right after
period boundary.

Here we introduce a task to call this snd_pcm_elapsed(), to make sure it
will not be actually run before the IPC IRQ is handled. The stress test
shows that it fixes this kind of ipc time out issue.

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments below, the clarity of the explanations isn't up to par and needs to be improved.

Comment thread sound/soc/sof/pcm.c Outdated
Comment thread sound/soc/sof/pcm.c Outdated
Comment thread sound/soc/sof/pcm.c Outdated
Comment thread sound/soc/sof/sof-priv.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/elapsed/period_elapsed/ in this patch please.

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
@ranj063

ranj063 commented Apr 19, 2019

Copy link
Copy Markdown
Collaborator

@plbossart @keyonjie I understand the rationale for scheduling period_elapsed_work for later but I feel like we might be missing something fundamental in the way we deal with shared IRQ. But the change feels OK for now.

I'll work with @lyakh after he's back from vacation to dig deeper.

@xiulipan xiulipan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks good to change snd_pcm_period_elapsed from sync to async. That will help to make sure IPC thread is not blocking.

But indeed need to refine the comment and commit to give a more convince explanation about why need to use a task for snd_pcm_period_elapsed

And it fix #808

[ 73.081644] sof-audio-acpi 80860F28:01: pcm: trigger stream 0 dir 0 cmd 0
[ 73.081668] sof-audio-acpi 80860F28:01: ipc tx: 0x60050000: GLB_STREAM_MSG: TRIG_STOP
[ 73.082610] sof-audio-acpi 80860F28:01: ipc tx succeeded: 0x60050000: GLB_STREAM_MSG: TRIG_STOP
[ 73.082650] sof-audio-acpi 80860F28:01: pcm: free stream 0 dir 0
[ 73.082664] sof-audio-acpi 80860F28:01: ipc tx: 0x60030000: GLB_STREAM_MSG: PCM_FREE
[ 73.082790] sof-audio-acpi 80860F28:01: ipc tx succeeded: 0x60030000: GLB_STREAM_MSG: PCM_FREE
[ 73.082883] sof-audio-acpi 80860F28:01: pcm: close stream 0 dir 0
[ 73.330420] sof-audio-acpi 80860F28:01: ipc rx: 0x90020000: GLB_TRACE_MSG
[ 73.330442] sof-audio-acpi 80860F28:01: ipc rx done: 0x90020000: GLB_TRACE_MSG

@ranj063

ranj063 commented Apr 20, 2019

Copy link
Copy Markdown
Collaborator

@plbossart @keyonjie the more I look into this code, the more confusing it is to me. When the stream interrupt handler arrives, it already defers processing by waking up the threaded interrupt handler( hda_dsp_stream_threaded_handler). The whole idea of a threaded interrupt handler is to be able to do the processing while the interrupts themselves are not disabled.

So when the hda_dsp_stream_threaded_handler calls snd_pcm_period_elapse() which in turn sends an IPC to the DSP and waits for a reply, the interrupts are not disabled. So this doesn't seem to explain why this would cause a timeout at all?

Please correct me if I am wrong.

@ranj063

ranj063 commented Apr 20, 2019

Copy link
Copy Markdown
Collaborator

I did a bit of reading on the topic and the threaded handler does disable interrupts until it is done processing. Sorry about the confusion.

ranj063
ranj063 previously approved these changes Apr 20, 2019
Comment thread sound/soc/sof/pcm.c Outdated
@RanderWang

RanderWang commented Apr 22, 2019 •

Copy link
Copy Markdown

Actually snd_pcm_period_elapsed is a complex function and one principle in Linux kernel development: never make interrupt function too complex.

@keqiaozhang

Copy link
Copy Markdown

I have verified #849 + #850 on GLK and WHL, simultaneous playback/capturing can pass 1K iterations without errors on both platforms.

@plbossart

Copy link
Copy Markdown
Member

@keyonjie I don't see any updated code and I will be unavailable tomorrow morning, so this PR will be delayed mechanically until mid-week...

@keyonjie

Copy link
Copy Markdown
Author

@plbossart updated now.

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic fixes needed

Comment thread sound/soc/sof/pcm.c Outdated
Comment thread sound/soc/sof/pcm.c Outdated
Comment thread sound/soc/sof/sof-priv.h Outdated
Comment thread sound/soc/sof/pcm.c Outdated
Comment thread sound/soc/sof/intel/hda-stream.c Outdated
Comment thread sound/soc/sof/ipc.c Outdated
@keyonjie

Copy link
Copy Markdown
Author

@plbossart thanks, one more update done today.

RanderWang
RanderWang previously approved these changes Apr 23, 2019

@RanderWang RanderWang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix what can be seen as a typo. it's period_elapsed.

Comment thread sound/soc/sof/sof-priv.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

period_elapsed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix what can be seen as a typo. it's period_elapsed.

OK, done.

plbossart
plbossart previously approved these changes Apr 24, 2019

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @keyonjie for making this PR really shiny.
I will wait for the build results and need a 2nd approver before merging.

…rrupt

context

The IPC implementation in SOF requires sending IPCs serially: we should
not send a new IPC command to the firmware before we get an ACK (or time
out) from firmware, and the IRQ processing is complete.

snd_pcm_period_elapsed() can be called in interrupt context before
IRQ_HANDLED is returned. When the PCM is done draining, a STOP
IPC will then be sent, which breaks the expectation that IPCs are
handled serially and leads to IPC timeouts.

This patch adds a workqueue to defer the call to snd_pcm_elapsed() after
the IRQ is handled.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Switch to a wrapper function which schedules the actual call of
snd_pcm_period_elapsed after the current IPC is completed.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Switch to a wrapper function which schedules the actual call of
snd_pcm_period_elapsed after the current IPC is completed.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
@xiulipan

Copy link
Copy Markdown

LGTM
@keqiaozhang @DarrenxWang @stevyan
This will influence BYT mostly. Please try to stress test on BYT if it is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants