zoukankan      html  css  js  c++  java
  • 对网卡中断绑定的脚本

     1 service irqbalance stop
     2 
     3 #@irqnum:网卡eth2的中断数
     4 #@cpunum:CPU数目
     5 irqnum=`cat /proc/interrupts | grep eth2.*- | awk -F : '{print $1}' | awk '{print $1}'`
     6 cpunum=`cat /proc/cpuinfo | grep processor | wc -l`
     7 param=1
     8 count=0
     9 
    10 for n in $irqnum
    11 do
    12         value=`printf "%08x" $param`   //转化为16进制
    13         awk -F , -v a=$value 'BEGIN{OFS=","}{$NF="";print $0 a}' /proc/irq/$n/smp_affinity > /proc/irq/$n/smp_affinity
    14         param=`expr $param * 2`
    15         count=`expr $count + 1`
    16         if [ $count -eq $cpunum ];then  
    17                 count=0
    18                 param=1
    19         fi
    20         echo `cat /proc/irq/$n/smp_affinity`
    21 done
    1.irqbalance 的介绍
    irqbalance 用于优化中断分配,它会自动收集系统数据以分析使用模式,并依据系统负载状况将工作状态置于 Performance mode 或 Power-save mode.处于 Performance mode时irqbalance 会将中断尽可能均匀地分发给各个CPU以充分利用 CPU 多核,提升性能.处于 Power-save mode时,irqbalance 会将中断集中分配给第一个 CPU,以保证其它空闲 CPU 的睡眠时间,降低能耗
     
     
    There is an important difference between
     
    print $2 $3
     
    and
     
    print $2, $3
     
    The first example prints out one field, and the second prints out two fields. In the first case, the two positional parameters are concatenated together and output without a space. In the second case, AWK prints two fields, and places the output field separator between them. Normally this is a space, but you can change this by modifying the variable "OFS".
     
    3. AWK中 Basic Structure
     
    The essential organization of an AWK program follows the form:
     
    pattern { action }
     
    The pattern specifies when the action is performed. Like most UNIX utilities, AWK is line oriented. That is, the pattern specifies a test that is performed with each line read as input. If the condition is true, then the action is taken. The default pattern is something that matches every line. This is the blank or null pattern. Two other important patterns are specified by the keywords "BEGIN" and "END". As you might expect, these two words specify actions to be taken before any lines are read, and after the last line is read. The AWK program below:
     
    BEGIN { print "START" }
          { print        }
    END  { print "STOP"  }
     
    adds one line before and one line after the input file. This isn't very useful, but with a simple change, we can make this into a typical AWK program:
     
    BEGIN { print "File Owner"}
    { print $8, " ", $3}
    END { print " - DONE -" }
     
    1.It is useful to know how many fields are on a line. 
    2.Don't forget the variable can be prepended with a "$". This allows you to print the last field of any column
     
     
    问题:
    1.为什么要将中断绑定到固定CPU
    In order to achieve the best performance, it is recommended that all the interruptions generated by a device
    queue is handled by the same CPU, instead of IRQ balancing. Although it is not expected, round robin IRQ
    distribution is not good for performance because when the interruption go to another fresh CPU, the new CPU
    probably will not have the interrupt handler function in the cache, and a long time will be required to get the
    properly interrupt handler from the main memory and run it. On the other hand, if the same CPU handles the
    same IRQ almost all the time, the IRQ handler function will unlikely leave the CPU cache, boosting the kernel
    performance。
     
    参考:
  • 相关阅读:
    Celery最佳实践(转)
    我希望知道的关于Django的11件事(转)
    Celery和Rabbitmq自学
    我眼中的各种编程语言(转)
    linux 的nohup & 和daemon 总结(转)
    模糊测试之AVI文件分析
    微信Netting-QRLJacking分析利用-扫我二维码获取你的账号权限
    一个Unix内核级别漏洞(一)
    一次对SNMP服务的渗透测试
    定位日站大法之-社会工程学
  • 原文地址:https://www.cnblogs.com/lxgeek/p/4105234.html
Copyright © 2011-2022 走看看