Chinaunix首页 | 论坛 | 博客
  • 博客访问: 457379
  • 博文数量: 42
  • 博客积分: 1325
  • 博客等级: 中尉
  • 技术积分: 1312
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-13 18:00
个人简介

呵~~~呵~~~

文章分类

全部博文(42)

文章存档

2016年(3)

2015年(1)

2014年(2)

2013年(2)

2012年(7)

2011年(11)

2010年(3)

2009年(13)

我的朋友

分类: LINUX

2016-09-02 16:36:46

一、查看IRQ
  1. cat /proc/interrupts
    命令执行结果的第一列,就是设备对应的irq号(irqno)。

二、查看IRQ亲和
  1. cat /proc/irq/$irqno/smp_affinity
    或者
  1. cat /proc/irq/$irqno/smp_affinity_list
    这两个文件相互联动,即:内容相同,描述方式不同;修改一个,则另一个相应变化。

三、设置IRQ亲和
  1. echo ff > /proc/irq/$irqno/smp_affinity
或者
  1. echo 0,1 > /proc/irq/$irqno/smp_affinity_list
  2. OR
  3. echo 0-2 > /proc/irq/$irqno/smp_affinity_list
    *注意
设置IRQ亲和前,必须先关闭irqbalance,否则设置无效

四、一般网卡
    可以将一个网卡的IRQ,同时绑定到多个CPU,进行负载均衡,效果如下:


五、多队列网卡
   
    图是Intel 82575硬件逻辑图。通过Hash网络四元组,将一条流放到相同的队列,及该队列绑定的中断。如果数据都来自于同一条流,有相同的四元组,则无法达到负载均衡的目的
    一个队列的IRQ,无法绑定到多个CPU
    均衡后效果如下:


