Propagate errors out from compressed streams
Subsystems (4)
PATCH v3 2/4 ALSA: compress: Add function to indicate the stream has gone bad
In reply to Charles KeepaxCurrently, the avail IOCTL doesn't pass any error status, which means typically on error it simply shows no data available. This can lead to situations where user-space is waiting indefinitely for data that will never come as the DSP has suffered an unrecoverable error.
Add snd_compr_stop_error which end drivers can call to indicate the stream has suffered an unrecoverable error and stop it. The avail and poll IOCTLs are then updated to report if the stream is in an error state to user-space. Allowing the error to propagate out. Processing of the actual snd_compr_stop needs to be deferred to a worker thread as the end driver may detect the errors during an existing operation callback.
--- include/sound/compress_driver.h | 4 +++ sound/core/compress_offload.c | 60 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-)
include/sound/compress_driver.h +4 -0
@@ -78,6 +78,7 @@ struct snd_compr_stream {struct snd_compr_ops *ops;struct snd_compr_runtime *runtime;struct snd_compr *device; +struct delayed_work error_work;enum snd_compr_direction direction;bool metadata_set;bool next_track;
@@ -187,4 +188,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream) wake_up(&stream->runtime->sleep); } +int snd_compr_stop_error (struct snd_compr_stream *stream, +snd_pcm_state_t state); +#endif
sound/core/compress_offload.c +59 -1
105 lines not on this page · raw message
Signature · 1 line
2.1.4
v3 cover Propagate errors out from compressed streams
If the DSP suffers an unrecoverable error, the driver likely knows about this, however the framework may not get informed because errors returned from pointer requests are ignored within the framework.
Things work out fine if user-space is doing a read as reads return error status back to user-space so the user can find out that things have gone bad. However, if user-space is doing an avail request there is no path for the error to come back up to user-space. The pointer request returns zero available data, so a read never happens and we basically just end up sitting waiting for data on a stream that we know full well has died.
This patch set attempts to address this and ensure that errors are fully propagated to user-space and we don't ever end up wait for data that will never come.
Changes since v2:
- Make naming of stop function more generic and allow it to specify target state
Thanks,
Charles
Charles Keepax (4):
ALSA: compress: Replace complex if statement with switch
ALSA: compress: Add function to indicate the stream has gone bad
ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure
ASoC: compress: Pass error out of soc_compr_pointer
include/sound/compress_driver.h | 4 +++ sound/core/compress_offload.c | 69 ++++++++++++++++++++++++++++++++++++++--- sound/soc/codecs/wm_adsp.c | 11 +++++-- sound/soc/soc-compress.c | 5 +-- 4 files changed, 81 insertions(+), 8 deletions(-)
Signature · 1 line
2.1.4
PATCH v3 1/4 ALSA: compress: Replace complex if statement with switch
A switch statement looks a bit cleaner than an if statement spread over 3 lines, as such update this to a switch.
--- sound/core/compress_offload.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
sound/core/compress_offload.c +6 -3
@@ -288,9 +288,12 @@ static ssize_t snd_compr_write(struct file *f, const char __user *buf, stream = &data->stream;mutex_lock (&stream->device->lock);/* write is allowed when stream is running or has been steup */ -if (stream->runtime->state !=SNDRV_PCM_STATE_SETUP && - stream->runtime->state !=SNDRV_PCM_STATE_PREPARED && - stream->runtime->state !=SNDRV_PCM_STATE_RUNNING ) { +switch (stream->runtime->state) { +case SNDRV_PCM_STATE_SETUP : +case SNDRV_PCM_STATE_PREPARED : +case SNDRV_PCM_STATE_RUNNING : +break ; +default :mutex_unlock (&stream->device->lock);return -EBADFD ; }
Signature · 1 line
2.1.4
PATCH v3 3/4 ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure
In reply to Charles KeepaxIf we encounter a fatal error on the compressed stream call the new snd_compr_stop_error to shutdown the stream and allow the core to inform user-space that the stream is no longer valid.
--- sound/soc/codecs/wm_adsp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
sound/soc/codecs/wm_adsp.c +9 -2
@@ -2913,6 +2913,7 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream, }if (compr->buf->error) { +snd_compr_stop_error (stream,SNDRV_PCM_STATE_XRUN ); ret = -EIO ; goto out; }
@@ -2930,8 +2931,12 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,*/ if (buf->avail <wm_adsp_compr_frag_words (compr)) { ret =wm_adsp_buffer_get_error (buf); -if (ret <0 ) +if (ret <0 ) { +if (compr->buf->error) +snd_compr_stop_error (stream, +SNDRV_PCM_STATE_XRUN ); goto out; + } ret =wm_adsp_buffer_reenable_irq (buf);if (ret <0 ) {
@@ -3029,8 +3034,10 @@ static int wm_adsp_compr_read(struct wm_adsp_compr *compr,if (!compr->buf)return -ENXIO ; -if (compr->buf->error) +if (compr->buf->error) { +snd_compr_stop_error (compr->stream,SNDRV_PCM_STATE_XRUN );return -EIO ; + } count /=WM_ADSP_DATA_WORD_SIZE ;
Signature · 1 line
2.1.4
PATCH v3 4/4 ASoC: compress: Pass error out of soc_compr_pointer
In reply to Charles KeepaxBoth soc_compr_pointer and the platform driver pointer callback return ints but current soc_compr_pointer always returns 0. Update this so we return the actual value from the platform driver callback. This doesn't fix any issues simply makes the code more consistent.
--- sound/soc/soc-compress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/soc-compress.c +3 -2
@@ -530,14 +530,15 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream, {struct snd_soc_pcm_runtime *rtd = cstream->private_data;struct snd_soc_platform *platform = rtd->platform; +int ret =0 ;mutex_lock_nested (&rtd->pcm_mutex, rtd->pcm_subclass);if (platform->driver->compr_ops && platform->driver->compr_ops->pointer) - platform->driver->compr_ops->pointer (cstream, tstamp); + ret = platform->driver->compr_ops->pointer (cstream, tstamp);mutex_unlock (&rtd->pcm_mutex); -return 0 ; +return ret; } static int soc_compr_copy(struct snd_compr_stream *cstream,
Signature · 1 line
2.1.4
Re: [PATCH v3 2/4] ALSA: compress: Add function to indicate the stream has gone bad
In reply to Charles KeepaxQuoted 74 lines · Charles Keepax
Currently, the avail IOCTL doesn't pass any error status, which means typically on error it simply shows no data available. This can lead to situations where user-space is waiting indefinitely for data that will never come as the DSP has suffered an unrecoverable error.
Add
snd_compr_stop_errorwhich end drivers can call to indicate the stream has suffered an unrecoverable error and stop it. The avail and poll IOCTLs are then updated to report if the stream is in an error state to user-space. Allowing the error to propagate out. Processing of the actualsnd_compr_stopneeds to be deferred to a worker thread as the end driver may detect the errors during an existing operation callback.Signed-off-by Charles Keepax <[email protected]>--- include/sound/compress_driver.h | 4 +++ sound/core/compress_offload.c | 60 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-)include/sound/compress_driver.h +4
-0@@ -78,6 +78,7 @@ struct snd_compr_stream {struct snd_compr_ops *ops;struct snd_compr_runtime *runtime;struct snd_compr *device; +struct delayed_work error_work;enum snd_compr_direction direction;bool metadata_set;bool next_track;@@ -187,4 +188,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream) wake_up(&stream->runtime->sleep); } +int snd_compr_stop_error (struct snd_compr_stream *stream, +snd_pcm_state_t state); +#endif sound/core/compress_offload.c +7
-0@@ -67,6 +67,8 @@ struct snd_compr_file {struct snd_compr_stream stream; }; +static void error_delayed_work (struct work_struct *work); +/* * a note on stream states used: * we use following states in the compressed core @@ -123,6 +125,9 @@ static int snd_compr_open(struct inode *inode, struct file *f)snd_card_unref (compr->card);return -ENOMEM ; } + +INIT_DELAYED_WORK (&data->stream.error_work, error_delayed_work); + data->stream.ops = compr->ops; data->stream.direction = dirn; data->stream.private_data = compr->private_data;@@ -153,6 +158,8 @@ static int snd_compr_free(struct inode *inode, struct file *f)struct snd_compr_file *data = f->private_data;struct snd_compr_runtime *runtime = data->stream.runtime; +cancel_delayed_work_sync (&data->stream.error_work); +switch (runtime->state) {case SNDRV_PCM_STATE_RUNNING :case SNDRV_PCM_STATE_DRAINING :
sound/core/compress_offload.c snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) · line 250
Quoted 7 lines
sound/core/compress_offload.c +4
-0@@ -237,6 +244,14 @@ snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) avail =snd_compr_calc_avail (stream, &ioctl_avail); ioctl_avail.avail = avail; +switch (stream->runtime->state) { +case SNDRV_PCM_STATE_OPEN : +case SNDRV_PCM_STATE_XRUN : +return -EBADFD ;
One question is whether we want a dedicated error code for XRUN or such a DSP error. On PCM, for example, we return -EPIPE traditionally for XRUN state. This is a clear indicator for user what to do at next.
Other than that, the patch series looks good to me.
thanks,
Takashi
Re: [PATCH v3 2/4] ALSA: compress: Add function to indicate the stream has gone bad
Quoted 12 lines · Takashi Iwai
sound/core/compress_offload.c snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) · line 250
Quoted 4 lines · Charles Keepax
sound/core/compress_offload.c +4
-0+switch (stream->runtime->state) { +case SNDRV_PCM_STATE_OPEN : +case SNDRV_PCM_STATE_XRUN : +return -EBADFD ;One question is whether we want a dedicated error code for XRUN or such a DSP error. On PCM, for example, we return
-EPIPEtraditionally for XRUN state. This is a clear indicator for user what to do at next.
Quoted 1 line
Other than that, the patch series looks good to me.
I think it probably makes sense to copy what the PCM framework does here, I will respin and use EPIPE.
Thanks,
Charles
Mark Brown
maintainerApplied "ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure" to the asoc tree
In reply to Charles KeepaxThe patch
ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
8d280664d26538cd37e7c08b1c2b58fe006cc482Mon Sep 17 00:00:00 2001
From: Charles Keepax <[email protected]>
Date: Mon, 13 Jun 2016 14:17:11 +0100
Subject: [PATCH] ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream
failure
If we encounter a fatal error on the compressed stream call the new snd_compr_stop_error to shutdown the stream and allow the core to inform user-space that the stream is no longer valid.
--- sound/soc/codecs/wm_adsp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
sound/soc/codecs/wm_adsp.c +9 -2
@@ -3043,6 +3043,7 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream, }if (compr->buf->error) { +snd_compr_stop_error (stream,SNDRV_PCM_STATE_XRUN ); ret = -EIO ; goto out; }
@@ -3060,8 +3061,12 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,*/ if (buf->avail <wm_adsp_compr_frag_words (compr)) { ret =wm_adsp_buffer_get_error (buf); -if (ret <0 ) +if (ret <0 ) { +if (compr->buf->error) +snd_compr_stop_error (stream, +SNDRV_PCM_STATE_XRUN ); goto out; + } ret =wm_adsp_buffer_reenable_irq (buf);if (ret <0 ) {
@@ -3159,8 +3164,10 @@ static int wm_adsp_compr_read(struct wm_adsp_compr *compr,if (!compr->buf)return -ENXIO ; -if (compr->buf->error) +if (compr->buf->error) { +snd_compr_stop_error (compr->stream,SNDRV_PCM_STATE_XRUN );return -EIO ; + } count /=WM_ADSP_DATA_WORD_SIZE ;
Signature · 1 line
2.8.1