• DPDK编译与演示


    环境

    虚拟机系统: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
    

    参考:

    1. 官方文档:https://dpdk-docs.readthedocs.io/en/latest/linux_gsg/intro.html
    2. 官方文档:https://core.dpdk.org/doc/
    3. meson编译:https://www.yuque.com/zzqcn/opensource/ik2tg2
    4. docker编译dpdk: https://www.cnblogs.com/yanhai307/p/10880089.html
  • 相关阅读:
    内置函数大总结
    关于 global nonlocal 用法
    Python 基础数据类型相互转换
    Python 嵌套
    Python 基础关于编码
    「总结」 字符串总结
    「总结」 MLEAutoMaton的各种板子总结
    【洛谷4770】 [NOI2018]你的名字(SAM,线段树合并)
    【洛谷4070】 [SDOI2016]生成魔咒(SAM)
    【SP1811】 LCS
  • 原文地址:https://www.cnblogs.com/abc36725612/p/14341663.html
Copyright © 2020-2023  润新知