From 823f6bb23922ad97d39d3eb4a36ceec1e261b94b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 8 Feb 2022 02:20:18 +0100 Subject: [PATCH] Prevent realtime scheduling for ad-hoc acceptors I noticed that there were some realtime adhoc-acceptors running on my system. That should of course not happen, since these only exist to catch some sporadic (and likely as a result of a badly behaving plugin) mutual recursion on the audio thread. --- CHANGELOG.md | 4 ++++ src/common/communication/common.h | 3 +++ src/common/utils.h | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3a86d8b..ade23b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ Versioning](https://semver.org/spec/v2.0.0.html). and [!1120](https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1120) have been merged. +- Prevented yabridge's ad-hoc socket acceptors from inheriting realtime + scheduling when spawned from audio threads. In practice this should not make + any difference as these threads are sleeping all the time except for under + very specific circumstances. ### Fixed diff --git a/src/common/communication/common.h b/src/common/communication/common.h index 0390f18e..724cf122 100644 --- a/src/common/communication/common.h +++ b/src/common/communication/common.h @@ -780,6 +780,9 @@ class AdHocSocketHandler { Thread secondary_requests_handler([&]() { pthread_setname_np(pthread_self(), "adhoc-acceptor"); + // Any secondary threads should not be realtime + set_realtime_priority(false); + secondary_context.run(); }); diff --git a/src/common/utils.h b/src/common/utils.h index 5405026f..d9c688c7 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -102,6 +102,12 @@ std::optional get_realtime_priority() noexcept; * * @return Whether the operation was successful or not. This will fail if the * user does not have the privileges to set realtime priorities. + * + * TODO: At some point, consider using `SCHED_RESET_ON_FORK` instead of manually + * disabling this when we don't want realtime scheduling to propagate. + * That would require a bit of careful analysis because we do want it to + * propagate to a Windows plugin's audio threads, and I don't think + * there's a way to go back once you've set `SCHED_RESET_ON_FORK`. */ bool set_realtime_priority(bool sched_fifo, int priority = 5) noexcept;