[pulseaudio-commits] r2014 - in /trunk/src: daemon/ modules/ pulsecore/

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Oct 31 19:58:27 PDT 2007


Author: lennart
Date: Thu Nov  1 03:58:26 2007
New Revision: 2014

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2014&root=pulseaudio&view=rev
Log:
make rtprio and nice level actually configurable

Modified:
    trunk/src/daemon/main.c
    trunk/src/modules/module-alsa-sink.c
    trunk/src/modules/module-alsa-source.c
    trunk/src/modules/module-combine.c
    trunk/src/modules/module-jack-sink.c
    trunk/src/modules/module-jack-source.c
    trunk/src/modules/module-oss.c
    trunk/src/pulsecore/core-util.c
    trunk/src/pulsecore/core-util.h
    trunk/src/pulsecore/core.c
    trunk/src/pulsecore/core.h

Modified: trunk/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/main.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/daemon/main.c (original)
+++ trunk/src/daemon/main.c Thu Nov  1 03:58:26 2007
@@ -419,9 +419,9 @@
     pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target, NULL);
 
     if (conf->high_priority && conf->cmd == PA_CMD_DAEMON)
-        pa_raise_priority();
-
-    if (suid_root && (conf->cmd != PA_CMD_DAEMON || !conf->high_priority)) {
+        pa_raise_priority(conf->nice_level);
+
+    if (suid_root && (conf->cmd != PA_CMD_DAEMON || !conf->realtime_scheduling)) {
         pa_drop_caps();
         pa_drop_root();
     }
@@ -636,7 +636,6 @@
     }
 
     c->is_system_instance = !!conf->system_instance;
-    c->high_priority = !!conf->high_priority;
     c->default_sample_spec = conf->default_sample_spec;
     c->default_n_fragments = conf->default_n_fragments;
     c->default_fragment_size_msec = conf->default_fragment_size_msec;
@@ -645,6 +644,8 @@
     c->module_idle_time = conf->module_idle_time;
     c->scache_idle_time = conf->scache_idle_time;
     c->resample_method = conf->resample_method;
+    c->realtime_priority = conf->realtime_priority;
+    c->realtime_scheduling = !!conf->realtime_scheduling;
 
     pa_assert_se(pa_signal_init(pa_mainloop_get_api(mainloop)) == 0);
     pa_signal_new(SIGINT, signal_callback, c);

Modified: trunk/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-sink.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-sink.c (original)
+++ trunk/src/modules/module-alsa-sink.c Thu Nov  1 03:58:26 2007
@@ -603,8 +603,8 @@
 
     pa_log_debug("Thread starting up");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority);
 
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);

Modified: trunk/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-source.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-source.c (original)
+++ trunk/src/modules/module-alsa-source.c Thu Nov  1 03:58:26 2007
@@ -592,8 +592,8 @@
 
     pa_log_debug("Thread starting up");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority);
 
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);

Modified: trunk/src/modules/module-combine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-combine.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/modules/module-combine.c (original)
+++ trunk/src/modules/module-combine.c Thu Nov  1 03:58:26 2007
@@ -233,8 +233,8 @@
 
     pa_log_debug("Thread starting up");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority+1);
 
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);

Modified: trunk/src/modules/module-jack-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-jack-sink.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/modules/module-jack-sink.c (original)
+++ trunk/src/modules/module-jack-sink.c Thu Nov  1 03:58:26 2007
@@ -214,8 +214,8 @@
 
     pa_log_debug("Thread starting up");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority);
 
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);
@@ -253,8 +253,8 @@
 
     pa_log_info("JACK thread starting up.");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority+4);
 }
 
 static void jack_shutdown(void* arg) {

Modified: trunk/src/modules/module-jack-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-jack-source.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/modules/module-jack-source.c (original)
+++ trunk/src/modules/module-jack-source.c Thu Nov  1 03:58:26 2007
@@ -191,8 +191,8 @@
 
     pa_log_debug("Thread starting up");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority);
 
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);
@@ -230,8 +230,8 @@
 
     pa_log_info("JACK thread starting up.");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority+4);
 }
 
 static void jack_shutdown(void* arg) {

Modified: trunk/src/modules/module-oss.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-oss.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/modules/module-oss.c (original)
+++ trunk/src/modules/module-oss.c Thu Nov  1 03:58:26 2007
@@ -863,8 +863,8 @@
 
     pa_log_debug("Thread starting up");
 
-    if (u->core->high_priority)
-        pa_make_realtime();
+    if (u->core->realtime_scheduling)
+        pa_make_realtime(u->core->realtime_priority);
 
     pa_thread_mq_install(&u->thread_mq);
     pa_rtpoll_install(u->rtpoll);

Modified: trunk/src/pulsecore/core-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/core-util.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/pulsecore/core-util.c (original)
+++ trunk/src/pulsecore/core-util.c Thu Nov  1 03:58:26 2007
@@ -512,8 +512,10 @@
     return b;
 }
 
-/* Make the current thread a realtime thread*/
-void pa_make_realtime(void) {
+/* Make the current thread a realtime thread, and acquire the highest
+ * rtprio we can get that is less or equal the specified parameter. If
+ * the thread is already realtime, don't do anything. */
+int pa_make_realtime(int rtprio) {
 
 #ifdef _POSIX_PRIORITY_SCHEDULING
     struct sched_param sp;
@@ -524,50 +526,87 @@
 
     if ((r = pthread_getschedparam(pthread_self(), &policy, &sp)) != 0) {
         pa_log("pthread_getschedgetparam(): %s", pa_cstrerror(r));
-        return;
-    }
-
-    sp.sched_priority = 1;
+        return -1;
+    }
+
+    if (policy == SCHED_FIFO && sp.sched_priority >= rtprio) {
+        pa_log_info("Thread already being scheduled with SCHED_FIFO with priority %i.", sp.sched_priority);
+        return 0;
+    }
+
+    sp.sched_priority = rtprio;
     if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) != 0) {
+
+        while (sp.sched_priority > 1) {
+            sp.sched_priority --;
+
+            if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) == 0) {
+                pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i, which is lower than the requested %i.", sp.sched_priority, rtprio);
+                return 0;
+            }
+        }
+
         pa_log_warn("pthread_setschedparam(): %s", pa_cstrerror(r));
