轉自:http://blog.csdn.net/sasoritattoo/article/details/9318893
轉自:http://fishermen.iteye.com/blog/1995862
使用系統命令top即可看到如下類似信息:
Cpu(s): 0.0%us, 0.5%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
但不知什么含義?google之
I try to explain these:
us: is meaning of "user CPU time"
sy: is meaning of "system CPU time"
ni: is meaning of" nice CPU time"
id: is meaning of "idle"
wa: is meaning of "iowait"
hi:is meaning of "hardware irq"
si : is meaning of "software irq"
st : is meaning of "steal time"
中文翻譯為:
us 用戶空間占用CPU百分比
sy 內核空間占用CPU百分比
ni 用戶進程空間內改變過優先級的進程占用CPU百分比
id 空閑CPU百分比
wa 等待輸入輸出的CPU時間百分比
hi 硬件中斷
si 軟件中斷
st: 實時
===========================================================================================================================================
對Linux 網卡軟中斷做負載均衡
測試中發現服務器整體負載較低,但有cpu負載特別高,其中一個cpu幾乎一半是軟中斷si,特別忙,而還有的cpu特別空閑。
- top - 16:12:08 up 31 days, 3:52, 1 user, load average: <span style="color: #ff0000;">0.11, 0.11, 0.06</span>
- Tasks: 242 total, 4 running, 238 sleeping, 0 stopped, 0 zombie
- Cpu0 : 12.3%us, 14.6%sy, 0.0%ni, 70.2%id, 0.0%wa, 0.0%hi, 3.0%si, 0.0%st
- Cpu1 : 21.6%us, 22.9%sy, 0.0%ni, 7.3%id, 0.0%wa, 0.0%hi, <span style="color: #ff0000;">48.2%si</span>, 0.0%st
- Cpu2 : 16.5%us, 19.1%sy, 0.0%ni, 43.9%id, 0.0%wa, 0.0%hi, 20.5%si, 0.0%st
- Cpu3 : 2.3%us, 2.6%sy, 0.0%ni, 94.1%id, 0.0%wa, 0.0%hi, 1.0%si, 0.0%st
- Cpu4 : 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
先用mpstat -I SUM -P ALL 5 來看一下每個cpu的終端情況,發現cpu1和cpu2處理的中斷確實很多,是什么dd在使用這兩個cpu做中斷呢?
- # mpstat -I SUM -P ALL 5
- Linux 2.6.32-220.13.1.el6.x86_64 (talus186) 12/26/2013 _x86_64_ (12 CPU)
- 04:15:18 PM CPU intr/s
- 04:15:23 PM all 62422.60
- 04:15:23 PM 0 0.00
- 04:15:23 PM 1 21566.20
- 04:15:23 PM 2 12123.00
- 04:15:23 PM 3 0.00
- 04:15:23 PM 4 1.00
使用 cat /proc/interrupts 查看中斷情況,間隔幾秒后再次cat /proc/interrupts,然后比較對應值的變化,發現eth0-1、eth0-2等使用cpu1、cpu2做中斷,這兩個對應的中斷號分別是95,96...
- 95: 33 325897741 0 30997484 72 0 93968731 0 0 0 426 864 IR-PCI-MSI-edge eth0-1
- 96: 50 206 66609822 117 0 0 0 0 0 0 0 24437509 IR-PCI-MSI-edge eth0-2
在使用 cat /proc/irq/95/smp_affinity cat /proc/irq/smp_affinity 等看出網卡的隊列都在使用cpu1 和cpu2
- cat /proc/irq/95/smp_affinity
- 00000002
- cat /proc/irq/96/smp_affinity
- 00000004
好了,把空閑的cpu用上來分攤網卡中斷
- echo 08 > /proc/irq/97/ smp_affinity
- echo 10 > /proc/irq/98/ smp_affinity
- ...
再進行測試,發現cpu消耗整體還不夠均衡,TOP下使用f,然后再加j,發現應用進程使用的cpu與網卡中斷使用的cpu重合,再把單線程應用進程綁定到其他CPU,終於均衡下來。
最后,網卡軟中斷綁定cpu需要滿足幾個條件:1 linux內核版本必須在2.4+; 2 網卡對應的中斷控制器必須是IO-APIC芯片,且需啟用IO-APIC;3 部分CPU可能不支持。