#!/bin/bash set_affinity() { if [ $VEC -ge 32 ] then MASK_FILL="" MASK_ZERO="00000000" let "IDX = $VEC / 32" for ((i=1; i<=$IDX;i++)) do MASK_FILL="${MASK_FILL},${MASK_ZERO}" done
let "VEC -= 32 * $IDX"
MASK_TMP=$((1<<$VEC))
MASK=$(printf "%X%s" $MASK_TMP $MASK_FILL)
else
MASK_TMP=$((1<<$VEC))
MASK=$(printf "%X" $MASK_TMP)
fi
printf "%s" $MASK > /proc/irq/$IRQ/smp_affinity
printf "%s %d %s -> /proc/irq/$IRQ/smp_affinity\n" $DEV $VEC $MASK ;
} network_irq(){
if [ "$1" = "" ] ; then
ARG="$(ifconfig | grep '^[[:alpha:]]' | awk '$1!~/^(lo|bond|br|docker|virbr)/{print $1}')"
else
ARG="$*"
fi
IRQBALANCE_ON=`ps ax | grep -v grep | grep -q irqbalance; echo $?`
if [ "$IRQBALANCE_ON" == "0" ] ; then
service irqbalance stop
fi
CPU=$(( $((`cat /proc/cpuinfo |grep processor|wc -l`)) - 1 ));
VEC=$CPU;
for DEV in $ARG
do
for IRQ in `cat /proc/interrupts |grep ${DEV}| cut -d: -f1| sed "s/ //g"`;
do
DIR=`cat /proc/interrupts | egrep -i -e "^$IRQ|^\s+$IRQ"| awk '{print $NF}'`;
if [ -n "$IRQ" ]; then
set_affinity;
VEC=$(($VEC - 1));
if [ "$VEC" -lt 0 ]; then
VEC=$CPU;
fi
else
echo -e "["`date "+%F %T"`"]\tget $DIR IRQ Failed.";
fi
done
done
echo -e "["`date "+%F %T"`"]\tSet down over." ;
}
network_irq