Skip to content

Fixes for xrun recovery and Soundwire node_id - #4829

Merged
plbossart merged 8 commits into
thesofproject:topic/sof-devfrom
ranj063:pr4816
Mar 4, 2024
Merged

plbossart merged 8 commits into
thesofproject:topic/sof-devfrom
ranj063:pr4816

Conversation

@ranj063

@ranj063 ranj063 commented Feb 20, 2024 •

Copy link
Copy Markdown
Collaborator

Replacement for #4816

bardliao
bardliao previously approved these changes Feb 21, 2024

@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

@ujfalusi

ujfalusi commented Feb 22, 2024 •

Copy link
Copy Markdown
Collaborator

CI is not happy with this yet.
Iow, it breaks HDA

@ranj063

ranj063 commented Feb 22, 2024 •

Copy link
Copy Markdown
Collaborator Author

CI is not happy with this yet. Iow, it breaks HDA

@ujfalusi no it was a different issue that broke all PRs. It was fixed

@ranj063

ranj063 commented Feb 22, 2024

Copy link
Copy Markdown
Collaborator Author

SOFCI TEST

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

@ranj063, I believe the xrun and sdw node_id fix needed together and cannot be separated?

Comment thread drivers/soundwire/intel.c Resolved
Comment thread sound/soc/sof/intel/hda.h Resolved
Comment thread sound/soc/sof/pcm.c Resolved
Comment thread sound/soc/sof/pcm.c Outdated
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
if (pcm_ops && pcm_ops->platform_stop_during_hw_free &&
cmd == SNDRV_PCM_TRIGGER_STOP)
spcm->stream_stopped[substream->stream] = 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.

a comment would really help here..
we set the stream_stopped flag to true when we have not stopped the stream?

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.

as far as ALSA is concerned the stream is stopped. The pipeline may not be stopped yet but thats different and thats what we need to handle when stream_stopped is set

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.

@ranj063, sure, as far as ALSA concerned the stream is stopped, but we are flagging a stream as stopped when we are not stopping it and we don't mark the stream as stopped when we did stopped it.

The flag is more like an indication that if a prepare is coming after this trigger (instead of close and free) we need to stop the stream and start it again - to really stop it as it should have been.

But why we cannot just stop it here?

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.

stopping pipelines here would be in theory the right thing to do but in order to keep the changes less invasive, we decided to keep the existing sequence. We can revisit this later if this needs to change

