init: Request SCHED_RR using CAP_SYS_NICE and add Python to nix dev shell (#2690)

* nix: add python3 to devShell

* init: request SCHED_RR scheduling policy

* init: checks if host supports reseting scheduler on fork

* init: make gainRealTime more compatible with other OSes

* init: remove linux-only code
This commit is contained in:
Mily 2023-07-23 15:51:00 -03:00 committed by GitHub
parent 50e6f368ff
commit 9fc5f4c48b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -77,7 +77,7 @@
devShells = genSystems (system: { devShells = genSystems (system: {
default = pkgsFor.${system}.mkShell { default = pkgsFor.${system}.mkShell {
name = "hyprland-shell"; name = "hyprland-shell";
nativeBuildInputs = with pkgsFor.${system}; [cmake]; nativeBuildInputs = with pkgsFor.${system}; [ cmake python3 ];
buildInputs = [self.packages.${system}.wlroots-hyprland]; buildInputs = [self.packages.${system}.wlroots-hyprland];
inputsFrom = [ inputsFrom = [
self.packages.${system}.wlroots-hyprland self.packages.${system}.wlroots-hyprland

View File

@ -3,3 +3,19 @@
bool Init::isSudo() { bool Init::isSudo() {
return getuid() != geteuid() || !geteuid(); return getuid() != geteuid() || !geteuid();
} }
void Init::gainRealTime() {
const int minPrio = sched_get_priority_min(SCHED_RR);
const struct sched_param param = {.sched_priority = minPrio};
if (pthread_setschedparam(pthread_self(), SCHED_RR, &param)) {
Debug::log(WARN, "Failed to change process scheduling strategy");
return;
}
pthread_atfork(NULL, NULL, []() {
const struct sched_param param = {.sched_priority = 0};
if (pthread_setschedparam(pthread_self(), SCHED_OTHER, &param))
Debug::log(WARN, "Failed to reset process scheduling strategy");
});
}

View File

@ -4,4 +4,5 @@
namespace Init { namespace Init {
bool isSudo(); bool isSudo();
void gainRealTime();
}; };

View File

@ -89,6 +89,7 @@ int main(int argc, char** argv) {
} }
std::cout << "Welcome to Hyprland!\n"; std::cout << "Welcome to Hyprland!\n";
Init::gainRealTime();
// let's init the compositor. // let's init the compositor.
// it initializes basic Wayland stuff in the constructor. // it initializes basic Wayland stuff in the constructor.