From 23d4d31d1f477591d7830712a1e53764e875955f Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Fri, 16 Feb 2024 19:49:28 +0000 Subject: [PATCH] vblank: set SCHED_RR for the SGI_video_sync thread Signed-off-by: Yuxuan Shui --- src/picom.c | 37 ------------------------------------- src/utils.c | 37 +++++++++++++++++++++++++++++++++++++ src/utils.h | 1 + src/vblank.c | 2 ++ 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/picom.c b/src/picom.c index a4d3e3e3..6bdfd1d9 100644 --- a/src/picom.c +++ b/src/picom.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -68,7 +67,6 @@ #include "file_watch.h" #include "list.h" #include "options.h" -#include "rtkit.h" #include "statistics.h" #include "uthash_extra.h" #include "vblank.h" @@ -2604,41 +2602,6 @@ err: return NULL; } -/// Switch to real-time scheduling policy (SCHED_RR) if possible -/// -/// Make picom realtime to reduce latency, and make rendering times more predictable to -/// help pacing. -/// -/// This requires the user to set up permissions for the real-time scheduling. e.g. by -/// setting `ulimit -r`, or giving us the CAP_SYS_NICE capability. -void set_rr_scheduling(void) { - int priority = sched_get_priority_min(SCHED_RR); - - if (rtkit_make_realtime(0, priority)) { - log_info("Set realtime priority to %d with rtkit.", priority); - return; - } - - // Fallback to use pthread_setschedparam - struct sched_param param; - int old_policy; - int ret = pthread_getschedparam(pthread_self(), &old_policy, ¶m); - if (ret != 0) { - log_info("Couldn't get old scheduling priority."); - return; - } - - param.sched_priority = priority; - - ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); - if (ret != 0) { - log_info("Couldn't set real-time scheduling priority to %d.", priority); - return; - } - - log_info("Set real-time scheduling priority to %d.", priority); -} - /** * Destroy a session. * diff --git a/src/utils.c b/src/utils.c index 53766d6d..68ec697e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,8 +1,10 @@ +#include #include #include #include #include "compiler.h" +#include "rtkit.h" #include "string_utils.h" #include "test.h" #include "utils.h" @@ -272,4 +274,39 @@ void rolling_quantile_pop_front(struct rolling_quantile *rq, int x) { } } +/// Switch to real-time scheduling policy (SCHED_RR) if possible +/// +/// Make picom realtime to reduce latency, and make rendering times more predictable to +/// help pacing. +/// +/// This requires the user to set up permissions for the real-time scheduling. e.g. by +/// setting `ulimit -r`, or giving us the CAP_SYS_NICE capability. +void set_rr_scheduling(void) { + int priority = sched_get_priority_min(SCHED_RR); + + if (rtkit_make_realtime(0, priority)) { + log_info("Set realtime priority to %d with rtkit.", priority); + return; + } + + // Fallback to use pthread_setschedparam + struct sched_param param; + int old_policy; + int ret = pthread_getschedparam(pthread_self(), &old_policy, ¶m); + if (ret != 0) { + log_info("Couldn't get old scheduling priority."); + return; + } + + param.sched_priority = priority; + + ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); + if (ret != 0) { + log_info("Couldn't set real-time scheduling priority to %d.", priority); + return; + } + + log_info("Set real-time scheduling priority to %d.", priority); +} + // vim: set noet sw=8 ts=8 : diff --git a/src/utils.h b/src/utils.h index 22da6c29..962f160f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -406,6 +406,7 @@ void rolling_quantile_destroy(struct rolling_quantile *rq); int rolling_quantile_estimate(struct rolling_quantile *rq, struct rolling_window *elements); void rolling_quantile_push_back(struct rolling_quantile *rq, int x); void rolling_quantile_pop_front(struct rolling_quantile *rq, int x); +void set_rr_scheduling(void); // Some versions of the Android libc do not have timespec_get(), use // clock_gettime() instead. diff --git a/src/vblank.c b/src/vblank.c index 81a6cb9e..776d258b 100644 --- a/src/vblank.c +++ b/src/vblank.c @@ -183,6 +183,8 @@ static void *sgi_video_sync_thread(void *data) { goto start_failed; } + log_init_tls(); + set_rr_scheduling(); pthread_mutex_lock(&args->start_mtx); args->start_status = 0; pthread_cond_signal(&args->start_cnd);