Linux 网卡CPU诊断命令

1. 查看网卡统计信息(来自网卡驱动)

# ethtool -S eth0 (不同的网卡和驱动的输出可能不一样)
NIC statistics:
     rx_packets: 60
     tx_packets: 32
     rx_bytes: 7371
     tx_bytes: 3061
     rx_broadcast: 0
     tx_broadcast: 0
     rx_multicast: 0
     tx_multicast: 0
     rx_errors: 0
     tx_errors: 0
     tx_dropped: 0
     multicast: 0
     collisions: 0
     rx_length_errors: 0
     rx_over_errors: 0
     rx_crc_errors: 0
     rx_frame_errors: 0
     rx_no_buffer_count: 0
     rx_missed_errors: 0
     tx_aborted_errors: 0
     tx_carrier_errors: 0
     tx_fifo_errors: 0
     tx_heartbeat_errors: 0
     tx_window_errors: 0
     tx_abort_late_coll: 0
     tx_deferred_ok: 0
     tx_single_coll_ok: 0
     tx_multi_coll_ok: 0
     tx_timeout_count: 0
     tx_restart_queue: 0
     rx_long_length_errors: 0
     rx_short_length_errors: 0
     rx_align_errors: 0
     tx_tcp_seg_good: 0
     tx_tcp_seg_failed: 0
     rx_flow_control_xon: 0
     rx_flow_control_xoff: 0
     tx_flow_control_xon: 0
     tx_flow_control_xoff: 0
     rx_long_byte_count: 7371
     rx_csum_offload_good: 52
     rx_csum_offload_errors: 0
     alloc_rx_buff_failed: 0
     tx_smbus: 0
     rx_smbus: 0
     dropped_smbus: 0

2. 查看操作系统UDP报文统计信息(来自Linux内核)

sender:~ # netstat -su -A inet6
    12500 total packets received
    0 incoming packets discarded
    12220 incoming packets delivered
    0 forwarded
    39227597 requests sent out
    20 outgoing packets dropped
    506 incoming multicast packets
    79 outgoing multicast packets
    Ip6InOctets: 1784565
    Ip6OutOctets: 44396413753
    Ip6InMcastOctets: 31144
    Ip6OutMcastOctets: 5776
    Ip6InBcastOctets: 0
    Ip6OutBcastOctets: 0
    955 ICMP messages received
    0 input ICMP message failed.
    786 ICMP messages sent
    Icmp6OutErrors: 0
    ICMP input histogram:
        echo requests: 220
        group member queries: 18
        group member responses: 19
        neighbour solicits: 452
        neighbour advertisement: 246
        Icmp6InMLDv2Reports: 0
        ICMP output histogram:
        echo replies: 220
        group member responses: 33
        router solicits: 3
        Icmp6OutRouterAdvertisements: 0
        neighbor solicits: 74
        neighbor advertisements: 452
        Icmp6OutMLDv2Reports: 4
        Icmp6InType128: 220
        Icmp6InType130: 18
        Icmp6InType131: 19
        Icmp6InType135: 452
        Icmp6InType136: 246
        Icmp6OutType129: 220
        Icmp6OutType131: 33
        Icmp6OutType133: 3
        Icmp6OutType135: 74
        Icmp6OutType136: 452
        Icmp6OutType143: 4
Udp6:
    0 packets received
    0 packets to unknown port received.
    0 packet receive errors
    39219160 packets sent
    Udp6RcvbufErrors: 0
    Udp6SndbufErrors: 20
UdpLite6:
    UdpLite6InDatagrams: 0
    UdpLite6NoPorts: 0
    UdpLite6InErrors: 0
    UdpLite6OutDatagrams: 0
    UdpLite6RcvbufErrors: 0
    UdpLite6SndbufErrors: 0

 

3.查看Kernel网络接口信息

# netstat -i eth0

Kernel Interface table
Iface   MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0   1500   0       65      0      0      0       36      0      0      0 BMRU
lo    16436   0        6      0      0      0        6      0      0      0 LRU

 

4. 查看CPU 各个Core的频率

# cat /proc/cpuinfo | grep Hz
model name : Intel(R) Core(TM) i5 CPU       M 520  @ 2.40GHz
cpu MHz  : 2394.209
model name : Intel(R) Core(TM) i5 CPU       M 520  @ 2.40GHz
cpu MHz  : 2394.209

# cpufreq-info

cpufrequtils 004: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to http://bugs.opensuse.org, please.
analyzing CPU 0:
  driver: pcc-cpufreq
  CPUs which need to switch frequency at the same time: 0
  hardware limits: 1.20 GHz - 2.00 GHz
  available cpufreq governors: conservative, userspace, powersave, ondemand, performance
  current policy: frequency should be within 1.20 GHz and 2.00 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 200 MHz (asserted by call to hardware).
analyzing CPU 1:
  driver: pcc-cpufreq
  CPUs which need to switch frequency at the same time: 1
  hardware limits: 1.20 GHz - 2.00 GHz
  available cpufreq governors: conservative, userspace, powersave, ondemand, performance
  current policy: frequency should be within 1.20 GHz and 2.00 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 460 MHz (asserted by call to hardware).

ondemand 表示CPU频率可以根据需要变化:

# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
ondemand

禁止CPU频率变化:

# echo performance > /sys/devices/system/cpu/cpu0(1,2...)/cpufreq/scaling_governor


5. 查看CPU的硬中断和软中断

# mpstat -P ALL 1
Linux 3.0.13-0.27-default (sle11-sp2-node1)  02/03/2013  _x86_64_
02:00:01 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
02:00:02 PM  all    3.06    0.00   13.27    0.00    0.00    0.51    0.00    0.00   83.16
02:00:02 PM    0    3.09    0.00   13.40    0.00    0.00    0.00    0.00    0.00   83.51
02:00:02 PM    1    2.06    0.00   13.40    0.00    0.00    1.03    0.00    0.00   83.51

 

6. 查看中断情况

# cat /proc/interrupts
        CPU0     CPU1    CPU2     CPU3    CPU4    CPU5    CPU6
  94:    77       0       0        0       0       0     4442  IR-PCI-MSI-edge  eth0-tx
  95:  5325       0       0        0       0       0        0  IR-PCI-MSI-edge  eth0-rxq0

 

7. 查看NIC固件和驱动版本

# ethtool -i eth0
driver: be2net
version: 4.1.450.7
firmware-version: 4.1.450.16
bus-info: 0000:04:00.0 (0000:04:00.0是PCI-E地址)
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: no

 

8. 查看NIC offload

# ethtool -k eth0
Offload parameters for eth0:
rx-checksumming: on
tx-checksumming: on
scatter-gather: on
tcp-segmentation-offload: on
udp-fragmentation-offload: off
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off
receive-hashing: off (接受端网卡如果支持多队列,根据地址端口做HASH,可以将网络报文分散到多个CPU/core执行,从而降低单个CPU/Core的使用率,提高网络流量吞吐)

 

9. 查看网卡PCI信息

# lspci -vvv | grep 04:00.0 (0000:04:00.0是PCI-E地址)
04:00.0 Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)

 

10. 查看网卡相关信息

