Created
August 16, 2018 15:00
-
-
Save pjhades/348c636060452d2cef985a2e4c2ce7d4 to your computer and use it in GitHub Desktop.
Distribute NIC interrupts evenly among the first X cores
This file contains 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 | |
mask() { | |
local bytes=$((($2+3)/4)) | |
local remaining=$((bytes%8)) | |
local groups=$((bytes/8)) | |
local s=$(printf "%0${bytes}x" $((1<<$1))) | |
local rc=${s::$remaining} | |
s=${s:$remaining} | |
while [ -n "$s" ]; do | |
rc="$rc,${s::8}" | |
s=${s:8} | |
done | |
echo $rc | |
} | |
if [ $1 == "show" ]; then | |
for irq in $(grep -P 'enp3s0f(0|1)-' /proc/interrupts | awk '{print $1}' | tr -d ':' | sort -n | xargs); do | |
echo $irq $(cat /proc/irq/$irq/smp_affinity) | |
done | |
exit 0 | |
fi | |
ncpu=$(lscpu | grep -P '^CPU\(s\):' | awk '{print $2}') | |
inuse=${1:-$ncpu} | |
if [ $inuse -gt $ncpu ]; then | |
echo "you've at most $ncpu CPUs, using $ncpu" | |
inuse=$ncpu | |
fi | |
cpuid=0 | |
for irq in $(grep -P 'enp3s0f(0|1)-' /proc/interrupts | awk '{print $1}' | tr -d ':' | sort -n | xargs); do | |
mask $cpuid $ncpu >/proc/irq/$irq/smp_affinity | |
cpuid=$(((cpuid+1)%inuse)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment