Skip to content

ASoC: SOF: sof-pci-dev: add .shutdown callback - #2581

Merged
bardliao merged 4 commits into
thesofproject:topic/sof-devfrom
keyonjie:shutdown
Dec 29, 2020
Merged

bardliao merged 4 commits into
thesofproject:topic/sof-devfrom
keyonjie:shutdown

Conversation

@keyonjie

Copy link
Copy Markdown

Add .shutdown callback to handle reboot/poweroff related stuff, and pull
DSP back to D0I0 before reboot if it is at D0I3, to fix the boot fail
issue at the consequent rebooting.

Fixes: #2571
Signed-off-by: Keyon Jie yang.jie@linux.intel.com

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @keyonjie . I think this looks ok. Please split to two patches (common/intel) and address the comments and then this is ready from my point of view.

Comment thread sound/soc/sof/core.c
}
EXPORT_SYMBOL(snd_sof_device_remove);

int snd_sof_device_shutdown(struct device *dev)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PCI driver shutdown has "void" return type, so we can't return an error to upper layer. But, but, I think it's ok to keep the "int" and return type, and keep this aligned with rest of SOF ops API.

Comment thread sound/soc/sof/intel/hda.c Outdated

/*
* turn DSP back to D0 from D0I3 before shutting down it,
* to avoid booting fail at some platforms from D0i3 status.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be good to split the Intel specific part into a separate patch. I.e. one to add shutdown op, and another to add Intel HDA implementation of it.

The comment is a bit vague, maybe just leave it out and explain the change in commit.

Comment thread sound/soc/sof/intel/hda.c Resolved
@keyonjie keyonjie changed the title [RFC]ASoC: SOF: sof-pci-dev: add .shutdown callback ASoC: SOF: sof-pci-dev: add .shutdown callback Nov 25, 2020
@keyonjie

Copy link
Copy Markdown
Author

Thanks, @kv2019i comments addressed now.

@keyonjie
keyonjie requested a review from kv2019i November 25, 2020 09:43
Comment thread sound/soc/sof/core.c Resolved
Comment thread sound/soc/sof/intel/hda.c Resolved
@keyonjie

Copy link
Copy Markdown
Author

Thanks @lyakh updated now.

@keyonjie
keyonjie requested a review from lyakh November 25, 2020 13:50

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two minor issues in git commit messages, otherwise good for me.

Comment thread sound/soc/sof/intel/hda.c Resolved
Comment thread sound/soc/sof/intel/tgl.c
@@ -26,6 +26,8 @@ const struct snd_sof_dsp_ops sof_tgl_ops = {
.probe = hda_dsp_probe,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In commit, "Fixes:" is only used when pointing to commit hashes. To refer to a bug URL, please use "BugLink: " instead.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kv2019i since we are here and I know on i.MX there might be similar issues, do you know how the HIFI DSP is reset / power on / power off on Intel platforms?
Does the BIOS takes care of this. Or DSP by itself can initiate the rest/power off procedure?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dbaluta Actual power-on is triggered via PCI MMIO writes, see hda-dsp.c:hda_dsp_core_power_down() in kernel. On DSP side, there is a sequence to ramp down resources and got a loop executing waiti, see for example platform_pm_runtime_power_off().

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@kv2019i fixes is a github construct, it should be used in PR description to help autoclose related bugs if possible. But yes i agree not in the commit message.

Comment thread sound/soc/sof/ops.h
@@ -37,6 +37,14 @@ static inline int snd_sof_remove(struct snd_sof_dev *sdev)
return 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In commit: "platform specific shutdown stuff" -> "platform specific actions at shutdown"

lyakh
lyakh previously approved these changes Nov 26, 2020

@lyakh lyakh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing! Once comments from @kv2019i are addressed, no more suggestions from me

@keyonjie

Copy link
Copy Markdown
Author

Thanks for reviewing @kv2019i @lyakh updated now.

kv2019i
kv2019i previously approved these changes Nov 26, 2020

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, looks good!

@lgirdwood lgirdwood 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.

@keyonjie can you confirm that shutdown() wont re-load FW just to set the D0 state ?

@keyonjie

Copy link
Copy Markdown
Author

@keyonjie can you confirm that shutdown() wont re-load FW just to set the D0 state ?

yes, the shutdown() here only doing possible switching of the ADSP state, from D0I3 to D0, no FW reloading will happen.

@plbossart

Copy link
Copy Markdown
Member

I looked into this before the Thanksgiving break and the .shutdown doesn't seem necessary.

See device_shutdown(), it does a put_device() at the end that will result in the PCI .remove() callback being called. I don't see a difference between the .shutdown and .remove here, so what does this PR bring?

Does this solve anything?

@keyonjie

keyonjie commented Dec 2, 2020

Copy link
Copy Markdown
Author

Hi @plbossart @kv2019i @ranj063 @lyakh please help to review the new implementation, basically I switch to call .remove() at .shutdown() for TGL platform, this will lead to longer reboot time (should be several ms level delta, not measure yet).

This behaves better during my local reboot stress test, it passes 30 iterations (the previous can't pass 10) and test is continue...

Hi @keqiaozhang can you help to test with the latest change at your end also.

@plbossart

Copy link
Copy Markdown
Member

when the system reboots, doesn't it close applications first? That would close the PCM device that was used for WoV and as a result transition to D0i0 - thus no longer running in low-power clock.

That's true, but since our D0->D0I3 transition happens at 5 seconds delayed work, there could be race there: e.g. the trigger stop just finish the transition to D0i0 at the exact point 5 seconds timeout, so the D0->D0I3 transition may happen following that...

That means we are missing a cancel_work_sync() ?

@keyonjie

keyonjie commented Dec 3, 2020

Copy link
Copy Markdown
Author

when the system reboots, doesn't it close applications first? That would close the PCM device that was used for WoV and as a result transition to D0i0 - thus no longer running in low-power clock.

That's true, but since our D0->D0I3 transition happens at 5 seconds delayed work, there could be race there: e.g. the trigger stop just finish the transition to D0i0 at the exact point 5 seconds timeout, so the D0->D0I3 transition may happen following that...

That means we are missing a cancel_work_sync() ?

Adding cancel_work_sync() can't eliminate the race thoroughly, I had another local change to add a mutex to protect this dsp_power_state access, but that can't make sure the delayed work won't be scheduled after trigger_stop (D0I3->D0), except we do a explicit cancel_work_sync() at PCM trigger stop. So with all this possibilities, adding an extra D0i3->D0 at .shutdown() looks the most light way to me.

On the other hand, to make things simpler and more robust, going with another way that just powering off the whole ADSP at .shutdown() (reflected in my latest update above) looks better to me, we can simplify with just power off DSP cores without doing other removal stuffs to speed up the .shutdown() running if needed. Please let me know what do you feel about that.

@plbossart

Copy link
Copy Markdown
Member

when the system reboots, doesn't it close applications first? That would close the PCM device that was used for WoV and as a result transition to D0i0 - thus no longer running in low-power clock.

That's true, but since our D0->D0I3 transition happens at 5 seconds delayed work, there could be race there: e.g. the trigger stop just finish the transition to D0i0 at the exact point 5 seconds timeout, so the D0->D0I3 transition may happen following that...

That means we are missing a cancel_work_sync() ?

Adding cancel_work_sync() can't eliminate the race thoroughly, I had another local change to add a mutex to protect this dsp_power_state access, but that can't make sure the delayed work won't be scheduled after trigger_stop (D0I3->D0), except we do a explicit cancel_work_sync() at PCM trigger stop. So with all this possibilities, adding an extra D0i3->D0 at .shutdown() looks the most light way to me.

I am lost here. If we have a design where we have a risk of race condition because of workqueue, then we need to fix this.
We've had problems before, we really need to make sure this is under control.

On the other hand, to make things simpler and more robust, going with another way that just powering off the whole ADSP at .shutdown() (reflected in my latest update above) looks better to me, we can simplify with just power off DSP cores without doing other removal stuffs to speed up the .shutdown() running if needed. Please let me know what do you feel about that.

No objection if the race condition is handled.

@keyonjie

keyonjie commented Dec 4, 2020 •

Copy link
Copy Markdown
Author

Adding cancel_work_sync() can't eliminate the race thoroughly, I had another local change to add a mutex to protect this dsp_power_state access, but that can't make sure the delayed work won't be scheduled after trigger_stop (D0I3->D0), except we do a explicit cancel_work_sync() at PCM trigger stop. So with all this possibilities, adding an extra D0i3->D0 at .shutdown() looks the most light way to me.

I am lost here. If we have a design where we have a risk of race condition because of workqueue, then we need to fix this.
We've had problems before, we really need to make sure this is under control.

Yes, let me submit a fix for that with another PR.

@keyonjie

keyonjie commented Dec 4, 2020

Copy link
Copy Markdown
Author

Adding cancel_work_sync() can't eliminate the race thoroughly, I had another local change to add a mutex to protect this dsp_power_state access, but that can't make sure the delayed work won't be scheduled after trigger_stop (D0I3->D0), except we do a explicit cancel_work_sync() at PCM trigger stop. So with all this possibilities, adding an extra D0i3->D0 at .shutdown() looks the most light way to me.

I am lost here. If we have a design where we have a risk of race condition because of workqueue, then we need to fix this.
We've had problems before, we really need to make sure this is under control.

Yes, let me submit a fix for that with another PR.

Here it is: #2600

Comment thread sound/soc/sof/intel/tgl.c Outdated
.probe = hda_dsp_probe,
.remove = hda_dsp_remove,

/* shutdown handling */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@keyonjie lets remove the comment. the code is self-explanatory

