Did you ever find out the answer to this question? I'm looking to setup a script to set nvidia driver persistence mode when a VM shuts down, so the gpu can enter low power state.
Thanks.
EDIT - looks like /etc/libvirt/hooks/qemu is the one you want to edit. I modified the existing script to the below to set nvidia persistence mode when a VM releases all resources. The script update appears to persist between boots.
#!/usr/bin/env php
<?php
if ($argv[2] == 'release' && $argv[3] == 'end'){
shell_exec('date +"%b %d %H:%M:%S libvirt hook: Setting nVidia Promiscuous mode to 1" >> /var/log/syslog');
shell_exec('nvidia-smi --persistence-mode=1');
}
if (!isset($argv[2]) || $argv[2] != 'start') {
exit(0);
}
$strXML = file_get_contents('php://stdin');
$doc = new DOMDocument();
$doc->loadXML($strXML);
$xpath = new DOMXpath($doc);
$args = $xpath->evaluate("//domain/*[name()='qemu:commandline']/*[name()='qemu:arg']/@value");
for ($i = 0; $i < $args->length; $i++){
$arg_list = explode(',', $args->item($i)->nodeValue);
if ($arg_list[0] !== 'vfio-pci') {
continue;
}
foreach ($arg_list as $arg) {
$keypair = explode('=', $arg);
if ($keypair[0] == 'host' && !empty($keypair[1])) {
vfio_bind($keypair[1]);
break;
}