fixup! WIP: rtkit support

This commit is contained in:
2024-11-25 16:48:29 +01:00
parent 27d430d9cf
commit 3a02588fbf
6 changed files with 21 additions and 13 deletions

View File

@@ -12,6 +12,7 @@
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include "lib/fmt/RuntimeError.hxx"
#elif defined(_WIN32)
#include <windows.h>
#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__
}
}