aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinod Koul <vinod.koul@intel.com>2013-11-07 04:08:22 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-29 14:11:45 -0500
commit86e6de789cfeb2bb6c532281e16a478d797f3598 (patch)
treee3e3b4294e97635015a0863099a889cfb78356e3
parent16442d4ff3014c84008266feee1e36befd84c8c3 (diff)
ALSA: compress: fix drain calls blocking other compress functions (v6)
commit f44f2a5417b2968a8724b352cc0b2545a6bcb1f4 upstream. The drain and drain_notify callback were blocked by low level driver until the draining was complete. Due to this being invoked with big fat mutex held, others ops like reading timestamp, calling pause, drop were blocked. So to fix this we add a new snd_compr_drain_notify() API. This would be required to be invoked by low level driver when drain or partial drain has been completed by the DSP. Thus we make the drain and partial_drain callback as non blocking and driver returns immediately after notifying DSP. The waiting is done while releasing the lock so that other ops can go ahead. [ The commit 917f4b5cba78 was wrongly applied from the preliminary patch. This commit corrects to the final version. Sorry for inconvenience! -- tiwai ] Signed-off-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--include/sound/compress_driver.h11
-rw-r--r--sound/core/compress_offload.c31
2 files changed, 23 insertions, 19 deletions
diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
index 175ab3237b58..ae6c3b8ed2f5 100644
--- a/include/sound/compress_driver.h
+++ b/include/sound/compress_driver.h
@@ -48,8 +48,6 @@ struct snd_compr_ops;
48 * the ring buffer 48 * the ring buffer
49 * @total_bytes_transferred: cumulative bytes transferred by offload DSP 49 * @total_bytes_transferred: cumulative bytes transferred by offload DSP
50 * @sleep: poll sleep 50 * @sleep: poll sleep
51 * @wait: drain wait queue
52 * @drain_wake: condition for drain wake
53 */ 51 */
54struct snd_compr_runtime { 52struct snd_compr_runtime {
55 snd_pcm_state_t state; 53 snd_pcm_state_t state;
@@ -61,8 +59,6 @@ struct snd_compr_runtime {
61 u64 total_bytes_available; 59 u64 total_bytes_available;
62 u64 total_bytes_transferred; 60 u64 total_bytes_transferred;
63 wait_queue_head_t sleep; 61 wait_queue_head_t sleep;
64 wait_queue_head_t wait;
65 unsigned int drain_wake;
66 void *private_data; 62 void *private_data;
67}; 63};
68 64
@@ -177,10 +173,11 @@ static inline void snd_compr_fragment_elapsed(struct snd_compr_stream *stream)
177 173
178static inline void snd_compr_drain_notify(struct snd_compr_stream *stream) 174static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
179{ 175{
180 snd_BUG_ON(!stream); 176 if (snd_BUG_ON(!stream))
177 return;
181 178
182 stream->runtime->drain_wake = 1; 179 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
183 wake_up(&stream->runtime->wait); 180 wake_up(&stream->runtime->sleep);
184} 181}
185 182
186#endif 183#endif
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 68d3ffcac78b..19799931c51d 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -123,7 +123,6 @@ static int snd_compr_open(struct inode *inode, struct file *f)
123 } 123 }
124 runtime->state = SNDRV_PCM_STATE_OPEN; 124 runtime->state = SNDRV_PCM_STATE_OPEN;
125 init_waitqueue_head(&runtime->sleep); 125 init_waitqueue_head(&runtime->sleep);
126 init_waitqueue_head(&runtime->wait);
127 data->stream.runtime = runtime; 126 data->stream.runtime = runtime;
128 f->private_data = (void *)data; 127 f->private_data = (void *)data;
129 mutex_lock(&compr->lock); 128 mutex_lock(&compr->lock);
@@ -669,8 +668,6 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
669 return -EPERM; 668 return -EPERM;
670 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); 669 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
671 if (!retval) { 670 if (!retval) {
672 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
673 wake_up(&stream->runtime->sleep);
674 snd_compr_drain_notify(stream); 671 snd_compr_drain_notify(stream);
675 stream->runtime->total_bytes_available = 0; 672 stream->runtime->total_bytes_available = 0;
676 stream->runtime->total_bytes_transferred = 0; 673 stream->runtime->total_bytes_transferred = 0;
@@ -680,6 +677,8 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
680 677
681static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) 678static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
682{ 679{
680 int ret;
681
683 /* 682 /*
684 * We are called with lock held. So drop the lock while we wait for 683 * We are called with lock held. So drop the lock while we wait for
685 * drain complete notfication from the driver 684 * drain complete notfication from the driver
@@ -691,12 +690,24 @@ static int snd_compress_wait_for_drain(struct snd_compr_stream *stream)
691 stream->runtime->state = SNDRV_PCM_STATE_DRAINING; 690 stream->runtime->state = SNDRV_PCM_STATE_DRAINING;
692 mutex_unlock(&stream->device->lock); 691 mutex_unlock(&stream->device->lock);
693 692
694 wait_event(stream->runtime->wait, stream->runtime->drain_wake); 693 /* we wait for drain to complete here, drain can return when
694 * interruption occurred, wait returned error or success.
695 * For the first two cases we don't do anything different here and
696 * return after waking up
697 */
698
699 ret = wait_event_interruptible(stream->runtime->sleep,
700 (stream->runtime->state != SNDRV_PCM_STATE_DRAINING));
701 if (ret == -ERESTARTSYS)
702 pr_debug("wait aborted by a signal");
703 else if (ret)
704 pr_debug("wait for drain failed with %d\n", ret);
705
695 706
696 wake_up(&stream->runtime->sleep); 707 wake_up(&stream->runtime->sleep);
697 mutex_lock(&stream->device->lock); 708 mutex_lock(&stream->device->lock);
698 709
699 return 0; 710 return ret;
700} 711}
701 712
702static int snd_compr_drain(struct snd_compr_stream *stream) 713static int snd_compr_drain(struct snd_compr_stream *stream)
@@ -707,17 +718,14 @@ static int snd_compr_drain(struct snd_compr_stream *stream)
707 stream->runtime->state == SNDRV_PCM_STATE_SETUP) 718 stream->runtime->state == SNDRV_PCM_STATE_SETUP)
708 return -EPERM; 719 return -EPERM;
709 720
710 stream->runtime->drain_wake = 0;
711 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); 721 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN);
712 if (retval) { 722 if (retval) {
713 pr_err("SND_COMPR_TRIGGER_DRAIN failed %d\n", retval); 723 pr_debug("SND_COMPR_TRIGGER_DRAIN failed %d\n", retval);
714 wake_up(&stream->runtime->sleep); 724 wake_up(&stream->runtime->sleep);
715 return retval; 725 return retval;
716 } 726 }
717 727
718 retval = snd_compress_wait_for_drain(stream); 728 return snd_compress_wait_for_drain(stream);
719 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
720 return retval;
721} 729}
722 730
723static int snd_compr_next_track(struct snd_compr_stream *stream) 731static int snd_compr_next_track(struct snd_compr_stream *stream)
@@ -752,10 +760,9 @@ static int snd_compr_partial_drain(struct snd_compr_stream *stream)
752 if (stream->next_track == false) 760 if (stream->next_track == false)
753 return -EPERM; 761 return -EPERM;
754 762
755 stream->runtime->drain_wake = 0;
756 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); 763 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN);
757 if (retval) { 764 if (retval) {
758 pr_err("Partial drain returned failure\n"); 765 pr_debug("Partial drain returned failure\n");
759 wake_up(&stream->runtime->sleep); 766 wake_up(&stream->runtime->sleep);
760 return retval; 767 return retval;
761 } 768 }