From 3e710e6d15bdea8688bc454895642a9f3e7c25e2 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:43:57 +0530 Subject: [PATCH 1/2] nixos/scx: init This adds a `services.scx.enable` option to enable sched-ext schedulers. Requires a kernel with sched-ext enabled (6.12+) or a kernel with the patchset. requiredKernelConfigs are taken from https://cateee.net/lkddb/web-lkddb/SCHED_CLASS_EXT.html --- nixos/modules/module-list.nix | 1 + nixos/modules/services/scheduling/scx.nix | 110 ++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 nixos/modules/services/scheduling/scx.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index a014c93afede..a43581cb029a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1292,6 +1292,7 @@ ./services/scheduling/atd.nix ./services/scheduling/cron.nix ./services/scheduling/fcron.nix + ./services/scheduling/scx.nix ./services/search/elasticsearch-curator.nix ./services/search/elasticsearch.nix ./services/search/hound.nix diff --git a/nixos/modules/services/scheduling/scx.nix b/nixos/modules/services/scheduling/scx.nix new file mode 100644 index 000000000000..279d13539b4f --- /dev/null +++ b/nixos/modules/services/scheduling/scx.nix @@ -0,0 +1,110 @@ +{ + lib, + pkgs, + config, + ... +}: +let + cfg = config.services.scx; +in +{ + options.services.scx = { + enable = lib.mkEnableOption null // { + description = '' + Whether to enable SCX service, a daemon to run schedulers from userspace. + + ::: {.note} + This service requires a kernel with the Sched-ext feature. + Generally, kernel version 6.12 and later are supported. + ::: + ''; + }; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.scx.full; + defaultText = lib.literalExpression "pkgs.scx.full"; + example = lib.literalExpression "pkgs.scx.rustland"; + description = '' + `scx` package to use. `scx.full`, which includes all schedulers, is the default. + You may choose a minimal package, such as `pkgs.scx.rustland`, if only one specific scheduler is needed. + + ::: {.note} + Overriding this does not change the default scheduler; you should set `services.scx.scheduler` for it. + ::: + ''; + }; + + scheduler = lib.mkOption { + type = lib.types.enum [ + "scx_bpfland" + "scx_central" + "scx_flatcg" + "scx_lavd" + "scx_layered" + "scx_nest" + "scx_pair" + "scx_qmap" + "scx_rlfifo" + "scx_rustland" + "scx_rusty" + "scx_simple" + "scx_userland" + ]; + default = "scx_rustland"; + example = "scx_bpfland"; + description = '' + Which scheduler to use. See [SCX documentation](https://github.com/sched-ext/scx/tree/main/scheds) + for details on each scheduler and guidance on selecting the most suitable one. + ''; + }; + + extraArgs = lib.mkOption { + type = lib.types.listOf lib.types.singleLineStr; + example = [ + "--slice-us 5000" + "--verbose" + ]; + description = '' + Parameters passed to the chosen scheduler at runtime. + + ::: {.note} + Run `chosen-scx-scheduler --help` to see the available options. Generally, + each scheduler has its own set of options, and they are incompatible with each other. + ::: + ''; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + + systemd.services.scx = { + description = "SCX scheduler daemon"; + + # SCX service should be started only if the kernel supports sched-ext + unitConfig.ConditionPathIsDirectory = "/sys/kernel/sched_ext"; + + startLimitIntervalSec = 30; + startLimitBurst = 2; + + serviceConfig = { + Type = "simple"; + ExecStart = "${lib.getExe' cfg.package cfg.scheduler} ${lib.concatStringsSep " " cfg.extraArgs}"; + Restart = "on-failure"; + StandardError = "journal"; + }; + + wantedBy = [ "multi-user.target" ]; + }; + + assertions = [ + { + assertion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.12"; + message = "SCX is only supported on kernel version >= 6.12."; + } + ]; + }; + + meta.maintainers = with lib.maintainers; [ johnrtitor ]; +} From d19bc236cffa5e7d0a425bedfe1cef56800bcf1a Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:05:18 +0530 Subject: [PATCH 2/2] nixos/release-notes-24.11: add scx module --- nixos/doc/manual/release-notes/rl-2411.section.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 8123f2ca52e9..3d0050321176 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -27,6 +27,9 @@ This also allows configuring runtime settings of AMDVLK and enabling experimental features. - The `moonlight-qt` package ([Moonlight game streaming](https://moonlight-stream.org/)) now has HDR support on Linux systems. +- [Sched-ext](https://github.com/sched-ext/scx), a Linux kernel feature to run schedulers in userspace, is now available [`services.scx`](options.html#opt-services.scx.enable). + Requires Linux kernel version 6.12 or later. + - PostgreSQL now defaults to major version 16. - `authelia` has been upgraded to version 4.38. This version brings several features and improvements which are detailed in the [release blog post](https://www.authelia.com/blog/4.38-release-notes/).