VFIO Success
This commit is contained in:
5
scripts/hooks/kvm.conf
Normal file
5
scripts/hooks/kvm.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
## Virsh devices
|
||||
VIRSH_GPU_VIDEO=pci_0000_01_00_0
|
||||
VIRSH_GPU_AUDIO=pci_0000_01_00_1
|
||||
MEMORY=20480
|
||||
WIN=/dev/nvme1n1p3
|
65
scripts/hooks/win10-igpu/prepare/begin/start.sh
Normal file
65
scripts/hooks/win10-igpu/prepare/begin/start.sh
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# Load Variables
|
||||
source "/etc/libvirt/hooks/kvm.conf"
|
||||
|
||||
# Unmount the Windows drive
|
||||
umount $WIN || /bin/true
|
||||
|
||||
# Stop LightDM
|
||||
systemctl stop lightdm.service
|
||||
sleep 2
|
||||
|
||||
# Calculate number of hugepages to allocate from memory (in MB)
|
||||
HUGEPAGES="$(($MEMORY/$(($(grep Hugepagesize /proc/meminfo | awk '{print $2}')/1024))))"
|
||||
|
||||
echo "Allocating hugepages..."
|
||||
echo $HUGEPAGES > /proc/sys/vm/nr_hugepages
|
||||
ALLOC_PAGES=$(cat /proc/sys/vm/nr_hugepages)
|
||||
|
||||
TRIES=0
|
||||
while (( $ALLOC_PAGES != $HUGEPAGES && $TRIES < 1000 ))
|
||||
do
|
||||
echo 1 > /proc/sys/vm/compact_memory ## defrag ram
|
||||
echo $HUGEPAGES > /proc/sys/vm/nr_hugepages
|
||||
ALLOC_PAGES=$(cat /proc/sys/vm/nr_hugepages)
|
||||
echo "Succesfully allocated $ALLOC_PAGES / $HUGEPAGES"
|
||||
let TRIES+=1
|
||||
done
|
||||
|
||||
if [ "$ALLOC_PAGES" -ne "$HUGEPAGES" ]
|
||||
then
|
||||
echo "Not able to allocate all hugepages. Reverting..."
|
||||
echo 0 > /proc/sys/vm/nr_hugepages
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Unload all Nvidia drivers
|
||||
modprobe -r nvidia_drm
|
||||
modprobe -r nvidia_modeset
|
||||
modprobe -r nvidia_uvm
|
||||
modprobe -r nvidia
|
||||
|
||||
# Unbind the GPU from display driver
|
||||
virsh nodedev-detach $VIRSH_GPU_VIDEO
|
||||
virsh nodedev-detach $VIRSH_GPU_AUDIO
|
||||
|
||||
# Load VFIO kernel module
|
||||
modprobe vfio
|
||||
modprobe vfio_pci
|
||||
modprobe vfio_iommu_type1
|
||||
|
||||
# Create looking glass shm
|
||||
systemd-tmpfiles --create /etc/tmpfiles.d/10-looking-glass.conf
|
||||
|
||||
# Enable CPU governor performance mode
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "performance" > $file; done
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
|
||||
# Isolate host
|
||||
systemctl set-property --runtime -- user.slice AllowedCPUs=12,13,14,15
|
||||
systemctl set-property --runtime -- system.slice AllowedCPUs=12,13,14,15
|
||||
systemctl set-property --runtime -- init.scope AllowedCPUs=12,13,14,15
|
43
scripts/hooks/win10-igpu/release/end/revert.sh
Normal file
43
scripts/hooks/win10-igpu/release/end/revert.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# Load Variables
|
||||
source "/etc/libvirt/hooks/kvm.conf"
|
||||
|
||||
# Unload VFIO kernel module
|
||||
modprobe -r vfio_pci
|
||||
modprobe -r vfio_iommu_type1
|
||||
modprobe -r vfio
|
||||
|
||||
# Rebind the GPU to display driver
|
||||
virsh nodedev-reattach $VIRSH_GPU_VIDEO
|
||||
virsh nodedev-reattach $VIRSH_GPU_AUDIO
|
||||
|
||||
# Read our nvidia configuration when before starting our graphics
|
||||
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
|
||||
|
||||
# Load all Nvidia drivers
|
||||
modprobe nvidia_drm
|
||||
modprobe nvidia_modeset
|
||||
modprobe nvidia_uvm
|
||||
modprobe nvidia
|
||||
|
||||
# Dealloc hugepages
|
||||
echo 0 > /proc/sys/vm/nr_hugepages
|
||||
|
||||
## Enable CPU governor schedutil mode
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "schedutil" > $file; done
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
|
||||
# Deisolate host
|
||||
systemctl set-property --runtime -- user.slice AllowedCPUs=0-15
|
||||
systemctl set-property --runtime -- system.slice AllowedCPUs=0-15
|
||||
systemctl set-property --runtime -- init.scope AllowedCPUs=0-15
|
||||
|
||||
# Delete looking glass shm
|
||||
rm /dev/shm/looking-glass
|
||||
|
||||
# Mount the Windows drive
|
||||
mount -a || /bin/true
|
17
scripts/hooks/win10-igpu/started/begin/lightdm.sh
Normal file
17
scripts/hooks/win10-igpu/started/begin/lightdm.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Uncomment autologin lines in /etc/lightdm/lightdm.conf
|
||||
sed -i 's/^#autologin-user=/autologin-user=/' /etc/lightdm/lightdm.conf
|
||||
sed -i 's/^#autologin-user-timeout=/autologin-user-timeout=/' /etc/lightdm/lightdm.conf
|
||||
sed -i 's/^#autologin-session=/autologin-session=/' /etc/lightdm/lightdm.conf
|
||||
|
||||
# Restart lightdm
|
||||
systemctl restart lightdm.service
|
||||
|
||||
# Sleep 10 seconds
|
||||
sleep 10
|
||||
|
||||
# Comment out autologin lines in /etc/lightdm/lightdm.conf
|
||||
sed -i 's/^autologin-user=/#autologin-user=/' /etc/lightdm/lightdm.conf
|
||||
sed -i 's/^autologin-user-timeout=/#autologin-user-timeout=/' /etc/lightdm/lightdm.conf
|
||||
sed -i 's/^autologin-session=/#autologin-session=/' /etc/lightdm/lightdm.conf
|
@@ -1,9 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Load the config file
|
||||
set -x
|
||||
|
||||
# Load Variables
|
||||
source "/etc/libvirt/hooks/kvm.conf"
|
||||
|
||||
## Calculate number of hugepages to allocate from memory (in MB)
|
||||
# Calculate number of hugepages to allocate from memory (in MB)
|
||||
HUGEPAGES="$(($MEMORY/$(($(grep Hugepagesize /proc/meminfo | awk '{print $2}')/1024))))"
|
||||
|
||||
echo "Allocating hugepages..."
|
||||
@@ -26,3 +28,13 @@ then
|
||||
echo 0 > /proc/sys/vm/nr_hugepages
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Enable CPU governor performance mode
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "performance" > $file; done
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
|
||||
# Isolate host
|
||||
systemctl set-property --runtime -- user.slice AllowedCPUs=14,15
|
||||
systemctl set-property --runtime -- system.slice AllowedCPUs=14,15
|
||||
systemctl set-property --runtime -- init.scope AllowedCPUs=14,15
|
16
scripts/hooks/win10/release/end/revert.sh
Normal file
16
scripts/hooks/win10/release/end/revert.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# Enable CPU governor schedutil mode
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "schedutil" > $file; done
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
|
||||
# Deisolate host
|
||||
systemctl set-property --runtime -- user.slice AllowedCPUs=0-15
|
||||
systemctl set-property --runtime -- system.slice AllowedCPUs=0-15
|
||||
systemctl set-property --runtime -- init.scope AllowedCPUs=0-15
|
||||
|
||||
# Dealloc hugepages
|
||||
echo 0 > /proc/sys/vm/nr_hugepages
|
0
scripts/iommu.sh
Normal file → Executable file
0
scripts/iommu.sh
Normal file → Executable file
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Enable CPU governor performance mode
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "performance" > $file; done
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
@@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# Load Variables
|
||||
source "/etc/libvirt/hooks/kvm.conf"
|
||||
|
||||
# Stop LightDM
|
||||
systemctl stop lightdm.service
|
||||
sleep 2
|
||||
|
||||
# Unbind VTconsoles
|
||||
echo 0 > /sys/class/vtconsole/vtcon0/bind
|
||||
echo 0 > /sys/class/vtconsole/vtcon1/bind
|
||||
|
||||
# Unbind EFI-Framebuffer
|
||||
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
|
||||
|
||||
# Avoid a race condition by waiting a couple of seconds. This can be calibrated to be shorter or longer if required for your system
|
||||
sleep 2
|
||||
|
||||
# Unload all Nvidia drivers
|
||||
modprobe -r nvidia_drm
|
||||
modprobe -r nvidia_modeset
|
||||
modprobe -r drm_kms_helper
|
||||
modprobe -r nvidia
|
||||
modprobe -r drm
|
||||
|
||||
# Unbind the GPU from display driver
|
||||
virsh nodedev-detach $VIRSH_GPU_VIDEO
|
||||
virsh nodedev-detach $VIRSH_GPU_AUDIO
|
||||
|
||||
# Load VFIO kernel module
|
||||
modprobe vfio
|
||||
modprobe vfio_pci
|
||||
modprobe vfio_iommu_type1
|
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Enable CPU governor on-demand mode
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
||||
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "schedutil" > $file; done
|
||||
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Load the config file
|
||||
source "/etc/libvirt/hooks/kvm.conf"
|
||||
|
||||
echo 0 > /proc/sys/vm/nr_hugepages
|
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
# Load the config file with our environmental variables
|
||||
source "/etc/libvirt/hooks/kvm.conf"
|
||||
|
||||
# Unload VFIO-PCI Kernel Driver
|
||||
modprobe -r vfio_pci
|
||||
modprobe -r vfio_iommu_type1
|
||||
modprobe -r vfio
|
||||
|
||||
# Re-Bind GPU to our display drivers
|
||||
virsh nodedev-reattach $VIRSH_GPU_VIDEO
|
||||
virsh nodedev-reattach $VIRSH_GPU_AUDIO
|
||||
|
||||
# Rebind VT consoles
|
||||
echo 1 > /sys/class/vtconsole/vtcon0/bind
|
||||
echo 1 > /sys/class/vtconsole/vtcon1/bind
|
||||
|
||||
# Read our nvidia configuration when before starting our graphics
|
||||
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
|
||||
|
||||
# Re-Bind EFI-Framebuffer
|
||||
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
|
||||
|
||||
# Load nvidia drivers
|
||||
modprobe nvidia_drm
|
||||
modprobe nvidia_modeset
|
||||
modprobe drm_kms_helper
|
||||
modprobe nvidia
|
||||
modprobe drm
|
||||
|
||||
# Restart Display Manager
|
||||
systemctl start lightdm.service
|
Reference in New Issue
Block a user