]> code.delx.au - pulseaudio/commitdiff
alsa: disable timer-based scheduling inside a VM
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Nov 2009 02:23:08 +0000 (03:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Nov 2009 02:23:08 +0000 (03:23 +0100)
In virtual machines sound card clocks and OS scheduling tend to become
unreliable, adding various 'uneven' latencies. The adaptive algorithm
that handles drop-outs does not handle it this well: in contrast to
drop-outs on real machines that are evenly distributed, small and can
easily be encountered via the adpative algorithms, drop-outs in VMs tend
to happen abruptly, and massively, which is not easy to counter.

This patch simply disables timer based scheduling in VMs reverting to
classic IO based scheduling. This should help make PA perform better in
VMs.

https://bugzilla.redhat.com/show_bug.cgi?id=532775

src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c
src/modules/alsa/alsa-util.c
src/modules/alsa/alsa-util.h

index 37419d98c426f21d7cb2860b66667e7495ff2351..856adb144f78cfa5f592b6d5b1a39d43a74fdb77 100644 (file)
@@ -1698,10 +1698,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
         goto fail;
     }
 
-    if (use_tsched && !pa_rtclock_hrtimer()) {
-        pa_log_notice("Disabling timer-based scheduling because high-resolution timers are not available from the kernel.");
-        use_tsched = FALSE;
-    }
+    use_tsched = pa_alsa_may_tsched(use_tsched);
 
     u = pa_xnew0(struct userdata, 1);
     u->core = m->core;
index 37dd64765bbed33cd5f2d0a6651a24dd3f6ef720..e775b20c60df34864fe19463dfea9c47c6252146 100644 (file)
@@ -1541,10 +1541,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         goto fail;
     }
 
-    if (use_tsched && !pa_rtclock_hrtimer()) {
-        pa_log_notice("Disabling timer-based scheduling because high-resolution timers are not available from the kernel.");
-        use_tsched = FALSE;
-    }
+    use_tsched = pa_alsa_may_tsched(use_tsched);
 
     u = pa_xnew0(struct userdata, 1);
     u->core = m->core;
index 0e22d17e467aaca47d8f004940a3a5461717204d..b8d135758439bc18c80a2b245f69cb3e7a21df44 100644 (file)
@@ -43,6 +43,7 @@
 #include <pulsecore/once.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/conf-parser.h>
+#include <pulsecore/core-rtclock.h>
 
 #include "alsa-util.h"
 #include "alsa-mixer.h"
@@ -1308,3 +1309,26 @@ const char* pa_alsa_strerror(int errnum) {
 
     return translated;
 }
+
+pa_bool_t pa_alsa_may_tsched(pa_bool_t want) {
+
+    if (!want)
+        return FALSE;
+
+    if (!pa_rtclock_hrtimer()) {
+        /* We cannot depend on being woken up in time when the timers
+        are inaccurate, so let's fallback to classic IO based playback
+        then. */
+        pa_log_notice("Disabling timer-based scheduling because high-resolution timers are not available from the kernel.");
+        return FALSE; }
+
+    if (pa_running_in_vm()) {
+        /* We cannot depend on being woken up when we ask for in a VM,
+         * so let's fallback to classic IO based playback then. */
+        pa_log_notice("Disabling timer-based scheduling because running inside a VM.");
+        return FALSE;
+    }
+
+
+    return TRUE;
+}
index f6206fe23631a71e43fe76320ccbf5df46a792a0..1d1256bd38dfde7b71b5452bb95cbf9b7316ca4b 100644 (file)
@@ -142,4 +142,6 @@ pa_bool_t pa_alsa_pcm_is_modem(snd_pcm_t *pcm);
 
 const char* pa_alsa_strerror(int errnum);
 
+pa_bool_t pa_alsa_may_tsched(pa_bool_t want);
+
 #endif