[alsa-devel] alsactl monitor spins at 100% cpu after unplugging USB headphones

Takashi Sakamoto o-takashi at sakamocchi.jp
Tue Oct 2 11:01:15 CEST 2018


Hi,

On Sep 30 2018 23:32, Thomas Gläßle wrote:
> on both my desktop and laptop (archlinux), `alsactl monitor` beginns
> spinning at 100% cpu when I unplug my USB headset. This happens every
> time and can be reproduced as follows:
> 
> - plug in USB headphones
> - start `alsactl monitor`
> - unplug headphones
> 
> It happens only if the headphones are already plugged in when starting
> alsactl.
> 
> The increased activity does not lead to spamming stdout or similar,
> alsactl continues to perform seemingly correct, i.e. reports when I
> change volume levels etc, but nothing apart from the ordinary.

Thank you for this report and I can regenerate this problem.

$ strace alsactl monitor
...
(disconnect my sound device)
poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}, {fd=4, 
events=POLLIN|POLLERR|POLLNVAL}, {fd=5, 
events=POLLIN|POLLERR|POLLNVAL}], 3, -1) = 1 ([{fd=5, 
revents=POLLERR|POLLNVAL}])
poll([{fd=3, events=POLLIN|POLLERR|POLLNVAL}, {fd=4, 
events=POLLIN|POLLERR|POLLNVAL}, {fd=5, 
events=POLLIN|POLLERR|POLLNVAL}], 3, -1) = 1 ([{fd=5, 
revents=POLLERR|POLLNVAL}])
...

This is a bug of alsactl due to handling return code of poll(2) system
call[1].

In an operation to ALSA control character devices, when handled device
is disconnected, a call of poll(2) returns positive value to notify
events with 'EPOLLERR | EPOLLNVAL'[2].

Soon I'll post a patch to improve this behaviour of alsactl.

> I'm sorry if this is not the right place to report this issue or if the
> problem is already, I couldn't find anything about it.
> 
> 
> Below is the output from alsa-info.sh:
> 
> with headphones:
> 
> http://www.alsa-project.org/db/?f=0dfc632e3adafb8bc78a182e0a225bcb13bea9fa
> 
> after unplugging:
> 
> http://www.alsa-project.org/db/?f=41dbf0735fdd7cd2416a6b4a602505715d25b44f
> 
> Please let me know if you need further info.

You did enough good. Thank you and wait for a while till I'll fix it.

[1] 
http://git.alsa-project.org/?p=alsa-utils.git;a=blob;f=alsactl/monitor.c;hb=HEAD#l120
[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/tree/sound/core/init.c?h=for-next#n347


Takashi Sakamoto


More information about the Alsa-devel mailing list