一台服务器运行多个DPDK程序

本文档详细介绍了如何在一台Linux服务器上同时运行多个DPDK程序,包括l3fwd和pktgen。步骤涉及查看网卡、CPU信息,规划资源分配,以及启动多个DPDK程序的命令行参数说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一台服务器运行多个DPDK程序

一台电脑运行多个DPDK程序(同时两个l3fwd+同时跑两个pktgen) 此博文包含图片 (2016-10-02 00:03:43)转载▼
标签: 多个 dpdk l3fwd --proc-typeauto 同时运行 分类: DPDK
作者:温兴泵,原文地址:http://blog.sina.com.cn/s/blog_90cfda2f0102x58j.html
版权所有,转载请注明以上信息,谢谢合作~

如何在一台电脑上同时运行多个DPDK程序呢?如果在你启动一个程序后,再启动第二个程序是会报错的!那么如何实现呢,本教程叫你如何实现一个电脑同时跑四个DPDK程序,两个l3fwd+两个pktgen~

所用的版本为DPDK16.04,pktgen2.9.17
(安装教程见我的之前一个博文:http://blog.sina.com.cn/s/blog_90cfda2f0102ws79.html)

step1:查看电脑的网卡

root@dpdk3-Super-Server:/home/dpdk3/wenxingbeng/dpdk-16.04# lspci | grep Ethernet
02:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
02:00.1 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
03:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
03:00.1 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)

06:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)
07:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)

其中黑色斜体部分是我教程中使用的四个DPDK绑定的网卡~

step2:查看电脑的CPU

root@dpdk3-Super-Server:/home/dpdk3/wenxingbeng/dpdk-16.04# ./tools/cpu_layout.py

Core and Socket Information (as reported by ‘/proc/cpuinfo’)

cores = [0, 1, 2, 3, 4, 5, 6, 7]
sockets = [0]

Socket 0
--------
Core 0 [0]
Core 1 [1]
Core 2 [2]
Core 3 [3]
Core 4 [4]
Core 5 [5]
Core 6 [6]
Core 7 [7]

可以看出电脑有一个Socket,没有开超线程,一个Socket有8个核~

step3:规划端口和核给l3fwd和pktgen在这里插入图片描述
step4:启动多个DPDK程序

【特别提醒:命令行第二行起,最好前面加一个多余的空格】

  • [1]第一个l3fwd
    ./build/l3fwd -c 0x3 -n 2 –proc-type auto \
    –socket-mem 512 --file-prefix pg1 \
    -w 02:00.0 \

    – -p 0x1 --config="(0,0,1)"

  • [2]第二个l3fwd
    ./build/l3fwd -c 0xC -n 2 --proc-type auto
    –socket-mem 512 --file-prefix pg2 \
    -w 02:00.1\

    – -p 0x1 --config="(0,0,3)"

  • [3]第一个pktgen
    ./app/app/x86_64-native-linuxapp-gcc/pktgen -c 0x30 -n 3 --proc-type auto
    –socket-mem 512 --file-prefix pg3 \
    -w 03:00.0\


    -T -P -m “5.0”
    -f themes/black-yellow.theme

  • [4]第二个pktgen
    ./app/app/x86_64-native-linuxapp-gcc/pktgen -c 0xC0 -n 3 --proc-type auto
    –socket-mem 512 --file-prefix pg4 \
    -w 03:00.1\


    -T -P -m “7.0”
    -f themes/black-yellow.theme

step5:在多个窗口中输入命令即可,界面如下一台电脑运行多个DPDK程序(同时两个l3fwd+同时跑两个pktgen)

在这里插入图片描述

EAL的启动命令可以在下面查到:
EAL common options:
  • -c COREMASK Hexadecimal bitmask of cores to run on
  • -l CORELIST List of cores to run on
    The argument format is [-c2][,c3[-c4],…]
    where c1, c2, etc are core indexes between 0 and 128
  • –lcores COREMAP Map lcore set to physical cpu set
    The argument format is
    ‘[<,lcores[@cpus]>…]’
    lcores and cpus list are grouped by ‘(’ and ‘)’
    Within the group, ‘-’ is used for range separator,
    ‘,’ is used for single number separator.
    ‘( )’ can be omitted for single element group,
    ‘@’ can be omitted if cpus and lcores have the same value
  • –master-lcore ID Core ID that is used as master
  • -n CHANNELS Number of memory channels
  • -m MB Memory to allocate (see also --socket-mem)
  • -r RANKS Force number of memory ranks (don’t detect)
  • -b, --pci-blacklist Add a PCI device in black list.
    Prevent EAL from using this PCI device. The argument
    format is .

