-
-
Save 7castle/2a92fc3340bc42959912 to your computer and use it in GitHub Desktop.
KVM CPU pinning for Proxmox VE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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