對網路卡中斷繫結的指令碼

lxgeek發表於2014-11-18
 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\tOwner"}
{ print $8, "\t", $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。
 
參考:

 

相關文章