diff options
-rw-r--r-- | include/sway/server.h | 2 | ||||
-rw-r--r-- | sway/main.c | 2 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/realtime.c | 40 |
4 files changed, 45 insertions, 0 deletions
diff --git a/include/sway/server.h b/include/sway/server.h index d8ccd64f..3d59ca56 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -173,4 +173,6 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data); void xdg_activation_v1_handle_request_activate(struct wl_listener *listener, void *data); +void set_rr_scheduling(void); + #endif diff --git a/sway/main.c b/sway/main.c index 78974e22..a0033c45 100644 --- a/sway/main.c +++ b/sway/main.c @@ -413,6 +413,8 @@ int main(int argc, char **argv) { goto shutdown; } + set_rr_scheduling(); + if (!server_start(&server)) { sway_terminate(EXIT_FAILURE); goto shutdown; diff --git a/sway/meson.build b/sway/meson.build index 0ad783e3..6762ef2d 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -7,6 +7,7 @@ sway_sources = files( 'ipc-server.c', 'lock.c', 'main.c', + 'realtime.c', 'server.c', 'swaynag.c', 'xdg_activation_v1.c', diff --git a/sway/realtime.c b/sway/realtime.c new file mode 100644 index 00000000..11154af0 --- /dev/null +++ b/sway/realtime.c @@ -0,0 +1,40 @@ +#include <sys/resource.h> +#include <sched.h> +#include <unistd.h> +#include <pthread.h> +#include "sway/server.h" +#include "log.h" + +static void child_fork_callback(void) { + struct sched_param param; + + param.sched_priority = 0; + + int ret = pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m); + if (ret != 0) { + sway_log(SWAY_ERROR, "Failed to reset scheduler policy on fork"); + } +} + +void set_rr_scheduling(void) { + int prio = sched_get_priority_min(SCHED_RR); + int old_policy; + int ret; + struct sched_param param; + + ret = pthread_getschedparam(pthread_self(), &old_policy, ¶m); + if (ret != 0) { + sway_log(SWAY_DEBUG, "Failed to get old scheduling priority"); + return; + } + + param.sched_priority = prio; + + ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); + if (ret != 0) { + sway_log(SWAY_INFO, "Failed to set scheduling priority to %d", prio); + return; + } + + pthread_atfork(NULL, NULL, child_fork_callback); +} |