-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqemu_fifo.sh
executable file
·60 lines (48 loc) · 1.6 KB
/
qemu_fifo.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
#!/bin/bash
HCPUS=8-15,24-31
MCPUS=0-7,16-23
ACPUS=0-31
disable_isolation () {
#vfio-isolate \
# cpuset-modify --cpus C$ACPUS /system.slice \
# cpuset-modify --cpus C$ACPUS /user.slice \
# irq-affinity mask C$ACPUS
systemctl set-property --runtime -- user.slice AllowedCPUs=$ACPUS
systemctl set-property --runtime -- system.slice AllowedCPUs=$ACPUS
systemctl set-property --runtime -- init.scope AllowedCPUs=$ACPUS
echo 950000 > /proc/sys/kernel/sched_rt_runtime_us
taskset -pc $ACPUS 2 # kthreadd reset
}
enable_isolation () {
chrt -a -f -p 99 $(pidof qemu-system-x86_64)
echo "Set QEMU execution policy!"
chrt -p $(pidof qemu-system-x86_64)
vfio-isolate \
drop-caches \
cpuset-modify --cpus C$HCPUS /system.slice \
cpuset-modify --cpus C$HCPUS /user.slice \
move-tasks / /system.slice \
compact-memory \
irq-affinity mask C$MCPUS
# schedule real-time processes to have more CPU time
echo -1 > /proc/sys/kernel/sched_rt_runtime_us
systemctl set-property --runtime -- user.slice AllowedCPUs=$HCPUS
systemctl set-property --runtime -- system.slice AllowedCPUs=$HCPUS
systemctl set-property --runtime -- init.scope AllowedCPUs=$HCPUS
taskset -pc $HCPUS 2 # kthreadd only on host cores
}
arg="$1"
shift
if [ "$arg" == "--cleanup" ]; then
ec\ho "Cleanup qemu fifo"
disable_isolation
exit 0
fi
if [[ $(sudo virsh list --all | grep running) ]]; then
echo "VM running, performing action"
enable_isolation
else
echo "VM no longer running, aborting"
disable_isolation
exit 1
fi