DPDK helloworld 解析

embedded/2024/9/22 16:12:43/

1. 学习目的

        计划通过学习 DPDK 官方提供的 demo, 对 DPDK API 的使用有一些了解,helloworld 程序是其中最简单的程序,还是实际上手学习能更快一些。

2. 编译 helloworld 源码

环境变量设置:

  • export RTE_SDK=/home//dpdk/dpdk-stable-19.08.2/
  • export RTE_TARGET=x86_64-native-linux-gcc

源码路径:./dpdk 源码/examples/helloworld/

编译方法:在上面路径下执行 make

目标文件路径:./dpdk 源码/examples/helloworld/build/helloworld

./helloworld/helloword 
------------------------------------------------------------------------
EAL: Detected 8 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'PA'
EAL: Probing VFIO support...
EAL: VFIO support initialized
hello from core 1
hello from core 2
hello from core 3
hello from core 4
hello from core 5
hello from core 6
hello from core 7
hello from core 0

3. DPDK API 学习

通过上面结果可以看出,hello 被输出了 8 次,通过查看源码发现,每个 cpu 都注册了一个 lcore_hello 函数,

也就表明当前运行程序的设备 CPU 是 8 核心的。

源码核心 API 有两个: rte_eal_init() 、rte_eal_remote_launch()

3.1. rte_eal_init()

#include <rte_eal.h>
int rte_eal_init(int argc, char *argv[]);
//作用:用于初始化DPDK的环境。

3.2. rte_eal_remote_launch()

#include <rte_launch.h>
int rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned int slave_id);
//作用:DPDK中用于在远程核心上启动指定函数的函数。
//参数:
//f   : 函数指针
//arg : 函数的参数
//slave_id: 远程核心的编号

4. 源代码

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>#include <rte_memory.h>
#include <rte_launch.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_debug.h>static int lcore_hello(__attribute__((unused)) void *arg)
{unsigned lcore_id;lcore_id = rte_lcore_id();printf("hello from core %u\n", lcore_id);return 0;
}int main(int argc, char **argv)
{int ret;unsigned lcore_id;// EAL 环境初始化ret = rte_eal_init(argc, argv);if (ret < 0)rte_panic("Cannot init EAL\n");/* 把lcore_hello函数注册给每一个cpu core *//* RTE_LCORE_FOREACH_SLAVE 这个宏会变量所以的核心*/RTE_LCORE_FOREACH_SLAVE(lcore_id) {rte_eal_remote_launch(lcore_hello, NULL, lcore_id);}/* 主线程也调用一次lcore_hello */lcore_hello(NULL);rte_eal_mp_wait_lcore();return 0;
}

http://www.ppmy.cn/embedded/11714.html

相关文章

「Qt Widget中文示例指南」如何实现行编辑功能

Qt 是目前最先进、最完整的跨平台C开发工具。它不仅完全实现了一次编写&#xff0c;所有平台无差别运行&#xff0c;更提供了几乎所有开发过程中需要用到的工具。如今&#xff0c;Qt已被运用于超过70个行业、数千家企业&#xff0c;支持数百万设备及应用。 Line Edits&#xf…

外包干了6个月,技术退步明显.......

先说一下自己的情况&#xff0c;大专生&#xff0c;18年通过校招进入杭州某软件公司&#xff0c;干了接近4年的功能测试&#xff0c;今年年初&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落! 而我已经在一个企业干了四年的功能测…

vue 实现级联选择器功能

vue开发中&#xff0c;通过使用 Element UI 的 el-cascader 组件来实现级联选择器功能,下面是一个示例代码&#xff0c;演示如何使用 el-cascader 组件初始化级联选择器&#xff0c;并设置默认值为单位 测试1 和部门 测试11 <template><div><el-cascaderv-mode…

history命令

history 命令&#xff1a; history 命令用于显示当前用户在命令行中输入的历史命令列表。它会列出之前执行过的所有命令&#xff0c;每条命令都会有一个编号。这个命令不进行过滤或搜索&#xff0c;只是简单地列出了所有的命令历史记录。 history | grep “git”&#xff1a;…

Linux系统安全:从面临的攻击和风险到安全加固、安全维护策略(文末有福利)

1. Linux面临的攻击与风险 1.1. Linux系统架构 Linux系统架构解读&#xff1a; 用户之间隔离内核态与用户态之间隔离用户进程一般以低权限用户运行系统服务一般以特权服务运行用户态通过系统调用进入内核态内核对系统资源进行管理和分配 1.2. Linux系统常见安全威胁 1.2.1.…

Linux进程详解二:创建、状态、进程排队

文章目录 进程创建进程状态进程排队 进程创建 pid_t fork(void) 创建一个子进程成功将子进程的pid返回给父进程&#xff0c;0返回给新创建的子进程 fork之后有两个执行分支&#xff08;父和子&#xff09;&#xff0c;fork之后代码共享 bash -> 父 -> 子 创建一个进…

培养个人复原力

Building personal resilience 随着时间的推移&#xff0c;能够有效拥抱变化的人依靠的是他们的韧性。 这指的是一种面对挑战时的总体韧性和迅速恢复的能力。 好消息是&#xff0c;任何人只要愿意&#xff0c;都可以培养自己的韧性。 每天从选择从积极的角度看待所发生的一切开…

医院信息化运维的解决方案与对策

一、医院信息化的特点 医院信息化是指利用现代信息技术和管理技术&#xff0c;实现医院各项业务流程的数字化、网络化和智能化。其特点主要体现在以下几个方面&#xff1a; 数据量大且复杂&#xff1a;医院日常运营产生的数据量巨大&#xff0c;包括患者信息、诊疗记录、药品库…