環境
虛擬機系統:ubuntu:1404
安裝dpdk
參考:https://www.cnblogs.com/yanhai307/p/10598138.html
先從官網(www.dpdk.org)下載安裝包,解壓到/opt目錄
/opt# tar -xvf dpdk-18.11.11.tar.xz
/opt# ls
dpdk-18.11.11.tar.xz dpdk-stable-18.11.11
安裝依賴
# apt install libnuma-dev
# apt-get install libpcap-dev
# apt-get install pkg-config
環境配置
/opt/dpdk-stable-18.11.11# export RTE_SDK=/opt/dpdk-stable-18.11.11
/opt/dpdk-stable-18.11.11# export RTE_TARGET=x86_64-native-linuxapp-gcc
/opt/dpdk-stable-18.11.11# sed -ri 's,(PMD_PCAP=).*,\1y,' config/common_base
/opt/dpdk-stable-18.11.11# make config T=$RTE_TARGET
Configuration done using x86_64-native-linuxapp-gcc
編譯
/opt/dpdk-stable-18.11.11# export DESTDIR=/usr/local
/opt/dpdk-stable-18.11.11# make -j 10 install T=$RTE_TARGET
編譯成功
Build complete [x86_64-native-linuxapp-gcc]
================== Installing /usr/local/
Installation in /usr/local/ complete
遇到過的問題
/home/code/dpdk-stable-16.11.11/mk/rte.subdir.mk:61: recipe for target 'linuxapp' failed
make[5]: *** [linuxapp] Error 2
/home/code/dpdk-stable-16.11.11/mk/rte.subdir.mk:61: recipe for target 'librte_eal' failed
make[4]: *** [librte_eal] Error 2
/home/code/dpdk-stable-16.11.11/mk/rte.sdkbuild.mk:78: recipe for target 'lib' failed
make[3]: *** [lib] Error 2
/home/code/dpdk-stable-16.11.11/mk/rte.sdkroot.mk:126: recipe for target 'all' failed
make[2]: *** [all] Error 2
/home/code/dpdk-stable-16.11.11/mk/rte.sdkinstall.mk:85: recipe for target 'pre_install' failed
make[1]: *** [pre_install] Error 2
/home/code/dpdk-stable-16.11.11/mk/rte.sdkroot.mk:101: recipe for target 'install' failed
make: *** [install] Error 2
root@2543f489a7d0:/home/code/dpdk-stable-16.11.11# apt-get install linuxapp
解決辦法:在VM編譯沒遇到
/opt/dpdk-stable-18.11.11/drivers/net/pcap/rte_eth_pcap.c:19:18: fatal error: pcap.h: No such file or directory
#include <pcap.h>
^
compilation terminated.
CC nfp_nsp_eth.o
make[6]: *** [rte_eth_pcap.o] Error 1
make[5]: *** [pcap] Error 2
make[5]: *** Waiting for unfinished jobs....
解決辦法1: apt-get install libpcap-dev
解決辦法2:libpcap 網絡數據包捕獲函數庫安裝
下載:http://www.tcpdump.org 找到libpcap並下載
# tar zxvf libpcap
# sudo apt-get install build-essential
# sudo apt-get install m4
# sudo apt-get install flex
# sudo apt-get install bison
# ./configure
# make
# sudo make install
dpdk使用
視頻教程:https://www.bilibili.com/video/BV1HU4y147Hk?t=372
dpdk的設置命令
dpdk-stable-18.11.11# ./usertools/dpdk-setup.sh
設置hugepage
cpu從內存中是以4k為單位拿取。設置了hugepage后則預先拿一整塊內存如:1G,減少了內存交換次數從而提高運行效率。
設置dpdk hugepage
dpdk-stable-18.11.11# ./usertools/dpdk-setup.sh
-----------------
RTE_SDK exported as /opt/dpdk-stable-18.11.11
[21] Setup hugepage mappings for non-NUMA systems
[22] Setup hugepage mappings for NUMA systems <<< NUMA: 統一內存塊
Option: 21 <<< 選項
Removing currently reserved hugepages
Unmounting /mnt/huge and removing directory
Input the number of 2048kB hugepages
Example: to have 128MB of hugepages available in a 2MB huge page system,
enter '64' to reserve 64 * 2MB pages <<< 2M一個頁單位
Number of pages: 64 <<< 配置hugepage
Reserving hugepages
Creating /mnt/huge and mounting as hugetlbfs
helloworld演示
編譯helloworld示例
# cd /opt/dpdk-stable-18.11.11/examples/helloworld
helloworld# export RTE_SDK=/opt/dpdk-stable-18.11.11
helloworld# make
或
# cd /opt/dpdk-stable-18.11.11/examples/helloworld
helloworld# gcc -o helloworld main.c -I /usr/local/include/dpdk/ -ldpdk -lnuma -lpthread -ldl
helloworld# ls
helloworld main.c Makefile meson.build
運行
helloworld# ./build/helloworld
EAL: Detected 2 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
EAL: PCI device 0000:03:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15ad:7b0 net_vmxnet3
hello from core 1
hello from core 0
遇到問題
helloworld# ./build/helloworld
EAL: Detected 2 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-2048kB
EAL: FATAL: Cannot get hugepage information.
EAL: Cannot get hugepage information.
PANIC in main():
Cannot init EAL
5: [./build/helloworld() [0x47e5af]]
4: [/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f586fcc5f45]]
3: [./build/helloworld() [0x473551]]
2: [./build/helloworld(__rte_panic+0xb8) [0x46001f]]
1: [./build/helloworld(rte_dump_stack+0x1a) [0x65308a]]
Aborted (core dumped)
解決:需要設置hugepage
timer演示
# cd /opt/dpdk-stable-18.11.11/examples/timer
timer# make
CC main.o
LD timer
INSTALL-APP timer
INSTALL-MAP timer.map
timer# ./build/timer
EAL: Detected 2 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Probing VFIO support...
EAL: PCI device 0000:03:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15ad:7b0 net_vmxnet3
Starting mainloop on core 1
Starting mainloop on core 0
timer1_cb() on lcore 1
timer1_cb() on lcore 0
timer0_cb() on lcore 0
timer1_cb() on lcore 1
參考: