Guide to setup on/off operation of GPU. Based on works collected in this thread.
GPU management scripts were created by tyrells to which manipulation of blacklist config was added.
- nvidia
- bumblebee (for optirun)
- tlp (optional)
- powertop (optional - for verification)
- unigine-valley (aur, optional - for verification)
This guide should be easily adapted to xrun as bumblebee is only used for optirun.
Add GPU to TLP RUNTIME_PM_BLACKLIST.
RUNTIME_PM_BLACKLIST="01:00.0"
Driver=nvidia
And in nvidia section:
PMMethod=none
Allow gpu to poweroff on boot
w /sys/bus/pci/devices/0000:01:00.0/power/control - - - - auto
Section "ServerFlags"
Option "AutoAddGPU" "off"
EndSection
Section "Device"
Identifier "Intel Graphics"
Driver "modesetting"
EndSection
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
blacklist nv
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uvm
blacklist ipmi_msghandler
blacklist ipmi_devintf
These modules are loaded together with nvidia and block its unloading. I do not need ipmi therefore I simply disabled this functionality.
install ipmi_msghandler /usr/bin/false
install ipmi_devintf /usr/bin/false
install nvidia /bin/false
GPU management scripts were created by tyrells to which manipulation of blacklist config was added.
Create two following management scripts. Creation of aliases is recommended.
#!/bin/sh
# allow to load nvidia module
mv /etc/modprobe.d/disable-nvidia.conf /etc/modprobe.d/disable-nvidia.conf.disable
# remove NVIDIA card (currently in power/control = auto)
echo -n 1 > /sys/bus/pci/devices/0000\:01\:00.0/remove
sleep 1
# change PCIe power control
echo -n on > /sys/bus/pci/devices/0000\:00\:01.0/power/control
sleep 1
# rescan for NVIDIA card (defaults to power/control = on)
echo -n 1 > /sys/bus/pci/rescan
modprobe -r nvidia_drm
modprobe -r nvidia_uvm
modprobe -r nvidia_modeset
modprobe -r nvidia
# change NVIDIA card power control
echo -n auto > /sys/bus/pci/devices/0000\:01\:00.0/power/control
sleep 1
# change PCIe power control
echo -n auto > /sys/bus/pci/devices/0000\:00\:01.0/power/control
sleep 1
# lock system form loading nvidia module
mv /etc/modprobe.d/disable-nvidia.conf.disable /etc/modprobe.d/disable-nvidia.conf
Service which locks GPU on shutdown / restart when it is not disabled by disableGpu.sh script is necessary. Otherwise on next boot nvidia will be loaded together with ipmi modules (even if we have blacklist with install command for them) and it would not be possible to unload them.
[Unit]
Description=Disables Nvidia GPU on OS shutdown
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/bin/bash -c "mv /etc/modprobe.d/lock-nvidia.conf.disable /etc/modprobe.d/lock-nvidia.conf || true"
[Install]
WantedBy=multi-user.target
Reload systemd daemons and enable service:
systemctl daemon-reload
systemctl enable disable-nvidia-on-shutdown.service
- Reboot and verify that nvidia is not loaded
lsmod | grep nvidia
- Disconnect charger and verify on powertop that power consumption is ~4W on idle (Dell XPS 4k, undervolt -168mV core / -145mV cache, disabled touchscreen, powertop --auto-tune)
- Enable GPU by using script.
- Verify if GPU is loaded by using
nvidia-smi
- Run unigine-valley
optirun unigine-valley
- Close all nvidia applications and disable gpu.
- Check again power consumption, it should have similar value as before.
In my case I get ~4w on idle with GPU disabled and ~6W with GPU enabled.