01 -- DPDK环境搭建和测试

官方文档请访问http://dpdk.org/,这里面很多干货


1、所需的配置

安装环境建议版本

GNUmake

coreutils:cmp, sed, grep, arch

gcc:versions  >= 4.5.x

libcheaders (glibc-devel.i686 / libc6-dev-i386; glibc-devel.x86_64 for 64-bitcompilation)

Linuxkernel headers or sources required to build kernel modules. (kernel- devel.x86_64)

Additionalpackages required for 32-bit compilation on 64-bit systems are: glibc.i686,libgcc.i686, libstdc++.i686 and glibc-devel.i686

Python,version 2.6 or 2.7
 

2、DPDK下载与测试

源码设置
在虚拟机终端从dpdk官方直接git clone最新的代码: 

git clone git://dpdk.org/dpdk

环境变量的设置
进入dpdk目录;编辑一个环境变量文件,然后source;

export RTE_SDK=`pwd`  
export RTE_TARGET=x86_64-default-linuxapp-gcc  
#export RTE_TARGET=i686-default-linuxapp-gcc  

由于我的是64虚拟机,所以我选择x86_64,将i686那行环境变量注释掉;
注意,你以后如果从新登陆终端,进入这个目录,都要source一下这个文件,才能正常运行dpdk的程序;

  1. 脚本运行
yhz@ubuntu:~/CC/dpdk$ ./usertools/dpdk-setup.sh 
------------------------------------------------------------------------------
 RTE_SDK exported as /home/yhz/CC/dpdk
------------------------------------------------------------------------------
----------------------------------------------------------
 Step 1: Select the DPDK environment to build
----------------------------------------------------------
[1] arm64-armv8a-linuxapp-clang
[2] arm64-armv8a-linuxapp-gcc
[3] arm64-dpaa2-linuxapp-gcc
[4] arm64-dpaa-linuxapp-gcc
[5] arm64-thunderx-linuxapp-gcc
[6] arm64-xgene1-linuxapp-gcc
[7] arm-armv7a-linuxapp-gcc
[8] i686-native-linuxapp-gcc
[9] i686-native-linuxapp-icc
[10] ppc_64-power8-linuxapp-gcc
[11] x86_64-native-bsdapp-clang
[12] x86_64-native-bsdapp-gcc
[13] x86_64-native-linuxapp-clang
[14] x86_64-native-linuxapp-gcc
[15] x86_64-native-linuxapp-icc
[16] x86_x32-native-linuxapp-gcc

----------------------------------------------------------
 Step 2: Setup linuxapp environment
----------------------------------------------------------
[17] Insert IGB UIO module
[18] Insert VFIO module
[19] Insert KNI module
[20] Setup hugepage mappings for non-NUMA systems
[21] Setup hugepage mappings for NUMA systems
[22] Display current Ethernet/Crypto device settings
[23] Bind Ethernet/Crypto device to IGB UIO module
[24] Bind Ethernet/Crypto device to VFIO module
[25] Setup VFIO permissions

----------------------------------------------------------
 Step 3: Run test application for linuxapp environment
----------------------------------------------------------
[26] Run test application ($RTE_TARGET/app/test)
[27] Run testpmd application in interactive mode ($RTE_TARGET/app/testpmd)

----------------------------------------------------------
 Step 4: Other tools
----------------------------------------------------------
[28] List hugepage info from /proc/meminfo

----------------------------------------------------------
 Step 5: Uninstall and system cleanup
----------------------------------------------------------
[29] Unbind devices from IGB UIO or VFIO driver
[30] Remove IGB UIO module
[31] Remove VFIO module
[32] Remove KNI module
[33] Remove hugepage mappings

[34] Exit Script
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

因为我是64位,所以先选择14。(Build)
在Step 1完成之后,选择17。Ubuntu 17.04似乎已经自带该驱动,所以直接OK。
然后选择20,设置hugepage,此处我设置的64,也见有人设置128,应该都可以。
继续选择22,查看当前设备,可以看到三块虚拟网卡的相关信息,其中0000:xx:xx.x 和 if=xxxx是我们待会要用到的东西。
网卡初始配置
可以从上图看到,三块虚拟网卡的状态都是active的,也是up的,我们要先去down掉他们,不然会报如下的错,

Enter PCI address of device to bind to IGB UIO driver: 02:06.0
Routing table indicates that interface 0000:02:06.0 is active. Not modifying
OK
  • 1
  • 2
  • 3
  • 4

down具体代码如下:

ifconfig xxx down
  • 1

注意:此处要down掉两个网卡,两个网卡!!!
接下来进行网卡bind,选择23,连续操作两次,bind刚刚down掉的两个网卡。然后可以自行查看一下当前网卡状态(Option:22

  1. 测试
    自动化脚本里面提供了两个选项,26和27
    但是我在测试26的时候报错:
Option: 26  


  Enter hex bitmask of cores to execute test app on
  Example: to execute app on cores 0 to 7, enter 0xff
bitmask: 0x3
Launching app
sudo: x86_64-native-linuxapp-gcc/app/test:找不到命令
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

查了资料说是以前留下的一个bug,网上都说明了,大家只要去./dpdk/lib/librte_eal/linuxapp/igb_uio下,打开igb_uio.c文件,找到if (pci_intx_mask_supported(udev->pdev)) 一句,改成如下所示即可。(即删掉if语句和dev_notice一段。)
注:由于版本不同可能变量名字不同,博主自己用的是dpdk-17.11的

这里写图片描述

不过改完之后,option 27可以运行,但似乎26依旧报同样的错误,暂时不知道为什么。

最后,测试27时同样有小问题,刚刚开始一个包都没有,查了资料说是网卡配置属性问题,要改为hostonly,但是我已经有了两个了呀,(= = 可能恰好这两个一个是NAT一个是hostonly吧,我脸黑已经是事实了)

希望自己能够尽快弄懂DPDK吧!

====2017.12.26更新====
昨天测试helloworld居然一直报这个错,说没有.config文件
config
我重新source,重新开一个终端也没用。。。。结果今天早上去目录下vi了一下.config文件,待会儿make就成功了。。玄学。。。

====2017.12.28更新====
之前测试helloworld,编译成功结果无法运行,如下所示:

yhz@ubuntu:~/cc/dpdk/examples/helloworld$ ./build/helloworld 
EAL: Detected 4 lcore(s)
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: Cannot obtain physical addresses: No such file or directory. Only vfio will function.
EAL: Failed to create shared memory!
EAL: FATAL: Cannot init memory

EAL: Cannot init memory

PANIC in main():
Cannot init EAL
5: [./build/helloworld(_start+0x2a) [0x5619f29c80fa]]
4: [/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1) [0x7f7f4d2233f1]]
3: [./build/helloworld(+0x5c02d) [0x5619f29c502d]]
2: [./build/helloworld(__rte_panic+0xc5) [0x5619f29bf921]]
1: [./build/helloworld(rte_dump_stack+0x2b) [0x5619f2a236cb]]
已放弃 (核心已转储)

里面的错怎么查也查不到,偶然发现大家似乎用的都是root在操作,然后我更改了一下,结果过了。。。。这是为啥啊。。。(不知道能不能自己解决掉哦。 = =)

自己仔仔细细看了Getting Started Guide for Linux之后,发现一段这样的话:
The instructions below will allow running DPDK as non-root with older Linux kernel versions. However, since version 4.0, the kernel does not allow unprivileged processes to read the physical address information from the pagemaps file, making it impossible for those processes to use HW devices which require physical addresses.

问题解决。

也算是正式开启了DPDK的大门 0.0

猜你喜欢

转载自blog.csdn.net/armlinuxww/article/details/88881568
今日推荐