作者:张华 发表于:2016-04-07
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
( http://blog.csdn.net/quqi99 )
硬件要求
网卡得支持DPDK,见:http://dpdk.org/doc/nics
CPU得支持DPDK, 测试命令:cat /proc/cpuinfo |grep pdpe1gb
打开大页支持
hua@node1:~$ cat /etc/default/grub |grep GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on pci=assign-busses"
GRUB_CMDLINE_LINUX="transparent_hugepage=never hugepagesz=2M hugepages=4 default_hugepagesz=1G"
vi /etc/fstab
nodev /mnt/huge hugetlbfs pagesize=2MB 0 0
sudo update-grub
sudo mkdir -p /mnt/huge
sudo reboot
hua@node1:~$ cat /proc/meminfo |grep HugePages_
HugePages_Total: 4
HugePages_Free: 4
HugePages_Rsvd: 0
HugePages_Surp: 0
hua@node1:~$ grep Hugepagesize /proc/meminfo
Hugepagesize: 2048 kB
配置网卡使用uio_pci_generic驱动
hua@node1:~$ sudo modprobe uio_pci_generic
hua@node1:~$ sudo dpdk_nic_bind --status
Network devices using DPDK-compatible driver
============================================
<none>
Network devices using kernel driver
===================================
0000:00:19.0 'Ethernet Connection I217-V' if=eth0 drv=e1000e unused=uio_pci_generic *Active*
0000:05:00.0 '82576 Gigabit Network Connection' if=eth1 drv=igb unused=uio_pci_generic *Active*
0000:05:00.1 '82576 Gigabit Network Connection' if=eth2 drv=igb unused=uio_pci_generic *Active*
Other network devices
=====================
0000:06:10.0 '82576 Virtual Function' unused=uio_pci_generic
0000:06:10.1 '82576 Virtual Function' unused=uio_pci_generic
0000:06:10.2 '82576 Virtual Function' unused=uio_pci_generic
0000:06:10.3 '82576 Virtual Function' unused=uio_pci_generic
hua@node1:~$ sudo dpdk_nic_bind -b uio_pci_generic 0000:05:00.0
Routing table indicates that interface 0000:05:00.0 is active. Not modifying
hua@node1:~$ sudo ifconfig eth1 down
hua@node1:~$ sudo dpdk_nic_bind -b uio_pci_generic 0000:05:00.0
hua@node1:~$ sudo dpdk_nic_bind --status
Network devices using DPDK-compatible driver
============================================
0000:05:00.0 '82576 Gigabit Network Connection' drv=uio_pci_generic unused=
Network devices using kernel driver
===================================
0000:00:19.0 'Ethernet Connection I217-V' if=eth0 drv=e1000e unused=uio_pci_generic *Active*
0000:05:00.1 '82576 Gigabit Network Connection' if=eth2 drv=igb unused=uio_pci_generic *Active*
Other network devices
=====================
0000:06:10.1 '82576 Virtual Function' unused=uio_pci_generic
0000:06:10.3 '82576 Virtual Function' unused=uio_pci_generic
配置OVS使用DPDK
hua@node1:~$ cat /etc/default/openvswitch-switch |grep DPDK
DPDK_OPTS='--dpdk -c 0x1 -n 2'
hua@node1:~$ sudo update-alternatives --set ovs-vswitchd /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk
update-alternatives: using /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk to provide /usr/sbin/ovs-vswitchd (ovs-vswitchd) in manual mode
hua@node1:~$ sudo stop openvswitch-switch; sudo start openvswitch-switch
hua@node1:~$ cat /var/log/openvswitch/ovs-ctl.log |grep dpdk
有一个bug设置了DPDK_OPTS不生效,见:https://bugs.launchpad.net/ubuntu/+source/openvswitch-dpdk/+bug/1547463, 所以直接使用下列命令启动,但仍然有错:
hua@node1:~$ sudo ovs-vswitchd --dpdk -c 0x1 -n 2 -- unix:$DB_SOCK --pidfile --detach
2016-04-07T11:48:03Z|00001|dpdk|INFO|No -cuse_dev_name provided - defaulting to vhost-net
EAL: Detected lcore 0 as core 0 on socket 0
EAL: Detected lcore 1 as core 1 on socket 0
EAL: Detected lcore 2 as core 2 on socket 0
EAL: Detected lcore 3 as core 3 on socket 0
EAL: Support maximum 128 logical core(s) by configuration.
EAL: Detected 4 lcore(s)
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Setting up memory...
EAL: Ask a virtual area of 0x200000 bytes
EAL: Virtual area found at 0x7f8609a00000 (size = 0x200000)
EAL: Ask a virtual area of 0x400000 bytes
EAL: Virtual area found at 0x7f8609400000 (size = 0x400000)
EAL: Ask a virtual area of 0x200000 bytes
EAL: Virtual area found at 0x7f8609000000 (size = 0x200000)
EAL: Requesting 4 pages of size 2MB from socket 0
EAL: rte_eal_common_log_init(): cannot create log_history mempool
PANIC in rte_eal_init():
Cannot init logs
7: [ovs-vswitchd() [0x40b053]]
6: [/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f860acc9ec5]]
5: [ovs-vswitchd() [0x40a059]]
4: [ovs-vswitchd() [0x639db1]]
3: [ovs-vswitchd() [0x43f7ad]]
2: [ovs-vswitchd() [0x407bad]]
1: [ovs-vswitchd() [0x444e58]]
测试
sudo ovs-vsctl add-br br-int
sudo ovs-vsctl set bridge br-int datapath_type=netdev
sudo ovs-vsctl add-port br-int dpdk0 -- set Interface dpdk0 type=dpdk #Port name shoud begin with dpdk
sudo ip addr add 10.0.1.2/24 dev dpdk0
sudo ip link set dev dpdk0 up
参考
[1] https://software.intel.com/en-us/blogs/2015/06/09/building-vhost-user-for-ovs-today-using-dpdk-200
[2] http://dpdk.readthedocs.org/en/v2.2.0/linux_gsg/index.html
[3] http://blog.csdn.net/xy010902100449/article/details/47282937