Comment thread sound/soc/sof/ops.h Resolved
@ranj063

ranj063 commented Dec 24, 2020

Copy link
Copy Markdown
Collaborator

@keyonjie I think the patches are good. Can you please remove the comment in the last patch and then the PR will be good to go. @sathya-nujella is testing it right now and once he reports back the results, we can merge this

@keyonjie

Copy link
Copy Markdown
Author

@ranj063 @kv2019i @bardliao updated.

@keyonjie
keyonjie requested a review from ranj063 December 24, 2020 03:09

@bardliao bardliao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@keyonjie I didn't see where is hda_dsp_shutdown() used. Do I miss something?

Comment thread sound/soc/sof/sof-priv.h Outdated
@@ -102,6 +102,8 @@ struct snd_sof_dsp_ops {
int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */
int (*remove)(struct snd_sof_dev *sof_dev); /* optional */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit-pick: It seems the empty line is not required.

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.

nit-pick: It seems the empty line is not required.

Then I should change the comment for "probe and remove" to "probe/remove and shutdown"?

Comment thread sound/soc/sof/intel/hda.h Outdated
*/
int hda_dsp_probe(struct snd_sof_dev *sdev);
int hda_dsp_remove(struct snd_sof_dev *sdev);
int hda_dsp_shutdown(struct snd_sof_dev *sdev);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Where does hda_dsp_shutdown be used?

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.

Where does hda_dsp_shutdown be used?

Good catch, this was previous used but now should be removed.

Add .shutdown() callback to the struct snd_sof_dsp_ops, for
doing platform specific actions at shutdown.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Add helper snd_sof_device_shutdown() to wrap the platform specific
.shutdown callbacks for SOF platforms.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Add the .shutdown() callback to the sof-pci-dev driver, to help to
handle shutting down specific tasks for SOF PCI platforms.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Invoke hda_dsp_remove() as the .shutdown() callback, this will help to
perform shutdown the DSP safely on TGL platforms before shutting down or
rebooting the system.

BugLink: thesofproject#2571
Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
@keyonjie

Copy link
Copy Markdown
Author

@bardliao updated now.

@keyonjie
keyonjie requested a review from bardliao December 25, 2020 06:45
@bardliao
bardliao merged commit 9949d3d into thesofproject:topic/sof-dev Dec 29, 2020
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.

[BUG][TGL] failed to ready HDA controller gctl 0x0 (sof_probe_work failed)

9 participants