-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop-dual-egpu.sh
executable file
·69 lines (51 loc) · 1.54 KB
/
stop-dual-egpu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Display each command after execution
set -x
# Treat undefined variables as error
set -u
# Load the config file
source "/etc/libvirt/hooks/kvm.conf"
# Exit if debug shutdown requested
if [[ -f "/home/$VIRSH_USER/.vmdebugshutdown" ]]; then
echo "doing debug stop, nothing to do"
exit 0
fi
# Stop display manager
systemctl stop gdm.service
# Avoid framebuffers being used while unbinding
sleep 2
# Unbind framebuffers
declare -a bound_framebuffers
for vtcon in /sys/class/vtconsole/vtcon*; do
if [[ $(cat "$vtcon/bind") == 1 ]]; then
echo 0 > "$vtcon/bind"
bound_framebuffers+=("$vtcon")
fi
done
# Avoid framebuffer still being bound while GPU is unbinding
sleep 2
# Rebind primary gpu
modprobe amdgpu
driver-rebind "$VIRSH_GPU_VIDEO" amdgpu
# Unbind secondary gpu
driver-rebind "$VIRSH_SECONDARY_GPU_VIDEO" vfio-pci
modprobe -r radeon
# Rebind gpu audio
#modprobe snd_hda_intel
#driver-rebind "$VIRSH_GPU_AUDIO" snd_hda_intel
# Unbind secondary gpu audio
#driver-rebind "$VIRSH_SECONDARY_GPU_AUDIO" vfio-pci
# Avoid GPU not being initialized while rebinding framebuffer
sleep 2
# Rebind framebuffers
for vtcon in "${bound_framebuffers[@]}"; do
echo 1 > "$vtcon/bind"
done
# Reverse cpu core isolation
systemctl set-property --runtime -- user.slice AllowedCPUs=0-11
systemctl set-property --runtime -- system.slice AllowedCPUs=0-11
systemctl set-property --runtime -- init.scope AllowedCPUs=0-11
# Avoid framebuffer not being bound while gdm is starting
sleep 2
# Start display manager
systemctl restart gdm.service