Interrupts Tuning

Аn interrupt request (or IRQ) is a hardware signal sent to the processor that temporarily stops a running program and allows a special program, an interrupt handler, to run instead. Hardware interrupts are used to handle events such as receiving data from a dvb or network card, key presses, or mouse movements. Information about interrupts available in the /proc/interrupts. File format:

           CPU0       CPU1       CPU2       CPU3
...
 45:          0          0          0          0   PCI-MSI-edge      eth0
 46:          0          0          0          0   PCI-MSI-edge      eth0-rx-0
 47:          0          0          0          0   PCI-MSI-edge      eth0-rx-1
 48:          0          0          0          0   PCI-MSI-edge      eth0-rx-2
 49:          0          0          0          0   PCI-MSI-edge      eth0-rx-3
 50:          0          0          0          0   PCI-MSI-edge      eth0-tx-0
 51:          0          0          0          0   PCI-MSI-edge      eth0-tx-1
 52:          0          0          0          0   PCI-MSI-edge      eth0-tx-2
 53:          0          0          0          0   PCI-MSI-edge      eth0-tx-3

To change the processor affinity value for a IRQ number /proc/irq/[IRQ Number]/smp_affinity:

echo [smp_affinity value] >/proc/irq/[IRQ Number]/smp_affinity

SMP Affinity Calculator:

SMP Affinity Value:  

To apply smp_affinity parameters on the system startup need to append in the file /etc/rc.local (example):

# CPU0
echo 1 >/proc/irq/45/smp_affinity
echo 1 >/proc/irq/46/smp_affinity
echo 1 >/proc/irq/47/smp_affinity
# CPU1
echo 2 >/proc/irq/48/smp_affinity
echo 2 >/proc/irq/49/smp_affinity
# CPU2
echo 4 >/proc/irq/50/smp_affinity
echo 4 >/proc/irq/51/smp_affinity
# CPU3
echo 8 >/proc/irq/52/smp_affinity
echo 8 >/proc/irq/53/smp_affinity

the script that distributes interrupts automatically.

For correct operation - the script must be run at system startup

#!/bin/bash
service irqbalance stop

ncpus=`grep -ciw ^processor /proc/cpuinfo`
test "$ncpus" -gt 1 || exit 1
n=0

for irq in `cat /proc/interrupts | grep 'tbsecp3\|eth\|ddbrige\|eno\|ens' | awk '{print $1}' | sed s/\://g` ; do
    f="/proc/irq/$irq/smp_affinity"
    test -r "$f" || continue
    cpu=$[$ncpus - ($n % $ncpus) - 1]
    if [ $cpu -ge 0 ] ; then
        mask=`printf %x $[2 ** $cpu]`
        echo "Assign SMP affinity: dev$n, irq $irq, cpu $cpu, mask 0x$mask"
        echo "$mask" > "$f"
        let n+=1
    fi
done