Last active
October 25, 2024 12:32
-
-
Save mdpuma/ef64865763f382dad399d3daf66dbd53 to your computer and use it in GitHub Desktop.
distribute hardware interrupts from Ethernet devices by CPU cores.
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 | |
| # | |
| # irq2smp -- distribute hardware interrupts from Ethernet devices by CPU cores. | |
| # | |
| # Should be called from /etc/rc.local. | |
| # | |
| ncpus=`grep -ciw ^processor /proc/cpuinfo` | |
| netmask="(eth|wan)" | |
| test "$ncpus" -gt 1 || exit 1 | |
| n=0 | |
| for irq in `cat /proc/interrupts | grep -E $netmask | 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: eth$n, irq $irq, cpu $cpu, mask 0x$mask" | |
| echo "$mask" > "$f" | |
| let n+=1 | |
| fi | |
| done | |
| # if network cards doesn't support MSI-X multiple queues | |
| if [ $n -lt 4 ]; then | |
| cpus=$(printf %x $[ 2 ** $ncpus - 1 ]) | |
| for iface in `ls -1 /sys/class/net/ | grep -E $netmask`; do | |
| if [ ! -f /sys/class/net/$iface/queues/rx-0/rps_cpus ]; then | |
| echo "`file /sys/class/net/$iface/queues/rx-0/rps_cpus`" | |
| else | |
| echo "Assign RPS $cpus to $iface" | |
| echo "$cpus" > /sys/class/net/$iface/queues/rx-0/rps_cpus | |
| fi | |
| done | |
| fi | |
| for i in `ls /sys/class/net | grep -E $netmask`; do | |
| # /sys/class/net/eth0/queues/rx-0/rps_flow_cnt | |
| [ ! -d /sys/class/net/$i ] && continue | |
| echo "set rps_flow_cnt=32768 for $i" | |
| echo 32768 > /sys/class/net/$i/queues/rx-0/rps_flow_cnt | |
| done | |
| echo 32768 > /proc/sys/net/core/rps_sock_flow_entries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment