Skip to content

Instantly share code, notes, and snippets.

@harukasan
Last active August 29, 2015 14:18
Show Gist options
  • Save harukasan/f8d5a013d8ed1f111427 to your computer and use it in GitHub Desktop.
Save harukasan/f8d5a013d8ed1f111427 to your computer and use it in GitHub Desktop.
RSS対応NICの各キューをCPUコアに割り当てる
# /etc/network/interface
# post-upに指定しておく
iface eth0 inet static
address 192.2.0.10
netmask 255.255.255.0
network 192.2.0.0
broadcast 192.2.0.255
gateway 192.2.0.1
post-up /var/scripts/set_irq_affinity.sh > /dev/null
#!/bin/bash
#
# = RSS対応NICの各キューをCPUコアに割り当てるスクリプト
#
# Author::harukasan <harukasan@pixiv.com>
#
# == Ref
# http://d.hatena.ne.jp/sfujiwara/20121221/1356084456のコメント欄
#
# == NOTE
# irqbalaceを使うとよくわからないタイミングでコア割り当てを
# 変更されるので、起動しないようにしておく
#
DEVICE="eth0"
# affinityを書き込む
# @param irq integer IRQ番号
# @param mask integer ビットマスク
set_affinity()
{
local irq=$1
local mask=$2
printf "set /proc/irq/%d/smp_affinity to '%X'\n" $irq $mask
printf "%X" $mask > /proc/irq/$irq/smp_affinity
}
#
# MAIN
#
NUM_CPU=$(grep processor /proc/cpuinfo | wc -l)
I=0
for IRQ in `cat /proc/interrupts | egrep -i "$DEVICE.*-[0-9]$" | cut -d: -f1 | sed "s/ //g)"`
do
MASK=$((1<<$I%$NUM_CPU)) # MASK = 1 << I % NUM_CPU
I=$((I+1))
set_affinity $IRQ $MASK
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment