materusPC: fix for reattach performance issue

This commit is contained in:
Mateusz Słodkowicz 2024-05-20 15:39:47 +02:00
parent ab43f858ea
commit c04f1f41fd
Signed by: materus
GPG Key ID: 28D140BCA60B4FD1
1 changed files with 33 additions and 10 deletions

View File

@ -1,5 +1,10 @@
{ config, pkgs, materusArg, ... }: { config, pkgs, materusArg, ... }:
let let
bar0_guest="15";
bar2_guest="8";
bar0_host="15";
bar2_host="8";
VM_UUID = "ad2632db-0da0-4204-98b3-0592a185ebd0"; VM_UUID = "ad2632db-0da0-4204-98b3-0592a185ebd0";
startedHook = '' startedHook = ''
@ -36,6 +41,8 @@ let
'' ''
+*/ +*/
'' ''
systemctl stop windows-share-mount.service
# Make sure nothing renders on gpu to prevent "sysfs: cannot create duplicate filename" after rebinding to amdgpu # Make sure nothing renders on gpu to prevent "sysfs: cannot create duplicate filename" after rebinding to amdgpu
chmod 0 /dev/dri/renderD128 chmod 0 /dev/dri/renderD128
fuser -k /dev/dri/renderD128 fuser -k /dev/dri/renderD128
@ -43,23 +50,36 @@ let
# Seems to fix reset bug for 7900 XTX # Seems to fix reset bug for 7900 XTX
echo "0" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/d3cold_allowed" echo "0" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/d3cold_allowed"
systemctl stop windows-share-mount.service #####################################################################
# Weird bug on kernel 6.7+, after changing bar sizes and binding to vfio driver, performance after returning to host will be lower than expected
# binding to amdgpu after changing bar sizes and binding after it to vfio will work as expected.
# I could skip changing bar sizes since I'm able to use full bar, but keeping it just in case
echo ''$VIRSH_GPU_VIDEO > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/driver/unbind"
sleep 1s
echo "${bar0_host}" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource0_resize"
echo "${bar2_host}" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource2_resize"
echo ''$VIRSH_GPU_VIDEO > /sys/bus/pci/drivers/amdgpu/bind
sleep 1s
chmod 0 /dev/dri/renderD128
fuser -k /dev/dri/renderD128
#####################################################################
echo ''$VIRSH_GPU_VIDEO > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/driver/unbind" echo ''$VIRSH_GPU_VIDEO > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/driver/unbind"
echo ''$VIRSH_GPU_AUDIO > "/sys/bus/pci/devices/''${VIRSH_GPU_AUDIO}/driver/unbind" echo ''$VIRSH_GPU_AUDIO > "/sys/bus/pci/devices/''${VIRSH_GPU_AUDIO}/driver/unbind"
sleep 1s echo "${bar0_guest}" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource0_resize"
echo "${bar2_guest}" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource2_resize"
echo "15" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource0_resize"
echo "8" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource2_resize"
sync sync
echo "3" > /proc/sys/vm/drop_caches echo "3" > /proc/sys/vm/drop_caches
sync sync
echo "1" > /proc/sys/vm/compact_memory echo "1" > /proc/sys/vm/compact_memory
systemctl set-property --runtime -- user.slice AllowedCPUs=${materusArg.materusPC.hostCores} systemctl set-property --runtime -- user.slice AllowedCPUs=${materusArg.materusPC.hostCores}
systemctl set-property --runtime -- system.slice AllowedCPUs=${materusArg.materusPC.hostCores} systemctl set-property --runtime -- system.slice AllowedCPUs=${materusArg.materusPC.hostCores}
@ -71,6 +91,9 @@ let
sysctl -w kernel.watchdog=0 sysctl -w kernel.watchdog=0
''; '';
stopHook = '' stopHook = ''
@ -101,8 +124,8 @@ let
echo "15" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource0_resize" echo "${bar0_host}" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource0_resize"
echo "8" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource2_resize" echo "${bar2_host}" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/resource2_resize"
echo "1" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/d3cold_allowed" echo "1" > "/sys/bus/pci/devices/''${VIRSH_GPU_VIDEO}/d3cold_allowed"