sender:~ # dmesg | grep be2net
[    4.224804] be2net 0000:04:00.0: PCI INT A -> GSI 32 (level, low) -> IRQ 32
[    4.224814] be2net 0000:04:00.0: setting latency timer to 64
[    4.399925] be2net 0000:04:00.0: No support for multiple RX queues
[    4.400041] be2net 0000:04:00.0: irq 94 for MSI/MSI-X
[    4.400055] be2net 0000:04:00.0: irq 95 for MSI/MSI-X
[    4.471777] be2net 0000:04:00.0: No support for multiple RX queues
[    4.471815] be2net 0000:04:00.0: Could create only 1 receive queues
[    4.555836] be2net 0000:04:00.0: eth0: numa node 0
[    4.555905] be2net 0000:04:00.0: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 0
[    4.556009] be2net 0000:04:00.1: PCI INT B -> GSI 36 (level, low) -> IRQ 36
[    4.556050] be2net 0000:04:00.1: setting latency timer to 64
[    4.687359] be2net 0000:04:00.1: No support for multiple RX queues
[    4.687454] be2net 0000:04:00.1: irq 96 for MSI/MSI-X
[    4.687469] be2net 0000:04:00.1: irq 97 for MSI/MSI-X
[    4.755221] be2net 0000:04:00.1: No support for multiple RX queues
[    4.755265] be2net 0000:04:00.1: Could create only 1 receive queues
[    4.824676] be2net 0000:04:00.1: eth1: numa node 0
[    4.824744] be2net 0000:04:00.1: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 1
[    4.824844] be2net 0000:04:00.2: PCI INT C -> GSI 37 (level, low) -> IRQ 37
[    4.824885] be2net 0000:04:00.2: setting latency timer to 64
[    4.942878] be2net 0000:04:00.2: No support for multiple RX queues
[    4.942972] be2net 0000:04:00.2: irq 98 for MSI/MSI-X
[    4.942986] be2net 0000:04:00.2: irq 99 for MSI/MSI-X
[    5.010723] be2net 0000:04:00.2: No support for multiple RX queues
[    5.010765] be2net 0000:04:00.2: Could create only 1 receive queues
[    5.089754] be2net 0000:04:00.2: eth2: numa node 0
[    5.089820] be2net 0000:04:00.2: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 0
[    5.089920] be2net 0000:04:00.3: PCI INT D -> GSI 38 (level, low) -> IRQ 38
[    5.089959] be2net 0000:04:00.3: setting latency timer to 64
[    5.206342] be2net 0000:04:00.3: No support for multiple RX queues
[    5.206437] be2net 0000:04:00.3: irq 100 for MSI/MSI-X
[    5.206451] be2net 0000:04:00.3: irq 101 for MSI/MSI-X
[    5.274217] be2net 0000:04:00.3: No support for multiple RX queues
[    5.274251] be2net 0000:04:00.3: Could create only 1 receive queues
[    5.343933] be2net 0000:04:00.3: eth3: numa node 0
[    5.343998] be2net 0000:04:00.3: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 1
[    5.344080] be2net 0000:04:00.4: PCI INT A -> GSI 32 (level, low) -> IRQ 32
[    5.344118] be2net 0000:04:00.4: setting latency timer to 64
[    5.461841] be2net 0000:04:00.4: No support for multiple RX queues
[    5.461940] be2net 0000:04:00.4: irq 102 for MSI/MSI-X
[    5.461953] be2net 0000:04:00.4: irq 103 for MSI/MSI-X
[    5.529706] be2net 0000:04:00.4: No support for multiple RX queues
[    5.529746] be2net 0000:04:00.4: Could create only 1 receive queues
[    5.599476] be2net 0000:04:00.4: eth4: numa node 0
[    5.599540] be2net 0000:04:00.4: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 0
[    5.599620] be2net 0000:04:00.5: PCI INT B -> GSI 36 (level, low) -> IRQ 36
[    5.599657] be2net 0000:04:00.5: setting latency timer to 64
[    5.717334] be2net 0000:04:00.5: No support for multiple RX queues
[    5.717432] be2net 0000:04:00.5: irq 104 for MSI/MSI-X
[    5.717446] be2net 0000:04:00.5: irq 105 for MSI/MSI-X
[    5.785206] be2net 0000:04:00.5: No support for multiple RX queues
[    5.785246] be2net 0000:04:00.5: Could create only 1 receive queues
[    5.854972] be2net 0000:04:00.5: eth5: numa node 0
[    5.855034] be2net 0000:04:00.5: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 1
[    5.855115] be2net 0000:04:00.6: PCI INT C -> GSI 37 (level, low) -> IRQ 37
[    5.855152] be2net 0000:04:00.6: setting latency timer to 64
[    5.972842] be2net 0000:04:00.6: No support for multiple RX queues
[    5.972941] be2net 0000:04:00.6: irq 106 for MSI/MSI-X
[    5.972954] be2net 0000:04:00.6: irq 107 for MSI/MSI-X
[    6.040706] be2net 0000:04:00.6: No support for multiple RX queues
[    6.040746] be2net 0000:04:00.6: Could create only 1 receive queues
[    6.110205] be2net 0000:04:00.6: eth6: numa node 0
[    6.110267] be2net 0000:04:00.6: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 0
[    6.110349] be2net 0000:04:00.7: PCI INT D -> GSI 38 (level, low) -> IRQ 38
[    6.110387] be2net 0000:04:00.7: setting latency timer to 64
[    6.228340] be2net 0000:04:00.7: No support for multiple RX queues
[    6.228428] be2net 0000:04:00.7: irq 108 for MSI/MSI-X
[    6.228442] be2net 0000:04:00.7: irq 109 for MSI/MSI-X
[    6.296205] be2net 0000:04:00.7: No support for multiple RX queues
[    6.296245] be2net 0000:04:00.7: Could create only 1 receive queues
[    6.365800] be2net 0000:04:00.7: eth7: numa node 0
[    6.365862] be2net 0000:04:00.7: Emulex OneConnect(be3) 10Gbps NIC "554FLB" port 1
[   13.490889] be2net 0000:04:00.0: eth0: Link up

 

