1 Principle of DPDK
1.1 Principles of Traditional Network Data
When the Linux network protocol stack processes data packets, it needs to go through two steps: first, copy the data from the physical network card to the kernel protocol stack; second, copy the data from the kernel space to the user space. The network data packet reaches the user space after two copies, because the copy will cause system interruption and lead to performance bottlenecks.
1.2 DPDK data processing principle
DPDK is a data plane acceleration theoretical framework (Intel Data Plane Development kit) proposed by Intel for the application scenarios of rapid development of chip technology and high-speed network interface technology. DPDK aims at high-speed processing of network data. One of the important technologies is zero-copy technology, which directly maps network data to memory space. At the same time, DPDK can skip the kernel space and directly obtain network card data to user space for network data operations, greatly speeding up network data processing. The figure below also defines the scope of DPDK. It is mainly between the physical network card and the kernel space. DPDK can directly obtain network card data and process it in user space. At the same time, it can flexibly write network data back to the kernel to follow the original kernel processing process.
2 DPDK Technology
2.1 hugepage
The main advantage of the huge page technology is to increase the data volume of a single page. It is mainly used in application scenarios that require large memory to reduce page switching and improve query efficiency. High-speed network data storage scenarios require a large data cache, so large page technology can greatly improve its efficiency.
2.2 User I/O (UIO)
The network card data is directly transferred to the user space to run, and the application program and the device are decoupled. This technology is the cornerstone of DPDK. LinuxUIO technology can directly transfer network card data to user space for network data processing. In the DPDK application initialization, the network card hardware registers are mapped to the user-mode memory space. Therefore, the DPDK driver can run in the user-mode, which can avoid unnecessary memory copies.
2.3 KNI technology
KNI is also a driver module, which is used to establish a channel between DPDK and the system kernel protocol stack, and users can feed back network data to the kernel protocol stack for processing.
2.4 CPU affinity
CPU affinity is mainly to bind a process to a CPU one-to-one. Multi-core CPU devices are used for system scheduling causing processes to be scheduled across CPUs. CPU affinity avoids this kind of CPU switching to fully put back the multi-core performance.
3 DPDK environment construction
3.1 Add network card
Add a virtual network card, here a NAT network card and a bridge network card are added.
Use the command line to check whether the network card is added successfully:
-a is needed here mainly because dhcp has not been configured and has not started.
ifconfig -a
Network configuration:
add eth1 and eth2 network cards here;
vi /etc/network/interfaces
auto eth1
iface eth1 inet dhcp
auto eth2
iface eth2 inet dhcp
Restart the network, you can see the new network card and ip address.
/etc/init.d/networking restart
3.2 Modify network card configuration
Mainly modify the name of the network card as a multi-queue network card: edit the Ubuntu16.04.vmx file in the root directory of the virtual machine Ubuntu
and change ethernet2.virtualDev from e1000 to vmxnet3
3.3 Modify the huge page size
Added huge page size, which is mainly used for the use of huge pages in dpdk.
vi /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 default_hugepages=1G hugepagesz=2M hugepages=1024 isolcpus=0-2"
Effective:
sudo update-grub
Check whether multi-queue network cards are supported, mainly for subsequent affinity development:
cat /proc/interrupts
3.3 DPDK download
Download dpdk source code: https://core.dpdk.org/download/
wget https://fast.dpdk.org/rel/dpdk-19.08.2.tar.xz
tar -xvf dpdk-19.08.2.tar.xz
chmod 777 -R ./dpdk-stable-19.08.2/
cd dpdk-stable-19.08.2/
3.4 Running DPDK
Use dpdk-setup.sh to configure the dpdk environment
./usertools/dpdk-setup.sh
#先选39选择编译器,然后开始编译
39
#再选43
#
Generate a x86_64-native-linux-gcc folder:
set environment variables:
export RTE_SDK=/home/disk/dpdk-stable-19.08.2
export RTE_TARGET=x86_64-native-linux-gcc
Set up the dpdk environment:
#43 Insert IGB UIO module,加入IGB_UIO
#45 插入kni
#46 设置巨页512
#49 绑定UIO网卡
#
Note that the network card needs to be turned off before executing 49:
ifconfig eth0 down
Execute the test program:
select 53 test program.
show port info 0
So far, the DPDK environment has been successfully installed, and related development can be carried out next.