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
Quoted 6 lines · John Lindgren
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.
Quoted 8 lines
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 asnd_pcm_waitcall with a timeout of -1.Is anyone working on this bug? Is there any more help I can provide?
Could you try this patch?
src/pcm/pcm_direct.c +1 -0
@@ -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 <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
Unfortunately, it doesn't make a difference.
Quoted 19 lines · Jaroslav Kysela
Could you try this patch?
src/pcm/pcm_direct.c +1
-0@@ -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 <[email protected]>
Quoted 1 line · John Lindgren
Unfortunately, it doesn't make a difference.
And this one?
src/pcm/pcm_direct.c +1 -1
@@ -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 <[email protected]>
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.
Quoted 27 lines · Jaroslav Kysela
And this one?
src/pcm/pcm_direct.c +1
-2@@ -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 <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
Quoted 6 lines · John Lindgren
Still no difference.
I also noticed that with or without the patch, Audacious will occasionally not hang up, and instead the
snd_pcm_writeicall 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 <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
Quoted 2 lines · Jaroslav Kysela
Could you provide a simple C program to test this issue? You may modify
alsa-lib/src/test/pcm_min.cfor 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=4914
Thanks for investigating this.
John Lindgren
Quoted 9 lines · John Lindgren
Quoted 2 lines · Jaroslav Kysela
Could you provide a simple C program to test this issue? You may modify
alsa-lib/src/test/pcm_min.cfor 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=4914
Thanks for investigating this.
This commit should solve this issue:
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=b9dbee694a94a724670b36f4df1aeceb0dd4a261
Jaroslav
-----
Jaroslav Kysela <[email protected]>
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
Quoted 5 lines · Jaroslav Kysela
This commit should solve this issue:
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=b9dbee694a94a724670b36f4df1aeceb0dd4a261
Jaroslav
Quoted 2 lines · John Lindgren
Confirmed, that fixes the hangup. A minor issue remains that
snd_pcm_writeistill always returns-EIOor-EBADFDin 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 <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.