* [PATCH v6 0/4] Propagate errors out from compressed streams
@ 2016-04-22 15:15 Charles Keepax
2016-04-22 15:15 ` [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch Charles Keepax
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Charles Keepax @ 2016-04-22 15:15 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
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 v5:
- Add a debug print to note which state we transition to in
snd_compr_stop_error
It might be easiest to put the ASoC changes through Mark's tree
as there are some merge conflicts otherwise, as such I have based
this series on Mark's tree.
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 | 5 +++
sound/core/compress_offload.c | 81 ++++++++++++++++++++++++++++++++++++++---
sound/soc/codecs/wm_adsp.c | 11 +++++-
sound/soc/soc-compress.c | 5 ++-
4 files changed, 93 insertions(+), 9 deletions(-)
--
2.1.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch
2016-04-22 15:15 [PATCH v6 0/4] Propagate errors out from compressed streams Charles Keepax
@ 2016-04-22 15:15 ` Charles Keepax
2016-05-04 15:01 ` Charles Keepax
2016-04-22 15:15 ` [PATCH v6 2/4] ALSA: compress: Add function to indicate the stream has gone bad Charles Keepax
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Charles Keepax @ 2016-04-22 15:15 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
A switch statement looks a bit cleaner than an if statement
spread over 3 lines, as such update this to a switch.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Vinod Koul <vinod.koul@intel.com>
---
sound/core/compress_offload.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index a9933c0..507071d 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -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;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 2/4] ALSA: compress: Add function to indicate the stream has gone bad
2016-04-22 15:15 [PATCH v6 0/4] Propagate errors out from compressed streams Charles Keepax
2016-04-22 15:15 ` [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch Charles Keepax
@ 2016-04-22 15:15 ` Charles Keepax
2016-05-03 16:57 ` Charles Keepax
2016-04-22 15:15 ` [PATCH v6 3/4] ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure Charles Keepax
2016-04-22 15:15 ` [PATCH v6 4/4] ASoC: compress: Pass error out of soc_compr_pointer Charles Keepax
3 siblings, 1 reply; 7+ messages in thread
From: Charles Keepax @ 2016-04-22 15:15 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
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_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.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Vinod Koul <vinod.koul@intel.com>
---
include/sound/compress_driver.h | 5 +++
sound/core/compress_offload.c | 72 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
index c0abcdc..cee8c00 100644
--- a/include/sound/compress_driver.h
+++ b/include/sound/compress_driver.h
@@ -68,6 +68,7 @@ struct snd_compr_runtime {
* @ops: pointer to DSP callbacks
* @runtime: pointer to runtime structure
* @device: device pointer
+ * @error_work: delayed work used when closing the stream due to an error
* @direction: stream direction, playback/recording
* @metadata_set: metadata set flag, true when set
* @next_track: has userspace signal next track transition, true when set
@@ -78,6 +79,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 +189,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
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 507071d..28fb0ad 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -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:
@@ -237,6 +244,15 @@ 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:
+ return -EBADFD;
+ case SNDRV_PCM_STATE_XRUN:
+ return -EPIPE;
+ default:
+ break;
+ }
+
if (copy_to_user((__u64 __user *)arg,
&ioctl_avail, sizeof(ioctl_avail)))
return -EFAULT;
@@ -346,11 +362,13 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
switch (stream->runtime->state) {
case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_PREPARED:
- case SNDRV_PCM_STATE_XRUN:
case SNDRV_PCM_STATE_SUSPENDED:
case SNDRV_PCM_STATE_DISCONNECTED:
retval = -EBADFD;
goto out;
+ case SNDRV_PCM_STATE_XRUN:
+ retval = -EPIPE;
+ goto out;
}
avail = snd_compr_get_avail(stream);
@@ -400,10 +418,18 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
return -EFAULT;
mutex_lock(&stream->device->lock);
- if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
+
+ switch (stream->runtime->state) {
+ case SNDRV_PCM_STATE_OPEN:
retval = -EBADFD;
goto out;
+ case SNDRV_PCM_STATE_XRUN:
+ retval = -EPIPE;
+ goto out;
+ default:
+ break;
}
+
poll_wait(f, &stream->runtime->sleep, wait);
avail = snd_compr_get_avail(stream);
@@ -423,6 +449,9 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
if (avail >= stream->runtime->fragment_size)
retval = snd_compr_get_poll(stream);
break;
+ case SNDRV_PCM_STATE_XRUN:
+ retval = -EPIPE;
+ break;
default:
if (stream->direction == SND_COMPRESS_PLAYBACK)
retval = POLLOUT | POLLWRNORM | POLLERR;
@@ -701,6 +730,45 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
return retval;
}
+static void error_delayed_work(struct work_struct *work)
+{
+ struct snd_compr_stream *stream;
+
+ stream = container_of(work, struct snd_compr_stream, error_work.work);
+
+ mutex_lock(&stream->device->lock);
+
+ if (!stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP))
+ wake_up(&stream->runtime->sleep);
+
+ mutex_unlock(&stream->device->lock);
+}
+
+/*
+ * snd_compr_stop_error: Report a fatal error on a stream
+ * @stream: pointer to stream
+ * @state: state to transition the stream to
+ *
+ * Stop the stream and set its state.
+ *
+ * Should be called with compressed device lock held.
+ */
+int snd_compr_stop_error(struct snd_compr_stream *stream,
+ snd_pcm_state_t state)
+{
+ if (stream->runtime->state == state)
+ return 0;
+
+ stream->runtime->state = state;
+
+ pr_debug("Changing state to: %d\n", state);
+
+ queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(snd_compr_stop_error);
+
static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
{
int ret;
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 3/4] ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure
2016-04-22 15:15 [PATCH v6 0/4] Propagate errors out from compressed streams Charles Keepax
2016-04-22 15:15 ` [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch Charles Keepax
2016-04-22 15:15 ` [PATCH v6 2/4] ALSA: compress: Add function to indicate the stream has gone bad Charles Keepax
@ 2016-04-22 15:15 ` Charles Keepax
2016-04-22 15:15 ` [PATCH v6 4/4] ASoC: compress: Pass error out of soc_compr_pointer Charles Keepax
3 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2016-04-22 15:15 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
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.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Reviewed-by: Vinod Koul <vinod.koul@intel.com>
---
sound/soc/codecs/wm_adsp.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index 3ac2e1f..d221ac9 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -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;
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 4/4] ASoC: compress: Pass error out of soc_compr_pointer
2016-04-22 15:15 [PATCH v6 0/4] Propagate errors out from compressed streams Charles Keepax
` (2 preceding siblings ...)
2016-04-22 15:15 ` [PATCH v6 3/4] ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure Charles Keepax
@ 2016-04-22 15:15 ` Charles Keepax
3 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2016-04-22 15:15 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
Both 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.
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Vinod Koul <vinod.koul@intel.com>
---
sound/soc/soc-compress.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 875733c..d2df46c 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -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,
--
2.1.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/4] ALSA: compress: Add function to indicate the stream has gone bad
2016-04-22 15:15 ` [PATCH v6 2/4] ALSA: compress: Add function to indicate the stream has gone bad Charles Keepax
@ 2016-05-03 16:57 ` Charles Keepax
0 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2016-05-03 16:57 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
On Fri, Apr 22, 2016 at 04:15:24PM +0100, Charles Keepax wrote:
> 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_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.
>
> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> Acked-by: Vinod Koul <vinod.koul@intel.com>
> ---
> @@ -400,10 +418,18 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
> return -EFAULT;
>
> mutex_lock(&stream->device->lock);
> - if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
> +
> + switch (stream->runtime->state) {
> + case SNDRV_PCM_STATE_OPEN:
> retval = -EBADFD;
> goto out;
> + case SNDRV_PCM_STATE_XRUN:
> + retval = -EPIPE;
> + goto out;
> + default:
> + break;
> }
One more issue to fix up before we can submit these I am afraid.
We can't return negative values from snd_compr_poll, I need to
fix both the original -EBADFD and the -EPIPE that my patch adds
here.
I will do a new rev of the patches shortly, sorry about missing
this until now.
Thanks,
Charles
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch
2016-04-22 15:15 ` [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch Charles Keepax
@ 2016-05-04 15:01 ` Charles Keepax
0 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2016-05-04 15:01 UTC (permalink / raw)
To: vinod.koul, tiwai, broonie; +Cc: alsa-devel, patches, lgirdwood
On Fri, Apr 22, 2016 at 04:15:23PM +0100, Charles Keepax wrote:
> A switch statement looks a bit cleaner than an if statement
> spread over 3 lines, as such update this to a switch.
>
> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> Acked-by: Vinod Koul <vinod.koul@intel.com>
> ---
As this patch only tenuously relates to the rest of this patch
chain I have included it in a new patch chain [1], best not merge the
one from here so they don't both end up merged through different
trees.
Thanks,
Charles
[1] http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107636.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-05-04 15:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-22 15:15 [PATCH v6 0/4] Propagate errors out from compressed streams Charles Keepax
2016-04-22 15:15 ` [PATCH v6 1/4] ALSA: compress: Replace complex if statement with switch Charles Keepax
2016-05-04 15:01 ` Charles Keepax
2016-04-22 15:15 ` [PATCH v6 2/4] ALSA: compress: Add function to indicate the stream has gone bad Charles Keepax
2016-05-03 16:57 ` Charles Keepax
2016-04-22 15:15 ` [PATCH v6 3/4] ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failure Charles Keepax
2016-04-22 15:15 ` [PATCH v6 4/4] ASoC: compress: Pass error out of soc_compr_pointer Charles Keepax
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).