From 7b77aebb19adea9a2421ba4023810d8dbae98cc2 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 25 Nov 2024 16:48:29 +0100 Subject: [PATCH] fixup! WIP: rtkit support --- shell.nix | 1 + src/event/Thread.cxx | 4 +++- src/lib/yajl/Callbacks.hxx | 2 +- src/lib/yajl/Gen.hxx | 2 +- src/lib/yajl/Handle.hxx | 2 +- src/thread/Util.cxx | 23 ++++++++++++++--------- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/shell.nix b/shell.nix index 0a45aabc5..25e692bab 100644 --- a/shell.nix +++ b/shell.nix @@ -8,6 +8,7 @@ pkgs.mkShell { # For documentation doxygen python3Packages.sphinx + python3Packages.sphinx-rtd-theme ]; buildInputs = with pkgs; [ diff --git a/src/event/Thread.cxx b/src/event/Thread.cxx index dc6299a6c..4982a74f8 100644 --- a/src/event/Thread.cxx +++ b/src/event/Thread.cxx @@ -8,6 +8,7 @@ #include "lib/fmt/ExceptionFormatter.hxx" #include "util/Domain.hxx" #include "Log.hxx" +#include static constexpr Domain event_domain("event"); @@ -47,7 +48,8 @@ EventThread::Run() noexcept } catch (...) { FmtInfo(event_domain, "RTIOThread could not get realtime scheduling, continuing anyway: {}", - std::current_exception()); + /* std::current_exception()); */ + boost::stacktrace::to_string(boost::stacktrace::stacktrace())); } } diff --git a/src/lib/yajl/Callbacks.hxx b/src/lib/yajl/Callbacks.hxx index f2bc9ffe3..16163daf1 100644 --- a/src/lib/yajl/Callbacks.hxx +++ b/src/lib/yajl/Callbacks.hxx @@ -7,7 +7,7 @@ #include -#include +#include namespace Yajl { diff --git a/src/lib/yajl/Gen.hxx b/src/lib/yajl/Gen.hxx index 84efdbcce..7d778790a 100644 --- a/src/lib/yajl/Gen.hxx +++ b/src/lib/yajl/Gen.hxx @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include diff --git a/src/lib/yajl/Handle.hxx b/src/lib/yajl/Handle.hxx index 28e4fe942..a821d0cd5 100644 --- a/src/lib/yajl/Handle.hxx +++ b/src/lib/yajl/Handle.hxx @@ -3,7 +3,7 @@ #pragma once -#include +#include #include diff --git a/src/thread/Util.cxx b/src/thread/Util.cxx index 0ba3d9d06..9e84ed944 100644 --- a/src/thread/Util.cxx +++ b/src/thread/Util.cxx @@ -12,6 +12,7 @@ #include #include #include +#include "lib/fmt/RuntimeError.hxx" #elif defined(_WIN32) #include #endif @@ -271,7 +272,7 @@ SetThreadRealtime() { #ifdef __linux__ struct sched_param sched_param; - sched_param.sched_priority = 40; + sched_param.sched_priority = 20; int policy = SCHED_FIFO; #ifdef SCHED_RESET_ON_FORK @@ -284,9 +285,13 @@ SetThreadRealtime() DBusError error; DBusConnection *system_bus; - if (!(system_bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { - throw MakeErrno("could not connect to dbus"); - } + dbus_error_init(&error); + + system_bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (dbus_error_is_set(&error)) { + throw FmtRuntimeError("could not connect to dbus: %s", error.message); + } + dbus_error_free(&error); int max_realtime_priority; if ((max_realtime_priority = rtkit_get_max_realtime_priority(system_bus)) < 0) { @@ -295,12 +300,12 @@ SetThreadRealtime() } if (max_realtime_priority < sched_param.sched_priority) { - dbus_connection_unref(system_bus); - throw MakeErrno("maximum realtime priority is below 40"); + sched_param.sched_priority = max_realtime_priority; + /* dbus_connection_unref(system_bus); */ + /* throw MakeErrno("maximum realtime priority is below 40"); */ } - pid_t pid = getpid(); - if (rtkit_make_realtime(system_bus, pid, sched_param.sched_priority) < 0) { + if (rtkit_make_realtime(system_bus, 0, sched_param.sched_priority) < 0) { dbus_connection_unref(system_bus); throw MakeErrno("failed to request realtime scheduling"); } @@ -313,4 +318,4 @@ SetThreadRealtime() // throw MakeErrno("sched_setscheduler failed"); // } #endif // __linux__ -} \ No newline at end of file +}