Skip to content

ASoC: SOF: keep prepare/unprepare widgets in sink path - #4022

Merged
plbossart merged 2 commits into
thesofproject:topic/sof-devfrom
bardliao:fis-io-err
Nov 29, 2022
Merged

ASoC: SOF: keep prepare/unprepare widgets in sink path#4022
plbossart merged 2 commits into
thesofproject:topic/sof-devfrom
bardliao:fis-io-err

Conversation

@bardliao

Copy link
Copy Markdown
Collaborator

The existing code return when a widget doesn't need to prepare/unprepare. This will prevent widgets in the sink path from being prepared/unprepared.

Signed-off-by: Bard Liao yung-chuan.liao@linux.intel.com

Fixes: #4021

@bardliao

Copy link
Copy Markdown
Collaborator Author

Thanks @ranj063 for finding this issue.

plbossart
plbossart previously approved these changes Nov 17, 2022
Comment thread sound/soc/sof/sof-audio.c
ranj063
ranj063 previously approved these changes Nov 17, 2022
@bardliao

Copy link
Copy Markdown
Collaborator Author

We should unprepare the widget if its use_count = 1.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
The existing code return when a widget doesn't need to
prepare/unprepare. This will prevent widgets in the sink path from being
prepared/unprepared.

Link: thesofproject#4021
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Comment thread sound/soc/sof/sof-audio.c
Comment thread sound/soc/sof/sof-audio.c Outdated

/* skip if the widget is in use or if it is already unprepared */
if (!swidget->prepared || swidget->use_count > 0)
if (swidget->use_count > 0)

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.

commit title should be ASoC: SOF: sof-audio: remove swidget->prepared flag

Comment thread sound/soc/sof/sof-audio.c Outdated
goto sink_prepare;

if (!widget_ops[widget->id].ipc_prepare || swidget->prepared)
if (!widget_ops[widget->id].ipc_prepare && !swidget->use_count)

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.

This works as long as we have always prepare followed by setup (where the reference count is increased).

If this is not the case and we can have multiple calls to prepare, then this would not work.

In the first case, there should be a deeper explanation in the commit message as to why this is ok.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@plbossart @ranj063 On the second thought, I think it is better to keep the prepared flag. Think about if a widget is prepared, but fail to setup. The use_count will be 0, but it is prepared. It will likely be a problem.

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.

But @bardliao don't we call unprepare if widget setup fails?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But @bardliao don't we call unprepare if widget setup fails?

Yes, we call sof_walk_widgets_in_order SOF_WIDGET_UNPREPARE if sof_walk_widgets_in_order SOF_WIDGET_SETUP failed. But what if one of the widget is failed and others are success? Those widgets that have already set up will not be unprepared since their use_count is 1. My point is that prepare and setup are handled in different helper functions, someone can easily break it even if it works well now.

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.

@bardliao when widget setup fails, we unroll and free all widgets that were previously set up in sof_set_up_widgets_in_path(). I am fairly certain the prepare flag is redundant

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.

But this PR is good enough for what it was intended for. We should follow up with another PR to remove the prepared flag

Comment thread sound/soc/sof/sof-audio.c

/* return if the widget is in use or if it is already unprepared */
if (!swidget->prepared || swidget->use_count > 1)
if (!swidget->prepared || swidget->use_count > 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.

Can the use_count go negative?

if (!swidget->prepared || swidget->use_count)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Can the use_count go negative?

if (!swidget->prepared || swidget->use_count)

Ideally, no. But I do see it is negative when I meet IPC errors. And sof_widget_free() will never work at that time.

@ranj063

ranj063 commented Nov 28, 2022

Copy link
Copy Markdown
Collaborator

@bardliao can you please take a look at the IPC4 device test failures

@plbossart
plbossart requested a review from ujfalusi November 28, 2022 22:57
@bardliao

Copy link
Copy Markdown
Collaborator Author

SOFCI TEST

@bardliao

Copy link
Copy Markdown
Collaborator Author

@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 merged commit 3786eeb into thesofproject:topic/sof-dev Nov 29, 2022
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] PCM IO error with multi stream capture topology on pause-resume test

5 participants