Skip to content

Commit 16cb9ed

Browse files
committed
nixos/nvidia: use kernel suspend notifiers if available
1 parent e99215c commit 16cb9ed

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

nixos/modules/hardware/video/nvidia.nix

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,19 @@ in
8888
the NVIDIA docs, on Chapter 21. Configuring Power Management Support
8989
'';
9090

91-
powerManagement.finegrained = lib.mkEnableOption ''
92-
experimental power management of PRIME offload. For more information, see
93-
the NVIDIA docs, on Chapter 22. PCI-Express Runtime D3 (RTD3) Power Management
94-
'';
91+
powerManagement.kernelSuspendNotifier =
92+
lib.mkEnableOption ''
93+
NVIDIA driver support for kernel suspend notifiers, which allows the driver
94+
to be notified of suspend and resume events by the kernel, rather than
95+
relying on systemd services.
96+
Requires NVIDIA driver version 595 or newer, and the open source kernel modules.
97+
''
98+
// {
99+
default = useOpenModules && lib.versionAtLeast nvidia_x11.version "595";
100+
defaultText = lib.literalExpression ''
101+
config.hardware.nvidia.open == true && lib.versionAtLeast config.hardware.nvidia.package.version "595"
102+
'';
103+
};
95104

96105
dynamicBoost.enable = lib.mkEnableOption ''
97106
dynamic Boost balances power between the CPU and the GPU for improved
@@ -465,6 +474,13 @@ in
465474
assertion = cfg.dynamicBoost.enable -> lib.versionAtLeast nvidia_x11.version "510.39.01";
466475
message = "NVIDIA's Dynamic Boost feature only exists on versions >= 510.39.01";
467476
}
477+
478+
{
479+
assertion =
480+
cfg.powerManagement.kernelSuspendNotifier
481+
-> (useOpenModules && lib.versionAtLeast nvidia_x11.version "595");
482+
message = "NVIDIA driver support for kernel suspend notifiers requires NVIDIA driver version 595 or newer, and the open source kernel modules.";
483+
}
468484
];
469485

470486
# If Optimus/PRIME is enabled, we:
@@ -576,7 +592,9 @@ in
576592
''
577593
);
578594

579-
systemd.packages = lib.optional cfg.powerManagement.enable nvidia_x11.out;
595+
systemd.packages = lib.optional (
596+
cfg.powerManagement.enable && !cfg.powerManagement.kernelSuspendNotifier
597+
) nvidia_x11.out;
580598

581599
systemd.services =
582600
let
@@ -592,7 +610,7 @@ in
592610
};
593611
in
594612
lib.mkMerge [
595-
(lib.mkIf cfg.powerManagement.enable {
613+
(lib.mkIf (cfg.powerManagement.enable && !cfg.powerManagement.kernelSuspendNotifier) {
596614
nvidia-suspend = nvidiaService "suspend";
597615
nvidia-hibernate = nvidiaService "hibernate";
598616
nvidia-resume = (nvidiaService "resume") // {
@@ -669,6 +687,9 @@ in
669687
++ lib.optional (
670688
(offloadCfg.enable || cfg.modesetting.enable) && lib.versionAtLeast nvidia_x11.version "545"
671689
) "nvidia-drm.fbdev=1"
690+
++ lib.optional (
691+
cfg.powerManagement.enable && cfg.powerManagement.kernelSuspendNotifier
692+
) "nvidia.NVreg_UseKernelSuspendNotifiers=1"
672693
++ lib.optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1"
673694
++ lib.optional useOpenModules "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1"
674695
++ lib.optional (config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport) "ibt=off";

0 commit comments

Comments
 (0)