I have a laptop that has Intel and Nvidia GPUs and the Nvidia GPU is not used by the host (no drivers installed). I only use it for GPU passthrough to VMs.
There’s a module called
bbswitch which can be used to shut down the Nvidia GPU when it is not in use, and this can greatly save battery life. Right now my solution to running VMs that get passed the gpu is to run the following commands before it starts up:
# turn on the dGPU echo ON > /proc/acpi/bbswitch # unload the bbswitch module rmmod bbswitch
and this when the VM shuts down:
# load bbswitch module modprobe bbswitch # turn off the dGPU echo OFF > /proc/acpi/bbswitch
What is the recommended solution to have LXD automate these tasks for me?
I managed to emulate the post-stop hook by writing a python-lxd script that listens for the “instance-shutdown” lifecycle event and turns off the GPU.
While there’s an event for when the instance starts up, it only happens when it is already started, and ideally we’d remove the bbswitch module before it starts up (I assume bbswitch binds to the GPU, which can cause problems if vfio-pci also tries to bind).