在 Ubuntu 系统上的环境配置方法。
安装
sudo apt install python3-pip libnuma-dev python3-pyelftools
sudo pip3 install meson ninja
# 可更换版本
wget https://fast.dpdk.org/rel/dpdk-21.11.1.tar.xz
tar xf dpdk-21.11.1.tar.xz
cd dpdk-stable-21.11.1
mkdir build
meson -Denable_kmods=true build
ninja -C build
cd build
sudo ninja install
大页内存配置
编辑 /etc/grub2.cfg
(视具体情况而定):
hpet=enable default_hugepagesz=1G hugepagesz=1G hugepages=4
验证成功:
cat /proc/meminfo | grep 'Huge'
运行
需要 root 权限。
mkdir -p /dev/hugepages
mountpoint -q /dev/hugepages || mount -t hugetlbfs nodev /dev/hugepages
# 预留大页内存
echo 2 > /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
echo 2 > /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
modprobe e1000 vfio vfio-pci
chmod 600 /sys/bus/pci/drivers/e1000/bind
chmod 600 /sys/bus/pci/drivers/e1000/unbind
chmod 600 /sys/bus/pci/drivers/vfio-pci/bind
chmod 600 /sys/bus/pci/drivers/vfio-pci/unbind
PCI_NUM=$(lspci | grep -i 'eth' | sed -r 's/\s.*//g' | tr -s '\n' ' ')
# `usertools` 目录位于 DPDK 项目中
# 将网卡与 vfio 驱动绑定
${RTE_SDK}/usertools/dpdk-devbind.py -b=vfio-pci $PCI_NUM
结束后可以绑回网卡原来的驱动:
${RTE_SDK}/usertools/dpdk-devbind.py -b=e1000 $PCI_NUM