1.pktgen安装:
https://wiki.linuxfoundation.org/networking/pktgen
modprobe pktgen
ls /proc/net/pktgen/
cat /proc/interrupts | grep eth
/etc/init.d/irqbalance stop
2.做中断亲和性绑定:
/proc/irq/<irq-id>/smp_affinity 中的值是亲和性的核id。
3.查看是否已经亲和性绑定了:
[root@localhost ~]# cat /proc/interrupts | grep eth
16: 2586 540 1351588 4172554 IO-APIC-fasteoi Ensoniq AudioPCI, eth6
19: 5117 1949714 6098060 40 IO-APIC-fasteoi eth4, eth5
[root@localhost ~]#cat /proc/irq/19/smp_affinity
4.若需要中断亲和性绑定:
[root@localhost ~]# cat /proc/interrupts | grep eth
16: 2586 540 1351588 4172554 IO-APIC-fasteoi Ensoniq AudioPCI, eth6
19: 5117 1949714 6098060 40 IO-APIC-fasteoi eth4, eth5
[root@localhost ~]# /etc/init.d/irqbalance stop
Stopping irqbalance: [ OK ]
[root@localhost ~]# echo 4 > /proc/irq/19/smp_affinity
[root@localhost ~]# echo 8 > /proc/irq/16/smp_affinity
[root@localhost ~]# cat /proc/irq/19/smp_affinity
04
[root@localhost ~]# cat /proc/irq/16/smp_affinity
08
5.测试脚本:
[root@R620 pktgen]# cat test.sh
#!/bin/sh
# pktgen.conf -- Sample configuration for send on two devices on a UP system
#modprobe pktgen
function pgset() {
local result
echo $1 > $PGDEV
result=`cat $PGDEV | fgrep "Result: OK:"`
if [ "$result" = "" ]; then
cat $PGDEV | fgrep Result:
fi
}
function pg() {
echo inject > $PGDEV
cat $PGDEV
}
# On UP systems only one thread exists -- so just add devices
# We use eth1, eth2
echo "Adding devices to run".
PGDEV=/proc/net/pktgen/kpktgend_0
pgset "rem_device_all"
pgset "add_device eth0"
pgset "max_before_softirq 10000"
# Configure the individual devices
echo "Configuring devices"
PGDEV=/proc/net/pktgen/eth0
#pgset "clone_skb 10000"
pgset "pkt_size 60"
pgset "dst 11.11.11.5"
pgset "dst_mac fa:16:3e:39:68:50"
pgset "count 0"
# Time to run
PGDEV=/proc/net/pktgen/pgctrl
echo "Running... ctrl^C to stop"
pgset "start"
echo "Done"
6.执行脚本:
sh test.sh
另开一个终端,执行mpstat命令查看cpu占用率,看网卡中断的处理是否正常:
[root@localhost ~]# mpstat -P 2,3 1
Linux 2.6.38.8 (localhost.localdomain) 01/15/2012 _x86_64_ (4 CPU)
09:13:16 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
09:13:17 AM 2 0.00 0.00 86.87 0.00 0.00 13.13 0.00 0.00 0.00
09:13:17 AM 3 0.00 0.00 74.23 0.00 0.00 25.77 0.00 0.00 0.00
09:13:18 AM 2 0.00 0.00 87.63 0.00 0.00 12.37 0.00 0.00 0.00
09:13:18 AM 3 0.00 0.00 76.53 0.00 0.00 23.47 0.00 0.00 0.00
09:13:19 AM 2 0.00 0.00 85.71 0.00 0.00 14.29 0.00 0.00 0.00
09:13:19 AM 3 0.00 0.00 75.51 0.00 0.00 24.49 0.00 0.00 0.00
09:13:20 AM 2 0.00 0.00 86.60 0.00 0.00 13.40 0.00 0.00 0.00
09:13:20 AM 3 0.00 0.00 70.10 0.00 0.00 29.90 0.00 0.00 0.00
^C
[root@localhost ~]# cat /proc/interrupts | grep eth
16: 2586 540 588 6664664 IO-APIC-fasteoi Ensoniq AudioPCI, eth6
19: 5117 714 9729867 40 IO-APIC-fasteoi eth4, eth5
[root@localhost ~]#
7.执行一段时间后,结束测试查看统计数据:
[root@dpdk-43-2 ~]# cat /proc/net/pktgen/eth0
Params: count 0 min_pkt_size: 60 max_pkt_size: 60
frags: 0 delay: 0 clone_skb: 0 ifname: eth0
flows: 0 flowlen: 0
queue_map_min: 0 queue_map_max: 0
dst_min: 11.11.11.16 dst_max:
src_min: src_max:
src_mac: fa:16:3e:4e:2f:c7 dst_mac: fa:16:3e:2a:20:9d
udp_src_min: 9 udp_src_max: 9 udp_dst_min: 9 udp_dst_max: 9
src_mac_count: 0 dst_mac_count: 0
Flags:
Current:
pkts-sofar: 944506531 errors: 0
started: 3700018075us stopped: 4210567081us idle: 49477us
seq_num: 944506532 cur_dst_mac_offset: 0 cur_src_mac_offset: 0
cur_saddr: 11.11.11.11 cur_daddr: 11.11.11.16
cur_udp_dst: 9 cur_udp_src: 9
cur_queue_map: 0
flows: 0
Result: OK: 510549006(c510499529+d49477) usec, 944506531 (60byte,0frags)
1849982pps 887Mb/sec (887991360bps) errors: 0
8.接收端查看统计
sar -n DEV 2