Problem with this is that i cant post a link to original site. Also because most of us are using virt-manager. Our script needs to be a bit different. We can put the script in the hooks folder under /etc/libvirt/hooks
This way it is automatically run when you launch the VM.
This script resolves the issue of the missing task scheduler on the isolated cpu cores and properly pins the QEMU threads.
This is a simple shell script which uses the debug-threads QEMU argument and taskset to find vCPU threads and pin them to an affinity variable set elsewhere in the script.
There is a chance i can find a script that does what we need, but its going to take alot of Google. The issue with isolcpus is already pretty deep to begin with.
Below is code taken from null-src. Credit to them
#!/bin/bash
# clear options
OPTS=""
# set vm name
NAME="PARASITE"
# host affinity list
THREAD_LIST="8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31"
# qemu options
OPTS="$OPTS -name $NAME,debug-threads=on"
OPTS="$OPTS -enable-kvm"
OPTS="$OPTS -cpu host"
OPTS="$OPTS -smp 16,cores=8,sockets=1,threads=2"
OPTS="$OPTS -m 32G"
OPTS="$OPTS -drive if=virtio,format=raw,aio=threads,file=/vms/disk-images/windows-10.img"
function run-vm {
# specify which host threads to run QEMU parent and worker processes on
taskset -c 0-7,16-32 qemu-system-x86_64 $OPTS
}
function set-affinity {
# sleep for 20 seconds while QEMU VM boots and vCPU threads are created
sleep 20 &&
HOST_THREAD=0
# for each vCPU thread PID
for PID in $(pstree -pa $(pstree -pa $(pidof qemu-system-x86_64) | grep $NAME | awk -F',' '{print $2}' | awk '{print $1}') | grep CPU | pstree -pa $(pstree -pa $(pidof qemu-system-x86_64) | grep $NAME | cut -d',' -f2 | cut -d' ' -f1) | grep CPU | sort | awk -F',' '{print $2}')
do
let HOST_THREAD+=1
# set each vCPU thread PID to next host CPU thread in THREAD_LIST
echo "taskset -pc $(echo $THREAD_LIST | cut -d',' -f$HOST_THREAD) $PID" | bash
done
}
set-affinity &
run-vm