-        return;
-    }
-
-    pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread.");
-#endif
-
-}
-
-#define NICE_LEVEL (-11)
-
-/* Raise the priority of the current process as much as possible and
-sensible: set the nice level to -11.*/
-void pa_raise_priority(void) {
+        return -1;
+    }
+
+    pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i.", sp.sched_priority);
+    return 0;
+#else
+    return -1;
+#endif
+}
+
+/* Raise the priority of the current process as much as possible that
+ * is <= the specified nice level..*/
+int pa_raise_priority(int nice_level) {
 
 #ifdef HAVE_SYS_RESOURCE_H
-    if (setpriority(PRIO_PROCESS, 0, NICE_LEVEL) < 0)
+    if (setpriority(PRIO_PROCESS, 0, nice_level) < 0) {
+        int n;
+
+        for (n = nice_level+1; n < 0; n++) {
+
+            if (setpriority(PRIO_PROCESS, 0, n) == 0) {
+                pa_log_info("Successfully acquired nice level %i, which is lower than the requested %i.", n, nice_level);
+                return 0;
+            }
+        }
+
         pa_log_warn("setpriority(): %s", pa_cstrerror(errno));
-    else
-        pa_log_info("Successfully gained nice level %i.", NICE_LEVEL);
+        return -1;
+    }
+
+    pa_log_info("Successfully gained nice level %i.", nice_level);
 #endif
 
 #ifdef OS_IS_WIN32
-    if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
-        pa_log_warn("SetPriorityClass() failed: 0x%08X", GetLastError());
-    else
-        pa_log_info("Successfully gained high priority class.");
-#endif
+    if (nice_level < 0) {
+        if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
+            pa_log_warn("SetPriorityClass() failed: 0x%08X", GetLastError());
+            return .-1;
+        } else
+            pa_log_info("Successfully gained high priority class.");
+    }
+#endif
+
+    return 0;
 }
 
 /* Reset the priority to normal, inverting the changes made by
- * pa_raise_priority() */
+ * pa_raise_priority() and pa_make_realtime()*/
 void pa_reset_priority(void) {
+#ifdef HAVE_SYS_RESOURCE_H
+    struct sched_param sp;
+
+    setpriority(PRIO_PROCESS, 0, 0);
+
+    memset(&sp, 0, sizeof(sp));
+    pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_OTHER, &sp) == 0);
+#endif
+
 #ifdef OS_IS_WIN32
     SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
-#endif
-
-#ifdef HAVE_SYS_RESOURCE_H
-    setpriority(PRIO_PROCESS, 0, 0);
 #endif
 }
 

Modified: trunk/src/pulsecore/core-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/core-util.h?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/pulsecore/core-util.h (original)
+++ trunk/src/pulsecore/core-util.h Thu Nov  1 03:58:26 2007
@@ -57,8 +57,8 @@
 
 char *pa_parent_dir(const char *fn);
 
-void pa_make_realtime(void);
-void pa_raise_priority(void);
+int pa_make_realtime(int rtprio);
+int pa_raise_priority(int nice_level);
 void pa_reset_priority(void);
 
 int pa_parse_boolean(const char *s) PA_GCC_PURE;

Modified: trunk/src/pulsecore/core.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/core.c?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/pulsecore/core.c (original)
+++ trunk/src/pulsecore/core.c Thu Nov  1 03:58:26 2007
@@ -107,7 +107,7 @@
     c->scache = NULL;
     c->autoload_idxset = NULL;
     c->autoload_hashmap = NULL;
-    c->running_as_daemon = 0;
+    c->running_as_daemon = FALSE;
 
     c->default_sample_spec.format = PA_SAMPLE_S16NE;
     c->default_sample_spec.rate = 44100;
@@ -134,10 +134,10 @@
 
     c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 3;
 
-    c->is_system_instance = 0;
-    c->disallow_module_loading = 0;
-    c->high_priority = 0;
-
+    c->is_system_instance = FALSE;
+    c->disallow_module_loading = FALSE;
+    c->realtime_scheduling = FALSE;
+    c->realtime_priority = 5;
 
     for (j = 0; j < PA_CORE_HOOK_MAX; j++)
         pa_hook_init(&c->hooks[j], c);
@@ -217,4 +217,3 @@
         c->quit_event = NULL;
     }
 }
-

Modified: trunk/src/pulsecore/core.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/core.h?rev=2014&root=pulseaudio&r1=2013&r2=2014&view=diff
==============================================================================
--- trunk/src/pulsecore/core.h (original)
+++ trunk/src/pulsecore/core.h Thu Nov  1 03:58:26 2007
@@ -113,10 +113,11 @@
 
     pa_time_event *scache_auto_unload_event;
 
-    int disallow_module_loading, running_as_daemon;
+    pa_bool_t disallow_module_loading, running_as_daemon;
     pa_resample_method_t resample_method;
-    int is_system_instance;
-    int high_priority;
+    pa_bool_t is_system_instance;
+    pa_bool_t realtime_scheduling;
+    int realtime_priority;
 
     /* hooks */
     pa_hook hooks[PA_CORE_HOOK_MAX];




More information about the pulseaudio-commits mailing list