Instantly share code, notes, and snippets.

@ayufan /taskset.sh
Last active Mar 25, 2018

Embed
What would you like to do?
KVM CPU pinning for Proxmox VE
#!/bin/bash
set -eo pipefail
VMID=200
cpu_tasks() {
expect <<EOF | sed -n 's/^.* CPU .*thread_id=\(.*\)$/\1/p' | tr -d '\r' || true
spawn qm monitor $VMID
expect ">"
send "info cpus\r"
expect ">"
EOF
}
VCPUS=($(cpu_tasks))
VCPU_COUNT="${#VCPUS[@]}"
if [[ $VCPU_COUNT -eq 0 ]]; then
echo "* No VCPUS for VM$VMID"
exit 1
fi
echo "* Detected ${#VCPUS[@]} assigned to VM$VMID..."
echo "* Resetting cpu shield..."
for CPU_INDEX in "${!VCPUS[@]}"
do
CPU_TASK="${VCPUS[$CPU_INDEX]}"
echo "* Assigning $CPU_INDEX to $CPU_TASK..."
taskset -pc "$CPU_INDEX" "$CPU_TASK"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment