From 0d3850e837d6b3aa3a5ba915f174188fef6de965 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 27 May 2021 13:48:34 +0200 Subject: [PATCH] Add a function for fetching the RTTIME limit We can use this to more easily diagnose issues caused by PipeWire. --- src/common/utils.cpp | 9 +++++++++ src/common/utils.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/common/utils.cpp b/src/common/utils.cpp index 91e31544..6ebd2469 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -48,6 +48,15 @@ bool set_realtime_priority(bool sched_fifo, int priority) noexcept { ¶ms) == 0; } +std::optional get_rttime_limit() noexcept { + rlimit limits{}; + if (getrlimit(RLIMIT_RTTIME, &limits) == 0) { + return limits.rlim_cur; + } else { + return std::nullopt; + } +} + bool pid_running(pid_t pid) { // With regular individually hosted plugins we can simply check whether the // process is still running, however Boost.Process does not allow you to do diff --git a/src/common/utils.h b/src/common/utils.h index 69c86d8e..843f591f 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -18,6 +18,8 @@ #include +#include + #ifdef __WINE__ #include "../wine-host/boost-fix.h" #endif @@ -86,6 +88,18 @@ boost::filesystem::path get_temporary_directory(); */ std::optional get_realtime_priority() noexcept; +/** + * Get the (soft) `RTTIME` resource limit, or the amount of time a `SCHED_FIFO` + * process may spend uninterrupted before being killed by the scheduler. A value + * of `-1`/`RLIM_INFINITY` means that there is no limit. If there was some error + * fetching this value, then a nullopt will be returned. + * + * This is useful to diagnose issues caused by PipeWire. They use rtkit at the + * moment, and both rtkit and PipeWire's rtkit module will enable a realtime CPU + * time limit with some low value. + */ +std::optional get_rttime_limit() noexcept; + /** * Set the scheduling policy to `SCHED_FIFO` with priority 5 for this process. * We explicitly don't do this for wineserver itself since from my testing that