Linux C/C++ 学习日记(41):dpdk(四):基于dpdk编写的第一个程序
注:该文用于个人学习记录和知识交流,如有不足,欢迎指点。
编写一个程序检测dpdk能否正常使用
一、导入Makefile
在package 创建一个ustack目录
cd ustack
创建一个ustack.c文件
然后cp ../dpdk-stable-19.08.2/examples/helloworld/Makefile
二、修改Makefile
sudo vim Makefile
看到

改为:

表示:编译的文件未ustack.c,生成的可执行文件为ustack
三、编写ustack.c的代码
#include <stdio.h>
#include <rte_eal.h>
#include <rte_ethdev.h>int main(int argc, char *argv[])
{// 初始化dpdkif (rte_eal_init(argc, argv) < 0){rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");}// 查看绑定的网卡数目int16_t nb_sys_ports = rte_eth_dev_count_avail();if (nb_sys_ports <= 0){rte_exit(EXIT_FAILURE, "No available eth dev\n");}printf("number of available eth dev: %d\n", nb_sys_ports);printf("hello, dpdk\n");return 0;
}四、编译,执行
su root
make
./build/ustack

至此:dpdk成功初始化,而且绑定的多队列网卡个数为1
