欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

使用Linux用户态协议栈和DPDK打造高效应用的方法

最编程 2024-08-10 10:12:37
...

一、dpdk环境开启

这里使用了已经搭建好的dpdk环境,dpdk的搭建过程网上有很多教程可以参考,后面有空再做一篇dpdk环境搭建文章吧!
(1)检查网卡状态

ifconfig

ping一下网卡IP,确定网卡是可以连通的。
(2)查看是不是支持多队列网卡

cat /proc/interrupts | grep eth0

多队列网卡是支持多队列中断的;只支持一个中断是无法使用dpdk的。
(3)导出dpdk环境变量

cd dpdk路径
# 如dpdk/dpdk-stable-19.08.2/
#切换root权限
sudo su 
export RTE_SDK=dpdk路径
export RTE_TARGET=x86_64-native-linux-gcc

可以做成shell脚本。
(4)配置dpdk

./usertools/dpdk-setup.sh

依次执行:
43(加载DPDK UIO 模块,即插入driver)
44(加载VFIO模块,也是一种driver)
45(加载KNI模块,将一些数据写回内核)
46(设置巨页,可以不需要频繁页交换,512)
47(设置巨页,可512)
49(执行之前需要eth0 down掉,执行sudo ifconfig eth0 down,使绑定dpdk)pci地址=对应eth0的(如0000:03:00.0)
60(退出)

执行过程如下:

------------------------------------------------------------------------------
 RTE_SDK exported as /home/king/share/dpdk/dpdk-stable-19.08.2
------------------------------------------------------------------------------
----------------------------------------------------------
 Step 1: Select the DPDK environment to build
----------------------------------------------------------
[1] arm64-armada-linuxapp-gcc
[2] arm64-armada-linux-gcc
[3] arm64-armv8a-linuxapp-clang
[4] arm64-armv8a-linuxapp-gcc
[5] arm64-armv8a-linux-clang
[6] arm64-armv8a-linux-gcc
[7] arm64-bluefield-linuxapp-gcc
[8] arm64-bluefield-linux-gcc
[9] arm64-dpaa2-linuxapp-gcc
[10] arm64-dpaa2-linux-gcc
[11] arm64-dpaa-linuxapp-gcc
[12] arm64-dpaa-linux-gcc
[13] arm64-octeontx2-linuxapp-gcc
[14] arm64-octeontx2-linux-gcc
[15] arm64-stingray-linuxapp-gcc
[16] arm64-stingray-linux-gcc
[17] arm64-thunderx2-linuxapp-gcc
[18] arm64-thunderx2-linux-gcc
[19] arm64-thunderx-linuxapp-gcc
[20] arm64-thunderx-linux-gcc
[21] arm64-xgene1-linuxapp-gcc
[22] arm64-xgene1-linux-gcc
[23] arm-armv7a-linuxapp-gcc
[24] arm-armv7a-linux-gcc
[25] i686-native-linuxapp-gcc
[26] i686-native-linuxapp-icc
[27] i686-native-linux-gcc
[28] i686-native-linux-icc
[29] ppc_64-power8-linuxapp-gcc
[30] ppc_64-power8-linux-gcc
[31] x86_64-native-bsdapp-clang
[32] x86_64-native-bsdapp-gcc
[33] x86_64-native-freebsd-clang
[34] x86_64-native-freebsd-gcc
[35] x86_64-native-linuxapp-clang
[36] x86_64-native-linuxapp-gcc
[37] x86_64-native-linuxapp-icc
[38] x86_64-native-linux-clang
[39] x86_64-native-linux-gcc
[40] x86_64-native-linux-icc
[41] x86_x32-native-linuxapp-gcc
[42] x86_x32-native-linux-gcc

----------------------------------------------------------
 Step 2: Setup linux environment
----------------------------------------------------------
[43] Insert IGB UIO module
[44] Insert VFIO module
[45] Insert KNI module
[46] Setup hugepage mappings for non-NUMA systems
[47] Setup hugepage mappings for NUMA systems
[48] Display current Ethernet/Baseband/Crypto device settings
[49] Bind Ethernet/Baseband/Crypto device to IGB UIO module
[50] Bind Ethernet/Baseband/Crypto device to VFIO module
[51] Setup VFIO permissions

----------------------------------------------------------
 Step 3: Run test application for linux environment
----------------------------------------------------------
[52] Run test application ($RTE_TARGET/app/test)
[53] Run testpmd application in interactive mode ($RTE_TARGET/app/testpmd)

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

----------------------------------------------------------
 Step 5: Uninstall and system cleanup
----------------------------------------------------------
[55] Unbind devices from IGB UIO or VFIO driver
[56] Remove IGB UIO module
[57] Remove VFIO module
[58] Remove KNI module
[59] Remove hugepage mappings

[60] Exit Script

Option: 43

Unloading any existing DPDK UIO module
Loading uio module
Loading DPDK UIO module

Press enter to continue ...

......

Option: 44

Unloading any existing VFIO module
Loading VFIO module
chmod /dev/vfio
OK

Press enter to continue ...

......

Option: 45

Unloading any existing DPDK KNI module
Loading DPDK KNI module

Press enter to continue ...
......

Option: 46

Removing currently reserved hugepages
Unmounting /mnt/huge and removing directory

  Input the number of 1048576kB hugepages
  Example: to have 128MB of hugepages available in a 2MB huge page system,
  enter '64' to reserve 64 * 2MB pages
Number of pages: 512
Reserving hugepages
Creating /mnt/huge and mounting as hugetlbfs

Press enter to continue ...

......

Option: 47

