-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/dev/snd/timer hangs on poll when using alsa dmix #1888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Confirmed as definitely hanging on Linux dev2 4.9.24-v7+ #993 SMP Wed Apr 26 18:01:23 BST 2017 with a standard config.
|
Still there in |
I can not reproduce the issue while working with the adafruit speaker bonnet, which uses |
Confirmed on |
Fairly old issue, but could anyone seeing the issue ensure they are running the latest kernel (currently 4.14.y) and confirm whether this issue is still present? |
Problem still exists in kernel 4.14.52 (commit be09ec5), running against rpi-firmware 2018-07-03 (commit 36ecc7f415d2593d975b6cfaed82a3a7cf344703) |
Stumbled on this one, still actual on
|
Still present on 4.19.71 (tested on Pi4) |
Been taking a brief look at this - the alsa code is fairly impenetrable so my suspicion is that it's going to take someone more expert in Alsa than me to figure out what the issue is. The code where it stalls is snd_timer_user_read in sound/core/timer.c. I've found a timer test app which does actually fail if run too quickly which might help, need to try it on an Ubuntu system to double check if the failure I see is expected. |
I see a similar issue with pyaudio. While aplay (without dmix) works fine, the simple pyaudio examples hang on an infinite loop of poll calls to /dev/snd/timer and never play any audio. Here's a strace snippet:
This is on a Pi4 with 4.19.118-v7l |
On my read of the code, this appears to be related to the PCM timer. Per kconfig:
The driver is meant to call snd_pcm_period_elapsed() at regular intervals in an IRQ which will wake-up the userspace processes waiting on the PCM timer. I suspect the bcm2835 driver is doing this incorrectly. My guess is the driver is only calling the period elapsed function after there's data but userspace expects to get the timer events before it sends data. See the comments in bcm2835_playback_fifo() |
I think you are mistaken about
Note that it says "when the PCM has processed the period size", not "when a period of time has elapsed". And the kernel document "Writing an ALSA driver" says:
and
Both of these cases - hardware interrupt and HR timer callback - call Some audio mixing frameworks play silence even when there are no clients actively generating audio. This would result in the kind of continuous callbacks you refer to, but that is not the way ALSA behaves natively - it handles a single client, starting playback when there is some data and stopping it at the end. |
Well, regardless of the documentation (which may be wrong and/or confusing), the fact of the matter is snd_pcm_period_elapsed() is what will trigger the timer interrupt and allow userspace to continue. It is not getting called at the appropriate time (whatever that may be) and userspace is hanging because of it. snd_pcm_period_elapsed() calls snd_timer_interrupt() which calls snd_timer_user_interrupt() (via the callback) and that function increments qused and wakes up qchange_sleep which is what will allow the userspace process to continue. |
Uh oh!
There was an error while loading. Please reload this page.
As far as I can tell, this has been around for a while.
To recreate, it should be as simple as:
The interesting thing seen in the strace is it appears that the first poll on /dev/snd/timer works fine and the 2nd one hangs.
Host
config.txt:
The text was updated successfully, but these errors were encountered: