1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

vblank: set SCHED_RR for the SGI_video_sync thread

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-02-16 19:49:28 +00:00
parent 7bbf316a7d
commit 23d4d31d1f
No known key found for this signature in database
GPG key ID: D3A4405BE6CC17F4
4 changed files with 40 additions and 37 deletions

View file

@ -19,7 +19,6 @@
#include <fcntl.h>
#include <inttypes.h>
#include <math.h>
#include <pthread.h>
#include <sched.h>
#include <stddef.h>
#include <stdio.h>
@ -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, &param);
if (ret != 0) {
log_info("Couldn't get old scheduling priority.");
return;
}
param.sched_priority = priority;
ret = pthread_setschedparam(pthread_self(), SCHED_RR, &param);
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.
*

View file

@ -1,8 +1,10 @@
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <sys/uio.h>
#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, &param);
if (ret != 0) {
log_info("Couldn't get old scheduling priority.");
return;
}
param.sched_priority = priority;
ret = pthread_setschedparam(pthread_self(), SCHED_RR, &param);
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 :

View file

@ -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.

View file

@ -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);