11. 查看网卡ring缓存的参数

# ethtool -g eth0

Ring parameters for eth0:

Pre-set maximums:

RX:             1024

RX Mini:        0

RX Jumbo:       0

TX:             2048

Current hardware settings:

RX:             999

RX Mini:        0

RX Jumbo:       0

TX:             0

 

修改ring缓存: # ethtool -G eth0 rx 4078 tx 4078

(注意改的是网卡固件的参数,而不是操作系统内核的。有的网卡不支持改操作)

 

修改后再查看:

# ethtool -g eth0
Ring parameters for eth0:
Pre-set maximums:
RX:             4078
RX Mini:        0
RX Jumbo:       0
TX:             4078
Current hardware settings:
RX:             4078
RX Mini:        0
RX Jumbo:       0
TX:             4078

 

12. 给内核启动参数intel_idle.max_cstate=0关闭C-State

# cat /boot/grub/menu.lst
# Modified by YaST2. Last modification on Fri Jan  4 10:04:39 CST 2013
default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title SUSE Linux Enterprise Server 11 SP2 - 3.0.42-0.7
    root (hd0,1)
    kernel /boot/vmlinuz-3.0.42-0.7-default root=/dev/disk/by-id/scsi-3600508b1001c15e7187a2ec743cecb0c-part2 resume=/dev/disk/by-id/scsi-3600508b1001c15e7187a2ec743cecb0c-part1 splash=silent crashkernel=256M-:128M showopts vga=0x314 intel_idle.max_cstate=0 processor.max_cstate=1
    initrd /boot/initrd-3.0.42-0.7-default

 

检查是否生效(0表示已经关闭):

# cat /sys/module/intel_idle/parameters/max_cstate
0

 

13.

# dstat
You did not select any stats, using -cdngy by default.
Color support is disabled, python-curses is not installed.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw
 13  35  52   0   0   0|2649B 5939B|   0     0 |   0     0 |  36k   47k
  0   0 100   0   0   0|   0     0 |  54M 4164B|   0     0 |  12k 2533
  0   0 100   0   0   0|   0     0 |  54M 3492B|   0     0 |  13k 2539

 

14. 打开网卡接收的IPV6 udp hashing

sender:~ # ethtool -N eth0 rx-flow-hash udp6 sdfn

 

查看hash情况,可以看到hash用的是src IP/dst IP/src port/dst port四元组

sender:~ # ethtool -n eth

你可能感兴趣的:(Linux 网卡CPU诊断命令)