Removing currently reserved hugepages
Unmounting /mnt/huge and removing directory

  Input the number of 1048576kB hugepages for each node
  Example: to have 128MB of hugepages available per node in a 2MB huge page system,
  enter '64' to reserve 64 * 2MB pages on each node
Number of pages for node0: 512
Reserving hugepages
Creating /mnt/huge and mounting as hugetlbfs

Press enter to continue ...
......

Option: 49


Network devices using kernel driver
===================================
0000:02:01.0 '82545EM Gigabit Ethernet Controller (Copper) 100f' if=eth2 drv=e1000 unused=igb_uio,vfio-pci *Active*
0000:02:06.0 '82545EM Gigabit Ethernet Controller (Copper) 100f' if=eth3 drv=e1000 unused=igb_uio,vfio-pci *Active*
0000:03:00.0 'VMXNET3 Ethernet Controller 07b0' if=eth0 drv=vmxnet3 unused=igb_uio,vfio-pci 
0000:0b:00.0 'VMXNET3 Ethernet Controller 07b0' if=eth1 drv=vmxnet3 unused=igb_uio,vfio-pci *Active*

No 'Baseband' devices detected
==============================

No 'Crypto' devices detected
============================

No 'Eventdev' devices detected
==============================

No 'Mempool' devices detected
=============================

No 'Compress' devices detected
==============================

No 'Misc (rawdev)' devices detected
===================================

Enter PCI address of device to bind to IGB UIO driver: 0000:03:00.0
OK

Press enter to continue ...

......

Option: 60

二、Windowe下配置静态IP表

需要管理员权限
(1)查看要加入的静态表接口

arp -a

示例结果如下,可以看到0x13这个位置,后面步骤用到。

接口: 192.168.2.130 --- 0x13
  Internet 地址         物理地址              类型
  192.168.0.20          00-17-16-07-b1-14     动态
  192.168.0.25          00-00-74-f8-0f-65     动态
  192.168.0.60          00-1e-67-6e-d4-c8     动态
  192.168.0.62          00-15-5d-00-29-01     动态
  192.168.0.80          00-00-5e-00-01-82     动态
  192.168.0.116         04-d4-c4-8f-03-d7     动态
  192.168.0.120         90-09-d0-0a-39-8b     动态
  192.168.0.128         18-c0-4d-5e-30-05     动态
  192.168.0.150         90-23-b4-b8-62-63     动态
  192.168.0.152         b8-cb-29-b1-82-5b     动态
  192.168.0.180         0c-c4-7a-79-21-8a     动态
  192.168.2.42          30-5a-3a-5a-63-cd     动态
  192.168.2.154         00-0e-c6-5c-39-34     动态
  192.168.2.227         18-c0-4d-de-e8-9d     动态
  192.168.3.111         30-b4-9e-76-e6-60     动态
  192.168.3.166         2c-56-dc-dc-d5-45     动态
  192.168.4.191         d8-5e-d3-20-7a-53     动态
  192.168.5.0           18-c0-4d-9b-65-fb     动态
  192.168.7.31          fc-aa-14-a2-e7-4a     动态
  192.168.7.98          18-c0-4d-de-dd-be     动态
  192.168.7.146         00-0c-29-39-a8-c4     动态
  192.168.7.234         18-c0-4d-cc-b7-da     动态
  192.168.7.248         d4-5d-64-d2-b7-23     动态
  192.168.7.253         50-81-40-f3-ed-90     动态
  192.168.8.1           70-8c-b6-ee-02-12     动态
  192.168.8.11          00-11-04-01-19-4d     动态
  192.168.8.17          00-11-04-01-01-c5     动态
  192.168.11.12         d4-5d-64-3c-5c-fa     动态
  192.168.11.21         e0-70-ea-f1-0b-77     动态
  192.168.11.45         0c-9d-92-85-52-d4     动态
  192.168.11.92         40-8d-5c-a8-08-00     动态
  192.168.11.95         04-42-1a-eb-b5-00     动态
  192.168.11.138        00-0e-c6-80-04-fa     动态
  192.168.11.202        98-29-a6-65-c9-2c     动态
  192.168.11.225        18-c0-4d-57-59-58     动态
  192.168.16.124        18-c0-4d-50-1e-da     动态
  192.168.17.140        d8-5e-d3-2a-56-78     动态
  192.168.17.174        70-5a-0f-4d-c7-e8     动态
  192.168.17.196        00-24-1d-9c-f2-15     动态
  192.168.17.199        38-d5-47-1c-5c-fb     动态
  192.168.20.188        e4-e7-49-ff-f0-9c     动态
  192.168.255.255       ff-ff-ff-ff-ff-ff     静态
  224.0.0.2             01-00-5e-00-00-02     静态
  224.0.0.22            01-00-5e-00-00-16     静态
  224.0.0.251           01-00-5e-00-00-fb     静态
  224.0.0.252           01-00-5e-00-00-fc     静态
  224.0.1.60            01-00-5e-00-01-3c     静态
  224.0.6.151           01-00-5e-00-06-97     静态
  224.100.100.100       01-00-5e-64-64-64     静态
  224.200.200.200       01-00-5e-48-c8-c8     静态
  229.111.112.12        01-00-5e-6f-70-0c     静态
  233.233.233.233       01-00-5e-69-e9-e9     静态
  234.200.200.200       01-00-5e-48-c8-c8     静态
  239.102.144.50        01-00-5e-66-90-32     静态
  239.192.152.143       01-00-5e-40-98-8f     静态
  239.193.3.64          01-00-5e-41-03-40     静态
  239.193.4.69          01-00-5e-41-04-45     静态
  239.193.5.133         01-00-5e-41-05-85     静态
  239.193.21.194        01-00-5e-41-15-c2     静态
  239.193.
																				
															

推荐阅读