-
Notifications
You must be signed in to change notification settings - Fork 2
/
set_affinity_qemu.sh
executable file
·50 lines (40 loc) · 1.18 KB
/
set_affinity_qemu.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
#!/bin/bash
# !
# ! Usage: ./set_affinity_memcached.sh <host net interface, e.g. eth1>
# !
if [[ $# -ne 1 ]]; then
cat $0 | grep ^"# !" | cut -d"!" -f2-
exit 1
fi
cur_cpu=0
total_cpus=`cat /proc/cpuinfo | grep processor | wc -l`
#total_cpus=1
NIC=$1
cpus4qemu=$((total_cpus-2))
if [[ $cpus4qemu -le 0 ]]; then
cpus4qemu=1
fi
echo "cpus4qemu=$cpus4qemu"
cpu_qemu_threads=0
# Set qemu threads affinity
for t in $(echo query-cpus | sudo qmp-shell -p /tmp/qmp-sock | grep thread_id | cut -d':' -f 2 | cut -d'}' -f 1)
do
sudo taskset -pc $cur_cpu $t
cur_cpu=$(((cur_cpu + 1) % cpus4qemu))
cpu_qemu_threads=$((cpu_qemu_threads+1))
done
cur_cpu=$((cpus4qemu % total_cpus))
if [[ $cur_cpu -gt $cpu_qemu_threads ]]; then
cur_cpu=$cpu_qemu_threads
fi
echo "Setting the vhost affinity to CPU $cur_cpu"
sudo taskset -pc $cur_cpu `pgrep vhost`
echo "Stoping irqbalance.."
sudo systemctl stop irqbalance.service
cur_cpu=$(((cur_cpu+1) % total_cpus))
# Set the affinity of the NIC irqs to the same
for i in `grep $NIC /proc/interrupts | awk -F: '{print $1}'`
do
echo "Setting the affinity of IRQ $i to CPU $cur_cpu"
sudo sh -c "echo $cur_cpu > /proc/irq/$i/smp_affinity_list"
done