From c9f192da9242f66cd9314b90632682d0326afa93 Mon Sep 17 00:00:00 2001 From: Masum Reza <50095635+JohnRTitor@users.noreply.github.com> Date: Tue, 27 May 2025 19:45:13 +0530 Subject: [PATCH] nixos/amdgpu: add overdrive and ppfeaturemask option (#411155) - `programs.corectrl.gpuOverclock.enable` -> `hardware.amdgpu.overdrive.enable` - `programs.corectrl.gpuOverclock.ppfeaturemask` -> `hardware.amdgpu.overdrive.ppfeaturemask` - `programs.tuxclocker.enableAMD` -> `hardware.amdgpu.overdrive.enable` --- .../manual/release-notes/rl-2511.section.md | 3 ++ nixos/modules/hardware/corectrl.nix | 35 ++++++------------- nixos/modules/services/hardware/amdgpu.nix | 35 +++++++++++++++---- nixos/modules/services/misc/tuxclocker.nix | 16 ++++----- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2511.section.md b/nixos/doc/manual/release-notes/rl-2511.section.md index d86c9b80de3a..21994daff24e 100644 --- a/nixos/doc/manual/release-notes/rl-2511.section.md +++ b/nixos/doc/manual/release-notes/rl-2511.section.md @@ -27,3 +27,6 @@ - `services.clamsmtp` is unmaintained and was removed from Nixpkgs. + +- `amdgpu` kernel driver overdrive mode can now be enabled by setting [hardware.amdgpu.overdrive.enable](#opt-hardware.amdgpu.overdrive.enable) and customized through [hardware.amdgpu.overdrive.ppfeaturemask](#opt-hardware.amdgpu.overdrive.ppfeaturemask). + This allows for fine-grained control over the GPU's performance and maybe required by overclocking softwares like Corectrl and Lact. These new options replace old options such as {option}`programs.corectrl.gpuOverclock.enable` and {option}`programs.tuxclocker.enableAMD`. diff --git a/nixos/modules/hardware/corectrl.nix b/nixos/modules/hardware/corectrl.nix index 6e680ddc846e..bbe59d1b5b9d 100644 --- a/nixos/modules/hardware/corectrl.nix +++ b/nixos/modules/hardware/corectrl.nix @@ -8,13 +8,23 @@ let inherit (lib) mkEnableOption mkIf - mkOption mkPackageOption ; cfg = config.programs.corectrl; in { + imports = [ + (lib.mkRenamedOptionModule + [ "programs" "corectrl" "gpuOverclock" "enable" ] + [ "hardware" "amdgpu" "overdrive" "enable" ] + ) + (lib.mkRenamedOptionModule + [ "programs" "corectrl" "gpuOverclock" "ppfeaturemask" ] + [ "hardware" "amdgpu" "overdrive" "ppfeaturemask" ] + ) + ]; + options.programs.corectrl = { enable = mkEnableOption '' CoreCtrl, a tool to overclock amd graphics cards and processors. @@ -24,23 +34,6 @@ in package = mkPackageOption pkgs "corectrl" { extraDescription = "Useful for overriding the configuration options used for the package."; }; - - gpuOverclock = { - enable = mkEnableOption '' - GPU overclocking - ''; - ppfeaturemask = mkOption { - type = lib.types.str; - default = "0xfffd7fff"; - example = "0xffffffff"; - description = '' - Sets the `amdgpu.ppfeaturemask` kernel option. - In particular, it is used here to set the overdrive bit. - Default is `0xfffd7fff` as it is less likely to cause flicker issues. - Setting it to `0xffffffff` enables all features. - ''; - }; - }; }; config = mkIf cfg.enable { @@ -61,12 +54,6 @@ in } }); ''; - - # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/include/amd_shared.h#n169 - # The overdrive bit - boot.kernelParams = mkIf cfg.gpuOverclock.enable [ - "amdgpu.ppfeaturemask=${cfg.gpuOverclock.ppfeaturemask}" - ]; }; meta.maintainers = with lib.maintainers; [ diff --git a/nixos/modules/services/hardware/amdgpu.nix b/nixos/modules/services/hardware/amdgpu.nix index 78f47d858105..4aff9cdd077d 100644 --- a/nixos/modules/services/hardware/amdgpu.nix +++ b/nixos/modules/services/hardware/amdgpu.nix @@ -16,21 +16,44 @@ in series cards. Note: this removes support for analog video outputs, which is only available in the `radeon` driver ''; + initrd.enable = lib.mkEnableOption '' loading `amdgpu` kernelModule in stage 1. Can fix lower resolution in boot screen during initramfs phase ''; + + overdrive = { + enable = lib.mkEnableOption ''`amdgpu` overdrive mode for overclocking''; + + ppfeaturemask = lib.mkOption { + type = lib.types.str; + default = "0xfffd7fff"; + example = "0xffffffff"; + description = '' + Sets the `amdgpu.ppfeaturemask` kernel option. It can be used to enable the overdrive bit. + Default is `0xfffd7fff` as it is less likely to cause flicker issues. Setting it to + `0xffffffff` enables all features, but also can be unstable. See + [the kernel documentation](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/include/amd_shared.h#n169) + for more information. + ''; + }; + }; + opencl.enable = lib.mkEnableOption ''OpenCL support using ROCM runtime library''; # cfg.amdvlk option is defined in ./amdvlk.nix module }; config = { - boot.kernelParams = lib.optionals cfg.legacySupport.enable [ - "amdgpu.si_support=1" - "amdgpu.cik_support=1" - "radeon.si_support=0" - "radeon.cik_support=0" - ]; + boot.kernelParams = + lib.optionals cfg.legacySupport.enable [ + "amdgpu.si_support=1" + "amdgpu.cik_support=1" + "radeon.si_support=0" + "radeon.cik_support=0" + ] + ++ lib.optionals cfg.overdrive.enable [ + "amdgpu.ppfeaturemask=${cfg.overdrive.ppfeaturemask}" + ]; boot.initrd.kernelModules = lib.optionals cfg.initrd.enable [ "amdgpu" ]; diff --git a/nixos/modules/services/misc/tuxclocker.nix b/nixos/modules/services/misc/tuxclocker.nix index f316994314be..b5d1eea767db 100644 --- a/nixos/modules/services/misc/tuxclocker.nix +++ b/nixos/modules/services/misc/tuxclocker.nix @@ -8,16 +8,18 @@ let cfg = config.programs.tuxclocker; in { + imports = [ + (lib.mkRenamedOptionModule + [ "programs" "tuxclocker" "enableAMD" ] + [ "hardware" "amdgpu" "overdrive" "enable" ] + ) + ]; + options.programs.tuxclocker = { enable = lib.mkEnableOption '' TuxClocker, a hardware control and monitoring program ''; - enableAMD = lib.mkEnableOption '' - AMD GPU controls. - Sets the `amdgpu.ppfeaturemask` kernel parameter to 0xfffd7fff to enable all TuxClocker controls - ''; - enabledNVIDIADevices = lib.mkOption { type = lib.types.listOf lib.types.int; default = [ ]; @@ -72,9 +74,5 @@ in ); in lib.concatStrings (map configSection cfg.enabledNVIDIADevices); - - # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/include/amd_shared.h#n207 - # Enable everything modifiable in TuxClocker - boot.kernelParams = lib.mkIf cfg.enableAMD [ "amdgpu.ppfeaturemask=0xfffd7fff" ]; }; }