alsa: fix 100% CPU load when idle w/ dmix

Submitted by Jindrich Makovicka on Oct. 17, 2010, 10:34 a.m.

Details

Message ID AANLkTinsQbVMmidLyVKDz+g0Figwi3kRhoii2L454u7L@mail.gmail.com
State New
Headers show

Commit Message

Jindrich Makovicka Oct. 17, 2010, 10:34 a.m.
Hi,

when using dmix as an ALSA output, the output cannot be polled and
ALSA (snd_pcm_poll_descriptors) returns the event mask set to POLLIN
instead. As this event mask is passed to the main loop, the select()
in main_loop_wait() never waits, because the output file descriptor is
never read. So, qemu/kvm ends up busy looping all the time.

The attached patch simply disables the poll mode, when ALSA returns
POLLIN in the event mask for the ALSA playback pcm handle.

Patch hide | download patch | download mbox

--- alsaaudio.c.orig	2010-10-13 12:55:11.000000000 +0200
+++ alsaaudio.c	2010-10-17 12:18:57.928834276 +0200
@@ -266,8 +266,13 @@ 
 
     for (i = 0; i < count; ++i) {
         if (pfds[i].events & POLLIN) {
-            err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,
-                                       NULL, hlp);
+            if (mask & POLLIN) {
+                err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,
+                                           NULL, hlp);
+            } else {
+                dolog ("Cannot use poll mode for output\n");
+                err = -1;
+            }
         }
         if (pfds[i].events & POLLOUT) {
             if (conf.verbose) {