From f3dfa9b9af6fae3b6b9345e40df93b96deee4ae6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 18 Jan 2022 13:32:25 +0100 Subject: [PATCH] module-rt: only change nice level on our servers Make the default nice.level an invalid value, that is not configured as the priority on a process. Explicitly enable a nice level on our daemon processes. Fixes #2034 --- src/daemon/client-rt.conf.in | 1 - src/daemon/filter-chain/demonic.conf | 1 - .../filter-chain/sink-dolby-surround.conf | 1 - src/daemon/filter-chain/sink-eq6.conf | 1 - .../filter-chain/sink-matrix-spatialiser.conf | 1 - .../sink-virtual-surround-5.1-kemar.conf | 1 - .../sink-virtual-surround-7.1-hesuvi.conf | 1 - src/daemon/filter-chain/source-rnnoise.conf | 1 - src/daemon/jack.conf.in | 1 - src/daemon/minimal.conf.in | 2 +- src/daemon/pipewire-pulse.conf.in | 2 +- src/daemon/pipewire.conf.in | 2 +- src/modules/module-rt.c | 35 ++++++++++--------- 13 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/daemon/client-rt.conf.in b/src/daemon/client-rt.conf.in index 35ff7c07c..cb0489cd0 100644 --- a/src/daemon/client-rt.conf.in +++ b/src/daemon/client-rt.conf.in @@ -37,7 +37,6 @@ context.modules = [ # Uses realtime scheduling to boost the audio thread priorities { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/demonic.conf b/src/daemon/filter-chain/demonic.conf index 36a8f8811..e6aab2e8b 100644 --- a/src/daemon/filter-chain/demonic.conf +++ b/src/daemon/filter-chain/demonic.conf @@ -22,7 +22,6 @@ context.modules = [ # Uses realtime scheduling to boost the audio thread priorities { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/sink-dolby-surround.conf b/src/daemon/filter-chain/sink-dolby-surround.conf index f9860a942..415c81924 100644 --- a/src/daemon/filter-chain/sink-dolby-surround.conf +++ b/src/daemon/filter-chain/sink-dolby-surround.conf @@ -14,7 +14,6 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/sink-eq6.conf b/src/daemon/filter-chain/sink-eq6.conf index b4e1013c2..35a18476e 100644 --- a/src/daemon/filter-chain/sink-eq6.conf +++ b/src/daemon/filter-chain/sink-eq6.conf @@ -14,7 +14,6 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/sink-matrix-spatialiser.conf b/src/daemon/filter-chain/sink-matrix-spatialiser.conf index 029e06b48..6d95e2041 100644 --- a/src/daemon/filter-chain/sink-matrix-spatialiser.conf +++ b/src/daemon/filter-chain/sink-matrix-spatialiser.conf @@ -15,7 +15,6 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/sink-virtual-surround-5.1-kemar.conf b/src/daemon/filter-chain/sink-virtual-surround-5.1-kemar.conf index ecb27aa70..6b87c0852 100644 --- a/src/daemon/filter-chain/sink-virtual-surround-5.1-kemar.conf +++ b/src/daemon/filter-chain/sink-virtual-surround-5.1-kemar.conf @@ -14,7 +14,6 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/sink-virtual-surround-7.1-hesuvi.conf b/src/daemon/filter-chain/sink-virtual-surround-7.1-hesuvi.conf index 872430015..aa23099ed 100644 --- a/src/daemon/filter-chain/sink-virtual-surround-7.1-hesuvi.conf +++ b/src/daemon/filter-chain/sink-virtual-surround-7.1-hesuvi.conf @@ -14,7 +14,6 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/filter-chain/source-rnnoise.conf b/src/daemon/filter-chain/source-rnnoise.conf index 3b30777db..36f11608a 100644 --- a/src/daemon/filter-chain/source-rnnoise.conf +++ b/src/daemon/filter-chain/source-rnnoise.conf @@ -14,7 +14,6 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/jack.conf.in b/src/daemon/jack.conf.in index 475f55de2..ba62c3a00 100644 --- a/src/daemon/jack.conf.in +++ b/src/daemon/jack.conf.in @@ -37,7 +37,6 @@ context.modules = [ # Boost the data thread priority. { name = libpipewire-module-rt args = { - #nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/minimal.conf.in b/src/daemon/minimal.conf.in index a01abb8fd..2a86a0eb2 100644 --- a/src/daemon/minimal.conf.in +++ b/src/daemon/minimal.conf.in @@ -66,7 +66,7 @@ context.modules = [ # scheduling. { name = libpipewire-module-rt args = { - #nice.level = -11 + nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/pipewire-pulse.conf.in b/src/daemon/pipewire-pulse.conf.in index a89c81733..302daad97 100644 --- a/src/daemon/pipewire-pulse.conf.in +++ b/src/daemon/pipewire-pulse.conf.in @@ -21,7 +21,7 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rt args = { - #nice.level = -11 + nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/daemon/pipewire.conf.in b/src/daemon/pipewire.conf.in index 4756051e8..f415ff4d1 100644 --- a/src/daemon/pipewire.conf.in +++ b/src/daemon/pipewire.conf.in @@ -73,7 +73,7 @@ context.modules = [ # scheduling. { name = libpipewire-module-rt args = { - #nice.level = -11 + nice.level = -11 #rt.prio = 88 #rt.time.soft = -1 #rt.time.hard = -1 diff --git a/src/modules/module-rt.c b/src/modules/module-rt.c index 225de98b5..62021a7e2 100644 --- a/src/modules/module-rt.c +++ b/src/modules/module-rt.c @@ -64,16 +64,18 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME); #ifdef SCHED_RESET_ON_FORK #define PW_SCHED_RESET_ON_FORK SCHED_RESET_ON_FORK #else -// FreeBSD compat +/* FreeBSD compat */ #define PW_SCHED_RESET_ON_FORK 0 #endif -#define DEFAULT_NICE_LEVEL -11 +#define IS_VALID_NICE_LEVEL(l) ((l)>=-20 && (l)<=19) + +#define DEFAULT_NICE_LEVEL 20 #define DEFAULT_RT_PRIO 88 #define DEFAULT_RT_TIME_SOFT -1 #define DEFAULT_RT_TIME_HARD -1 -#define MODULE_USAGE "[nice.level=] " \ +#define MODULE_USAGE "[nice.level=] " \ "[rt.prio=] " \ "[rt.time.soft=start = start_routine; this->arg = arg; - // This thread list is only used for the RTKit implementation + /* This thread list is only used for the RTKit implementation */ pthread_mutex_lock(&impl->lock); err = pthread_create(&this->thread, NULL, custom_start, this); if (err != 0) @@ -687,7 +689,7 @@ static int impl_acquire_rt(void *data, struct spa_thread *thread, int priority) pthread_t pt = (pthread_t)thread; pid_t pid; - // See the docstring on `spa_thread_utils_methods::acquire_rt` + /* See the docstring on `spa_thread_utils_methods::acquire_rt` */ if (priority == -1) { priority = impl->rt_prio; } @@ -797,8 +799,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) impl->rt_time_soft = pw_properties_get_int32(props, "rt.time.soft", DEFAULT_RT_TIME_SOFT); impl->rt_time_hard = pw_properties_get_int32(props, "rt.time.hard", DEFAULT_RT_TIME_HARD); - // If the user has permissions to use regular realtime scheduling, then - // we'll use that instead of RTKit + /* If the user has permissions to use regular realtime scheduling, then + * we'll use that instead of RTKit */ if (check_rtprio_rlimit(impl->rt_prio)) { use_rtkit = false; } else { @@ -808,7 +810,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) goto error; } - // TODO: Should this be pw_log_warn or pw_log_debug instead? + /* TODO: Should this be pw_log_warn or pw_log_debug instead? */ pw_log_info("could not use realtime scheduling, falling back to using RTKit instead"); } @@ -822,7 +824,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) } } - set_nice(impl, impl->nice_level); + if (IS_VALID_NICE_LEVEL(impl->nice_level)) + set_nice(impl, impl->nice_level); set_rlimit(impl); impl->thread_utils.iface = SPA_INTERFACE_INIT(