最新内容:
各位centos用户在安装DPDK时,完全可以使用yum安装dpdk,本身的yum源已经支持到DPDK18.11了,完全够用。新版本可以使用scl源或者其他三方源直接yum一键安装。
$ yum info dpdk
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Available Packages
Name : dpdk
Arch : x86_64
Version : 18.11.8
Release : 1.el7_8
Size : 1.7 M
Repo : extras/7/x86_64
Summary : Set of libraries and drivers for fast packet processing
URL : http://dpdk.org
License : BSD and LGPLv2 and GPLv2
Description : The Data Plane Development Kit is a set of libraries and drivers for
: fast packet processing in the user space.
一、虚拟机设置多队列网卡(接收队列rxq 发送队列txq)
找到虚拟机所在文件夹目录,找到虚拟机的vmx文件,将网卡类型:
ethernet序号.virtualDev = "e1000"
修改为:
ethernet序号.virtualDev = "vmxnet3"
- 检查是否已经支持多队列网卡
cat /proc/interrupts | grep ens # 第二列至第五列都是CPU核心
二、检查系统环境是否满足要求
- 检查内核版本需大于2.6.33
uname -r
- 检查glibc的版本需大于2.7
ldd --version
三、开始编译dpdk
- 下载源码 http://core.dpdk.org/download/
最新版本的 DPDK (20.11) 不再支持以 make 的方式构建,而是改用 meson 与 ninja 这两个工具。
- meson和ninja工具的安装
# 先安装python3及pip工具
sudo yum install python3
sudo yum -y install epel-release
sudo yum install python-pip
sudo pip install --upgrade pip
# 安装meson的依赖包emacs-filesystem
sudo yum install emacs-filesystem -y
# 安装ninja的依赖包vim-filesystem
sudo yum install vim-filesystem -y
# 下载安装meson的依赖包ninja rpm包
https://cbs.centos.org/koji/buildinfo?buildID=24453
sudo rpm -ivh ninja-build-xxx.rpm
# 安装meson rpm包
https://cbs.centos.org/koji/buildinfo?buildID=27917
sudo rpm rpm -ivh meson-xxx.rpm
# 也可用pip安装ninja
sudo pip3 install ninja
- 编译测试
tar -xvf dpkg-xx
cd dpdk-stable-20.11.3
meson -Dexamples=all build
cd build
sudo ninja-build install # 此处ninja-build也可以是ninja
设置巨页
内存页面大小默认是4K,x86还可以设置为2M和1G,可以根据内存大小对巨页设置,巨页所占内存一定小于内存总量,不然不一定能开机而且其他程序没法跑
# 首先安装libhugetlbfs库
sudo yum install libhugetlbfs
# 设置hugepages
vim /etc/default/grub
# 在GRUB_CMDLINE_LINUX属性值最后追加巨页设置
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap =cl/root =cl/swap rhgb quiet transparent_hugepage=never default_hugepagesz=2M hugepagesz=2M hugepages=1024 "
# 追加的内容有:每页大小为1G,一共设置1页面,即1GB,根据内存大小设置
transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G hugepages=1
# 重新生成 grub.cfg
grub2-mkconfig -o /boot/grub2/grub.cfg
# 重启查看是否设置好巨页
cat /proc/meminfo |grep -i HugePages
[chuancey@localhost ~]$ cat /proc/meminfo | grep -i HugePages
AnonHugePages: 0 kB
HugePages_Total: 1
HugePages_Free: 1
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 1048576 kB
加载VFIO驱动
- 首先设置VT-d
dpdk的驱动有VFIO和UIO,VFIO比UIO好用。需要开启vt-d
# 开启VT-d后 检查是否设置成功
dmesg | grep -e DMAR -e IOMMU
# [5.265000] DMAR-IR: IOAPIC id 128 under DRHD base 0xfec10000 IOMMU 0
- 让内核支持VT-d
# 先检查现在是否已经支持
cat /proc/cmdline | grep iommu=pt
cat /proc/cmdline | grep intel_iommu=on
# 没有输出则需要修改grub
vim /etc/default/grub
# 在GRUB_CMDLINE_LINUX= 的值中添加 iommu=pt intel_iommu=on
grub_cmdline_linux="crashkernel=auto =centos/root =centos/swap rhgb quiet iommu=pt intel_iommu=on transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G hugepages=1"
# 更新配置和重启
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot
# 重新验证一次
cat /proc/cmdline | grep intel_iommu=on
cat /proc/cmdline | grep iommu=pt
- 加载VFIO驱动
# 加载驱动
modprobe vfio-pci enable_sriov=1
# 绑定网卡 ens192网卡不是供ssh连接网卡,专供dpdk通信的网卡
sudo ifconfig ens192 down
sudo usertools/dpdk-devbind.py --bind=vfio-pci ens192
# 查看绑定状态
sudo usertools/dpdk-devbind.py --status
- 修改权限供非root用户使用vfio
chmod +x /dev/vfio
chmod 0666 /dev/vfio/*
- 运行hello-world测试程序
# 以管理员身份运行
sudo build/examples/dpdk-helloworld -l 1-3 -n 3
# 输出如下
EAL: Detected 4 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Detected static linkage of DPDK
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'VA'
EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: using IOMMU type 1 (Type 1)
EAL: Ignore mapping IO port bar(3)
EAL: Probe PCI driver: net_vmxnet3 (15ad:7b0) device: 0000:0b:00.0 (socket 0)
EAL: No legacy callbacks, legacy socket not created
hello from core 2
hello from core 3
hello from core 1