[alsa-devel] snd_pcm_drop causing lockup with DMix
Hi,
A couple of weeks ago I reported a rather serious bug #4914 that can cause a multi-threaded using ALSA to lock up so that it can only be ended with SIGKILL.
I maintain the ALSA output part of Audacious, and I need to be able to play audio in one thread of the program and then signal that thread to stop from another. The way to do this in ALSA, if I understand correctly, is to interrupt the thread that is sending audio with a call to snd_pcm_drop. But using DMix makes the first thread hang up in a snd_pcm_wait call with a timeout of -1.
Is anyone working on this bug? Is there any more help I can provide?
John Lindgren
On Sun, 28 Feb 2010, John Lindgren wrote:
Hi,
A couple of weeks ago I reported a rather serious bug #4914 that can cause a multi-threaded using ALSA to lock up so that it can only be ended with SIGKILL.
I maintain the ALSA output part of Audacious, and I need to be able to play audio in one thread of the program and then signal that thread to stop from another. The way to do this in ALSA, if I understand correctly, is to interrupt the thread that is sending audio with a call to snd_pcm_drop. But using DMix makes the first thread hang up in a snd_pcm_wait call with a timeout of -1.
Is anyone working on this bug? Is there any more help I can provide?
Could you try this patch?
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index d9e596e..8c7ca06 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1274,6 +1274,7 @@ int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix) snd_timer_params_set_ticks(params, 1); if (dmix->tread) { filter = (1<<SND_TIMER_EVENT_TICK) | + (1<<SND_TIMER_EVENT_STOP) | dmix->timer_event_suspend | dmix->timer_event_resume; snd_timer_params_set_filter(params, filter);
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Unfortunately, it doesn't make a difference.
On Sun, 2010-02-28 at 17:22 +0100, Jaroslav Kysela wrote:
Could you try this patch?
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index d9e596e..8c7ca06 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1274,6 +1274,7 @@ int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix) snd_timer_params_set_ticks(params, 1); if (dmix->tread) { filter = (1<<SND_TIMER_EVENT_TICK) |
(1<<SND_TIMER_EVENT_STOP) | dmix->timer_event_suspend | dmix->timer_event_resume;
snd_timer_params_set_filter(params, filter);
Jaroslav
Jaroslav Kysela perex@perex.cz
On Sun, 28 Feb 2010, John Lindgren wrote:
Unfortunately, it doesn't make a difference.
And this one?
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index d9e596e..ae32fab 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -540,7 +540,6 @@ void snd_pcm_direct_clear_timer_queue(snd_pcm_direct_t *dmix) int snd_pcm_direct_timer_stop(snd_pcm_direct_t *dmix) { snd_timer_stop(dmix->timer); - snd_pcm_direct_clear_timer_queue(dmix); return 0; }
@@ -1274,6 +1273,7 @@ int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix) snd_timer_params_set_ticks(params, 1); if (dmix->tread) { filter = (1<<SND_TIMER_EVENT_TICK) | + (1<<SND_TIMER_EVENT_STOP) | dmix->timer_event_suspend | dmix->timer_event_resume; snd_timer_params_set_filter(params, filter);
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Still no difference.
I also noticed that with or without the patch, Audacious will occasionally not hang up, and instead the snd_pcm_writei call that is interrupted will return -EBADFD. I haven't seen the test case do the same.
On Mon, 2010-03-01 at 07:53 +0100, Jaroslav Kysela wrote:
And this one?
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index d9e596e..ae32fab 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -540,7 +540,6 @@ void snd_pcm_direct_clear_timer_queue(snd_pcm_direct_t *dmix) int snd_pcm_direct_timer_stop(snd_pcm_direct_t *dmix) { snd_timer_stop(dmix->timer);
- snd_pcm_direct_clear_timer_queue(dmix); return 0; }
@@ -1274,6 +1273,7 @@ int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix) snd_timer_params_set_ticks(params, 1); if (dmix->tread) { filter = (1<<SND_TIMER_EVENT_TICK) |
snd_timer_params_set_filter(params, filter);(1<<SND_TIMER_EVENT_STOP) | dmix->timer_event_suspend | dmix->timer_event_resume;
Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
On Mon, 1 Mar 2010, John Lindgren wrote:
Still no difference.
I also noticed that with or without the patch, Audacious will occasionally not hang up, and instead the snd_pcm_writei call that is interrupted will return -EBADFD. I haven't seen the test case do the same.
Could you provide a simple C program to test this issue? You may modify alsa-lib/src/test/pcm_min.c for example.
Thanks, Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
On Tue, 2010-03-02 at 14:25 +0100, Jaroslav Kysela wrote:
Could you provide a simple C program to test this issue? You may modify alsa-lib/src/test/pcm_min.c for example.
There is already one attached to the bug report page:
https://bugtrack.alsa-project.org/alsa-bug/bug_view_advanced_page.php?bug_id...
Thanks for investigating this.
John Lindgren
On Tue, 2 Mar 2010, John Lindgren wrote:
On Tue, 2010-03-02 at 14:25 +0100, Jaroslav Kysela wrote:
Could you provide a simple C program to test this issue? You may modify alsa-lib/src/test/pcm_min.c for example.
There is already one attached to the bug report page:
https://bugtrack.alsa-project.org/alsa-bug/bug_view_advanced_page.php?bug_id...
Thanks for investigating this.
This commit should solve this issue:
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=b9dbee694a94a7246...
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
Confirmed, that fixes the hangup. A minor issue remains that snd_pcm_writei still always returns -EIO or -EBADFD in this situation.
John Lindgren
On Wed, 2010-03-03 at 11:01 +0100, Jaroslav Kysela wrote:
This commit should solve this issue:
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=b9dbee694a94a7246...
Jaroslav
On Wed, 3 Mar 2010, John Lindgren wrote:
Confirmed, that fixes the hangup. A minor issue remains that snd_pcm_writei still always returns -EIO or -EBADFD in this situation.
I don't see a problem here. If transfer is stopped, the pcm handle is not initialized for I/O transactions, thus upper layers return these errors.
Your application should check snd_pcm_state() in case of error and look if stream is inactive (back in SND_PCM_STATE_SETUP), because your application invoked the drop() call.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
participants (2)
-
Jaroslav Kysela
-
John Lindgren