六、附:管理irq亲和的脚本
  1. #!/usr/bin/perl 
  2. #
  3. # =====================================================================================
  4. # Filenamei : irqmgr.sh
  5. #
  6. # Description :
  7. #
  8. # Version : 0.1.0
  9. # Created : Mon Sep 5 16:18:06 2016
  10. # Author : zhonghaohua
  11. # Mail : zhonghaohua@gmail.com
  12. #
  13. # Change log :
  14. # =====================================================================================
  15. #

  16. $_name = 'irqmgr';
  17. $_version = 'ver0.1.0';
  18. $_author = 'zhonghaohua@gddev.com';

  19. #BEGIN
  20. if( $ARGV[0] eq 'show') {
  21.     if( @ARGV == 1) {
  22.         &show( 'all');
  23.     }
  24.     elsif( @ARGV == 2) {
  25.         &show( $ARGV[1]);
  26.     }
  27.     else {
  28.         &help;
  29.     }
  30. }
  31. elsif( $ARGV[0] eq 'set') {
  32.     if( @ARGV == 2 || @ARGV == 3) {
  33.         shift( @ARGV);
  34.         &set( @ARGV);
  35.     }
  36.     else {
  37.         &help;
  38.     }
  39. }
  40. else {
  41.     &help;
  42. }

  43. exit;
  44. #END

  45. sub help {
  46.     print $_name." ".$_version." ".$_author."\n\n";

  47.     print "Usage:";
  48.     print "\t$_name show all\n";
  49.     print "\t$_name show eth0\n";
  50.     print "\t$_name set eth\n";
  51.     print "\t$_name set eth0 [0-3|0,1,2,3]\n";
  52.     print "\t$_name (print this help information)\n";
  53.     print "\n";
  54. }

  55. sub set {
  56.     my( $devname, $cpus) = @_;

  57.     if(    !&check_irqbalance) {
  58.         return;
  59.     }

  60.     @irqlist = &get_irqlist( $devname, 0);

  61.     $cpucnt = &cnt_cpus();
  62.     $irqcnt = @irqlist;
  63.     
  64.     print "Startup settings: ";

  65.     if( $cpucnt * 2 < $irqcnt) {
  66.         print "\33[1m\33[31m";
  67.     }
  68.     elsif( $cpucnt < $irqcnt) {
  69.         print "\33[1m\33[33m";
  70.     }
  71.     else {
  72.         print "\33[1m\33[32m";
  73.     }

  74.     print "\33[0m\n";

  75.     for( $i = 0; $i < @irqlist; $i++) {
  76.     
  77.         $loop = 1;
  78.         while( $loop) {
  79.         
  80.             $r = "[$irqlist[$i][0], $irqlist[$i][1]] ";
  81.             $cpumask = `cat /proc/irq/$irqlist[$i][0]/smp_affinity`;
  82.             chomp( $cpumask);
  83.             $cpulist = `cat /proc/irq/$irqlist[$i][0]/smp_affinity_list`;
  84.             chomp( $cpulist);
  85.             print $r."running-config: mask[".$cpumask."] cpu[".$cpulist."]\n";
  86.             
  87.             print "\twould you want to set (CPUMask/Next/Quit):";
  88.             chomp( $_ = <STDIN>);
  89.             if( /(^[0-9a-fA-F]+)/) {
  90.                 `echo $1 >> /proc/irq/$irqlist[$i][0]/smp_affinity`;
  91.             }
  92.             elsif( /^[nN]/) {
  93.                 $loop = 0;
  94.             }
  95.             elsif( /^[qQeE]/) {
  96.                 return;
  97.             }
  98.             else {
  99.                 print "\33[1m\33[33m\t$_ is an invalid value for the CPUMask.\33[0m\n";
  100.             }
  101.         }
  102.     }
  103. }

  104. sub show {
  105.     my( $devname, ) = @_;

  106.     @irqlist = &get_irqlist( $devname, 1);
  107.     &show_irqlist( @irqlist);
  108. }

  109. sub get_irqlist {
  110.     my( $devname, $flag_display) = @_;

  111.     if( $devname eq 'all') {
  112.         @irqrequest = split( /\n/, `cat /proc/interrupts`);
  113.     }
  114.     else {
  115.         @irqrequest = split( /\n/, `cat /proc/interrupts |grep $devname`);
  116.     }

  117.     $i = 0;
  118.     foreach( @irqrequest) {
  119.         if( $flag_display == 1) {
  120.             print $_."\n";
  121.         }

  122.         if( /(\d+):(\s+\S+){9}\s+(\S+)/ ) {
  123.             $irqlist[$i][0] = $1;
  124.             $irqlist[$i][1] = $3;
  125.             $i++;
  126.         }
  127.     }

  128.     return @irqlist;
  129. }

  130. sub show_irqlist {
  131.     $i = 0;
  132.     foreach( @_) {
  133.         $r = "[$_[$i][0], $_[$i][1]] ";
  134.         $cmd1 = `cat /proc/irq/$_[$i][0]/smp_affinity`;
  135.         chomp($cmd1);
  136.         $cmd2 = `cat /proc/irq/$_[$i][0]/smp_affinity_list`;
  137.         chomp($cmd2);

  138.         print $r."running-config: mask[".$cmd1."] cpu[".$cmd2."]\n";
  139.         $i++;
  140.     }
  141. }

  142. sub check_irqbalance {
  143.     @result = `ps aux|grep irqbalance`;
  144.     $isworking = 0;

  145.     foreach( @result) {    
  146.         if( !(/grep/)) {
  147.             $isworking = 1;
  148.         }    
  149.     }

  150.     if( $isworking) {
  151.         print "\33[1m\33[33mirqbalance is running, would you want to stop?\33[0m[Yes/No]:";
  152.         chomp( $_ = <STDIN>);
  153.         if( /yes/i) {
  154.             `killall irqbalance`;
  155.             &delay(2);
  156.             print "\33[1m\33[32mirqbalance is stoped.\33[0m\n\n";
  157.             return 1;
  158.         }
  159.         else {
  160.             return 0;
  161.         }
  162.     }

  163.     return 1;
  164. }

  165. sub cnt_cpus {
  166.     @cpuinfo = split( /\n/, `cat /proc/cpuinfo |grep processor`);
  167.     foreach( @cpuinfo) {
  168.         $_ =~ /(\d+)$/;
  169.         $cpucnt = $1;
  170.     }

  171.     return $cpucnt;
  172. }

  173. sub delay {
  174.     my($interval, ) = @_;

  175.     $total = $interval * 1000 * 1000;
  176.     $t = 200 * 1000;

  177.     for( ; $total > 0; $total -= $t) {
  178.         print '.';
  179.         `usleep $t`;
  180.     }

  181.     print ' ';
  182. }



  183. #ENDFILE


END.


阅读(2609) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~