CPU亲和性

本文介绍了一个用于设置多队列网卡中断亲和性的脚本,该脚本可以将每个队列绑定到相同编号的核心上,例如tx0和rx0绑定到cpu0,tx1和rx1绑定到cpu1等。脚本首先检查irqbalance是否正在运行,并给出警告,因为irqbalance可能会覆盖脚本的设置。随后脚本通过读取/proc/interrupts来确定设备的中断并设置相应的smp亲和性。

http://blog.youkuaiyun.com/turkeyzhou/article/details/7528182
http://www.tuicool.com/articles/jiY7Zn

脚本如下:

setting up irq affinity according to /proc/interrupts

2008-11-25 Robert Olsson

2009-02-19 updated by Jesse Brandeburg

#

> Dave Miller:

(To get consistent naming in /proc/interrups)

I would suggest that people use something like:

char buf[IFNAMSIZ+6];

#

sprintf(buf, “%s-%s-%d”,

netdev->name,

(RX_INTERRUPT ? “rx” : “tx”),

queue->index);

#

Assuming a device with two RX and TX queues.

This script will assign:

#

eth0-rx-0 CPU0

eth0-rx-1 CPU1

eth0-tx-0 CPU0

eth0-tx-1 CPU1

#
set_affinity()
{
MASK= ((1<< VEC))
printf “%s mask=%X for /proc/irq/%d/smp_affinity\n” DEV MASK IRQprintf MASK > /proc/irq/IRQ/smp_affinity  
    #echo
DEV mask= MASKfor/proc/irq/ IRQ/smp_affinity
#echo MASK>/proc/irq/ IRQ/smp_affinity
}
if [ “ 1=];thenechoDescription:echoThisscriptattemptstobindeachqueueofamultiqueueNICechotothesamenumberedcore,ietx0¦rx0>cpu0,tx1¦rx1>cpu1echousage:echo 0 eth0 [eth1 eth2 eth3]”
fi

check for irqbalance running

IRQBALANCE_ON=ps ax ¦ grep -v grep ¦ grep -q irqbalance; echo $?
if [ “$IRQBALANCE_ON” == “0” ] ; then
echo ” WARNING: irqbalance is running and will”
echo ” likely override this script’s affinitization.”
echo ” Please stop the irqbalance service and/or execute”
echo ” ‘killall irqbalance’”
fi
#

Set up the desired devices.

#
for DEV in $*
do
for DIR in rx tx TxRx
do
MAX=grep $DEV-$DIR /proc/interrupts ¦ wc -l
if [ “$MAX” == “0” ] ; then
MAX=egrep -i "$DEV:.*$DIR" /proc/interrupts ¦ wc -l
fi
if [ “ MAX==0];thenechono DIR vectors found on $DEV
continue
#exit 1
fi
for VEC in seq 0 1 $MAX
do
IRQ=cat /proc/interrupts ¦ grep -i $DEV-$DIR-$VEC"$" ¦ cut -d: -f1 ¦ sed "s/ //g"
if [ -n “$IRQ” ]; then
set_affinity
else
IRQ=cat /proc/interrupts ¦ egrep -i $DEV:v$VEC-$DIR"$" ¦ cut -d: -f1 ¦ sed "s/ //g"
if [ -n “$IRQ” ]; then
set_affinity
fi
fi
done
done
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值