一、查看IRQ
命令执行结果的第一列,就是设备对应的
irq号(irqno)。
二、查看IRQ亲和
-
cat /proc/irq/$irqno/smp_affinity
或者
-
cat /proc/irq/$irqno/smp_affinity_list
这两个文件相互联动,即:内容相同,描述方式不同;修改一个,则另一个相应变化。
三、设置IRQ亲和
-
echo ff > /proc/irq/$irqno/smp_affinity
或者
-
echo 0,1 > /proc/irq/$irqno/smp_affinity_list
-
OR
-
echo 0-2 > /proc/irq/$irqno/smp_affinity_list
*注意:设置IRQ亲和前,必须先关闭irqbalance,否则设置无效。
四、一般网卡
可以将一个网卡的IRQ,同时绑定到多个CPU,进行负载均衡,效果如下:
五、多队列网卡
图是Intel 82575硬件逻辑图。通过Hash网络四元组,将一条流放到相同的队列,及该队列绑定的中断。如果数据都来自于同一条流,有相同的四元组,则
无法达到负载均衡的目的。
一个队列的IRQ,
无法绑定到多个CPU。
均衡后效果如下:
六、附:管理irq亲和的脚本
-
#!/usr/bin/perl
-
#
-
# =====================================================================================
-
# Filenamei : irqmgr.sh
-
#
-
# Description :
-
#
-
# Version : 0.1.0
-
# Created : Mon Sep 5 16:18:06 2016
-
# Author : zhonghaohua
-
# Mail : zhonghaohua@gmail.com
-
#
-
# Change log :
-
# =====================================================================================
-
#
-
-
$_name = 'irqmgr';
-
$_version = 'ver0.1.0';
-
$_author = 'zhonghaohua@gddev.com';
-
-
#BEGIN
-
if( $ARGV[0] eq 'show') {
-
if( @ARGV == 1) {
-
&show( 'all');
-
}
-
elsif( @ARGV == 2) {
-
&show( $ARGV[1]);
-
}
-
else {
-
&help;
-
}
-
}
-
elsif( $ARGV[0] eq 'set') {
-
if( @ARGV == 2 || @ARGV == 3) {
-
shift( @ARGV);
-
&set( @ARGV);
-
}
-
else {
-
&help;
-
}
-
}
-
else {
-
&help;
-
}
-
-
exit;
-
#END
-
-
sub help {
-
print $_name." ".$_version." ".$_author."\n\n";
-
-
print "Usage:";
-
print "\t$_name show all\n";
-
print "\t$_name show eth0\n";
-
print "\t$_name set eth\n";
-
print "\t$_name set eth0 [0-3|0,1,2,3]\n";
-
print "\t$_name (print this help information)\n";
-
print "\n";
-
}
-
-
sub set {
-
my( $devname, $cpus) = @_;
-
-
if( !&check_irqbalance) {
-
return;
-
}
-
-
@irqlist = &get_irqlist( $devname, 0);
-
-
$cpucnt = &cnt_cpus();
-
$irqcnt = @irqlist;
-
-
print "Startup settings: ";
-
-
if( $cpucnt * 2 < $irqcnt) {
-
print "\33[1m\33[31m";
-
}
-
elsif( $cpucnt < $irqcnt) {
-
print "\33[1m\33[33m";
-
}
-
else {
-
print "\33[1m\33[32m";
-
}
-
-
print "\33[0m\n";
-
-
for( $i = 0; $i < @irqlist; $i++) {
-
-
$loop = 1;
-
while( $loop) {
-
-
$r = "[$irqlist[$i][0], $irqlist[$i][1]] ";
-
$cpumask = `cat /proc/irq/$irqlist[$i][0]/smp_affinity`;
-
chomp( $cpumask);
-
$cpulist = `cat /proc/irq/$irqlist[$i][0]/smp_affinity_list`;
-
chomp( $cpulist);
-
print $r."running-config: mask[".$cpumask."] cpu[".$cpulist."]\n";
-
-
print "\twould you want to set (CPUMask/Next/Quit):";
-
chomp( $_ = <STDIN>);
-
if( /(^[0-9a-fA-F]+)/) {
-
`echo $1 >> /proc/irq/$irqlist[$i][0]/smp_affinity`;
-
}
-
elsif( /^[nN]/) {
-
$loop = 0;
-
}
-
elsif( /^[qQeE]/) {
-
return;
-
}
-
else {
-
print "\33[1m\33[33m\t$_ is an invalid value for the CPUMask.\33[0m\n";
-
}
-
}
-
}
-
}
-
-
sub show {
-
my( $devname, ) = @_;
-
-
@irqlist = &get_irqlist( $devname, 1);
-
&show_irqlist( @irqlist);
-
}
-
-
sub get_irqlist {
-
my( $devname, $flag_display) = @_;
-
-
if( $devname eq 'all') {
-
@irqrequest = split( /\n/, `cat /proc/interrupts`);
-
}
-
else {
-
@irqrequest = split( /\n/, `cat /proc/interrupts |grep $devname`);
-
}
-
-
$i = 0;
-
foreach( @irqrequest) {
-
if( $flag_display == 1) {
-
print $_."\n";
-
}
-
-
if( /(\d+):(\s+\S+){9}\s+(\S+)/ ) {
-
$irqlist[$i][0] = $1;
-
$irqlist[$i][1] = $3;
-
$i++;
-
}
-
}
-
-
return @irqlist;
-
}
-
-
sub show_irqlist {
-
$i = 0;
-
foreach( @_) {
-
$r = "[$_[$i][0], $_[$i][1]] ";
-
$cmd1 = `cat /proc/irq/$_[$i][0]/smp_affinity`;
-
chomp($cmd1);
-
$cmd2 = `cat /proc/irq/$_[$i][0]/smp_affinity_list`;
-
chomp($cmd2);
-
-
print $r."running-config: mask[".$cmd1."] cpu[".$cmd2."]\n";
-
$i++;
-
}
-
}
-
-
sub check_irqbalance {
-
@result = `ps aux|grep irqbalance`;
-
$isworking = 0;
-
-
foreach( @result) {
-
if( !(/grep/)) {
-
$isworking = 1;
-
}
-
}
-
-
if( $isworking) {
-
print "\33[1m\33[33mirqbalance is running, would you want to stop?\33[0m[Yes/No]:";
-
chomp( $_ = <STDIN>);
-
if( /yes/i) {
-
`killall irqbalance`;
-
&delay(2);
-
print "\33[1m\33[32mirqbalance is stoped.\33[0m\n\n";
-
return 1;
-
}
-
else {
-
return 0;
-
}
-
}
-
-
return 1;
-
}
-
-
sub cnt_cpus {
-
@cpuinfo = split( /\n/, `cat /proc/cpuinfo |grep processor`);
-
foreach( @cpuinfo) {
-
$_ =~ /(\d+)$/;
-
$cpucnt = $1;
-
}
-
-
return $cpucnt;
-
}
-
-
sub delay {
-
my($interval, ) = @_;
-
-
$total = $interval * 1000 * 1000;
-
$t = 200 * 1000;
-
-
for( ; $total > 0; $total -= $t) {
-
print '.';
-
`usleep $t`;
-
}
-
-
print ' ';
-
}
-
-
-
-
#ENDFILE
END.
阅读(2609) | 评论(0) | 转发(0) |