From b93bdf459a86c71a2a1e5dff3396b71c4d93a1d8 Mon Sep 17 00:00:00 2001 From: Boria138 <36843745+Boria138@users.noreply.github.com> Date: Tue, 12 Sep 2023 05:30:16 +0600 Subject: [PATCH] Fixed suspend in nvidia and hybrid mode (#127) * Fixed suspend in nvidia and hybrid mode I had suspend not working on nvidia and hybrid mods after I added to envycontrol settings for nvidia from https://github.com/CachyOS/CachyOS-Settings everything worked. * Fixed rtd3 * Returned the right things and deleted the unnecessary ones * Added loging --- README.md | 3 ++- envycontrol.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a2f737..a256db4 100644 --- a/README.md +++ b/README.md @@ -176,10 +176,11 @@ The [GPU profile selector](https://github.com/LorenzoMorelli/GPU_profile_selecto ### Wayland session is missing on Gnome 43+ -GDM now requires `NVreg_PreserveVideoMemoryAllocations` kernel parameter which is set automatically by EnvyControl however you might need to enable the `nvidia-suspend` services: +GDM now requires `NVreg_PreserveVideoMemoryAllocations` kernel parameter which breaks sleep in nvidia and hybrid mode, as well as rtd3 in hybrid mode, so EnvyControl disables it, if you need a Wayland session follow the instructions below ``` sudo systemctl enable nvidia-{suspend,resume,hibernate} +sudo ln -s /dev/null /etc/udev/rules.d/61-gdm.rules ``` ### The `/usr/share/sddm/scripts/Xsetup` file is missing on my system diff --git a/envycontrol.py b/envycontrol.py index 1eb22bc..3f4169f 100755 --- a/envycontrol.py +++ b/envycontrol.py @@ -8,7 +8,7 @@ # begin constants definition -VERSION = '3.2.0' +VERSION = '3.3.0' BLACKLIST_PATH = '/etc/modprobe.d/blacklist-nvidia.conf' @@ -148,14 +148,14 @@ MODESET_CONTENT = '''# Automatically generated by EnvyControl options nvidia-drm modeset=1 -options nvidia NVreg_PreserveVideoMemoryAllocations=1 +options nvidia NVreg_UsePageAttributeTable=1 NVreg_InitializeSystemMemoryAllocations=0 ''' MODESET_RTD3 = '''# Automatically generated by EnvyControl options nvidia-drm modeset=1 options nvidia "NVreg_DynamicPowerManagement=0x0{}" -options nvidia NVreg_PreserveVideoMemoryAllocations=1 +options nvidia NVreg_UsePageAttributeTable=1 NVreg_InitializeSystemMemoryAllocations=0 ''' SDDM_XSETUP_PATH = '/usr/share/sddm/scripts/Xsetup' @@ -193,6 +193,16 @@ def graphics_mode_switcher(graphics_mode, user_display_manager, enable_force_com print(f"Switching to {graphics_mode} mode") if graphics_mode == 'integrated': + + if logging.getLogger().level == logging.DEBUG: + service = subprocess.run(["systemctl", "disable", "nvidia-persistenced.service"]) + else: + service = subprocess.run(["systemctl", "disable", "nvidia-persistenced.service"],stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if service.returncode == 0: + print('Successfully disabled nvidia-persistenced.service') + else: + logging.error("An error ocurred while disabling service") + cleanup() # blacklist all nouveau and Nvidia modules @@ -207,6 +217,15 @@ def graphics_mode_switcher(graphics_mode, user_display_manager, enable_force_com f"Enable PCI-Express Runtime D3 (RTD3) Power Management: {rtd3_value or False}") cleanup() + if logging.getLogger().level == logging.DEBUG: + service = subprocess.run(["systemctl", "enable", "nvidia-persistenced.service"]) + else: + service = subprocess.run(["systemctl", "enable", "nvidia-persistenced.service"],stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if service.returncode == 0: + print('Successfully enabled nvidia-persistenced.service') + else: + logging.error("An error ocurred while enabling service") + if rtd3_value == None: create_file(MODESET_PATH, MODESET_CONTENT) else: @@ -219,6 +238,15 @@ def graphics_mode_switcher(graphics_mode, user_display_manager, enable_force_com print(f"Enable ForceCompositionPipeline: {enable_force_comp}") print(f"Enable Coolbits: {coolbits_value or False}") + if logging.getLogger().level == logging.DEBUG: + service = subprocess.run(["systemctl", "enable", "nvidia-persistenced.service"]) + else: + service = subprocess.run(["systemctl", "enable", "nvidia-persistenced.service"],stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if service.returncode == 0: + print('Successfully enabled nvidia-persistenced.service') + else: + logging.error("An error ocurred while enabling service") + cleanup() # get the Nvidia dGPU PCI bus nvidia_gpu_pci_bus = get_nvidia_gpu_pci_bus()