Archive

Posts Tagged ‘中断’

PCI-E SSD卡中断配置问题

January 15th, 2013 9 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: PCI-E SSD卡中断配置问题

随着PCI-E SSD卡的普及,很多高性能的服务器都用上了如fusionio这样的设备来提升IO的性能,这样会带来一些问题。 这些高速的IO设备在运作的时候会产生大量的中断来通知IO的完成,全速运转的系统上中断达到14000irqs/sec 如图:

perf_top_irq_cnt

而中断是默认摊到所有的CPU:

#cat /proc/irq/1/smp_affinity
ffffffff

在实践中来看会落在最繁忙的0核心上,这样就会给性能雪上加霜,效果如下:

cat /proc/interrupts |grep fct
144: 39913474 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI-edge iodrive-fct0
145: 44976079 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI-edge iodrive-fct1

中断144,145属于iodrive-fct高速设备的,都落在了0号核心上。

对于大多数的高性能服务器通常都有16-32个核心,越靠后面的核心越闲,那为什么我们不把中断移到后面的核心,让核心0解放出来多做其他的事情呢?毕竟由于历史原因,很多东西还是在核心0上做的,减负!

这个问题的核心就是要设置/proc/N/145/smp_affinity的CPU掩码, 手工做比较麻烦。

好了,脚本来了:

# cat set_fio_affinity.sh 
#!/bin/bash

set_affinity()
{
    MASK_TMP=$((1<<(`expr $VEC + $CORE`)))
    MASK=`printf "%X" $MASK_TMP`
    printf "%s mask=%s for /proc/irq/%d/smp_affinity\n" $DEV$VEC $MASK $IRQ
    printf "%s" $MASK > /proc/irq/$IRQ/smp_affinity
}


if [ $# -ne 1 ] ; then
    echo "usage:"
    echo "    $0 core "
    exit
fi

CORE=$1
DEV="iodrive-fct"
MAX=`grep -i $DEV /proc/interrupts | wc -l`
if [ "$MAX" == "0" ] ; then
    echo no $DIR vectors found on $DEV
    exit
fi

for VEC in `seq 0 1 $MAX`
do
    for IRQ in `cat /proc/interrupts | grep -i $DEV$VEC|cut  -d:  -f1| sed "s/ //g"`
    do
        set_affinity
    done
done

# ./set_fio_affinity.sh 30 
iodrive-fct0 mask=40000000 for /proc/irq/144/smp_affinity
iodrive-fct1 mask=80000000 for /proc/irq/145/smp_affinity

再cat /proc/interrupts看下实践效果就可以看到后面的核心已经有中断了,而且0号核心上的数字没变!

fusionio_irq

# perf top –cpu=31

也验证了这一点:

iomemory_perf_top

另外一姐妹篇 “MYSQL数据库网卡软中断不平衡问题及解决方案” 参见 这里

祝玩的开心!

Post Footer automatically generated by wp-posturl plugin for wordpress.

itop更方便的了解Linux下中断情况

March 4th, 2011 3 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: itop更方便的了解Linux下中断情况

乘着公司搬家的功夫,写点东西!

在作网络程序的时候, 经常需要了解interrupts和软中断的平衡情况, 需要知道每秒有多少中断发生,发生在哪个cpu上.
Linux下中断来源可以从 /proc/interrupts 中了解到:

$ cat /proc/interrupts 
           CPU0       CPU1       
  0:     247701     250313   IO-APIC-edge      timer
  1:        501        567   IO-APIC-edge      i8042
  3:          1          1   IO-APIC-edge    
  8:          1          0   IO-APIC-edge      rtc0
  9:        256        240   IO-APIC-fasteoi   acpi
 12:       1134       1149   IO-APIC-edge      i8042
 16:        629        554   IO-APIC-fasteoi   nvidia
 17:      21313      20869   IO-APIC-fasteoi   firewire_ohci, eth1
 18:          0          0   IO-APIC-fasteoi   mmc0
 19:      51822      50079   IO-APIC-fasteoi   ata_piix, ata_piix
 20:       5605       5255   IO-APIC-fasteoi   ehci_hcd:usb2, uhci_hcd:usb3, uhci_hcd:usb6
 21:          0          0   IO-APIC-fasteoi   uhci_hcd:usb4, uhci_hcd:usb7
 22:         33         33   IO-APIC-fasteoi   ehci_hcd:usb1, uhci_hcd:usb5, uhci_hcd:usb8
 45:        337        247   PCI-MSI-edge      eth0
 46:        441        447   PCI-MSI-edge      hda_intel
NMI:          0          0   Non-maskable interrupts
LOC:     169176     174899   Local timer interrupts
SPU:          0          0   Spurious interrupts
PMI:          0          0   Performance monitoring interrupts
PND:          0          0   Performance pending work
RES:      42289      40236   Rescheduling interrupts
CAL:        154       1076   Function call interrupts
TLB:       5838       5365   TLB shootdowns
TRM:          0          0   Thermal event interrupts
THR:          0          0   Threshold APIC interrupts
MCE:          0          0   Machine check exceptions
MCP:          5          5   Machine check polls
ERR:          1
MIS:          0

软中断可以从/proc/softirqs 了解到:

$ cat /proc/softirqs 
                CPU0       CPU1       
      HI:          0          0
   TIMER:     160508    1170976
  NET_TX:          2          2
  NET_RX:       3303       3165
   BLOCK:      50964      49198
BLOCK_IOPOLL:          0          0
 TASKLET:      24743      24284
   SCHED:      39483      41848
 HRTIMER:         34         40
     RCU:      92193      92592

总的中断次数可以从vmstat或者dstat了解到:

$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 3  0      0  44160 327144 876600    0    0   894   584  458 2295 11  5 70 15

itop提供了更方便的方式了解,作者Hunz在源码里面写:

It’s quite simple but it does its job.

虽然简单,但是适用:

Ubutun下可以这样安装: apt-get install itop

$ itop
INT                NAME          RATE             MAX
  0 [PIC-edge      time]   628 Ints/s     (max:   628)
  1 [PIC-edge      i804]     4 Ints/s     (max:     4)
 17 [PIC-fasteoi   fire]     8 Ints/s     (max:    22)
 19 [PIC-fasteoi   ata_]     1 Ints/s     (max:    14)
 20 [PIC-fasteoi   ehci]    25 Ints/s     (max:    25)
 45 [MSI-edge      eth0]     1 Ints/s     (max:     1)

他会计算每秒每个中断源中断的次数,看起来比较方便.

祝玩的开心!

Post Footer automatically generated by wp-posturl plugin for wordpress.