Comment thread sound/soc/sof/pcm.c Outdated
if (spcm->prepared[substream->stream])
return 0;
if (spcm->prepared[substream->stream]) {
if (!spcm->stream_stopped[substream->stream])

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 you re-use the pcm_ops->platform_stop_during_hw_free for the same result here?
I think the prepare is not called between SNDRV_PCM_TRIGGER_PAUSE_PUSH and SNDRV_PCM_TRIGGER_PAUSE_RELEASE, so if we are here when the spcm->prepared flag is true then we know that the stream needs to be freed.

Or rename the flag to be easier to relate to it's meaning?

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.

no @ujfalusi thats not true. In the regular start case also, the stream will be prepared and nothing needs to be done in that case. We can't really reuse platform_stop_during_hw_free either. We really need to know if the stream was stopped when the prepare gets called.

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 a regular case the prepared flag would not be set (I'm mostly sure about this as we need to run the rest of the function), no?

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.

no it will be set in the hw_params callback in the regular case as well

@ranj063

ranj063 commented Feb 23, 2024

Copy link
Copy Markdown
Collaborator Author

@ranj063, I believe the xrun and sdw node_id fix needed together and cannot be separated?

Yes, the xrun fixes will break SDW, so they need to go together

Comment thread drivers/soundwire/intel.c Resolved
Comment thread sound/soc/sof/intel/hda.h Resolved
Comment thread sound/soc/sof/pcm.c Outdated
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
if (pcm_ops && pcm_ops->platform_stop_during_hw_free &&
cmd == SNDRV_PCM_TRIGGER_STOP)
spcm->stream_stopped[substream->stream] = 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.

@ranj063, sure, as far as ALSA concerned the stream is stopped, but we are flagging a stream as stopped when we are not stopping it and we don't mark the stream as stopped when we did stopped it.

The flag is more like an indication that if a prepare is coming after this trigger (instead of close and free) we need to stop the stream and start it again - to really stop it as it should have been.

But why we cannot just stop it here?

Comment thread sound/soc/sof/sof-audio.h Outdated
struct list_head list; /* list in sdev pcm list */
struct snd_pcm_hw_params params[2];
bool prepared[2]; /* PCM_PARAMS set successfully */
bool stream_stopped[2]; /* only used if (!pcm_ops->platform_stop_during_hw_free) */

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.

based on the code it is only used if (pcm_ops->platform_stop_during_hw_free)

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 we rename this flag to stream_restart_needed or trigger_stop_pending or something else?
We really set this flag when we don't stop the stream and we use it as an indication that the stream was not stopped to stop it in prepare (when hw_params() is skipped).

Comment thread sound/soc/sof/pcm.c Outdated
if (spcm->prepared[substream->stream])
return 0;
if (spcm->prepared[substream->stream]) {
if (!spcm->stream_stopped[substream->stream])

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 a regular case the prepared flag would not be set (I'm mostly sure about this as we need to run the rest of the function), no?

Comment thread sound/soc/sof/pcm.c Outdated
default:
spcm->stream_stopped[substream->stream] = false;
break;
}

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.

Just unconditionally clear the flag?

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.

or handle the flag in one place:

	/*
	 * The stream is not stopped in case of platform_stop_during_hw_free == true
	 * During consequent prepare callback it will be needed to be stopped before
	 * starting the stream again (part of xrun handling)
	 */
	if (cmd == SNDRV_PCM_TRIGGER_STOP && pcm_ops &&
	    pcm_ops->platform_stop_during_hw_free)
		spcm->trigger_stop_pending[substream->stream] = true;
	else
		spcm->trigger_stop_pending[substream->stream] = false;

but after the second switch() section?

Comment thread sound/soc/sof/sof-audio.h Outdated
struct list_head list; /* list in sdev pcm list */
struct snd_pcm_hw_params params[2];
bool prepared[2]; /* PCM_PARAMS set successfully */
bool stream_stopped[2]; /* only used if (!pcm_ops->platform_stop_during_hw_free) */

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 we rename this flag to stream_restart_needed or trigger_stop_pending or something else?
We really set this flag when we don't stop the stream and we use it as an indication that the stream was not stopped to stop it in prepare (when hw_params() is skipped).

Comment thread sound/soc/sof/pcm.c Resolved
@ranj063
ranj063 force-pushed the pr4816 branch 2 times, most recently from b5587ba to df4a7a5 Compare March 4, 2024 16:18
plbossart
plbossart previously approved these changes Mar 4, 2024
ujfalusi
ujfalusi previously approved these changes Mar 4, 2024

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

@ranj063, with the rename and the comments it is much better.
I only have two nitpicks, if you think they worth addressing, please do.

Thanks for the updates.

Comment thread drivers/soundwire/intel.c Resolved
Comment thread drivers/soundwire/intel.c Resolved
ranj063 and others added 6 commits March 4, 2024 08:38
Add the intel_free_stream() callback to deal with the change in IPC that
requires additional steps to be done to clear the gateway node_id.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
To allow using widget_to_sdev() in other files, move it as static inline
in shared header file.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
When an xrun happens, the BE DAI hw_params doesn't get invoked before
the stream restarts with a prepare. In this case, clearing the node ID
when the DAI widget is freed and unprepared will result in an error when
it is re-initialized. In order to avoid this, move the code to clear the
node ID to the BE DAI hw_free op to keep it balanced with the BE DAI
hw_params.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
…d logs

For some reason the existing code stops on the first error, which
potentially leaves the DMA and widgets in a weird state.

Change to free-up all resources even in case of errors.

Also add a more consistent error handling and logs, with the first
error code returned to the caller.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
The same sequence is used twice, use common helper.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Add a state variable to keep track of delayed stops, in case
pcm_ops->platform_stop_during_hw_free is set.

This patch should be iso-functionality, possibly removing no-op
cases. The main purpose of this new state variable is to prepare a
follow-up patch to reset all PCM and DMAs in case of stop/prepare xrun
sequences.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
plbossart and others added 2 commits March 4, 2024 08:38
With the delayed stops, the xrun handling is problematic: the
applications expects everything to be reset but the firmware and DMA
are still in a PAUSED state.

This patch makes sure the prepare while pending_stop is set is
special-cased.

Co-developed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
The node_id for multi-gateway ALH DAI's get overwritten with the
group_id during the DAI copier's ipc_prepare op. So, save the ALH
dai_index during the BE DAI hw_params in the dai_index field of struct
ipc4_copier and use that to set the device ID in the configuration blob.
This will avoid errors during copier init after an xrun.

Note that the dai_index is typically set in topology for DMIC/SSP, but
it's not used for ALH. Reclaiming this dai_index field to store the
node_id does not generate a conflict with topology-defined values.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>

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

@ranj063, thanks for the quick update!

@plbossart

Copy link
Copy Markdown
Member

@ranj063 let's merge this after CI results. Not sure we can upstream this in the current kernel cycle though, we are now at -rc7

@plbossart

Copy link
Copy Markdown
Member

results look ok, merging

@plbossart
plbossart merged commit da70425 into thesofproject:topic/sof-dev Mar 4, 2024
@ranj063
ranj063 deleted the pr4816 branch March 4, 2024 22:16
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.

5 participants