Skip to content

[TEST v2] fix suspend/resume with SoundWire - #1320

Closed
plbossart wants to merge 4 commits into
thesofproject:integration/soundwire-intelfrom
plbossart:integration/soundwire-20191015
Closed

plbossart wants to merge 4 commits into
thesofproject:integration/soundwire-intelfrom
plbossart:integration/soundwire-20191015

Conversation

@plbossart

Copy link
Copy Markdown
Member

Alternate solution based on @bardliao 's feedback, that seems to deal with suspend-resume, underflows and pause/play

It still see odd messages on the command line so more testing is needed

Write error: -86,Streams pipe error
Can't recovery from suspend, prepare failed: No data available
Write error: -77,File descriptor in bad state
xrun_recovery failed: -77,File descriptor in bad state
Transfer failed: File descriptor in bad state

The state machine and notes don't accurately explain or allow
transitions from STREAM_DEPREPARED and STREAM_DISABLED.

Add more explanations and allow for more transitions as a result of a
trigger_stop(), trigger_suspend() and prepare(), depending on the
ALSA/ASoC layer behavior defined by the INFO_RESUME and INFO_PAUSE
flags.

Also add basic checks to help debug inconsistent states and illegal
state machine transitions.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Comment thread drivers/soundwire/stream.c Resolved
plbossart and others added 3 commits October 15, 2019 13:41
…transition

After a system suspend, the ALSA/ASoC core will invoke the .prepare()
callback and a TRIGGER_START when INFO_RESUME is not supported.

Likewise, when an underflow occurs, the .prepare callback will be invoked.

In both cases, the stream can be in DISABLED mode, and will transition
into the PREPARED mode. We however don't want the bus bandwidth to be
recomputed.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
The .prepare() callback is invoked for underflows or during the system
resume transition. In the latter case, the context for the ALH PDIs is
lost, and the DSP is not initialized properly either, but the bus
parameters don't need to be recomputed.

Keep track of the TRIGGER_SUSPEND transition with a boolean flag, and
use it during the .prepare step to check if the ALH PDIs need to be
reconfigured.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

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

@plbossart We are closed but still some thing need to be clarify.


sdw_acquire_bus_lock(stream);

if (stream->state != SDW_STREAM_DISABLED) {

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.

@plbossart prepared <--> deprepared is valid, right? I can see hw_parames -> prepare -> hw_free without ant trigger when pulseaudio on. I.e. No enable/disable between prepare/deprepare. I think it makes sense since the application may only want to configure the stream but not to play it. So I think we can add && stream->state != SDW_STREAM_PREPARED here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are right, but that requires an update to the state machine as well. Will fix.
Nice catch, thanks @bardliao


ret = _sdw_prepare_stream(stream);
if (stream->state != SDW_STREAM_CONFIGURED &&
stream->state != SDW_STREAM_DISABLED) {

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.

@plbossart Will it be better if we do the check before sdw_acquire_bus_lock() and move state_err: after sdw_release_bus_lock()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@bardliao I think we have to use the lock before checking the state.
Put differently, the state is changed when the bus is locked, so it would be odd to allow the state to be checked without taking the lock as well, you could have race conditions when you read a state that becomes immediately inconsistent.

Comment thread drivers/soundwire/intel.c
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_SUSPEND:
dev_err(dai->dev, "%s: %s: suspend\n", __func__, dai->name);
dma->suspend_reinitialize = true;

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.

@plbossart set suspend_reinitialize = true here may not be the best place. The reason we need to reinitialize cdns is when system is suspended. So I think it is better to set suspend_reinitialize = true in intel_suspend(). We may need bardliao@d0247d3

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, I don't think we can set suspend_reinitialize in intel_suspend. The reason is that we need to reprogram the ALH stream ID, and if you have more than one DAI for a given device then with your patch you would only restore the first ALH stream ID. It's got to be done on a DAI-basis, so the flag has to be stored in the dma structure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That said, you are right @bardliao that if the DAI is prepared but not triggered, it still needs to be re-initialized. I guess the solution is a mix of yours and mine, we can't use TRIGGER suspend but can't use the .suspend either since each DAI needs to be reinitialized.

@plbossart

Copy link
Copy Markdown
Member Author

@plbossart plbossart closed this Oct 16, 2019
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.

3 participants