-w, --pci-whitelist Add a PCI device in white list.
Only use the specified PCI devices. The argument format
is <[domain:]bus:devid.func>. This option can be present
several times (once per device).
[NOTE: PCI whitelist cannot be used with -b option]
例如使用两个网口,用逗号隔开,-w pci1 -w pci2

  • –vdev Add a virtual device.
    The argument format is [,key=val,…]
    (ex: --vdev=eth_pcap0,iface=eth2).
  • -d LIB.so|DIR Add a driver or driver directory
    (can be used multiple times)
  • –vmware-tsc-map Use VMware TSC map instead of native RDTSC

–proc-type Type of this process (primary|secondary|auto)

  • –syslog Set syslog facility
  • –log-level Set default log level
  • -v Display version information on startup
  • -h, --help This help
EAL options for DEBUG use only:
  • –huge-unlink Unlink hugepage files after init
  • –no-huge Use malloc instead of hugetlbfs
  • –no-pci Disable PCI
  • –no-hpet Disable HPET
  • –no-shconf No shared config (mmap’d files)
EAL Linux options:

–socket-mem Memory to allocate on sockets (comma separated
values) 例如:双numa节点的,需要给每个socket配置大页内存并用逗号隔开,–socket-mem=512,512

  • –huge-dir Directory where hugetlbfs is mounted

–file-prefix Prefix for hugepage filenames

  • –base-virtaddr Base virtual address
  • –create-uio-dev Create /dev/uioX (usually done by hotplug)
  • –vfio-intr Interrupt mode for VFIO (legacy|msi|msix)
  • –xen-dom0 Support running on Xen dom0 without hugetlbfs
使用DPDK开发一个简单的收发程序涉及以下几个步骤: 1. **环境准备**: - 安装DPDK:首先,你需要下载并安装DPDK的最新版本,配置环境变量以便编译器能找到库文件。 - 创建工程:使用DPDK提供的EAL (Early Access Layer) 构建一个基础项目结构。 2. **网络设备绑定**: - EAL初始化时,选择要使用的网卡,并将它们分配给应用程序的内存池。 3. **数据缓冲区管理**: - 分配和管理由DPDK管理的RX/TX数据包缓冲区,用于接收和发送数据。 4. **网络协议头部解析/构造**: - 如果是自定义协议,可能需要解析或构造网络包头,如UDP/IP。 5. **主循环**: - 在一个无限循环中,从RX队列读取数据包,处理数据(比如解密、计算等),然后将其放入TX队列发送出去。 6. **事件驱动**: - 利用DPDK的异步模型,当数据准备好时,回调函数会被自动调用,而不是阻塞整个进程。 7. **错误处理**: - 添加适当的错误检查和处理机制,例如网络连接中断或数据包校验失败。 8. **示例代码**: - 可能会涉及到` rte_eth_dev` API(用于网络设备操作)、` rte_mempool`(内存池管理)和` rte_ring`(数据通道)等功能的使用。 ```c #include <rte_mempool.h> #include <rte_event.h> void packet_recv(void *arg); void packet_send(void *arg); // 主函数 int main(int argc, char **argv) { // 初始化... rte_event_init(); // 网络设备操作... // 创建接收和发送事件 rte_event_dev_request_event(packet_recv, ...); rte_event_dev_request_event(packet_send, ...); // 永久循环,等待事件触发 while (true) { rte_event_service(); } return 0; } // 数据包接收处理函数 void packet_recv(void *arg) { // 从RX队列读取数据包,处理并添加到TX队列 // ... } // 数据包发送处理函数 void packet_send(void *arg) { // 从用户数据构建数据包,放入TX队列 // ... } ``` 记得始终遵循DPDK的最佳实践,比如限制内核模式下的上下文切换,以充分利用硬件加速。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值