Skip to content

Commit

Permalink
Fixed suspend in nvidia and hybrid mode (#127)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Boria138 authored Sep 11, 2023
1 parent 66cb0e2 commit b93bdf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 31 additions & 3 deletions envycontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# begin constants definition

VERSION = '3.2.0'
VERSION = '3.3.0'

BLACKLIST_PATH = '/etc/modprobe.d/blacklist-nvidia.conf'

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit b93bdf4

Please sign in to comment.