Created
August 17, 2023 20:36
-
-
Save dohq/583f3a35e57d23657e5c3ee43d4e414f to your computer and use it in GitHub Desktop.
Gaming on Windows in comfort with PCI passthrough
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /etc/libvirt/hooks/qemu.d/windows10/prepare/begin/isolate_cpu.sh | |
GUEST_NAME="$1" | |
GUEST_ACTION="$2/$3" | |
ALLOWED_CPUS="0-7,16-23" | |
ALL_CPUS="0-31" | |
# All checks passed, continue | |
if [[ "$GUEST_ACTION" == "prepare/begin" ]]; then | |
echo "libvirt-qemu cset: Reserving CPUs for VM $GUEST_NAME" > /dev/kmsg 2>&1 | |
# Allocate CPUs | |
systemctl set-property --runtime -- system.slice AllowedCPUs="${ALLOWED_CPUS}" | |
systemctl set-property --runtime -- user.slice AllowedCPUs="${ALLOWED_CPUS}" | |
systemctl set-property --runtime -- init.scope AllowedCPUs="${ALLOWED_CPUS}" | |
# Set CPU Govener | |
echo "libvirt-qemu cset: Set CPU governor to performance for VM $GUEST_NAME" > /dev/kmsg 2>&1 | |
echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | |
echo "libvirt-qemu cset: Set ReBar 8GB for VM $GUEST_NAME" > /dev/kmsg 2>&1 | |
# https://forum.level1techs.com/t/vfio-2023-radeon-7000-edition-wip/199252/1#re-size-bar-complications-6 | |
rmmod vfio_pci | |
echo 13 > /sys/bus/pci/devices/0000:0e:00.0/resource0_resize | |
echo 3 > /sys/bus/pci/devices/0000:0e:00.0/resource2_resize | |
modprobe vfio_pci | |
sleep 2 | |
lspci -vvvs 0000:0e:00.0 | grep -A 2 "Physical Resizable BAR" | sed -z -e 's/^[ \t ]*//; s/\n//g' | tee /dev/kmsg 2>&1 | |
elif [[ "$GUEST_ACTION" == "release/end" ]]; then | |
echo "libvirt-qemu cset: Releasing CPUs from VM $GUEST_NAME" > /dev/kmsg 2>&1 | |
# Allocate CPUs | |
systemctl set-property --runtime -- system.slice AllowedCPUs="${ALL_CPUS}" | |
systemctl set-property --runtime -- user.slice AllowedCPUs="${ALL_CPUS}" | |
systemctl set-property --runtime -- init.scope AllowedCPUs="${ALL_CPUS}" | |
# Set CPU Govener | |
echo "libvirt-qemu cset: Set CPU governor to ondemand for VM $GUEST_NAME" > /dev/kmsg 2>&1 | |
echo ondemand | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment