编译环境
Centos 7.6
腾讯云服务器
2G 2核心
40G 硬盘
选择版本 DPDK 20.11
编译安装DPDK
- 从官网下载DPDK,解压。
- 使用 meson build 安装
第一个坑来了,DPDK20.11需要安装meson核ninja两个工具,这两个工具安装方式有两个,一个是编译安装,一个是使用python安装工具安装, 并且 DPDK20.11这个东西需要使用python 3.7及以上版本,需要解决的问题有:
- meson和 ninja的编译安装
- python3.8的安装,
- cmake的安装(系统默认的cmake版本低,ninja的安装需要用到更高的版本
- 安装re2c(cmake需要)
- 使用python -m pip install --user ninja 安装的ninja版本不对,需要手动编译安装,
注: 3-4 步骤在我第一次安装的时候发现使用步骤5 安装不上,后来偶然发现meson和ninja安装到了root/.local目录下面,用一个软连接链接过去就行了
ln -s /root/.local/meson /usr/bin/meson
ln -s /root/.local/meson /usr/bin/ninja
- 使用 "meson build"configure dpdk
- 使用 ninja && ninja install 安装dpdk
- 因为使用的是centos系统,隶属于红帽官方文档中给出:
On some linux distributions, such as Fedora or Redhat, paths in /usr/local are not in the default paths for the loader. Therefore, on these distributions, /usr/local/lib and /usr/local/lib64 should be added to a file in /etc/ld.so.conf.d/ before running ldconfig.
也就是说,需要在 /etc/ld.so.conf.d/ 目录下面将编译目录写到某个文件下面,这里没有指出需要写到什么页面当中去,随便创建了一个文件,dpdk-x86.64.conf 增加
/usr/local/lib /usr/local/lib64
执行命令
ldconfig
此时,到hello world 目录下面已经可以编译通过了
但是,到./example/helloworld/build目录下,执行hellowold的时候,会报错,找了一下原因说是需要配置一下环境变量
export PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig/"
刚刚在看官方文档的时候偶然间有看到
For correctly identifying and using any dependency packages, the
pkg-config
tool must also be configured to look in the appropriate directory for .pc files for 32-bit libraries. This is done by settingPKG_CONFIG_LIBDIR
to the appropriate path.
行吧是我眼大没看见。
关于pkd-config是什么需要关注一下这篇博文
这时候执行helloworld已经不报动态库的错误了,但是新的问题又来了
执行helloworld的时候,显示大页没有配置,那么好吧,参考官方文档配置大页
echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
Emmmmmm 这种方式只能临时用用,重启之后就没了
这里需要声明,之前官方文档中给出了条件需要linux版本和内核版本一致,我的虚拟机与内核版本是一致的,做了检查,没做记录。
现在 hello world终于能跑起来了
下面尝试跑l2fwd
命令行函数由两部分构成:EAL参数和应用程序参数分别由rte_eal_init函数和l2fwd_parse_args函数来解析
-p会对l2fwd_enabled_port_mask变量赋值,这个值表示的就是端口掩码,也就是一个比特位表示一个端口,如果这个端口开启,就把对应的比特位置1,-q会对l2fwd_rx_queue_per_lcore变量赋值,表示的是每个逻辑核处理多少个端口。-T会对timer_period变量赋值,也就是打印端口数据的周期
首先需要绑定网卡,dpdk官方给了一个官方的工具,可以直接绑定网卡,在./usertools目录下面dpdk-devbind.py
需要绑定网卡的时候需要使用modprobe自动加载一些模块
sudo modprobe uio_pci_generic
在centos系统中 并不支持其他两种模式
python3 dpdk-devbind.py -b uio_pci_generic eth1
python3 dpdk-devbind.py -b uio_pci_generic eth2
查看了一下脚本,总共支持三种模式
# global dict ethernet devices present. Dictionary indexed by PCI address.
# Each device within this is itself a dictionary of device properties
devices = {}
# list of supported DPDK drivers
dpdk_drivers = ["igb_uio", "vfio-pci", "uio_pci_generic"]
好吧我整了一天,l2fwd, 发现数据一直是在跑的,但是收发数据量都是0 不知道是为什么,日志一直在刷新(先不看这一块内容了,考虑一下如何实现收发包,认真看看官方文档吧)