[pulseaudio-commits] src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Mon Jun 10 06:53:02 PDT 2013


 src/pulsecore/core-util.c |   38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)

New commits:
commit 07290d9da7a50ab9b3c6b3a7acaac6353d09801b
Author: Jan Alexander Steffens (heftig) <jan.steffens at gmail.com>
Date:   Sun Jun 9 18:47:05 2013 +0200

    core-util: Clamp RLIMIT_RTTIME to what RealtimeKit accepts
    
    In the default configuration, PulseAudio's rlimit-rttime is set to
    1000000 (100%), which is higher than what RealtimeKit requires from
    its clients (200000, 20%).
    
    Make an attempt to still get realtime scheduling by clamping the
    current RLIMIT_RTTIME to what RealtimeKit accepts. Warn about doing
    this.

diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index da8266b..aa8c3f1 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -684,6 +684,10 @@ static int set_scheduler(int rtprio) {
     struct sched_param sp;
 #ifdef HAVE_DBUS
     int r;
+    long long rttime;
+#ifdef HAVE_SYS_RESOURCE_H
+    struct rlimit rl;
+#endif
     DBusError error;
     DBusConnection *bus;
 
@@ -721,16 +725,36 @@ static int set_scheduler(int rtprio) {
      * https://bugs.freedesktop.org/show_bug.cgi?id=16924 */
     dbus_connection_set_exit_on_disconnect(bus, FALSE);
 
-    r = rtkit_make_realtime(bus, 0, rtprio);
-    dbus_connection_close(bus);
-    dbus_connection_unref(bus);
+    rttime = rtkit_get_rttime_usec_max(bus);
+    if (rttime >= 0) {
+#ifdef HAVE_SYS_RESOURCE_H
+        r = getrlimit(RLIMIT_RTTIME, &rl);
 
-    if (r >= 0) {
-        pa_log_debug("RealtimeKit worked.");
-        return 0;
+        if (r >= 0 && (long long) rl.rlim_max > rttime) {
+            pa_log_warn("Clamping rlimit-rttime to %lld for RealtimeKit\n", rttime);
+            rl.rlim_cur = rl.rlim_max = rttime;
+            r = setrlimit(RLIMIT_RTTIME, &rl);
+
+            if (r < 0)
+                pa_log_info("setrlimit() failed: %s", pa_cstrerror(errno));
+        }
+#endif
+        r = rtkit_make_realtime(bus, 0, rtprio);
+        dbus_connection_close(bus);
+        dbus_connection_unref(bus);
+
+        if (r >= 0) {
+            pa_log_debug("RealtimeKit worked.");
+            return 0;
+        }
+
+        errno = -r;
+    } else {
+        dbus_connection_close(bus);
+        dbus_connection_unref(bus);
+        errno = -rttime;
     }
 
-    errno = -r;
 #else
     errno = 0;
 #endif



More information about the pulseaudio-commits mailing list