Trouble setting up vfio-isolate

hi yall ive been trying to get my cpu performance well in my vm and its been a struggle im using a single gpu passthrough and in all my games my performance is about a 1/3 to less.

im getting this error…
Error starting domain: Hook script execution failed: internal error: Child process (LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin /etc/libvirt/hooks/qemu sweetpea12 prepare begin -) unexpected exit status 127: /etc/libvirt/hooks/qemu: line 62: enable_isolation: command not found

i tried following another post here and ended up getting confused is there anyone willing to help that would be amazing thank you:)

1 Like

also, i dont know if this has anything to do with it im still new-ish to linux, and i installed vfio-isolate via yay and im questioning if thats one of the reasons i wouldnt think so but its a thought im having…

1 Like

heres the script inside the qemu file.

##if [ “$1” != “sweetpea12” ]; then
exit 0
fi

RSET=/

HSET=/host.slice
HNODE=C0-6,14-16

MNODE=C8-15,0-13

UNDOFILE=/var/run/libvirt/qemu/vfio-isolate-undo.bin

disable_isolation () {
vfio-isolate
restore $UNDOFILE

taskset -pc 0-31 2
}

case “$2” in
“prepare”)
enable_isolation
;;
“started”)
;;
“release”)
disable_isolation
;;
esac

ive commented it out to use the vm…

1 Like

Installation via Yay works, there is an issue with your hook script.

There is you issue. You are missing part of the script. Scripts in the hook folder get executed anytime a virtual machine changes state. This script gets called with two parameters i.e. name followed by state e.g. "qemu gaming-vm prepare". The if condition in the beginning is a check (of the first parameter, in this example “gaming-vm”) to see if this is a virtual machine that we want to apply this script for or one we want to ignore. After that you define the slices, meaning which cores the host will have access to and which will be reserved to the virtual machine. Then we define (but not execute, yet) two functions, one which gets triggered during the prepare and one that gets triggered during the release stage. The bottom part with the switch-statement checks during which stage the script got called. As I mentioned earlier the script will get automatically executed anytime the state of the virtual machine changes. The prepare stage gets executed before the virtual machine gets started and runs the function to enable vfio-isolate (enable_isolation ()), while the release stage gets executed after the virtual machine has shut down. The release stage calls the second function (disable_isolation ()) to revert the changes this script does.

From what you have posted it seems you have a 16 core processor with 32 threads available and you want to run the virtual machine on the last 8 cores of the processor while the host should use the first 6 cores. The following should represent a valid hook script for this setup with up-to-date syntax.

#!/bin/bash

if  [ "$1" != "sweetpea12" ]; then
	exit 0
fi

HCPUS=0-6,16-21
MCPUS=8-15,24-31

UNDOFILE=/var/run/libvirt/qemu/vfio-isolate-undo.bin

disable_isolation() {
	vfio-isolate \
		restore $UNDOFILE

	taskset -pc 0-31 2  # kthreadd reset
}

enable_isolation () {
	vfio-isolate \
		-u $UNDOFILE \
		drop-caches \
		cpuset-modify --cpus C$HCPUS /system.slice \
		cpuset-modify --cpus C$HCPUS /user.slice \
		compact-memory \
		irq-affinity mask C$MCPUS

	taskset -pc $HCPUS 2  # kthreadd only on host cores
}

case "$2" in
"prepare")
	enable_isolation
	;;
"started")
	;;
"release")
	disable_isolation
	;;
esac