Skip to content

Instantly share code, notes, and snippets.

@roobre
Created July 3, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roobre/b8eadcee61b097c8c22a02eeedb6615b to your computer and use it in GitHub Desktop.
Save roobre/b8eadcee61b097c8c22a02eeedb6615b to your computer and use it in GitHub Desktop.
Libvirt qemu hook
#!/bin/bash
PINNED=2-7,10-15
UNPINNED=0-1,8-9
if [[ $2 == "start" ]]; then
echo "Allocating hugepages..."
#hp 16 || ( echo "Could not allocate hugepages" >&2 && exit 1 )
echo "Stopping sanoid"
systemctl stop sanoid.timer
echo "Isolating cpu set"
cset shield --kthread=on --cpu=$PINNED
echo '0' >> /sys/fs/cgroup/cpuset/system/cpuset.cpu_exclusive
echo '0' >> /sys/fs/cgroup/cpuset/user/cpuset.cpu_exclusive
echo "Setting min turbo perf to 40"
echo 40 > /sys/devices/system/cpu/intel_pstate/min_perf_pct
elif [[ $2 == "started" ]]; then
grep -e vfio /proc/interrupts | cut -d: -f1 | tr -d ' ' | grep -E '^[0-9]+$' | while read int; do
echo $PINNED > /proc/irq/$int/smp_affinity_list
done
grep -ve vfio /proc/interrupts | cut -d: -f1 | tr -d ' ' | grep -E '^[0-9]+$' | while read int; do
echo $UNPINNED > /proc/irq/$int/smp_affinity_list || true
done
true
elif [[ $2 == "stopped" ]]; then
cset shield --reset
cset set -d machine
systemctl start sanoid.timer
echo 16 > /sys/devices/system/cpu/intel_pstate/min_perf_pct # 16 was the default
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment